/* GestCar 1.4.11 — styles (CSS natif) */
:root {
  --green: #1f4d3a;
  --green-2: #2d6a50;
  --green-soft: #e3f0e8;
  --bg: #f3f5f2;
  --panel: #ffffff;
  --text: #1b2a22;
  --muted: #5f6f66;
  --line: #dde4df;
  --danger: #b3261e;
  --danger-soft: #fbe4e2;
  --warn: #9a6500;
  --warn-soft: #fff3cd;
  --blue: #2f5f8f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 2px 10px rgba(0, 0, 0, .04);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; color: var(--green); }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.print-only { display: none; }

/* ---------- Boutons et champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: .55em 1em; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none;
  min-height: 38px;
}
.btn:hover { border-color: var(--green-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.danger { color: var(--danger); border-color: #e7b9b5; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: rgba(255, 255, 255, .35); color: inherit; }
.btn.small { padding: .3em .7em; min-height: 32px; font-size: .88em; }
.btn.block { display: flex; width: 100%; margin-bottom: .5em; }
.link { background: none; border: 0; padding: 0; color: var(--blue); text-decoration: underline; cursor: pointer; font: inherit; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
  font-size: 1.1rem; line-height: 1; cursor: pointer; color: var(--text);
}
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #c7d0ca; border-radius: 8px; padding: .5em .6em; min-height: 38px; width: 100%;
}
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--green); flex: none; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--green-2); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .8em; }
label > input, label > select, label > textarea, label > .with-unit { margin-top: .3em; font-weight: 400; }
label.check { display: flex; align-items: center; gap: .5em; font-weight: 400; }
.with-unit { display: flex; align-items: center; gap: .5em; }
.with-unit span { color: var(--muted); font-weight: 400; white-space: nowrap; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .6em .8em; margin: 0 0 .8em; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .3em; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: .5em .7em; border-radius: 8px; }
.warning { color: var(--warn); background: var(--warn-soft); padding: .5em .7em; border-radius: 8px; }
.warning-text { color: var(--warn); font-weight: 600; }

/* ---------- Connexion ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--green) 0%, #16362a 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; padding: 28px 24px; border-radius: 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.brand { display: flex; align-items: center; gap: .6em; font-weight: 700; font-size: 1.25rem; }
.brand-login { color: var(--green); font-size: 1.5rem; margin-bottom: .3em; }

/* ---------- Structure ---------- */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--green); color: #fff; padding: 18px 12px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  text-align: left; background: none; border: 0; color: rgba(255, 255, 255, .85); padding: .65em .8em;
  border-radius: 8px; font: inherit; cursor: pointer;
}
.nav button:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav button.active { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: .9rem; }
.sidebar-footer .muted { color: rgba(255, 255, 255, .7); }
.main { min-width: 0; padding: 0 24px 40px; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 0; position: sticky; top: 0;
  background: var(--bg); z-index: 5; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.topbar h1 { margin: 0; flex: 1; }
.topbar-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.vehicle-picker { margin: 0; }
.vehicle-picker select { margin: 0; min-width: 180px; font-weight: 600; }
.menu-btn { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 19; }
.sync-pill { font-size: .8rem; padding: .3em .7em; border-radius: 999px; background: var(--green-soft); color: var(--green); white-space: nowrap; }
.sync-pill.syncing { background: #e6eef7; color: var(--blue); }
.sync-pill.offline { background: #eceff1; color: #455a64; }
.sync-pill.error { background: var(--danger-soft); color: var(--danger); }
.notice { padding: .7em 1em; border-radius: 8px; margin-bottom: 14px; background: #e6eef7; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warning { background: var(--warn-soft); color: var(--warn); }

.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar.wrap { flex-wrap: wrap; margin-top: 12px; }
.toolbar label.check { margin: 0 0 0 8px; }
.toolbar select { width: auto; max-width: 100%; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- Cartes ---------- */
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border-top: 3px solid var(--green); }
.card-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.card-value { font-size: 1.4rem; font-weight: 700; margin: .2em 0; }
.card-sub { font-size: .85rem; color: var(--muted); }
.card.high { border-top-color: var(--danger); }
.card.low { border-top-color: var(--blue); }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .15em .55em; border-radius: 999px; vertical-align: middle; background: var(--green-soft); color: var(--green); }
.badge.alert { background: var(--warn-soft); color: var(--warn); }
.badge.overdue { background: var(--danger-soft); color: var(--danger); }
.badge.unknown { background: #eceff1; color: #455a64; }
.badge.curative { background: #efe7f6; color: #5b3a80; }
.tag { font-size: .72rem; font-weight: 700; padding: .1em .5em; border-radius: 4px; background: var(--green-soft); color: var(--green); }
.tag.maintenance { background: #e6eef7; color: var(--blue); }
.conso.high { color: var(--danger); font-weight: 600; }
.conso.low { color: var(--blue); font-weight: 600; }

/* ---------- Listes ---------- */
.due-list, .activity, .rule-list, .purchase-list { list-style: none; margin: 0; padding: 0; }
.due-list li, .activity li, .rule-list li { padding: .6em 0; border-bottom: 1px solid var(--line); }
.due-list li:last-child, .activity li:last-child, .rule-list li:last-child { border-bottom: 0; }
.due.overdue { border-left: 3px solid var(--danger); padding-left: .6em; }
.due.alert { border-left: 3px solid #e0a100; padding-left: .6em; }
.rule-list li { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn + .btn { margin-left: 6px; }

/* ---------- Graphique ---------- */
.chart { width: 100%; height: auto; max-height: 260px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { font-size: 11px; fill: var(--muted); }
.chart .line { fill: none; stroke: var(--green); stroke-width: 2.2; }
.chart .dot { fill: var(--green); }
.chart .dot.high { fill: var(--danger); }
.chart .dot.low { fill: var(--blue); }
.chart .limit { stroke-width: 1.2; stroke-dasharray: 5 4; }
.chart .limit.low { stroke: var(--blue); }
.chart .limit.high { stroke: var(--danger); }

/* ---------- Tableaux ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55em .6em; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: #fafcfb; }
.sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; font-weight: 600; }
.sort.active { color: var(--green); }
.table.prep tr.to-buy td:first-child { box-shadow: inset 3px 0 0 #e0a100; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper output { min-width: 2ch; text-align: center; font-weight: 700; }
.prep-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 8px; }
.prep-head label { margin: 0; min-width: 240px; }
.estimate { display: flex; justify-content: flex-end; gap: 12px; align-items: baseline; margin-top: 12px; font-size: 1.05rem; }
.estimate strong { font-size: 1.25rem; }

/* ---------- Achat ---------- */
.purchase-row {
  display: grid; grid-template-columns: 60px minmax(0, 1fr) 150px 150px 90px; gap: 10px; align-items: center;
  padding: .7em 0; border-bottom: 1px solid var(--line);
}
.purchase-row.confirmed { background: var(--green-soft); }
.purchase-row.confirmed .p-main strong { text-decoration: line-through; text-decoration-color: rgba(31, 77, 58, .4); }
.p-ok { margin: 0; display: flex; align-items: center; gap: .4em; padding-left: 6px; }
.p-price { display: flex; flex-direction: column; align-items: flex-end; }
.p-remove { text-align: right; padding-right: 6px; }
.purchase-footer { margin-top: 8px; }

/* ---------- Paramètres ---------- */
.settings-form { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px; align-items: end; }
.settings-form label { margin: 0; }
.form-actions { display: flex; gap: 8px; }
.backup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.backup-grid .btn.block { justify-content: flex-start; }

/* ---------- Boîtes de dialogue ---------- */
.modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal::backdrop { background: rgba(10, 25, 18, .45); }
.dialog-form, .confirm-form { padding: 20px 22px; }
.dialog-body { max-height: calc(100vh - 200px); overflow: auto; padding: 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.confirm { width: min(440px, calc(100vw - 24px)); }
.confirm-form p { margin-top: 0; font-size: 1rem; }
.vehicle-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; }
.vehicle-option, .import-option { display: flex; align-items: center; gap: .55em; font-weight: 400; margin: 0; padding: .35em 0; }
.import-option.disabled { color: var(--muted); }
.import-list { max-height: 50vh; overflow: auto; }
.rule-part-row { display: grid; grid-template-columns: 1fr 80px; gap: 8px; align-items: center; padding: .2em 0; }
.rule-part-row label { margin: 0; }
.rule-part-row .qty { min-height: 34px; padding: .3em .5em; }
.rule-parts { margin: -.4em 0 .8em; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1b2a22; color: #fff;
  padding: .7em 1.2em; border-radius: 999px; z-index: 50; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px);
}

/* ======================================================================
   Téléphone (moins de 720 px)
   ====================================================================== */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .app { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 260px; height: auto; z-index: 20;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 20px rgba(0, 0, 0, .2);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 0 12px 32px; }
  .menu-btn { display: inline-block; }
  .topbar { gap: 8px; padding: 10px 0; }
  .topbar h1 { font-size: 1.1rem; }
  .topbar-tools { width: 100%; }
  .vehicle-picker { flex: 1; }
  .vehicle-picker select { min-width: 0; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card-value { font-size: 1.15rem; }
  .grid-2, .backup-grid, .settings-form { grid-template-columns: 1fr; }
  .panel { padding: 12px; }

  /* Historiques et tableaux : cartes empilées */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; padding: 6px 10px; }
  .table td { border: 0; padding: .25em 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .85em; text-align: left; flex: none; }
  .table td.actions { justify-content: flex-end; padding-top: .5em; }
  .table td.actions:empty { display: none; }
  .table td.actions::before { content: none; }
  .parts-table td:first-child { font-size: 1.05em; }

  /* Formulaires : la règle générique masque les suffixes d'unité… */
  .dialog-form label span { display: none; }
  /* …mais ne doit jamais masquer les libellés imbriqués (OBLIGATOIRE). */
  .dialog-form .vehicle-option span,
  .dialog-form .import-option span { display: inline; }
  .vehicle-options { grid-template-columns: 1fr; }
  .import-source { display: block; }
  .import-source select { display: block; width: 100%; }
  .modal { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .dialog-form { padding: 16px; }
  .dialog-body { max-height: calc(100vh - 170px); }

  /* Achat : deux colonnes, puis estimation et validation empilées */
  .purchase-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "main main" "qty price" "ok remove";
    gap: 6px 10px; padding: .7em .4em;
  }
  .p-ok { grid-area: ok; }
  .p-main { grid-area: main; }
  .p-qty { grid-area: qty; }
  .p-price { grid-area: price; }
  .p-remove { grid-area: remove; text-align: right; }
  .purchase-footer .toolbar { flex-direction: column; align-items: stretch; }
  .purchase-footer .toolbar .btn { width: 100%; }
  .estimate { justify-content: space-between; }
  .prep-head label { min-width: 0; width: 100%; }
  .toolbar.wrap > select { flex: 1 1 100%; }
  .toolbar.wrap .spacer { display: none; }
}

/* ======================================================================
   Impression (page Achat)
   ====================================================================== */
@media print {
  body { background: #fff; font-size: 12pt; }
  .sidebar, .topbar, .notice, .toast, .backdrop, .no-print, .toolbar, .modal, .p-ok, .p-remove, .icon-btn { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .panel { box-shadow: none; padding: 0; }
  .print-only { display: block; }
  span.print-only { display: inline; }
  .purchase-row { grid-template-columns: minmax(0, 1fr) 120px 120px; break-inside: avoid; background: none !important; }
  .purchase-row .p-main strong { text-decoration: none !important; }
  .warning { border: 1px solid #999; }
}
