:root {
  color-scheme: light dark;
  --bg: #f3f6f8;
  --card: #ffffff;
  --ink: #1d2a33;
  --muted: #66757f;
  --line: #e2e8ec;
  --rose: #0e6e80;       /* accent (name kept for shared CSS) */
  --rose-ink: #ffffff;
  --rose-soft: #dcebef;
  --pain: #1497a8;
  --warn-bg: #fff4e0;
  --warn-ink: #7a4b00;
  --err: #b4233c;
  --shadow: 0 6px 22px rgba(20, 50, 70, 0.08);
  --radius: 18px;
  --tab-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a20; --card: #18262e; --ink: #eef4f7; --muted: #9db0ba; --line: #2a3a44;
    --rose: #3fb6c8; --rose-ink: #06232a; --rose-soft: #1f3a44; --pain: #3fb6c8;
    --warn-bg: #3a2c16; --warn-ink: #f3cf8f; --err: #ff8a9b; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; }
.app-shell main {
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 560px;
  margin: 0 auto;
}
.page-title { font-size: 1.9rem; font-weight: 750; letter-spacing: -0.02em; margin: 8px 4px 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.12rem; margin-bottom: 6px; }
.card h3 { font-size: 0.95rem; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }
.lead { color: var(--muted); line-height: 1.45; margin: 4px 0 14px; }
.small { color: var(--muted); font-size: 0.88rem; line-height: 1.45; margin: 6px 0; }
.meta { color: var(--muted); font-size: 0.88rem; margin: 10px 0 0; min-height: 1em; }
.center { text-align: center; }
.note { background: var(--rose-soft); border-radius: 14px; padding: 12px 14px; font-size: 0.92rem; margin: 0 0 12px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; line-height: 1.45; }
.disclaimer { color: var(--muted); font-size: 0.78rem; margin: 12px 0 0; }

/* buttons */
.btn-primary, .btn-secondary, .btn-danger, .btn-danger-soft {
  display: block; width: 100%; min-height: 50px; border-radius: 14px; border: 0;
  font-size: 1.02rem; font-weight: 600; padding: 12px 16px; text-align: center;
}
.btn-primary { background: var(--rose); color: var(--rose-ink); }
.btn-primary:disabled { opacity: 0.5; }
.btn-secondary { background: var(--rose-soft); color: var(--ink); }
.btn-danger { background: #c2334f; color: #fff; }
.btn-danger-soft { background: transparent; color: #c2334f; border: 1.5px solid currentColor; }
@media (prefers-color-scheme: dark) { .btn-danger-soft { color: #ff8aa0; } }
.btn-ghost { background: none; border: 0; color: var(--rose); font-weight: 600; padding: 14px; margin-top: 6px; }
.btn-col { display: grid; gap: 10px; }
.file-btn { display: flex; align-items: center; justify-content: center; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--card);
  font-size: 1.8rem; line-height: 1; box-shadow: var(--shadow); color: var(--rose);
}
.info-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--muted); background: transparent;
  color: var(--muted); font-weight: 700; font-style: italic; font-family: Georgia, serif; flex: none; padding: 0;
}

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line);
}
.tab { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.78rem; color: var(--muted); min-height: 52px; font-weight: 600; }
.tab .ti { font-size: 1.35rem; line-height: 1.2; }
.tab.active { color: var(--rose); }

/* modal + toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 10, 12, 0.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--card); border-radius: 22px; padding: 22px; max-width: 420px; width: 100%; max-height: 86vh; overflow-y: auto; }
.modal-card h2 { font-size: 1.2rem; margin-bottom: 10px; }
#modal-body { color: var(--ink); line-height: 1.5; margin-bottom: 18px; }
#modal-body p { margin: 0 0 10px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 60; font-weight: 600; font-size: 0.92rem;
}

/* lock screen */
.lock-screen { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto; }
.lock-card { width: 100%; max-width: 360px; text-align: center; }
.lock-card .logo { border-radius: 16px; margin-bottom: 14px; }
.lock-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.lock-field { display: block; text-align: left; margin: 14px 0; }
.lock-field span { display: block; font-weight: 600; margin-bottom: 6px; color: var(--muted); font-size: 0.9rem; }
.lock-field input {
  display: block; width: 100%; font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; padding: 12px;
  border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
}
.lock-field input:focus { outline: none; border-color: var(--rose); }
.pin-input { -webkit-text-security: disc; text-security: disc; }
.pin-input.reveal { -webkit-text-security: none; text-security: none; }
.pin-show { display: flex; gap: 0.5rem; align-items: center; font-size: 0.92rem; margin: 4px 0 8px; color: var(--muted); }
.pin-show input { width: 20px; height: 20px; accent-color: var(--rose); }
.lock-error { color: #c2334f; min-height: 1.3em; font-size: 0.92rem; margin: 6px 0; }
@media (prefers-color-scheme: dark) { .lock-error { color: #ff8aa0; } }
#lock-form .btn-secondary { margin-top: 10px; }

/* forms */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.year-select { font: inherit; font-size: 1.05rem; font-weight: 650; padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); min-height: 44px; }
.form { display: grid; gap: 12px; }
.f { display: block; }
.f > span { display: block; font-size: 0.86rem; font-weight: 650; color: var(--muted); margin-bottom: 5px; }
.f input, .f select, .f textarea {
  width: 100%; font: inherit; font-size: 17px; padding: 12px 14px; min-height: 50px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); -webkit-appearance: none; appearance: none;
}
.f textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.f input:focus, .f select:focus, .f textarea:focus { outline: none; border-color: var(--rose); }
.route { display: grid; grid-template-columns: 1fr; gap: 6px; position: relative; }
.swap { position: absolute; right: 8px; top: 50%; transform: translateY(-30%); z-index: 2; width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card); color: var(--rose); font-size: 1.2rem; }
.route .f:first-child input, .route .f:last-child input { padding-right: 56px; }
.km-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.km-row input { font-variant-numeric: tabular-nums; font-size: 1.15rem; }
.km-live { text-align: center; font-size: 1.6rem; font-weight: 760; padding: 8px; border-radius: 14px; background: var(--rose-soft); color: var(--muted); font-variant-numeric: tabular-nums; }
.km-live.ok { color: var(--rose); }
.km-live.bad { color: var(--err); font-size: 1rem; }
.messages:empty { display: none; }
.msg { margin: 0 0 6px; padding: 10px 12px; border-radius: 12px; font-size: 0.9rem; line-height: 1.4; }
.msg.warn { background: var(--warn-bg); color: var(--warn-ink); }
.msg.err { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err); font-weight: 600; }
.btn-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.btn-row:has(#btn-cancel-edit:not([hidden])) { grid-template-columns: 1fr 1fr; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.btn-quick { flex: none; border: 0; border-radius: 999px; background: var(--rose); color: var(--rose-ink); font-weight: 700; padding: 10px 16px; min-height: 44px; }
.tpl-chips { display: flex; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; min-height: 40px; font-size: 0.92rem; white-space: nowrap; }
.chip.tpl { min-height: 44px; font-weight: 600; }
.chip small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.btn-danger-soft { display: block; width: 100%; min-height: 48px; border-radius: 14px; background: transparent; color: var(--err); border: 1.5px solid currentColor; font-weight: 600; font-size: 1rem; }
.btn-secondary.file-btn { display: flex; align-items: center; justify-content: center; }
.link-danger { background: none; border: 0; color: var(--err); font-weight: 600; padding: 8px; min-height: 40px; }

/* trips list */
.year-total { color: var(--muted); margin: -6px 4px 8px; }
.month { margin-top: 18px; }
.m-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.05rem; margin: 0 4px 6px; }
.m-sum { font-size: 0.88rem; font-weight: 500; color: var(--muted); }
.m-sum b { color: var(--ink); }
.trips { list-style: none; margin: 0; padding: 4px 0; }
.trips.card { padding: 4px 0; margin: 0; }
.trip { width: 100%; text-align: left; background: none; border: 0; padding: 12px 16px; display: grid; gap: 3px; border-bottom: 1px solid var(--line); }
.trips li:last-child .trip { border-bottom: 0; }
.t-top { display: flex; justify-content: space-between; align-items: baseline; }
.t-date { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.t-km { font-weight: 760; font-variant-numeric: tabular-nums; color: var(--rose); font-size: 1.05rem; }
.t-route { font-weight: 650; font-size: 1.02rem; }
.t-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.82rem; color: var(--muted); align-items: center; font-variant-numeric: tabular-nums; }
.t-note { font-size: 0.88rem; color: var(--ink); background: var(--bg); border-left: 3px solid var(--rose); border-radius: 6px; padding: 6px 9px; margin-top: 4px; white-space: pre-wrap; }
.tag { background: var(--rose-soft); color: var(--ink); border-radius: 999px; padding: 2px 9px; font-weight: 600; font-size: 0.78rem; }
.recent .trips { margin: 0 -18px; }

/* year */
.hero { background: linear-gradient(135deg, #0b4f63, #0f7f8c); color: #fff; }
.hero .kicker { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.76rem; font-weight: 700; opacity: 0.85; }
.hero .big { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em; margin: 4px 0; font-variant-numeric: tabular-nums; }
.hero .sub { opacity: 0.9; }
.estimate { margin: 12px 0 4px; font-size: 1.05rem; }
.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; }
.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; }
.bars li { display: grid; grid-template-columns: 2.6em 1fr 4.5em; align-items: center; gap: 10px; font-size: 0.9rem; }
.b-v { text-align: right; font-variant-numeric: tabular-nums; }
progress { width: 100%; height: 12px; appearance: none; -webkit-appearance: none; border: 0; border-radius: 6px; background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 6px; }
progress::-webkit-progress-value { background: var(--pain); border-radius: 6px; }
progress::-moz-progress-bar { background: var(--pain); }
.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.kv li:last-child { border-bottom: 0; }
.vlist { list-style: none; padding: 0; margin: 0 0 12px; }
.vlist li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.radio { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.radio input { width: 22px; height: 22px; accent-color: var(--rose); }
.vehicle-add { display: grid; gap: 10px; }
.small { color: var(--muted); font-size: 0.88rem; line-height: 1.45; margin: 6px 0; }
.btn-danger { background: #b4233c; color: #fff; }

/* print view (only visible when printing) */
.print-view { display: none; }
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body.printing .app-shell, body.printing .lock-screen, body.printing .modal, body.printing .toast { display: none !important; }
  body.printing .print-view { display: block !important; color: #000; background: #fff; font: 9pt/1.35 -apple-system, Helvetica, Arial, sans-serif; }
  html, body { background: #fff !important; }
}
.print-view h1 { font-size: 18pt; margin: 0 0 4px; }
.print-view .pv-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.print-view .pv-head p { margin: 0; }
.print-view .pv-total { font-size: 13pt; font-weight: 700; text-align: right; color: #0e5e6e; }
.print-view .pv-total span { font-size: 10pt; font-weight: 500; color: #333; }
.print-view table { width: 100%; border-collapse: collapse; }
.print-view th { background: #0e5e6e; color: #fff; text-align: left; padding: 3px 4px; font-size: 8.5pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.print-view td { border-bottom: 0.5pt solid #ccd; padding: 3px 4px; vertical-align: top; }
.print-view thead { display: table-header-group; }
.print-view tr { break-inside: avoid; page-break-inside: avoid; }
.print-view .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.print-view .note { white-space: pre-wrap; background: none; color: inherit; padding: 3px 4px; border-radius: 0; font-size: inherit; }
.print-view tfoot td:first-child { text-align: right; }
.print-view tr.sub td { background: #e8f1f3; font-weight: 700; text-align: right; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.print-view tfoot td { font-weight: 700; background: #d6e6ea; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.print-view .pv-sum { break-before: auto; break-inside: avoid; margin-top: 14px; }
.print-view .pv-sum h2 { font-size: 12pt; margin: 0 0 6px; }
.print-view .pv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.print-view .pv-note { font-size: 8pt; color: #555; }
