:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --surface-2: #eef2f2;
  --text: #13201f;
  --muted: #5b6b6a;
  --border: #dbe3e2;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d5efec;
  --danger: #c2410c;
  --danger-soft: #fde8dc;
  --warn: #a16207;
  --warn-soft: #fdf3d0;
  --ok: #15803d;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1515;
    --surface: #172120;
    --surface-2: #1f2b2a;
    --text: #e6eeed;
    --muted: #94a5a3;
    --border: #2a3837;
    --accent: #2dd4bf;
    --accent-ink: #062320;
    --accent-soft: #123b37;
    --danger: #fb923c;
    --danger-soft: #3b2216;
    --warn: #facc15;
    --warn-soft: #3a3214;
    --ok: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1515; --surface: #172120; --surface-2: #1f2b2a; --text: #e6eeed; --muted: #94a5a3;
  --border: #2a3837; --accent: #2dd4bf; --accent-ink: #062320; --accent-soft: #123b37;
  --danger: #fb923c; --danger-soft: #3b2216; --warn: #facc15; --warn-soft: #3a3214; --ok: #4ade80;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: .78rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
main a { color: var(--accent); font-weight: 600; text-decoration: none; }
.small { font-size: .85rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(.6rem + env(safe-area-inset-top)) 16px .6rem;
  background: var(--accent); color: var(--accent-ink);
}
.vehicle-picker { flex: 1; min-width: 0; }
.vehicle-picker select {
  width: 100%; max-width: 100%;
  appearance: none; border: 0; background: transparent; color: inherit;
  font: 600 1.1rem/1.2 inherit; padding: .2rem 1.4rem .2rem 0;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 10px) 55%, calc(100% - 5px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
  text-overflow: ellipsis;
}
.vehicle-picker select option { color: #13201f; background: #fff; }

main { padding: 16px 16px 72px; max-width: 720px; margin: 0 auto; outline: none; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--muted); font-size: .78rem; }
.kpi .value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .sub { color: var(--muted); font-size: .75rem; }

.row { display: flex; align-items: center; gap: .5rem; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .5rem; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 0; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.item .badge {
  flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 1.1rem;
}
.item .badge.expense { background: var(--surface-2); color: var(--muted); }
.item .body { flex: 1; min-width: 0; }
.item .title, .item .sub { display: block; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--muted); font-size: .82rem; }
.item .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.month-head { display: flex; justify-content: space-between; margin: 18px 4px 6px; color: var(--muted); font-size: .85rem; font-weight: 600; }
.month-head span:first-child { text-transform: capitalize; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.pill.overdue { background: var(--danger-soft); color: var(--danger); }
.pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--surface-2); color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 99px; font: inherit; font-size: .88rem; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Buttons */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; padding: .6rem 1rem;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
button.ghost { background: transparent; color: var(--accent); }
.topbar button.ghost { color: var(--accent-ink); border-color: currentColor; }
button.small { padding: .3rem .7rem; font-size: .85rem; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.block { width: 100%; }
button:disabled { opacity: .5; cursor: default; }
.btn-grid { display: grid; gap: 8px; }

.fab {
  position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 6;
  width: 56px; height: 56px; border-radius: 18px; padding: 0;
  font-size: 2rem; line-height: 1; box-shadow: 0 6px 18px rgb(0 0 0 / .25);
}

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: .7rem;
}
.tabbar a .ico { font-size: 1.2rem; line-height: 1.2; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }

/* Forms / dialog */
dialog {
  width: 100%; max-width: 560px; max-height: 92vh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
@media (min-width: 600px) { dialog { margin: auto; border-radius: 20px; } }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.form { padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
.form label { display: block; margin-bottom: 12px; font-size: .85rem; color: var(--muted); }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea {
  display: block; width: 100%; margin-top: 4px; padding: .65rem .75rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; font-size: 1rem;
}
.form textarea { min-height: 64px; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form .check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: 1rem; }
.form .check input { width: 20px; height: 20px; accent-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions .spacer { flex: 1; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 14px; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: .5rem; border-radius: 9px; color: var(--text); font-weight: 600; font-size: .95rem; cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.form[data-type="fuel"] [data-for="expense"], .form[data-type="expense"] [data-for="fuel"] { display: none; }
.hint { font-size: .8rem; color: var(--muted); margin: -6px 0 12px; }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--accent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.hbar { margin-bottom: 10px; }
.hbar .row { font-size: .9rem; }
.hbar .track { height: 8px; border-radius: 99px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-radius: 99px; }

.empty { text-align: center; padding: 28px 12px; }
.empty .big { font-size: 2.6rem; margin-bottom: .3rem; }

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Station : champ + bouton carte */
.input-with-btn { display: flex; gap: 8px; margin-top: 4px; }
.form .input-with-btn input { margin-top: 0 !important; flex: 1; min-width: 0; }
.input-with-btn button { flex: none; padding: .5rem .75rem; }
[hidden] { display: none !important; }

/* Carte plein écran */
dialog.map-sheet {
  width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; border-radius: 0;
  display: flex; flex-direction: column;
}
dialog.map-sheet:not([open]) { display: none; }
.map-head {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--border);
}
.map-head .spacer { flex: 1; }
.map { flex: 1; min-height: 0; background: var(--surface-2); }
.map-status { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); font-size: .85rem; color: var(--muted); border-top: 1px solid var(--border); }
.pin-wrap { background: none; border: 0; }
.pin {
  display: inline-block; transform: translate(-50%, -100%); white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); font: 700 12px/1 system-ui, sans-serif;
  padding: 5px 7px; border-radius: 8px; box-shadow: 0 2px 6px rgb(0 0 0 / .3); position: relative;
}
.pin::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--accent); border-bottom: 0;
}
.pin.noprice { background: #64748b; color: #fff; }
.pin.noprice::after { border-top-color: #64748b; }
.pop { font: 14px/1.4 system-ui, sans-serif; }
.pop .muted { color: #5b6b6a; }
.pop .prices { list-style: none; margin: 6px 0; padding: 0; }
.pop .prices li { display: flex; justify-content: space-between; gap: 12px; padding: 1px 4px; border-radius: 4px; }
.pop .prices li.hl { background: #d5efec; font-weight: 700; }
.pop button { margin-top: 8px; background: #0f766e; border-color: #0f766e; color: #fff; }
.leaflet-container { font: inherit; }

/* Scan de ticket */
.scan-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 10px; }
.scan-status { font-size: .85rem; margin: -2px 0 12px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); color: var(--text); }
.scan-status.error { background: var(--danger-soft); color: var(--danger); }
.form .filled { background: var(--warn-soft) !important; border-color: var(--warn) !important; }

/* v2 : navigation, étiquettes, recherche, garage, photos, synchro */
.icon-btn { color: var(--accent-ink); text-decoration: none; font-size: 1.35rem; line-height: 1; padding: 4px 6px; border-radius: 8px; }
.icon-btn[aria-current] { background: rgb(255 255 255 / .18); }
.tag { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin: 3px 4px 0 0; font-weight: 600; }
.item .tags { display: block; }
.clip { font-size: .8rem; }
.small-chip { padding: 4px 10px; font-size: .8rem; }
.search {
  width: 100%; padding: .7rem .9rem; margin-bottom: 10px; font: inherit;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
}
.search:focus { outline: 2px solid var(--accent); border-color: transparent; }
.warn-card { border-color: var(--warn); background: var(--warn-soft); }
.warn-card p { margin: 4px 0 10px; }
.home-head { min-height: 0; margin-bottom: 8px; justify-content: flex-end; }
.home-head:empty { display: none; }
.sync-pill {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 99px;
}
.sync-pill.auth, .sync-pill.error { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.sync-pill.running { color: var(--accent); }
.kpi.wide { grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 6px 4px; text-align: right; white-space: nowrap; border-top: 1px solid var(--border); }
.table th:first-child, .table td:first-child { text-align: left; }
.table thead th { color: var(--muted); font-weight: 600; border-top: 0; }
.chart .dot.suspect { fill: var(--danger); }
.thumb { flex: none; width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.thumb-lg { display: block; max-width: 100%; max-height: 180px; border-radius: 10px; margin: 6px 0; cursor: zoom-in; background: var(--surface-2); }
img.missing { min-width: 44px; min-height: 44px; }
.item.align-top { align-items: flex-start; }
.item .parts { display: block; font-size: .82rem; white-space: pre-line; margin-top: 2px; }
.field { margin-bottom: 12px; }
.field-label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field .chips { margin-bottom: 6px; }
.photo-field .row { flex-wrap: wrap; }
.steps { padding-left: 1.2rem; margin: 8px 0; }
.steps li { margin-bottom: 6px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
code { font-size: .85em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; word-break: break-all; }
dialog.photo-viewer {
  max-width: 100%; max-height: 100%; width: 100%; height: 100%; margin: 0; border-radius: 0; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px;
}
dialog.photo-viewer:not([open]) { display: none; }
dialog.photo-viewer img { max-width: 100%; max-height: calc(100% - 56px); object-fit: contain; }
dialog.photo-viewer button { align-self: flex-end; color: #fff; border-color: #fff; margin-bottom: 8px; }
