:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d2125;
  --muted: #5b636b;
  --line: #dcd9d1;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --focus: #1a5fb4;
  --ok-bg: #e5f3ec;
  --ok-text: #14513f;
  --err-bg: #fbe9e7;
  --err-text: #8a1c12;
  --info-bg: #e8eef8;
  --info-text: #1e3d6b;
  --radius: 12px;
  --tap: 44px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1f2226;
    --text: #e9e7e2;
    --muted: #a5abb2;
    --line: #353a40;
    --accent: #5cc3a5;
    --accent-text: #0d1f1a;
    --focus: #8fb8ff;
    --ok-bg: #173329;
    --ok-text: #a8e3cc;
    --err-bg: #3a1c19;
    --err-text: #ffb4a9;
    --info-bg: #1b2a40;
    --info-text: #b8d0f5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* ---- layout: bottom tab bar on phones, sidebar on wider screens ---- */
.app main { padding: 1.25rem 16px calc(5.5rem + env(safe-area-inset-bottom)); max-width: 960px; }
.app main:focus { outline: none; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 5;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .brand, .nav .signout { display: none; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: space-around; }
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px; min-width: var(--tap); padding: 6px 12px; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: 0.75rem;
}
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

@media (min-width: 760px) {
  .app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
  .nav { position: sticky; top: 0; height: 100vh; inset: auto; border-top: 0; border-right: 1px solid var(--line); padding: 1.25rem 0.75rem; display: flex; flex-direction: column; }
  .nav .brand { display: block; font-weight: 700; padding: 0 0.75rem 1rem; }
  .nav ul { flex-direction: column; gap: 2px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 10px; min-height: var(--tap); font-size: 1rem; border-radius: 8px; }
  .nav a[aria-current="page"] { background: var(--bg); }
  .nav .signout { display: block; margin-top: auto; padding: 0 0.75rem; }
  .app main { padding: 2rem 2.5rem; }
}

.plain main.narrow { max-width: 440px; margin: 0 auto; padding: 2.5rem 16px 3rem; }
.brand { color: var(--muted); font-weight: 600; margin: 0 0 0.5rem; }

/* ---- content ---- */
.lede { color: var(--muted); }
.grid { display: grid; gap: 1rem; }
@media (min-width: 900px) { .grid { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.1rem 1rem; margin-bottom: 1rem; }
.grid .card { margin: 0; }
.empty { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 0; }
.badge { display: inline-block; margin-left: 0.5rem; padding: 0 0.5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 0.8rem; color: var(--muted); }
.rows { list-style: none; margin: 0 0 1rem; padding: 0; }
.rows li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.rows li:last-child { border-bottom: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.alert { border-radius: 8px; padding: 0.75rem 1rem; margin-bottom: 1rem; }
.alert.error { background: var(--err-bg); color: var(--err-text); }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }
.alert.info { background: var(--info-bg); color: var(--info-text); }

/* ---- forms ---- */
.stack { display: grid; gap: 1rem; }
.stack h2 { margin: 0.5rem 0 0; }
.field label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 0.55rem 0.75rem;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
}
button {
  min-height: var(--tap); padding: 0.5rem 1.1rem; font: inherit; font-weight: 600;
  color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { background: none; border: 0; padding: 0; color: var(--muted); font-weight: 400; text-decoration: underline; }
.qr { width: 220px; max-width: 100%; background: #fff; padding: 8px; border-radius: 8px; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { word-break: break-all; }

/* ---- milestone 2+ ---- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wide-only { display: none; }
@media (min-width: 760px) { .wide-only { display: block; } .phone-only { display: none; } }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
a.button {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0.5rem 1.1rem; font-weight: 600;
  color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-decoration: none;
}
a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--err-text); }
button[aria-busy="true"] { opacity: 0.6; }
.badge.warn { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.in { color: var(--ok-text); }
.grow { flex: 1; min-width: 0; }
.rows li .grow strong, .rows li > div > a strong { overflow-wrap: anywhere; }
.two { display: grid; gap: 1rem; }
@media (min-width: 600px) { .two { grid-template-columns: 1fr 1fr; } }
.check { display: flex; gap: 0.6rem; align-items: center; min-height: var(--tap); }
.check input { width: 1.3rem; min-height: 1.3rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
form.inline { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.4rem; }
form.inline select { width: auto; max-width: 100%; flex: 1 1 12rem; }
form.inline.compact { margin-top: 0.3rem; }
.narrow-input { width: 5.5rem; }
.filters { display: grid; gap: 0.75rem; grid-template-columns: 1fr 1fr; margin-bottom: 1rem; }
.filters .field:first-child { grid-column: 1 / -1; }
@media (min-width: 900px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr auto; align-items: end; } .filters .field:first-child { grid-column: auto; } }
.filter-actions { display: flex; gap: 0.75rem; align-items: center; }
.pager { display: flex; justify-content: space-between; margin-top: 0.75rem; }
.stats { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th.num, td.num { text-align: right; }
tr.duplicate td, tr.error td { color: var(--muted); }
tr.possible_duplicate td { background: var(--info-bg); }
.consent ul { padding-left: 1.2rem; }
.consent li { margin-bottom: 0.5rem; }
.menu a { display: block; padding: 0.4rem 0; min-height: var(--tap); }
ol.rows { padding-left: 0; }
textarea { resize: vertical; }

/* ---- milestones 3-4 ---- */
.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: 0.6rem 0.9rem; min-height: var(--tap); text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.month-nav { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.month-nav h2 { margin: 0; }
.month-nav a { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap); text-decoration: none; font-size: 1.2rem; }
.summary { margin-bottom: 1rem; }
.chart { margin: 0.75rem 0; }
.chart svg { width: 100%; height: auto; max-height: 120px; }
.chart .line.accent { stroke: var(--accent); }
.chart .line.warn { stroke: var(--err-text); }
.chart .dot.accent { fill: var(--accent); }
.chart .dot.warn { fill: var(--err-text); }
.bars { display: grid; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.bar-row { display: grid; grid-template-columns: 9rem 1fr auto; gap: 0.75rem; align-items: center; }
@media (max-width: 520px) { .bar-row { grid-template-columns: 1fr auto; } .bar-track { grid-column: 1 / -1; grid-row: 2; } }
.bar-svg { width: 100%; height: 12px; display: block; background: var(--bg); border-radius: 6px; }
.bar-svg .fill { fill: var(--accent); }
.bar-svg .over { fill: var(--err-text); }
.bar-svg .target { fill: var(--text); }
.bar-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.check.small { min-height: auto; font-size: 0.9rem; }
.rows.compact li { padding: 0.45rem 0; }
details { margin-top: 0.75rem; }
summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; color: var(--accent); }
li.series { align-items: flex-start; }
.table-wrap:focus-visible { outline: 3px solid var(--focus); }
