:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #0f1b2a;
  --muted: #5b6b7d;
  --border: #d9e1e8;
  --brand: #0c4a6e;
  --brand-2: #0369a1;
  --accent: #0ea5e9;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef9c3;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 27, 42, 0.06), 0 4px 16px rgba(15, 27, 42, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1420;
    --surface: #121e2c;
    --surface-2: #182739;
    --text: #e6eef6;
    --muted: #93a5b8;
    --border: #253649;
    --brand: #7dd3fc;
    --brand-2: #38bdf8;
    --accent: #38bdf8;
    --ok: #4ade80;
    --ok-bg: #0f2e1c;
    --warn: #facc15;
    --warn-bg: #2e2708;
    --bad: #f87171;
    --bad-bg: #3a1414;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
}
a { color: var(--brand-2); }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
[hidden] { display: none !important; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: var(--brand); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #0a2a40; } }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; margin-right: auto; }
.brand svg { width: 22px; height: 22px; fill: #7dd3fc; }
nav { display: flex; gap: 2px; overflow-x: auto; max-width: 100%; }
nav a {
  color: #d6ecfa; text-decoration: none; padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: 0.95rem;
  display: flex; align-items: center;
}
nav a:hover { background: rgba(255, 255, 255, 0.1); }
nav a.active { background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 600; }
.icon { width: 18px; height: 18px; }
@media (max-width: 560px) {
  .topbar { padding: 10px 10px 6px; gap: 6px; }
  nav { width: 100%; justify-content: space-between; gap: 0; flex-wrap: wrap; overflow: visible; }
  nav a { padding: 6px 6px; font-size: 0.875rem; }
}

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* ---------- cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 0.85rem; }
.chart-box { position: relative; height: 320px; }
@media (max-width: 560px) { .chart-box { height: 260px; } }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; border: 1px solid transparent; }
.banner.due { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.done { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.banner strong { display: block; }

/* ---------- buttons & forms */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
button:hover, .btn:hover { background: var(--surface-2); }
button.primary, .btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { button.primary, .btn.primary { color: #062033; } }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); background: var(--brand-2); }
button.danger { color: var(--bad); }
button.big, .btn.big { padding: 14px 20px; font-size: 1.05rem; width: 100%; }
button.link { border: 0; background: none; padding: 0; color: var(--brand-2); text-decoration: underline; }
button:disabled { opacity: 0.55; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.reading { font-size: 1.8rem; font-weight: 700; letter-spacing: 0.06em; padding: 10px 14px; }
input[type='checkbox'] { width: auto; }
.check { display: flex; gap: 8px; align-items: center; }
select.inline { width: auto; }

.msg { border-radius: 10px; padding: 10px 14px; margin: 10px 0; font-size: 0.95rem; }
.msg.error { background: var(--bad-bg); color: var(--bad); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.info { background: var(--surface-2); }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
th:first-child, td:first-child { text-align: left; }
td.left, th.left { text-align: left; }
tr.interim td { color: var(--muted); font-style: italic; }
td.total { font-weight: 700; }
td.flag { color: var(--warn); }
td input { min-width: 120px; text-align: right; }
.pill { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-style: normal; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; vertical-align: middle; }

/* ---------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--brand-2); font-weight: 600; }

/* ---------- login */
.login { max-width: 420px; margin: 6vh auto 0; }
.login .logo { text-align: center; margin-bottom: 18px; }
.login .logo svg { width: 54px; height: 54px; fill: var(--accent); }
.login h1 { text-align: center; }
.hh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.hh-grid button { padding: 16px 10px; font-weight: 600; font-size: 1.05rem; }
.hh-grid button.selected { border-color: var(--brand-2); background: color-mix(in srgb, var(--brand-2) 12%, var(--surface)); }
input.pin { font-size: 2rem; letter-spacing: 0.5em; text-align: center; padding: 10px; }

/* ---------- submit */
.photo-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer; background: var(--surface-2);
}
.photo-drop:hover { border-color: var(--brand-2); }
.photo-drop svg { width: 40px; height: 40px; stroke: var(--brand-2); }
.photo-preview { width: 100%; max-height: 420px; object-fit: contain; border-radius: var(--radius); background: #000; display: block; }
.calc-line { font-size: 0.95rem; margin: -6px 0 14px; }
.two-col { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; align-items: start; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- toast & modal */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #0f1b2a; color: #fff; padding: 10px 18px; border-radius: 10px; transition: 0.2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; max-width: min(560px, calc(100% - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto 12px; border-radius: 8px; }
.pin-big { font-size: 2.4rem; font-weight: 800; letter-spacing: 0.2em; text-align: center; margin: 12px 0; }

/* ---------- billing */
.money { font-variant-numeric: tabular-nums; }
tr.total-row td { font-weight: 700; border-top: 2px solid var(--border); }
.bill-meta { display: flex; gap: 6px 18px; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); margin-bottom: 12px; }
.bill-meta strong { color: var(--text); }
.inline-form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.inline-form label.field { margin: 0; }
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .topbar, #toast, .no-print, body.printing .card:not(.print-target), body.printing .page-head, body.printing .banner { display: none !important; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .print-only { display: block; }
  th, td { color: #000 !important; }
}

code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.85em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; word-break: break-all; }
ol.small li { margin-bottom: 8px; }

/* ---------- header tank meter (battery style) */
.tank-meter { display: flex; align-items: center; gap: 8px; color: #e0f2fe; text-decoration: none; padding: 4px 6px; border-radius: 8px; white-space: nowrap; }
.tank-meter:hover { background: rgba(255, 255, 255, 0.1); }
.tm-battery {
  position: relative; width: 62px; height: 22px; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 5px;
  padding: 2px; display: inline-block; box-sizing: border-box;
}
.tm-battery::after { content: ''; position: absolute; right: -6px; top: 5px; width: 4px; height: 8px; border-radius: 0 2px 2px 0; background: rgba(255, 255, 255, 0.85); }
.tm-fill { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--tm-color, #4ade80); transition: width 0.6s ease; }
.tm-pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 800; color: #fff; text-shadow: 0 0 3px rgba(0, 0, 0, 0.9), 0 0 1px #000; }
.tm-gal { font-size: 0.85rem; font-weight: 600; }
.tank-meter.ok { --tm-color: #4ade80; }
.tank-meter.mid { --tm-color: #fbbf24; }
.tank-meter.low { --tm-color: #f87171; }
.tank-meter.stale { --tm-color: #94a3b8; }
.tank-meter.stale .tm-gal::after { content: ' ⚠'; }
@media (max-width: 380px) { .tm-gal { display: none; } }
