/* KM Logbook
   ──────────
   Dark is the dashboard at dusk. Light is the same instrument seen in daylight:
   paper-pale surfaces, cool steel structure — but the odometer window stays dark
   in both. A real car keeps a dark instrument panel at noon, so it reads as
   intentional, and it keeps the one element you squint at while driving at full
   contrast regardless of theme. */

:root,
:root[data-theme="dark"]{
  --odo-bg:   #090c11;
  --odo-line: #2a3441;
  --odo-num:  #f2b465;
  --odo-dim:  #3a3226;
  --odo-glow: #f2b46540;
  --ink:      #0e1218;
  --ink-2:    #18202b;
  --panel:    #161c25;
  --panel-2:  #1d2531;
  --line:     #2a3441;
  --line-2:   #364252;
  --text:     #e6ebf2;
  --muted:    #7f8da0;
  --accent:   #f2b465;
  --steel:    #8fb2d4;
  --good:     #6fcf9a;
  --bad:      #e08585;

  --bar:      #0e1218e6;
  --btn:      linear-gradient(#2d3a4c, #223040);
  --btn-line: #3c4b60;
  --btn-text: #ffffff;
  --shadow:   0 8px 24px #0009;

  --bad-bg:   #3a1f24;
  --bad-line: #5c3138;
  --bad-text: #ffc9c9;
  --good-bg:  #1c3329;
  --good-line:#2f5442;
  --good-text:#bdf0d5;
  --warn-bg:  #2a2015;
  --warn-line:#5a4526;
}

:root[data-theme="light"]{
  --odo-bg:   #e4e9f0;
  --odo-line: #c9d2df;
  --odo-num:  #9a5b09;
  --odo-dim:  #aab4c2;
  --odo-glow: transparent;
  --ink:      #f2f5f9;
  --ink-2:    #ffffff;
  --panel:    #ffffff;
  --panel-2:  #eef1f6;
  --line:     #dde3ec;
  --line-2:   #c9d2df;
  --text:     #16202c;
  --muted:    #5f6d7e;
  --accent:   #9a5b09;
  --steel:    #3f6c9e;
  --good:     #1d8a52;
  --bad:      #b3383f;

  --bar:      #f2f5f9e8;
  --btn:      linear-gradient(#3b5878, #2f4863);
  --btn-line: #2f4863;
  --btn-text: #ffffff;
  --shadow:   0 8px 24px #1a2a3d1f;

  --bad-bg:   #fdecec;
  --bad-line: #eab8ba;
  --bad-text: #8e2b31;
  --good-bg:  #e8f6ee;
  --good-line:#a9d8c0;
  --good-text:#17683f;
  --warn-bg:  #fdf1de;
  --warn-line:#e0bd85;
}

@media (prefers-color-scheme: light){
  :root[data-theme="system"]{
    --odo-bg:   #e4e9f0;
    --odo-line: #c9d2df;
    --odo-num:  #9a5b09;
    --odo-dim:  #aab4c2;
    --odo-glow: transparent;
    --ink:      #f2f5f9;
    --ink-2:    #ffffff;
    --panel:    #ffffff;
    --panel-2:  #eef1f6;
    --line:     #dde3ec;
    --line-2:   #c9d2df;
    --text:     #16202c;
    --muted:    #5f6d7e;
    --accent:   #9a5b09;
    --steel:    #3f6c9e;
    --good:     #1d8a52;
    --bad:      #b3383f;

    --bar:      #f2f5f9e8;
    --btn:      linear-gradient(#3b5878, #2f4863);
    --btn-line: #2f4863;
    --btn-text: #ffffff;
    --shadow:   0 8px 24px #1a2a3d1f;

    --bad-bg:   #fdecec;
    --bad-line: #eab8ba;
    --bad-text: #8e2b31;
    --good-bg:  #e8f6ee;
    --good-line:#a9d8c0;
    --good-text:#17683f;
    --warn-bg:  #fdf1de;
    --warn-line:#e0bd85;
  }
}

:root{
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --r: 14px;
  --pad: 16px;
  --tabbar: 62px;
}

*{ box-sizing:border-box; }
html{ -webkit-text-size-adjust:100%; }

body{
  margin:0;
  background:radial-gradient(120% 60% at 50% -10%, var(--ink-2) 0%, var(--ink) 60%) fixed;
  color:var(--text);
  font-family:var(--sans);
  font-size:16px;
  line-height:1.45;
  -webkit-font-smoothing:antialiased;
  min-height:100dvh;
  overscroll-behavior-y:none;
}

[hidden]{ display:none !important; }
h1,h2{ margin:0; font-weight:650; letter-spacing:-0.015em; }

/* ── Sign in / recovery ── */
.auth-wrap{
  max-width:420px; margin:0 auto;
  padding:max(48px, env(safe-area-inset-top)) var(--pad) 40px;
  min-height:100dvh; display:flex; flex-direction:column; justify-content:center;
}
.brandmark{ text-align:center; margin-bottom:32px; }
.brandmark__odo{
  display:inline-block; font-family:var(--mono); font-size:28px;
  letter-spacing:0.24em; color:var(--odo-num);
  background:var(--odo-bg); border:1px solid var(--odo-line); border-radius:6px;
  padding:8px 14px 8px 20px;
  box-shadow:inset 0 2px 8px #000a, 0 0 22px #f2b46518;
}
.brandmark__name{ font-size:26px; margin-top:18px; }
.brandmark__sub{ margin:4px 0 0; color:var(--muted); font-size:14px; }

.stack{ display:flex; flex-direction:column; gap:14px; }

/* ── Fields ── */
.field{ display:block; }
.field__label{
  display:block; font-size:12px; text-transform:uppercase;
  letter-spacing:0.09em; color:var(--muted); margin-bottom:6px; font-weight:600;
}
.field input, .field select{
  width:100%; font:inherit; color:var(--text);
  background:var(--panel-2); border:1px solid var(--line);
  border-radius:10px; padding:13px 12px; min-height:48px;
}
.field input::placeholder{ color:var(--muted); opacity:.6; }
.field--inline{ display:flex; align-items:center; gap:10px; }
.field--inline .field__label{ margin:0; }
.field--inline input{ width:auto; flex:1; min-height:40px; padding:8px 10px; font-size:15px; }

input:focus-visible, select:focus-visible, button:focus-visible{
  outline:2px solid var(--steel); outline-offset:2px;
}

/* ── Buttons ── */
.btn{
  font:inherit; font-weight:600; color:var(--text);
  background:var(--panel-2); border:1px solid var(--line);
  border-radius:10px; padding:14px 16px; min-height:50px;
  cursor:pointer; width:100%;
}
.btn--primary{ background:var(--btn); border-color:var(--btn-line); color:var(--btn-text); }
.btn--primary:active{ filter:brightness(.9); }
.btn--quiet{ background:transparent; border-color:transparent; color:var(--muted); min-height:44px; }
.btn:disabled{ opacity:.5; }
.btn--go{
  background:linear-gradient(#6b4a16, #4d3510);
  border-color:#6b5530; color:#ffdba8;
}
.btn--go:active{ filter:brightness(.9); }

/* ── Notices ── */
.notice{ margin:0; font-size:14px; padding:10px 12px; border-radius:9px; }
.notice--bad{ background:var(--bad-bg); color:var(--bad-text); border:1px solid var(--bad-line); }
.notice--good{ background:var(--good-bg); color:var(--good-text); border:1px solid var(--good-line); }

/* ── Top bar ── */
.topbar{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  background:var(--bar); backdrop-filter:blur(10px);
  border-bottom:1px solid var(--line);
}
.topbar__name{ font-weight:650; letter-spacing:-0.01em; }
.pill{
  display:inline-flex; align-items:center; gap:6px;
  font:inherit; font-size:12px; font-weight:600; color:var(--muted);
  background:var(--panel); border:1px solid var(--line);
  border-radius:999px; padding:4px 10px; cursor:pointer;
}
.pill__dot{ width:7px; height:7px; border-radius:50%; background:var(--muted); flex:none; }
.pill[data-state="synced"]  .pill__dot{ background:var(--good); }
.pill[data-state="pending"] .pill__dot{ background:var(--accent); }
.pill[data-state="offline"] .pill__dot{ background:var(--bad); }

/* ── Page + tab panels ── */
.page{
  max-width:560px; margin:0 auto;
  padding:16px var(--pad) calc(var(--tabbar) + 28px + env(safe-area-inset-bottom));
}
.panel-view{ display:flex; flex-direction:column; gap:18px; }
.panel-view[hidden]{ display:none; }

.section-title{
  font-size:12px; font-weight:700; letter-spacing:0.09em; text-transform:uppercase;
  color:var(--muted); margin:6px 0 -8px;
}

.card{
  background:var(--panel); border:1px solid var(--line);
  border-radius:var(--r); padding:16px;
  display:flex; flex-direction:column; gap:14px;
}

/* ── Bottom tab bar ── */
.tabbar{
  position:fixed; left:0; right:0; bottom:0; z-index:50;
  display:grid; grid-template-columns:repeat(4,1fr);
  background:var(--bar); backdrop-filter:blur(12px);
  border-top:1px solid var(--line);
  padding-bottom:env(safe-area-inset-bottom);
}
.tab{
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:3px; padding:9px 4px 8px; min-height:var(--tabbar);
  background:none; border:0; cursor:pointer;
  color:var(--muted); font:inherit; font-size:10px; font-weight:650;
  letter-spacing:0.03em;
}
.tab svg{ width:22px; height:22px; fill:none; stroke:currentColor; stroke-width:1.7;
          stroke-linecap:round; stroke-linejoin:round; }
.tab[aria-selected="true"]{ color:var(--text); }
.tab[aria-selected="true"] svg{ stroke:var(--accent); }
.tab__dot{
  position:absolute; margin:-16px 0 0 20px;
  width:6px; height:6px; border-radius:50%; background:var(--accent);
}

/* ── The odometer window ── */
.odo__head{ display:flex; align-items:center; justify-content:space-between; gap:10px; }
.tag{
  font-size:11px; font-weight:700; letter-spacing:0.1em; text-transform:uppercase;
  color:var(--accent); border:1px solid var(--warn-line); background:var(--warn-bg);
  padding:3px 8px; border-radius:999px;
}
.odo__window{
  background:var(--odo-bg); border:1px solid var(--odo-line); border-radius:12px;
  padding:6px 12px;
  box-shadow:inset 0 3px 10px #000c, inset 0 -1px 0 #ffffff08;
}
.odo__row{ display:flex; align-items:center; gap:12px; }
.odo__tag{
  font-size:11px; letter-spacing:0.12em; text-transform:uppercase;
  color:#7f8da0; font-weight:700; width:38px; flex:none;
}
.odo__num{
  flex:1; width:100%; min-width:0;
  background:none; border:0; padding:12px 0;
  font-family:var(--mono); font-size:30px; font-variant-numeric:tabular-nums;
  letter-spacing:0.1em; text-align:right;
  color:var(--odo-num); text-shadow:0 0 14px var(--odo-glow);
}
.odo__num::placeholder{ color:var(--odo-dim); text-shadow:none; }
.odo__num:focus{ outline:none; }
.odo__num:focus-visible{ outline:2px solid var(--steel); outline-offset:4px; border-radius:4px; }

.odo__gap{ display:flex; align-items:center; gap:10px; }
.odo__rule{ flex:1; height:1px; background:var(--odo-line); }
.odo__delta{
  font-family:var(--mono); font-size:13px; font-variant-numeric:tabular-nums;
  color:#8fb2d4; letter-spacing:0.04em; white-space:nowrap;
}
.odo__delta[data-bad="1"]{ color:#e08585; }

.odo__actions{ display:flex; flex-direction:column; gap:8px; }

/* ── Continuity / hints ── */
.continuity{
  margin:0; font-size:13px; line-height:1.4;
  padding:9px 11px; border-radius:9px;
  border:1px solid var(--line); background:var(--panel-2); color:var(--muted);
}
.continuity[data-tone="warn"]{
  border-color:var(--bad-line); background:var(--bad-bg); color:var(--bad-text);
}

/* ── Trip in progress ── */
.running{
  background:var(--panel); border:1px solid var(--warn-line); border-radius:var(--r);
  padding:14px 15px; display:flex; flex-direction:column; gap:8px;
  box-shadow:var(--shadow);
}
.running[data-stale="1"]{ border-color:var(--bad-line); }
.running__head{ display:flex; align-items:center; gap:8px; }
.running__pulse{
  width:8px; height:8px; border-radius:50%; background:var(--accent); flex:none;
  animation:pulse 2s ease-in-out infinite;
}
.running[data-stale="1"] .running__pulse{ background:var(--bad); }
@keyframes pulse{ 50%{ opacity:.25; } }
.running__label{
  font-size:11px; font-weight:700; letter-spacing:0.12em; text-transform:uppercase;
  color:var(--accent);
}
.running[data-stale="1"] .running__label{ color:var(--bad); }
.running__since{ margin-left:auto; font-size:12px; color:var(--muted); }
.running__reading{
  display:flex; align-items:baseline; gap:10px; width:100%;
  background:var(--odo-bg); border:1px solid var(--odo-line); border-radius:10px;
  padding:10px 12px; cursor:pointer; text-align:left;
  box-shadow:inset 0 2px 8px #000a;
}
.running__from{
  font-size:11px; letter-spacing:0.1em; text-transform:uppercase;
  color:#7f8da0; font-weight:700;
}
.running__km{
  margin-left:auto;
  font-family:var(--mono); font-size:24px; font-variant-numeric:tabular-nums;
  letter-spacing:0.08em; color:var(--odo-num); text-shadow:0 0 12px var(--odo-glow);
}
.running__who{ margin:0; font-size:13px; color:var(--muted); }
.running__stale{
  margin:0; font-size:13px; line-height:1.4; color:var(--bad-text);
  background:var(--bad-bg); border:1px solid var(--bad-line); border-radius:9px; padding:9px 11px;
}

/* ── Totals ── */
.totals{
  display:grid; grid-template-columns:repeat(3,1fr); gap:1px;
  background:var(--line); border:1px solid var(--line);
  border-radius:var(--r); overflow:hidden;
}
.totals--one{ grid-template-columns:1fr; }
.totals__cell{ background:var(--panel); padding:12px 8px; text-align:center; }
.totals__cell b{
  display:block; font-family:var(--mono); font-size:19px; font-weight:500;
  font-variant-numeric:tabular-nums; color:var(--text);
}
.totals--one .totals__cell b{ font-size:30px; color:var(--accent); }
.totals__cell span{
  display:block; font-size:11px; letter-spacing:0.08em; text-transform:uppercase;
  color:var(--muted); margin-top:3px; font-weight:600;
}

/* ── Filters ── */
.filters{ display:flex; gap:8px; align-items:stretch; }
.filters select{
  font:inherit; font-size:14px; color:var(--text);
  background:var(--panel-2); border:1px solid var(--line);
  border-radius:10px; padding:0 10px; min-height:44px; flex:none;
}
.filters__search{ position:relative; flex:1; min-width:0; }
.filters__search input{
  width:100%; font:inherit; font-size:14px; color:var(--text);
  background:var(--panel-2); border:1px solid var(--line);
  border-radius:10px; padding:0 34px 0 12px; min-height:44px;
  -webkit-appearance:none; appearance:none;
}
.filters__search input::-webkit-search-cancel-button{ display:none; }
.filters__clear{
  position:absolute; right:4px; top:50%; transform:translateY(-50%);
  width:32px; height:32px; border:0; border-radius:8px;
  background:none; color:var(--muted); font-size:20px; line-height:1; cursor:pointer;
}

/* ── Trip list ── */
.list{ display:flex; flex-direction:column; gap:20px; }
.daygroup__head{
  display:flex; align-items:baseline; justify-content:space-between;
  padding:0 2px 8px; border-bottom:1px solid var(--line); margin-bottom:8px;
}
.daygroup__date{ font-size:13px; font-weight:650; }
.daygroup__sum{
  font-family:var(--mono); font-size:13px; color:var(--muted);
  font-variant-numeric:tabular-nums;
}
.trip{
  display:flex; align-items:center; gap:12px; width:100%; text-align:left;
  background:var(--panel); border:1px solid var(--line);
  border-radius:11px; padding:12px 13px; margin-bottom:8px;
  font:inherit; color:inherit; cursor:pointer;
}
.trip:active{ background:var(--panel-2); }
.trip__km{
  font-family:var(--mono); font-size:18px; font-variant-numeric:tabular-nums;
  color:var(--accent); min-width:74px; text-align:right; flex:none;
}
.trip__body{ min-width:0; flex:1; }
.trip__purpose{ font-size:15px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.trip__purpose--none{ color:var(--muted); font-style:italic; }
.trip__reading{
  font-family:var(--mono); font-size:12px; color:var(--muted);
  font-variant-numeric:tabular-nums; margin-top:2px;
}
.trip__flag{ width:7px; height:7px; border-radius:50%; background:var(--accent); flex:none; }

.empty{
  color:var(--muted); text-align:center; font-size:15px;
  border:1px dashed var(--line); border-radius:var(--r); padding:28px 20px; margin:0;
}

/* ── Client totals ── */
.ctotal{ display:grid; grid-template-columns:1fr auto; gap:3px 10px; align-items:center; }
.ctotal__name{ font-size:14px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ctotal__km{
  font-family:var(--mono); font-size:13px; font-variant-numeric:tabular-nums;
  color:var(--accent); text-align:right;
}
.ctotal__bar{ grid-column:1 / -1; height:3px; border-radius:2px; background:var(--panel-2); overflow:hidden; }
.ctotal__fill{ display:block; height:100%; background:var(--steel); border-radius:2px; }

/* ── Twelve-week progress ── */
.progress{ height:6px; border-radius:3px; background:var(--panel-2); overflow:hidden; margin:10px 0 8px; }
.progress__fill{ display:block; height:100%; background:var(--accent); border-radius:3px; }
.muted{ color:var(--muted); font-size:13px; margin:0; line-height:1.45; }

/* ── Segmented control (theme picker) ── */
.seg{
  display:grid; grid-template-columns:repeat(3,1fr); gap:3px;
  background:var(--panel-2); border:1px solid var(--line);
  border-radius:11px; padding:3px;
}
.seg__opt{
  font:inherit; font-size:14px; font-weight:600; color:var(--muted);
  background:none; border:0; border-radius:8px; padding:10px 6px;
  cursor:pointer; min-height:42px;
}
.seg__opt--on{
  background:var(--panel); color:var(--text);
  box-shadow:0 1px 3px #0003;
}

.yearodo{ display:grid; grid-template-columns:1fr 1fr; gap:10px; align-items:stretch; }
/* Labels of different heights would otherwise push their inputs out of line —
   the grid stretches both cells, and margin-top:auto pins the inputs to the
   bottom of whichever cell is taller. */
.yearodo .field{ display:flex; flex-direction:column; }
.yearodo .field input{ margin-top:auto; }
.yearodo .field__label{ hyphens:auto; }

/* ── Toast + update bar ── */
.toast{
  position:fixed; left:50%; transform:translateX(-50%);
  bottom:calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); z-index:80;
  background:var(--panel-2); border:1px solid var(--line-2);
  color:var(--text); font-size:14px; font-weight:550;
  padding:11px 16px; border-radius:999px; box-shadow:var(--shadow);
  max-width:calc(100vw - 32px);
}
.updatebar{
  position:fixed; left:50%; transform:translateX(-50%);
  bottom:calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); z-index:90;
  display:flex; align-items:center; gap:10px;
  background:var(--panel-2); border:1px solid var(--btn-line);
  border-radius:999px; padding:8px 8px 8px 16px;
  box-shadow:var(--shadow); max-width:calc(100vw - 24px);
}
.updatebar__text{ font-size:14px; font-weight:550; }
.updatebar__go{
  font:inherit; font-size:13px; font-weight:700; color:var(--btn-text);
  background:var(--btn); border:1px solid var(--btn-line);
  border-radius:999px; padding:7px 14px; cursor:pointer;
}
.updatebar__go:disabled{ opacity:.6; }
.updatebar__x{
  font:inherit; font-size:18px; line-height:1; color:var(--muted);
  background:none; border:0; cursor:pointer; padding:4px 8px;
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration:0.001ms !important; transition-duration:0.001ms !important; }
}
