/* Flex Log — pastel consumer (tasteskill app sheet, seed 242535080).
   White cards under one large radius on a cool ground; pay, miles and fuel each have a pale tint
   with the dark of its own hue as ink. Money is set in Manrope with the pence smaller and grey.
   Grid at 1440: sidebar 240 + canvas 1200; canvas padding 40 + 40 → 1120 = 736 + 24 + 360. */
:root {
  --ground: #f3f5f7;
  --surface: #ffffff;
  --raised: #f2f8fd;
  --sunk: #eef1f4;
  --active: #e7eaee;
  --border: #e6e6e6;
  --rule: #eef0f2;
  --control: #d6d9dd;
  --text: #1b1d1f;
  --muted: #5c6064;
  --accent: #1d5fd6;
  --on-accent: #ffffff;
  --accent-soft: #dcf1ff;  --accent-ink: #0a3a80;   /* pay */
  --teal: #2a8798;
  --teal-soft: #d9f1f4;    --teal-ink: #0b4a55;     /* miles */
  --amber: #b45309;
  --amber-soft: #fdeedc;   --amber-ink: #6a2f06;    /* fuel */
  --stop: #c9ced4;
  --chart-1: #1d5fd6; --chart-muted: #c9d3df; --grid: #e8ebee; --axis-ink: #5c6064; --ink: #1b1d1f;
  --positive: #2f7a45;
  --negative: #c41c29;
  --pill-warning-bg: #fffbeb; --pill-warning-ink: #92400e;
  --pill-neutral-bg: #eef1f4; --pill-neutral-ink: #3a3d40;
  --radius-card: 20px;
  --radius-tile: 10px;
  --gap: 16px;
  --row: 64px;
  --touch: 48px;
  --font: "Manrope", Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

/* Night mode, switched on by theme.js between sunset and sunrise (not by the phone's setting). */
:root[data-theme="night"] {
  --ground: #0b0c0d;
  --surface: #17191b;
  --raised: #1d2227;
  --sunk: #202326;
  --active: #26292d;
  --border: #2a2d31;
  --rule: #24272a;
  --control: #44484d;
  --text: #f4f5f6;
  --muted: #b0b4b9;
  --accent: #6fa0f0;
  --on-accent: #06142b;
  --accent-soft: #15253d;  --accent-ink: #b5d1ff;
  --teal: #58b8c7;
  --teal-soft: #11292d;    --teal-ink: #9adbe5;
  --amber: #e0954a;
  --amber-soft: #2c1f11;   --amber-ink: #f3c38f;
  --stop: #4a4f55;
  --chart-1: #6fa0f0; --chart-muted: #3a414a; --grid: #2a2d31; --axis-ink: #b0b4b9; --ink: #f4f5f6;
  --positive: #5cc07c;
  --negative: #f06a75;
  --pill-warning-bg: #2d2410; --pill-warning-ink: #f2c46b;
  --pill-neutral-bg: #26292d; --pill-neutral-ink: #d4d7da;
  color-scheme: dark;
}
html { transition: background-color 400ms ease; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ground);
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
.num, input, select, td, th { font-variant-numeric: tabular-nums; }
.nil { color: var(--muted); }
.pence { font-size: 0.62em; font-weight: 500; color: var(--muted); letter-spacing: 0; }

/* ---------- Shell ----------
   Phone: one screen at a time, one viewport tall; the top-level screens get a bottom tab bar.
   Desktop: a labelled sidebar on the ground, the screen beside it. */
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}
main {
  flex: 1;
  min-height: 0;
  padding: 8px 16px 16px;
  overflow-y: auto;
}
.side { display: none; }

.tabbar { display: none; }
body.top .tabbar {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 4px max(8px, calc((100% - 640px) / 2)) env(safe-area-inset-bottom);
  background: var(--surface);
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--text); }
.tabbar a[aria-current="page"] svg { color: var(--accent); }
.tabbar a:active { background: var(--sunk); }

/* ---------- Title row ---------- */
.bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 64px;
  padding: env(safe-area-inset-top) 8px 0;
}
.bar-mark { display: flex; padding: 0 6px 0 8px; }
.mark { width: 32px; height: 32px; flex: none; }
.spacer { flex: 1; }
.bar-title { flex: 1; min-width: 0; padding: 0 4px; }
.bar-title h1 { font-size: 24px; font-weight: 600; line-height: 1.2; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title p { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn, .text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch);
  height: var(--touch);
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text);
  font: 600 15px var(--font);
  text-decoration: none;
  cursor: pointer;
}
.text-btn { padding: 0 16px; }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover, .text-btn:hover { background: var(--sunk); }
.icon-btn:active, .text-btn:active { background: var(--active); }

/* ---------- Segmented tabs ---------- */
.tabs {
  flex-shrink: 0;
  display: flex;
  gap: 2px;
  margin: 8px 16px 0;
  padding: 4px;
  border-radius: 999px;
  background: var(--sunk);
}
main .tabs { margin: 0 0 var(--gap); }
.tab {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 600 15px var(--font);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); }

/* ---------- Pinned actions ---------- */
.actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--ground);
}
body.top .actions { padding-bottom: 10px; }
.actions .btn.primary { flex: 1; padding: 0 16px; white-space: nowrap; }
.actions .btn.secondary, .actions .btn.danger { flex: 0 0 auto; padding: 0 22px; }
.range { flex: 0 0 auto; min-width: 64px; text-align: center; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  font: 600 17px var(--font);
  text-decoration: none;
  cursor: pointer;
  transition: transform 90ms ease, background-color 120ms ease, opacity 120ms ease;
}
.btn svg { width: 20px; height: 20px; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn.secondary, .btn.square { background: var(--surface); color: var(--text); }
.btn.secondary:hover:not(:disabled), .btn.square:hover:not(:disabled) { background: var(--sunk); }
.btn.square { width: 52px; padding: 0; }
.btn.danger { background: none; color: var(--negative); border: 1px solid var(--control); }
.btn.danger:hover { background: var(--sunk); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Cards ---------- */
.card {
  margin-bottom: var(--gap);
  border-radius: var(--radius-card);
  background: var(--surface);
}
.empty { padding: 24px 20px; color: var(--muted); }
.empty strong { color: var(--text); font-weight: 600; }
.error { padding: 20px; }
.error .text-btn { margin: 8px 0 0 -16px; }

/* Two columns on desktop (736 + 24 + 360); on a phone the side card comes first. */
.cols { display: flex; flex-direction: column; }
.col-side { order: -1; }
.col-side.desk, .desk-only { display: none; }
.chart { margin-top: 12px; }
.chart-card { padding: 20px; }
main.stack .cols, main.stack .col-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- Summary card: the sum with what explains it ---------- */
.sum { padding: 20px; }
.sum-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sum-head h2 { font-size: 16px; font-weight: 500; }
.sum-head span { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum-fig { display: block; margin-top: 6px; font-size: 36px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sum-sub { margin-top: 4px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.tile { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 10px 12px; border-radius: var(--radius-tile); }
.tile span { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile strong { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile.pay { background: var(--accent-soft); color: var(--accent-ink); }
.tile.miles { background: var(--teal-soft); color: var(--teal-ink); }
.tile.fuel { background: var(--amber-soft); color: var(--amber-ink); }
.tile.plain { background: var(--sunk); color: var(--text); }
.tile .nil { color: inherit; opacity: 0.7; }

/* ---------- Week lists (blocks and fuel) ---------- */
.list { overflow: hidden; }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--row);
  padding: 0 20px;
  text-decoration: none;
  transition: background-color 120ms ease;
}
.list-row + .list-row { border-top: 1px solid var(--rule); }
.week-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 12px; }
.week-what, .week-earn { display: flex; flex-direction: column; min-width: 0; }
.week-what { flex: 1; }
.week-earn { flex: none; align-items: flex-end; }
.week-head strong { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week-head strong span { font-weight: 400; color: var(--muted); }
.week-head small { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week-earn strong { font-size: 22px; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; overflow: visible; }
a.list-row:hover { background: var(--raised); }
a.list-row:active { background: var(--sunk); }
.day-chip {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-tile);
  background: var(--sunk);
  line-height: 1.05;
}
.day-chip b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.day-chip small { font-size: 11px; font-weight: 500; color: var(--muted); }
.day-chip.today { background: var(--accent-soft); color: var(--accent-ink); }
.day-chip.today small { color: var(--accent-ink); }
.day-chip.fuel { background: var(--amber-soft); color: var(--amber-ink); }
.day-chip.fuel small { color: var(--amber-ink); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main strong { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small, .row-fig small { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-fig { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.row-fig span { font-size: 16px; font-weight: 600; }
.row-note { flex: none; font-size: 14px; color: var(--muted); }
.pill {
  flex: none;
  white-space: nowrap;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.pill.warning { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.pill.neutral { background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); }
.pill.accent { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- Forms ---------- */
.form { padding: 20px; }
label { display: block; margin-bottom: 16px; font-size: 14px; font-weight: 500; color: var(--text); }
.form label:last-child, .step label:last-child { margin-bottom: 0; }
input, textarea, select {
  min-height: var(--touch);
  margin: 0;
  border: 1px solid var(--control);
  border-radius: var(--radius-tile);
  background: var(--surface);
  color: var(--text);
  font: 400 17px var(--font); /* >= 16px stops iOS zooming on focus */
  transition: border-color 120ms ease;
}
input:hover, textarea:hover, select:hover { border-color: var(--muted); }
input, textarea { display: block; width: 100%; margin-top: 8px; padding: 10px 14px; }
textarea { resize: none; min-height: 72px; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input.auto { color: var(--accent-ink); background: var(--accent-soft); border-color: transparent; font-weight: 600; } /* litres, worked out */
.form .hint { margin: 0 0 4px; }
select { flex: 1; min-width: 0; padding: 0 4px; text-align: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 > * { min-width: 0; }
.field { margin-bottom: 16px; }
.field-label { display: block; font-size: 14px; font-weight: 500; }
.lengths { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.length {
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--sunk);
  color: var(--text);
  font: 600 15px var(--font);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 120ms ease, transform 90ms ease;
}
.length:hover:not(:disabled) { background: var(--active); }
.length:active:not(:disabled) { transform: scale(0.95); }
.length[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.length:disabled { opacity: 0.4; cursor: default; }
.time-pick { display: flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 17px; }
.dt-pick { display: flex; align-items: center; gap: 8px; }
.dt-pick .date-field { flex: 1.3; padding: 0 12px; }
.date-field {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: var(--touch);
  margin-top: 8px;
  padding: 0 14px;
  border: 1px solid var(--control);
  border-radius: var(--radius-tile);
  background: var(--surface);
  font-size: 17px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
}
.date-field:hover { border-color: var(--muted); }
.date-field:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.date-field input { /* the native picker, invisible, covering the box so a tap opens it */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}
.date-field input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; opacity: 0; cursor: pointer; }
.dt-pick .time-pick { flex: 1; }
input.odo { font-size: 26px; font-weight: 600; letter-spacing: 0.01em; min-height: 60px; }

/* Desktop forms: a label column with the screen's help beside the panel. */
.split-label { display: none; }

/* ---------- Record ---------- */
main.stack { display: flex; flex-direction: column; overflow: hidden; }
main.stack .step { flex-shrink: 0; margin-bottom: 0; }
.recap { flex: 1; min-height: 0; padding-top: var(--gap); }
.recap .card { overflow: hidden; margin-bottom: 0; }
.hint + #cur-time { margin-top: 16px; }
#cur-time label { margin-bottom: 16px; }
.recap td { height: 40px; font-size: 14px; }
.recap tr + tr td { border-top: 1px solid var(--rule); }
.step { padding: 20px; }
.cells { display: flex; gap: 4px; }
.cells span { flex: 1; height: 8px; border-radius: 999px; background: var(--sunk); }
.cells .on { background: var(--teal); }
.cells .skip { background: var(--stop); }
.cells .now { background: var(--accent); }
.meta { margin-top: 10px; font-size: 14px; color: var(--muted); }
.step h2 { margin-top: 2px; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.hint { margin-top: 4px; font-size: 14px; color: var(--muted); }
.well {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  margin: 16px 0;
  padding: 10px 14px;
  border-radius: var(--radius-tile);
  background: var(--sunk);
  font-size: 15px;
}
.well small { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.well .num { white-space: nowrap; font-weight: 600; }

/* ---------- Log (ledger of steps) ---------- */
/* Real tables (Log and the Record recap): columns size to their content, so a "+1d" time,
   a six-figure odometer or "No returns" never runs into the next column. */
.ledger, .recap .card { overflow: hidden; }
.ledger table, .recap table { width: 100%; border-collapse: collapse; }
.ledger th, .ledger td, .recap td { padding: 0 0 0 12px; white-space: nowrap; }
.ledger th:first-child, .ledger td:first-child, .recap td:first-child { padding-left: 20px; }
.recap td:last-child { padding-right: 20px; }
.ledger th { height: 44px; font-size: 13px; font-weight: 500; color: var(--muted); text-align: left; }
.ledger td { height: 52px; border-top: 1px solid var(--rule); font-size: 16px; }
.ledger .num, .recap .num { text-align: right; }
.ledger td.num { font-weight: 600; }
.ledger .icon { width: 16px; padding-right: 16px; }
td.name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; } /* takes the spare width */
tr.now td.name { color: var(--accent); font-weight: 600; }
tr.todo td.name { color: var(--muted); }
.ledger tr[role="button"] { cursor: pointer; }
.ledger tr[role="button"]:hover td { background: var(--raised); }
.ledger tr[role="button"]:active td { background: var(--sunk); }
.plus-day { margin-left: 2px; font-size: 11px; color: var(--muted); vertical-align: 3px; }
.row-icon { display: block; width: 16px; height: 16px; color: var(--muted); }
.foot { padding: 0 4px; font-size: 14px; color: var(--muted); }

/* ---------- Summary ---------- */
.lead { padding: 20px; }
.lead p { font-size: 14px; color: var(--muted); }
.lead-fig { display: block; margin: 4px 0; font-size: 36px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.lead-fig small { margin-left: 4px; font-size: 18px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.lead .tiles { margin-top: 16px; }

.day { padding: 20px 20px 8px; }
.day h2 { font-size: 16px; font-weight: 600; }

.strip { position: relative; margin: 14px 0 6px; padding-top: 24px; }
.paid { position: absolute; top: 0; height: 18px; border: 1px dashed var(--muted); border-bottom: 0; border-radius: 6px 6px 0 0; }
.paid span { position: absolute; left: 6px; top: 1px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.track { position: relative; height: 24px; border-radius: 6px; background: var(--sunk); overflow: hidden; }
.seg { position: absolute; top: 0; bottom: 0; border-right: 2px solid var(--surface); }
.seg.drive, .swatch.drive { background: var(--teal); }
.seg.stop, .swatch.stop { background: var(--stop); }
.seg.main, .swatch.main { background: var(--accent); }
.seg.whole { background: var(--stop); }
.legs-none { padding: 6px 0 12px; }
.axis { position: relative; height: 18px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.axis span { position: absolute; top: 0; transform: translateX(-50%); }
.axis span.start { transform: none; }
.axis span.end { transform: translateX(-100%); }

.legs { width: 100%; border-collapse: collapse; font-size: 15px; }
.legs th { height: 32px; font-size: 13px; font-weight: 500; color: var(--muted); text-align: left; }
.legs td { height: 36px; border-top: 1px solid var(--rule); }
.legs .num { text-align: right; }
.legs td.num { font-weight: 600; }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 10px; border-radius: 3px; vertical-align: 0; }

/* Block facts beside the tracker on desktop. */
.facts { padding: 20px; }
.facts h2 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.facts dl { display: grid; grid-template-columns: auto 1fr; margin: 0; }
.facts dt, .facts dd { padding: 10px 0; border-top: 1px solid var(--rule); font-size: 15px; }
.facts dt:first-of-type, .facts dd:first-of-type { border-top: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; padding-left: 16px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.facts .text-btn { margin: 8px 0 0 -16px; }

/* ---------- Settings ---------- */
main > .card.rows, .card.rows { overflow: hidden; }
#station-form label { margin-bottom: 12px; }
.setting { padding: 20px 20px 4px; }
.setting-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.setting h2 { font-size: 18px; font-weight: 600; }
.saved { font-size: 14px; color: var(--positive); font-weight: 500; }
.setting .well { margin: 4px 0 16px; }

/* Week start: one row of day buttons (radios underneath, so it is still a radio group). */
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin: 16px 0; }
.weekday { position: relative; margin: 0; }
.weekday input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; opacity: 0; cursor: pointer; }
.weekday span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  border-radius: 999px;
  background: var(--sunk);
  font-size: 14px;
  font-weight: 600;
  transition: background-color 120ms ease;
}
.weekday:hover span { background: var(--active); }
.weekday input:checked + span { background: var(--accent-soft); color: var(--accent-ink); }
.weekday input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Menu and data rows: two-line rows, each a link, a download or a picker. */
.rows { margin: 12px -20px 0; }
.card.rows { margin: 0 0 var(--gap); }
.row-link {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  margin: 0;
  padding: 10px 20px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease;
}
.row-link + .row-link, .row-link + input + .row-link { border-top: 1px solid var(--rule); }
.row-link:hover { background: var(--raised); }
.row-link:active { background: var(--sunk); }
button.row-link {
  width: 100%;
  border: 0;
  background: none;
  font-family: var(--font);
  text-align: left;
}
.row-link.destructive, .row-link.destructive .row-icon { color: var(--negative); }
.sheet .rows { margin: 0 -20px 12px; }
.sheet a.btn { width: 100%; margin-bottom: 8px; }

/* ---------- Import from MySQL ---------- */
select.wide { display: block; width: 100%; margin-top: 8px; padding: 0 14px; text-align: left; }
.map { padding: 0 20px; }
.map-row { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.map-row select.wide { min-height: 44px; }
.map-row + .map-row { border-top: 1px solid var(--rule); }
.map-label { flex: 1 1 45%; min-width: 0; display: flex; flex-direction: column; font-size: 15px; font-weight: 600; }
.map-label small { font-size: 13px; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-row select.wide { flex: 1 1 55%; min-width: 0; margin: 0; font-size: 15px; }
.form-error { margin: 0 4px; font-size: 14px; color: var(--negative); }
.row-link > span { flex: 1; display: flex; flex-direction: column; }
.row-link small { font-size: 14px; font-weight: 400; color: var(--muted); }
.row-link .row-icon { width: 20px; height: 20px; }
.sheet .note { margin: 6px 0 14px; font-size: 14px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); padding: 8px; gap: 8px; }
.kpis div { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; min-width: 0; border-radius: var(--radius-tile); background: var(--sunk); }
.kpis span { font-size: 13px; color: var(--muted); }
.kpis strong { font-size: 20px; font-weight: 600; }

/* ---------- Bottom sheet ---------- */
dialog {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 -8px 32px rgb(0 0 0 / 0.18); /* the sheet floats */
}
dialog[open] { animation: sheet-in 200ms ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet { padding: 24px 20px calc(16px + env(safe-area-inset-bottom)); }
.sheet h2 { margin-bottom: 16px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.sheet .hint { margin: -8px 0 16px; }
.sheet .btn { width: 100%; }
.sheet .btn.primary { margin-bottom: 8px; }
.sheet .btn.secondary { background: var(--sunk); }
.sheet .grid-2 { gap: 8px; }

/* Short phones: keep the list in view by dropping the summary's tiles. */
@media (max-height: 700px) and (max-width: 1023px) {
  .sum .tiles { display: none; }
  .sum { padding: 16px 20px; }
}

@media (min-width: 600px) {
  dialog { margin: auto; border-radius: 24px; }
}

/* ---------- Desktop: sidebar + canvas ---------- */
@media (min-width: 1024px) {
  body { display: grid; grid-template-columns: 240px minmax(0, 1fr); }
  .side {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: 28px 12px 24px;
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 0 12px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; text-decoration: none; }
  .nav { display: flex; flex-direction: column; gap: 2px; margin-top: 32px; }
  .nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 40px;
    padding: 0 12px;
    border-radius: 12px;
    color: var(--muted);
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 120ms ease, color 120ms ease;
  }
  .nav a svg { width: 18px; height: 18px; }
  .nav a:hover { background: var(--sunk); color: var(--text); }
  .nav a[aria-current="page"] { background: var(--active); color: var(--text); }
  .side-foot { margin-top: auto; padding: 0 12px; font-size: 13px; color: var(--muted); }

  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "bar actions" "tabs tabs" "main main";
    column-gap: 24px;
    max-width: 1200px;
    height: 100dvh;
    margin: 0;
    padding: 0 40px;
  }
  .bar { grid-area: bar; min-height: 0; padding: 36px 0 0; }
  .bar-mark { display: none; }
  .bar-title { padding: 0; }
  .bar .icon-btn:first-child { margin-left: -12px; }
  .bar-title h1 { font-size: 28px; }
  #app > .tabs { grid-area: tabs; justify-self: start; min-width: 360px; margin: 24px 0 0; }
  main { grid-area: main; padding: 24px 0 32px; }
  .actions { grid-area: actions; align-self: end; padding: 36px 0 0; background: none; }
  body.top .actions { padding-bottom: 0; }
  .actions .btn { min-height: 44px; font-size: 15px; }
  .actions .btn.primary { flex: none; padding: 0 22px; }
  .actions .btn.square { width: 44px; }
  .actions .btn.secondary, .actions .btn.square { background: var(--surface); }

  .cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; height: 100%; }
  .col-main { min-height: 0; height: 100%; display: flex; flex-direction: column; }
  .col-side, .col-side.desk, .desk-only { order: 0; display: block; }
  main.stack .cols { display: grid; }
  .col-main > .card:last-child { margin-bottom: 0; }

  /* Forms and settings: a label column (help, current values) beside the panel. */
  .split { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 24px; align-items: start; max-width: 1120px; }
  .split + .split { margin-top: 32px; padding-top: 32px; border-top: 1px solid var(--border); }
  .split-label { display: block; padding-top: 20px; }
  .split-label h2 { font-size: 18px; font-weight: 600; }
  .split-label p { margin-top: 6px; font-size: 15px; color: var(--muted); }
  .split-label p + p { margin-top: 10px; }
  .split > .card, .split > div > .card { margin-bottom: 0; }

  main.stack { overflow: hidden; }
  dialog { max-width: 520px; }
}

@media (prefers-reduced-motion: reduce) {
  html, .btn, .tab, .length, .list-row, .row-link { transition: none; }
  .btn:active:not(:disabled), .length:active:not(:disabled) { transform: none; }
  dialog[open] { animation: none; }
}

/* Stations compared: a short table under the list. */
.foot + .compare { margin-top: var(--gap); }
.compare th:last-child, .compare td:last-child { padding-right: 20px; }
.compare h2 { padding: 18px 20px 2px; font-size: 16px; font-weight: 600; }

/* Remove block: a quiet destructive text action, under the Log and in the block's facts. */
.text-btn.destructive { color: var(--negative); }
.remove-block { margin: 12px 0 0 -12px; }
.facts .text-btn.destructive { margin: 8px 0 0 -16px; }
@media (min-width: 1024px) { .remove-block { display: none; } } /* the facts card has it beside the Log */

/* What a block's fuel cost was worked out from, under its tiles. */
.fuel-note { margin-top: 12px; font-size: 13px; color: var(--muted); }

/* Pay still to come, at the foot of the week card. */
.coming { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule); }
.coming > span { display: flex; flex-direction: column; font-size: 15px; font-weight: 600; }
.coming small { font-size: 13px; font-weight: 400; color: var(--muted); }
.coming strong { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--accent-ink); }

/* A calendar week with nothing in it keeps its heading and says so. */
.week-empty { padding: 4px 20px 20px; font-size: 15px; color: var(--muted); }

/* Four tiles sit two by two, so the figures keep their size on a phone and in the side column. */
.tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------- Report ---------- */
.report-grid { display: grid; gap: var(--gap); }
.report-grid .card { margin-bottom: 0; }
.report h2 { padding: 18px 20px 0; font-size: 16px; font-weight: 600; }
.report-sub { padding: 2px 20px 6px; font-size: 13px; color: var(--muted); }
.report td { height: 58px; }
.report td small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); line-height: 1.3; }
.report td.num { font-weight: 500; }
.report td.strong { font-weight: 600; }
.report th:last-child, .report td:last-child { padding-right: 20px; }
.report-grid + .foot { margin-top: var(--gap); }
@media (min-width: 1024px) { .report-grid { grid-template-columns: 1fr 1fr; align-items: start; } }

/* A block's pay after fuel against the average for its length. */
.compare-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-tile); background: var(--sunk); }
.compare-row > span { display: flex; flex-direction: column; font-size: 15px; font-weight: 600; }
.compare-row small { font-size: 13px; font-weight: 400; color: var(--muted); }
.compare-row strong { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.compare-row strong.up { color: var(--positive); }
.compare-row strong.down { color: var(--negative); }
.row-fig small.up { color: var(--positive); font-weight: 600; }
.row-fig small.down { color: var(--negative); font-weight: 600; }

/* ---------- Live page (/live.html): one block followed from elsewhere ---------- */
body.live { display: block; height: auto; min-height: 100%; overflow-y: auto; }
html:has(body.live) { overflow-y: auto; }
.live-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 960px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px 8px; }
.live-brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; }
.live-state { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--muted); }
.live-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--stop); }
.live-state[data-mode="live"]::before { background: var(--positive); animation: live-pulse 2s ease-in-out infinite; }
@keyframes live-pulse { 50% { opacity: 0.35; } }
.live-main { max-width: 960px; margin: 0 auto; padding: 8px 16px 32px; }
.live-now { padding: 24px 20px 20px; }
.live-now h1 { font-size: 30px; font-weight: 600; line-height: 1.15; letter-spacing: -0.02em; }
.live-since { margin: 6px 0 16px; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.live-steps h2 { padding: 18px 20px 6px; font-size: 16px; font-weight: 600; }
.live-steps tr.done td.num { font-weight: 600; }
.live-steps td:last-child { padding-right: 20px; }
.live-next { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: var(--radius-tile); background: var(--accent-soft); color: var(--accent-ink); }
.live-next > span { display: flex; flex-direction: column; font-weight: 600; }
.live-next small { font-size: 13px; font-weight: 400; }
.live-next strong { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
@media (min-width: 900px) {
  .live-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }
  .live-main .card { margin-bottom: 0; }
  .live-bar, .live-main { padding-left: 32px; padding-right: 32px; }
}
@media (prefers-reduced-motion: reduce) { .live-state[data-mode="live"]::before { animation: none; } }
.live-share { padding-bottom: 20px; }
.live-share .well .num { white-space: normal; overflow-wrap: anywhere; text-align: right; }
.live-share .btn { min-height: 44px; font-size: 15px; }
.live-now .tile span { white-space: normal; }

/* ---------- Sign in ---------- */
body.auth .side, body.auth .tabbar { display: none !important; }
.auth-main { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; margin: 0; padding: 28px 24px 20px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; font-size: 18px; font-weight: 600; }
.auth-card h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.auth-card .hint { margin: 4px 0 20px; }
.auth-card .btn { width: 100%; margin-top: 4px; }
.auth-card .form-error { margin: 0 0 12px; }
.auth-switch { margin-top: 16px; font-size: 14px; color: var(--muted); text-align: center; }
.auth-switch .text-btn { min-height: 40px; padding: 0 8px; font-size: 14px; color: var(--accent); }
.account { padding-bottom: 20px; }
.account .btn { width: 100%; min-height: 44px; font-size: 15px; margin-top: 12px; }
.live-share .text-btn { margin: 8px 0 0 -16px; }
@media (min-width: 1024px) { body.auth { display: block; } body.auth #app { display: block; max-width: none; padding: 0; } }
/* Secondary buttons sitting inside a white card take the grey fill, so they read as buttons. */
.card .btn.secondary { background: var(--sunk); }
.card .btn.secondary:hover:not(:disabled) { background: var(--active); }
.live-share .well { grid-template-columns: 1fr; }
.live-share .well .num { text-align: left; font-weight: 500; }
