:root {
  color-scheme: dark;
  --bg: #121316;
  --surface: #1b1d21;
  --surface-2: #25282e;
  --line: #33373e;
  --ink: #f2f1ec;
  --ink-2: #b9bbc0;
  --ink-3: #8d9097;
  --accent: #ff6a00;
  --on-accent: #16120d;
  --red: #ff6b5e;
  --red-bg: #3a1c1a;
  --amber: #f5b83d;
  --amber-bg: #372b12;
  --green: #5bcf8c;
  --green-bg: #15301f;
  --grey-bg: #2b2e34;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 62px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f3ef;
    --surface: #ffffff;
    --surface-2: #ecebe5;
    --line: #d9d7cf;
    --ink: #17181b;
    --ink-2: #4c4f55;
    --ink-3: #6a6d74;
    --red: #bf2a1d;
    --red-bg: #fbe5e2;
    --amber: #8a5a00;
    --amber-bg: #fbeecd;
    --green: #17703f;
    --green-bg: #dff3e6;
    --grey-bg: #e8e7e1;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
main { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px 32px; }
main.with-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 92px); }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.loading { padding: 48px 0; color: var(--ink-2); text-align: center; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

#banner {
  background: var(--amber-bg); color: var(--amber);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; font-size: 14px; text-align: center;
}
#banner + main { padding-top: 8px; }

/* Barra de topo */
.topbar { display: flex; align-items: center; gap: 8px; min-height: 52px; margin-bottom: 8px; }
.topbar h1 { font-size: 20px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar.home h1 { font-size: 28px; letter-spacing: -0.02em; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  background: none; border: 0; border-radius: 12px; color: var(--ink);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }

/* Secções e cartões */
section { margin-top: 24px; }
section:first-of-type { margin-top: 8px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sec-head h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; }
.card + .card { margin-top: 8px; }
.card.notice { background: var(--surface-2); }
.card h3 { font-size: 16px; font-weight: 650; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.tiny { font-size: 13px; color: var(--ink-2); }
.stack > * + * { margin-top: 8px; }
.links a { display: inline-block; padding: 6px 0; margin-right: 16px; font-size: 14px; color: var(--ink-2); }
.empty { padding: 24px 16px; text-align: center; color: var(--ink-2); background: var(--surface); border-radius: var(--radius); }

/* Listas */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; min-height: 56px;
  padding: 12px 16px; text-align: left; background: none; border: 0; text-decoration: none;
}
.list .row + .row, .list .row + .sub-head, .list .sub-head + .row { border-top: 1px solid var(--line); }
button.row:active, a.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; }
.row-end { flex: none; text-align: right; font-size: 14px; }
.row-end b { display: block; font-size: 16px; font-weight: 650; }
.dot { flex: none; width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--bike, var(--accent)); }
.sub-head { padding: 12px 16px 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }

.list.group + .list.group { margin-top: 8px; }
.group-head { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; background: var(--surface-2); }
.row.compact { min-height: 44px; padding: 10px 16px; font-size: 15px; align-items: center; }
.row.compact.action { justify-content: center; gap: 8px; font-weight: 600; color: var(--ink); }
.row.compact.action svg { width: 20px; height: 20px; color: var(--bike); }
.list .group-head + .row { border-top: 0; }

/* Estados: sempre com ícone e texto, nunca só cor */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap; background: var(--grey-bg); color: var(--ink-2);
}
.pill.overdue { background: var(--red-bg); color: var(--red); }
.pill.soon { background: var(--amber-bg); color: var(--amber); }
.pill.ok, .pill.done { background: var(--green-bg); color: var(--green); }

/* Cartão de mota */
.bike-card {
  display: block; position: relative; overflow: hidden; text-decoration: none; padding-left: 20px;
  background: var(--surface); border-radius: var(--radius); padding-top: 14px; padding-bottom: 14px; padding-right: 16px;
}
.bike-card + .bike-card { margin-top: 8px; }
.bike-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--bike); }
.bike-card:active { background: var(--surface-2); }
.bike-card h3 { font-size: 18px; font-weight: 700; }
.bike-stats { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 6px; }
.bike-stats b { font-size: 18px; font-weight: 600; }
.bike-stats span { font-size: 13px; color: var(--ink-2); margin-left: 3px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* Conta-quilómetros */
.odo { background: var(--surface); border-radius: var(--radius); padding: 16px; border-top: 4px solid var(--bike); }
.odo-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 24px; }
.odo-val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 38px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.odo-val small { font-family: var(--sans); font-size: 16px; font-weight: 500; letter-spacing: 0; color: var(--ink-2); margin-left: 4px; }
.odo .btn { margin-top: 12px; }

/* Grelha de números */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tile b { display: block; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.tile span { font-size: 13px; color: var(--ink-2); }

table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th { font-weight: 500; text-align: left; color: var(--ink-2); font-size: 13px; padding: 4px 0; }
table.data th:not(:first-child), table.data td:not(:first-child) { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data td { padding: 6px 0; border-top: 1px solid var(--line); }
table.data tfoot td { font-weight: 650; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; text-decoration: none;
}
.btn:active { filter: brightness(1.2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { background: none; border-color: var(--line); color: var(--red); }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1 1 auto; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px; margin: 0 -2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: none; color: var(--ink-2); font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* Navegação inferior e botão de registo */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; min-width: 0; max-width: 128px; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 12px; font-weight: 600; color: var(--ink-3); text-decoration: none;
}
.bottom-nav a[aria-current="page"] { color: var(--ink); }
.bottom-nav a[aria-current="page"] svg { color: var(--bike); }
.bottom-nav svg { width: 24px; height: 24px; }
.fab {
  position: fixed; z-index: 11; right: max(16px, calc(50% - 304px)); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  height: 56px; padding: 0 20px 0 16px; display: flex; align-items: center; gap: 8px; border: 0; border-radius: 28px;
  background: var(--accent); color: var(--on-accent); font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.fab svg { width: 24px; height: 24px; }

/* Folha inferior */
dialog#sheet {
  width: 100%; max-width: 640px; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink); overflow: auto; overscroll-behavior: contain;
}
dialog#sheet::backdrop { background: rgba(0,0,0,.6); }
.sheet-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { flex: 1; font-size: 18px; font-weight: 700; min-width: 0; }
.sheet-body { padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.field > small { display: block; font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.field input:not([type=checkbox]):not([type=color]), .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); appearance: none; -webkit-appearance: none;
}
.field input[type=date] { display: block; }
.field textarea { min-height: 80px; resize: vertical; }
.field input[type=color] { width: 64px; height: 44px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; margin-bottom: 8px; font-weight: 500; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.check small { display: block; font-size: 13px; color: var(--ink-2); font-weight: 400; }
.form-error { padding: 10px 12px; margin-bottom: 14px; border-radius: 10px; background: var(--red-bg); color: var(--red); font-size: 14px; }
.picker { margin-bottom: 14px; }
.picker summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; font-size: 14px; }
.picker .list { margin-top: 4px; }
.picker .check { margin: 0; padding: 8px 12px; border-top: 1px solid var(--line); }
.picker .sub-head { padding: 10px 12px 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 15px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.menu-btn { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 60px; padding: 10px 16px; background: var(--surface); border: 0; border-radius: var(--radius); text-align: left; font-weight: 600; }
.menu-btn + .menu-btn { margin-top: 8px; }
.menu-btn small { display: block; font-weight: 400; font-size: 13px; color: var(--ink-2); }
.menu-btn svg { width: 26px; height: 26px; flex: none; color: var(--bike, var(--accent)); }
details.plain > summary { min-height: 44px; display: flex; align-items: center; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; }

/* Importação de documentos */
.file-input { position: fixed; left: -100px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.reading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 32px 8px; text-align: center; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 4s; } }
.doc-warnings { margin: 0 0 14px; padding: 10px 12px 10px 28px; border-radius: 10px; background: var(--amber-bg); color: var(--amber); font-size: 14px; overflow-wrap: anywhere; }
.doc-warnings li + li { margin-top: 4px; }
.doc-note { margin-bottom: 10px; font-size: 14px; color: var(--ink-2); }
.doc-fill { margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.cert-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin-top: 6px; }
.file-row { flex-wrap: wrap; }
.file-row .row-main { flex-basis: 100%; }
.file-actions { display: flex; flex-wrap: wrap; gap: 8px; flex-basis: 100%; }
.file-actions .btn { flex: 1 1 auto; }

/* Via Verde */
.plate-row, .statement { flex-direction: column; align-items: stretch; gap: 8px; }
.plate-head { display: flex; align-items: flex-start; gap: 12px; }
.plate-row select {
  width: 100%; min-height: 46px; padding: 10px 36px 10px 12px; font-size: 16px; border-radius: 10px; border: 1px solid var(--line); background-color: var(--surface);
  appearance: none; -webkit-appearance: none; background-repeat: no-repeat; background-position: right 12px center; background-size: 12px 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.500l5 5 5-5' fill='none' stroke='%238d9097' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.recon { font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.recon span { white-space: nowrap; }
.recon b { font-weight: 600; color: var(--ink); }
.statement-error { padding: 8px 10px; border-radius: 10px; background: var(--red-bg); color: var(--red); overflow-wrap: anywhere; }
.statement .doc-warnings { margin: 0; }
.steps { margin: 12px 0; padding-left: 22px; font-size: 15px; }
.steps > li + li { margin-top: 12px; }
.step-btn { margin-top: 8px; }
.code-box {
  display: block; width: 100%; margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  font: 13px/1.4 var(--mono); white-space: pre; overflow: auto; resize: vertical;
}

/* Gráfico */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--ink-3); font: 12px var(--mono); }
.chart .series { fill: none; stroke: var(--bike); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .mark { fill: var(--bike); stroke: var(--surface); stroke-width: 2; }
.chart .cursor { stroke: var(--ink-3); stroke-width: 1; }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%); padding: 4px 8px; border-radius: 8px; white-space: nowrap;
  background: var(--ink); color: var(--bg); font-size: 13px; pointer-events: none;
}

/* Entrada */
.auth { max-width: 380px; margin: 12vh auto 0; }
.auth h1 { font-size: 32px; letter-spacing: -0.02em; margin-bottom: 4px; }
.auth p { color: var(--ink-2); margin-bottom: 24px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 10px); z-index: 50; width: max-content; text-align: center;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 14px;
}
dialog #toast { position: fixed; }
