/* Km tournées — style « Route »
   Fond bitume, borne kilométrique (blanc + chapeau rouge), marquage jaune pour les actions,
   journée dessinée comme une route. Police Overpass (servie localement si présente). */

@font-face {
  font-family: "Overpass";
  src: url("/fonts/overpass-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* Thème sombre (par défaut) */
:root {
  --ground: #26292d;      /* bitume */
  --surface: #1c1e21;     /* champs, barre d'onglets */
  --raised: #2f3338;      /* panneaux */
  --road: #3a3e43;        /* chaussée de la frise */
  --dash: #f3f4f1;        /* ligne blanche */
  --line: #41464c;
  --ink: #f3f4f1;
  --muted: #a9aeb2;
  --marking: #f2c230;     /* marquage jaune : actions */
  --marking-ink: #1d1a0e;
  --marking-text: #f2c230;
  --borne: #ffffff;
  --borne-ink: #26292d;
  --cap: #c8102e;         /* chapeau rouge de la borne */
  --danger: #ff8a7a;
  --danger-soft: #3d2320;
  --notice: #3a3420;
  --focus: #f2c230;
  --backdrop: rgba(0, 0, 0, .55);

  --font: "Overpass", "Avenir Next", "Helvetica Neue", -apple-system, system-ui, sans-serif;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

/* Thème clair « Route de jour » : plus lisible en plein soleil */
:root[data-theme="light"] {
  --ground: #e9eae7;
  --surface: #ffffff;
  --raised: #ffffff;
  --road: #3a3e43;
  --dash: #f3f4f1;
  --line: #cfd2d4;
  --ink: #1f2226;
  --muted: #5b6168;
  --marking: #f2c230;
  --marking-ink: #1d1a0e;
  --marking-text: #8a5f00;
  --danger: #b3261e;
  --danger-soft: #fbe3df;
  --notice: #fbf0cc;
  --focus: #1f4e9c;
  --backdrop: rgba(20, 22, 25, .45);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --ground: #e9eae7; --surface: #ffffff; --raised: #ffffff; --line: #cfd2d4;
    --ink: #1f2226; --muted: #5b6168; --marking-text: #8a5f00; --danger: #b3261e;
    --danger-soft: #fbe3df; --notice: #fbf0cc; --focus: #1f4e9c; --backdrop: rgba(20, 22, 25, .45);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 17px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
b, strong { font-weight: 800; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 14px) 18px calc(var(--tabbar-h) + var(--safe-b) + 28px);
}
.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }

/* ---------- en-tête ---------- */
.screen-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 18px; }
.screen-sub { margin: 0 0 2px; color: var(--muted); font-size: 15px; }
.screen-title { margin: 0; font-weight: 900; font-size: 34px; line-height: 1; letter-spacing: -.01em; }
.head-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; border: 0;
  background: var(--notice); color: var(--ink);
  font-size: 13px; font-weight: 700;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--marking); }
.pill-btn {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  font-weight: 700; font-size: 14px;
}

/* ---------- borne kilométrique ---------- */
.borne {
  width: 132px; height: 170px; flex: none;
  border-radius: 66px 66px 10px 10px;
  background: var(--borne);
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
}
:root[data-theme="light"] .borne { box-shadow: 0 0 0 1px #cfd2d4, 0 8px 20px rgba(0, 0, 0, .12); }
.borne-cap {
  height: 60px; flex: none;
  background: var(--cap); color: #fff;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 8px 7px; text-align: center;
  font-weight: 800; font-size: 14px; line-height: 1.1;
}
.borne-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--borne-ink); padding: 0 6px;
}
.borne-num { font-weight: 900; font-size: 64px; line-height: .9; font-variant-numeric: tabular-nums; letter-spacing: -.02em; white-space: nowrap; }
.borne-num.l { font-size: 38px; }
.borne-num.xl { font-size: 30px; }
.borne.is-empty .borne-num { color: #b8bcc0; }
.borne-unit { font-weight: 700; font-size: 15px; }

.hero { display: flex; gap: 16px; align-items: center; }
.hero-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.hero-meta { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.hero-meta b { color: var(--ink); }
.hero-big { margin: 0; display: flex; flex-direction: column; }
.hero-big span { color: var(--muted); font-size: 14px; }
.hero-big b { font-size: 30px; font-weight: 900; line-height: 1.1; }

/* ---------- compteur façon plaque ---------- */
.plate-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.plate-label { font-size: 14px; font-weight: 700; }
.plate {
  width: 100%; min-height: 54px;
  border: 2px solid var(--ink); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  padding: 8px 12px;
  font-weight: 800; font-size: 28px; letter-spacing: .03em;
  font-variant-numeric: tabular-nums;
}
.plate::placeholder { color: var(--muted); opacity: .55; }
.plate:focus { outline: none; border-color: var(--marking); box-shadow: 0 0 0 3px rgba(242, 194, 48, .35); }
.hint { margin: 10px 0 0; font-size: 14px; color: var(--muted); min-height: 1.2em; }
.hint.warn { color: var(--danger); }

.vehicle-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 700; min-height: 36px;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }

/* ---------- panneaux et formulaires ---------- */
.panel { margin: 0; }
.panel.boxed { background: var(--raised); border-radius: 18px; padding: 16px; border: 1px solid var(--line); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 14px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 48px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  padding: 10px 12px; font-size: 17px;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--marking); }
.textarea { min-height: 76px; resize: vertical; }
input[type="time"].input, input[type="date"].input { -webkit-appearance: none; appearance: none; text-align: left; }
.note-toggle { margin-top: 12px; }
.note-toggle summary { cursor: pointer; color: var(--muted); font-size: 15px; font-weight: 700; padding: 6px 0; list-style: none; }
.note-toggle summary::-webkit-details-marker { display: none; }
.note-toggle summary::before { content: "+ "; }
.note-toggle[open] summary::before { content: "– "; }
.note-toggle .textarea { margin-top: 6px; }

.switch-row, .field.switch-row { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + i { background: var(--marking); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 3px solid var(--focus); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 18px;
  border-radius: 10px; border: 0;
  background: var(--marking); color: var(--marking-ink);
  font-weight: 800; font-size: 17px;
}
.btn.block { width: 100%; margin-top: 16px; }
.btn.marking { min-height: 58px; font-size: 18px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.small { min-height: 42px; font-size: 15px; padding: 0 14px; border-radius: 8px; }
.btn:disabled { opacity: .45; }
.btn:active { transform: translateY(1px); }
.link {
  background: none; border: 0; padding: 10px 0; color: var(--ink);
  font-size: 15px; font-weight: 700; text-decoration: underline; text-decoration-color: var(--marking);
  text-decoration-thickness: 2px; text-underline-offset: 4px;
}
.link-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.row-actions .btn { flex: 1; }
.error-msg { margin: 10px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 15px; }
.error-msg:empty { display: none; }

/* ---------- la route (frise de la journée) ---------- */
.section { margin-top: 28px; }
.section-title { margin: 0 0 12px; font-weight: 900; font-size: 21px; line-height: 1.15; }
.section-note { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.road { position: relative; padding-left: 50px; display: flex; flex-direction: column; }
.road::before {
  content: ""; position: absolute; left: 10px; top: 4px; bottom: 4px; width: 26px;
  border-radius: 5px; background: var(--road);
}
.road::after {
  content: ""; position: absolute; left: 22px; top: 12px; bottom: 12px; width: 2px;
  background: repeating-linear-gradient(180deg, var(--dash) 0 10px, transparent 10px 20px);
}
.stop {
  position: relative; display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 58px; padding: 8px 0;
  background: none; border: 0; text-align: left; color: var(--ink);
}
.stop + .stop { border-top: 1px solid var(--line); }
.stop-dot {
  position: absolute; left: -44px; top: 50%; margin-top: -10px; z-index: 1;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--dash); border: 4px solid var(--road);
}
.stop.running .stop-dot { background: var(--marking); width: 24px; height: 24px; left: -46px; margin-top: -12px; }
.stop.anomaly .stop-dot { background: var(--danger); }
.stop-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stop-time { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.stop.running .stop-time b { color: var(--marking-text); }
.stop-sub { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop.anomaly .stop-sub { color: var(--danger); white-space: normal; }
.stop-km { font-weight: 900; font-size: 22px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stop-km small { font-size: 14px; font-weight: 700; color: var(--muted); }
.stop.running .stop-km { color: var(--marking-text); }
.road-gap { margin: 0; padding: 4px 0 6px; font-size: 13px; color: var(--muted); border-top: 1px dashed var(--line); }
.tag { display: inline-block; font-size: 12px; font-weight: 800; padding: 2px 7px; border-radius: 6px; vertical-align: 2px; margin-left: 6px; }
.tag.pending { background: var(--notice); color: var(--ink); }

.day-head { display: flex; justify-content: space-between; align-items: baseline; margin: 26px 0 6px; font-size: 15px; font-weight: 800; color: var(--muted); }
.day-head span { color: var(--ink); }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.month-nav .label { font-weight: 900; font-size: 22px; text-transform: capitalize; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--ink);
}
.icon-btn:disabled { opacity: .3; }
.totals-line { margin: 0 0 4px; color: var(--muted); font-size: 15px; }
.totals-line b { color: var(--ink); font-size: 17px; }
.empty { padding: 26px 18px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: 14px; }
.empty p { margin: 0 0 12px; }
.month-strip { margin: 26px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.month-strip b { color: var(--ink); }

/* ---------- récap ---------- */
.ledger { background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px; margin-top: 18px; }
.ledger-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.ledger-row:first-child { border-top: 0; }
.ledger-row span { color: var(--muted); font-size: 15px; }
.ledger-row b { font-size: 19px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger-row.total { border-top: 2px solid var(--ink); }
.ledger-row.total span { color: var(--ink); font-weight: 800; }
.ledger-row.total b { font-size: 24px; font-weight: 900; color: var(--marking-text); }

.bars { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 5px; align-items: end; height: 150px; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; border: 0; padding: 0; background: none; gap: 2px; }
.bar i { display: block; width: 100%; border-radius: 3px 3px 0 0; }
.bar .pro { background: var(--marking); }
.bar .perso { background: repeating-linear-gradient(135deg, var(--muted) 0 3px, transparent 3px 6px); border: 1px solid var(--muted); border-bottom: 0; }
.bar[aria-pressed="true"] .pro { background: var(--ink); }
.bar-labels { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 5px; margin-top: 6px; text-align: center; font-size: 12px; color: var(--muted); }
.bar-labels span.sel { color: var(--ink); font-weight: 900; }
.legend { display: flex; gap: 16px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -1px; margin-right: 6px; }
.legend .pro { background: var(--marking); }
.legend .perso { background: repeating-linear-gradient(135deg, var(--muted) 0 3px, transparent 3px 6px); border: 1px solid var(--muted); }

.export-card { background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.export-card + .export-card { margin-top: 12px; }
.export-card h3 { margin: 0 0 4px; font-size: 17px; font-weight: 800; }
.export-card p { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.export-card .row-actions { margin-top: 0; }
.notice { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--notice); font-size: 14px; }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.fine { font-size: 13px; color: var(--muted); margin: 10px 2px 0; }

/* ---------- listes (réglages, véhicules) ---------- */
.list { background: var(--raised); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; min-height: 56px; background: transparent; border: 0;
  border-top: 1px solid var(--line); color: var(--ink);
}
.list > .list-item:first-child { border-top: 0; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .t1 { display: block; font-size: 17px; font-weight: 700; }
.list-item .t1.add { color: var(--marking-text); }
.list-item .t2 { display: block; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .t2.wrap { white-space: normal; }
.list-item .km { font-weight: 900; font-size: 20px; white-space: nowrap; }
.list-item .chev { color: var(--muted); flex: none; }
.settings-group { margin-top: 26px; }
.settings-group .pad { padding: 14px; }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.segmented button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 800; font-size: 15px; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--ground); }

/* ---------- connexion ---------- */
.login { padding-top: 12vh; }
.login .brand { display: flex; align-items: center; gap: 16px; margin-bottom: 28px; }
.login .brand img { width: 64px; height: 64px; border-radius: 15px; }
.login h1 { margin: 0; font-weight: 900; font-size: 34px; line-height: 1; }
.login p { margin: 6px 0 0; color: var(--muted); }

/* ---------- barre d'onglets ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar-inner { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; max-width: 560px; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-h); border: 0; background: none; color: var(--muted);
  font-size: 11px; font-weight: 800;
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--marking-text); }

/* ---------- feuilles ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--backdrop); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--raised); border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(20px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: sheet-in .22s cubic-bezier(.2,.8,.2,1); }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: .4; } }
}
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-head h2 { margin: 0; font-weight: 900; font-size: 24px; line-height: 1.1; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  transform: translate(-50%, 20px); max-width: calc(100% - 32px);
  background: var(--ink); color: var(--ground);
  padding: 11px 16px; border-radius: 10px;
  font-size: 15px; font-weight: 800;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--cap); color: #fff; }

@media (max-width: 360px) {
  .borne { width: 116px; height: 156px; }
  .borne-num { font-size: 54px; }
  .plate { font-size: 24px; }
  .screen-title { font-size: 30px; }
}
