/* Mobile first: the base styles are the phone. Larger screens add to them
   under min-width queries at the end of this file. */
:root {
  color-scheme: light;
  --bg: #f6f5f1; --surface: #fcfcfb; --surface-2: #efeee8; --line: #e0ded6;
  --text: #1c1b19; --text-2: #52514e; --text-3: #75736d;
  --accent: #8a2b3c; --accent-ink: #ffffff; --accent-soft: #f6e8ea;
  --bar: #2a78d6; --bar-muted: #a8a69e;
  --fast-bg: #d6eefb; --fast-ink: #0b4a6b; --done-bg: #00803c; --done-ink: #ffffff;
  --mid-bg: #fff0b8; --mid-ink: #6b4e00; --slow-bg: #fbd9de; --slow-ink: #8a1c2c;
  --none-bg: #e4e3dd; --none-ink: #45443f;
  --warn-bg: #fff0b8; --warn-ink: #6b4e00;
  --shadow: 0 1px 2px rgb(0 0 0 / .05);
  --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141413; --surface: #1c1c1a; --surface-2: #262623; --line: #363531;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #9c9b92;
    --accent: #e39aa8; --accent-ink: #2a0d13; --accent-soft: #3a2025;
    --bar: #3987e5; --bar-muted: #6d6c65;
    --fast-bg: #123a4f; --fast-ink: #b9e4fa; --done-bg: #0c5f31; --done-ink: #e5fbee;
    --mid-bg: #4a3a0a; --mid-ink: #ffe394; --slow-bg: #52202a; --slow-ink: #ffc9d1;
    --none-bg: #33322e; --none-ink: #d3d2c9;
    --warn-bg: #4a3a0a; --warn-ink: #ffe394;
    --shadow: none;
  }
}

/* ---------- foundations ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
code { overflow-wrap: anywhere; }
.muted { color: var(--text-2); } .small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100vh; min-height: 100dvh; }
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top)); }
.brand { font-weight: 700; color: var(--accent); white-space: nowrap; }
.asof { flex-basis: 100%; order: 2; color: var(--text-2); font-size: 12.5px; }
.nav, .who { display: none; }
main { width: 100%; padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); }
.head { margin-bottom: 14px; }
.head p { margin: 2px 0 0; color: var(--text-2); }

.tabbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; font-size: 11.5px; color: var(--text-2); text-decoration: none; }
.tabbar a.on { color: var(--accent); font-weight: 600; }

/* ---------- controls ---------- */
.btn { min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px; cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px; }
.btn:active { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.link { border: 0; background: none; color: var(--text-2); padding: 8px; text-decoration: underline; }

/* 16px stops iPhones zooming in when a field is tapped. */
.filters select, .filters input, .field input, .field select, .pick input[type=search], .sort-pick select { font-size: 16px; min-height: var(--tap); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; max-width: 100%; }

.filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 16px; }
.filter-top { display: flex; gap: 8px; }
.filter-top input { flex: 1; min-width: 0; }
.filter-toggle { white-space: nowrap; }
.filter-more { display: none; }
.filter-more.open { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.filter-more select { width: 100%; }
.sort-pick { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.sort-pick select { flex: 1; color: var(--text); }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.tabs a { min-height: var(--tap); display: inline-flex; align-items: center; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); text-decoration: none; color: var(--text-2); white-space: nowrap; font-size: 14px; }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pager { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.pager-btns { display: inline-flex; gap: 8px; }

/* ---------- cards and figures ---------- */
.tile, .card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { padding: 10px 12px; }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 22px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.tile .sub { display: none; }
.card { padding: 16px; margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.grid2 > .card { margin-bottom: 0; }

.todo-card { padding: 14px 0 0; overflow: hidden; }
.todo-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 0 16px 8px; }
.todo-head h2 { margin: 0; }
.todo { display: grid; grid-template-columns: minmax(0, 1fr); }
.todo a { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 8px 16px; border-top: 1px solid var(--line); color: var(--text); text-decoration: none; }
.todo a:active { background: var(--surface-2); }
.todo strong { font-weight: 600; }
.todo-nums { text-align: right; white-space: nowrap; }
.todo .big { display: block; font-size: 18px; line-height: 1.2; font-weight: 650; font-variant-numeric: tabular-nums; }

.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(84px, 120px) minmax(0, 1fr) 72px; gap: 8px; align-items: center; font-size: 13.5px; padding: 3px 0; }
.bar-row .name { color: var(--text-2); line-height: 1.2; }
.bar-row .num { text-align: right; white-space: nowrap; }
.bar-track { height: 10px; }
.bar-fill { height: 10px; min-width: 2px; background: var(--bar); border-radius: 0 4px 4px 0; }
.bar-fill.unknown { background: var(--bar-muted); }
.cols { display: flex; align-items: flex-end; gap: 12px; height: 150px; border-bottom: 1px solid var(--line); }
.col { flex: 1; min-width: 0; max-width: 56px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.col-fill { background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; }
.col-labels { display: flex; gap: 12px; font-size: 12px; color: var(--text-3); margin-top: 4px; }
.col-labels span { flex: 1; min-width: 0; max-width: 56px; text-align: center; white-space: nowrap; }

.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.st-done { background: var(--done-bg); color: var(--done-ink); } .st-fast { background: var(--fast-bg); color: var(--fast-ink); }
.st-mid { background: var(--mid-bg); color: var(--mid-ink); } .st-slow { background: var(--slow-bg); color: var(--slow-ink); }
.st-none { background: var(--none-bg); color: var(--none-ink); } .warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- data: cards on a phone, table on a large screen ---------- */
table { border-collapse: collapse; width: 100%; font-size: 14px; }
table.stack, table.stack tbody { display: block; }
table.stack thead { display: none; }
table.stack tr { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table.stack tr:last-child { margin-bottom: 0; }
table.stack td { min-width: 0; overflow-wrap: anywhere; }
table.stack .title-cell, table.stack .wide, table.stack .advice { flex: 1 0 100%; }
table.stack td.hide-empty, table.stack td:empty { display: none; }
table.stack td[data-l]::before { content: attr(data-l); display: block; font-size: 11.5px; font-weight: 400; color: var(--text-3); }
table.stack td:last-child:has(button) { flex: 1 0 100%; text-align: right; }
tbody tr.click { cursor: pointer; }
tbody tr.click:active { background: var(--surface-2); }
td.strong { font-weight: 600; }
.title-cell strong { display: block; font-weight: 600; }
.title-cell span { color: var(--text-2); font-size: 13px; }
.advice strong { display: block; font-weight: 600; }
.advice span:not(.chip) { color: var(--text-2); font-size: 13px; }

.empty { padding: 28px; text-align: center; color: var(--text-2); }
.err { color: var(--slow-ink); background: var(--slow-bg); padding: 8px 10px; border-radius: 6px; margin: 8px 0; font-size: 14px; }
.ok { color: var(--fast-ink); background: var(--fast-bg); padding: 8px 10px; border-radius: 6px; margin: 8px 0; font-size: 14px; }

/* ---------- forms and menus ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 24px; display: grid; gap: 12px; }
.login .brand { font-size: 20px; }
.field { display: grid; gap: 3px; font-size: 13px; color: var(--text-2); }
.field input, .field select { color: var(--text); width: 100%; }
.check { display: flex; gap: 8px; align-items: center; min-height: var(--tap); padding: 4px 0; font-size: 14px; color: var(--text); }
.check input, .pick input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px 14px; }
.picks { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 12px; }
.pick { border: 1px solid var(--line); border-radius: 6px; padding: 8px; min-width: 0; }
.pick input[type=search] { width: 100%; margin: 4px 0; }
.pick .list { height: 220px; overflow: auto; font-size: 13.5px; }
.pick label { display: flex; gap: 6px; align-items: center; min-height: var(--tap); padding: 4px 0; }
.pick label[hidden] { display: none; }
.pick .hd { font-weight: 600; font-size: 13.5px; display: flex; justify-content: space-between; }
.menu { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.menu a, .menu button { display: block; width: 100%; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); text-decoration: none; text-align: left; font-size: 16px; cursor: pointer; }
.menu > :last-child { border-bottom: 0; color: var(--accent); }
#up { display: grid; }
#up input[type=file] { width: 100%; font-size: 15px; padding: 8px 0; }

/* ---------- barcode detail: full screen on a phone ---------- */
.detail { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0; border: 0; background: var(--surface); color: var(--text); }
.detail::backdrop { background: rgb(0 0 0 / .4); }
.detail-head { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.detail-head .btn { align-self: flex-start; }
.detail-body { padding: 14px 16px; }
.detail table.stack tr { background: var(--bg); }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; margin-bottom: 14px; }
.facts div > span:first-child { display: block; font-size: 12.5px; color: var(--text-2); }
.tip { position: fixed; z-index: 20; background: var(--text); color: var(--bg); font-size: 13px; padding: 5px 8px; border-radius: 5px; pointer-events: none; max-width: 280px; }
details.check-card { margin-bottom: 10px; }
details.check-card summary { cursor: pointer; padding: 6px 0; }
.check-card .why { color: var(--text-2); font-size: 14px; margin: 2px 0 8px; }

/* ---------- phone held sideways: keep the screen for content ---------- */
@media (max-height: 480px) {
  .top { position: static; }
  .asof, .head p { display: none; }
  .head { margin-bottom: 8px; }
  .tabbar a { min-height: 46px; flex-direction: row; gap: 6px; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-more.open { grid-column: 1 / -1; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- larger phones and small tablets ---------- */
@media (min-width: 600px) {
  .tile .sub { display: block; color: var(--text-3); font-size: 12.5px; }
  .tile .value { font-size: 26px; }
  .tile { padding: 12px 16px; }
  .todo { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .todo a:nth-child(odd) { border-right: 1px solid var(--line); }
  .facts { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}

/* ---------- desktop and large tablets ---------- */
@media (min-width: 901px) {
  .top-row { flex-wrap: nowrap; gap: 16px; padding: 10px 24px; max-width: 1320px; margin: 0 auto; }
  .asof { flex-basis: auto; order: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nav { display: flex; gap: 2px; padding: 0 24px; max-width: 1320px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
  .nav a { padding: 8px 12px; color: var(--text-2); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; font-size: 14px; }
  .nav a:hover { color: var(--text); }
  .nav a.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }
  .who { margin-left: auto; display: flex; gap: 8px; align-items: center; font-size: 13px; white-space: nowrap; }
  .tabbar { display: none; }
  main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; }

  .filters { display: flex; flex-wrap: wrap; align-items: center; }
  .filter-top, .filter-more, .filter-more.open { display: contents; }
  .filter-toggle { display: none; }
  .filter-top input { flex: 0 1 200px; }
  .filter-more select { width: auto; max-width: 220px; }
  .filters .grow { margin-left: auto; }

  .tabs { margin: 0 0 14px; padding: 0; }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .todo { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .todo a:nth-child(odd) { border-right: 0; }
  .todo a:not(:nth-child(3n)) { border-right: 1px solid var(--line); }
  .bar-row { grid-template-columns: minmax(96px, 200px) 1fr 86px; gap: 10px; }
  .bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: inherit; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .picks { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pick .list { height: 190px; }
  #up { display: flex; }
  #up input[type=file] { width: auto; }

  /* Data becomes a real table. */
  .table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
  table.stack { display: table; }
  table.stack thead { display: table-header-group; }
  table.stack tbody { display: table-row-group; }
  table.stack tr { display: table-row; padding: 0; margin: 0; background: none; border: 0; border-radius: 0; }
  table.stack td, table.stack td.hide-empty { display: table-cell; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
  table.stack tr:last-child td { border-bottom: 0; }
  table.stack td[data-l]::before { content: none; }
  table.stack td.num { text-align: right; white-space: nowrap; }
  table.stack td:last-child:has(button) { text-align: right; }
  .detail table.stack tr { background: none; }
  th { text-align: left; font-size: 12.5px; color: var(--text-2); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap; position: sticky; top: 0; }
  th.num { text-align: right; }
  th.sort { cursor: pointer; } th.sort:hover { color: var(--text); }
  .sort-pick { display: none; }
  .advice { min-width: 260px; max-width: 420px; }
  .pager { justify-content: flex-end; }

  .detail { width: min(1000px, calc(100vw - 24px)); height: auto; max-height: 86vh; margin: auto; border: 1px solid var(--line); border-radius: 10px; }
  .detail-head { padding: 14px 16px; }
}

/* A mouse needs less room than a finger. */
@media (min-width: 901px) and (pointer: fine) {
  :root { --tap: 34px; }
  .filters select, .filters input { font-size: 15px; }
  .btn { padding: 6px 12px; }
  .btn:hover { background: var(--surface-2); }
  .btn.primary:hover { background: var(--accent); }
  .tabs a { padding: 6px 12px; }
  .check, .pick label { min-height: 0; padding: 2px 0; }
  .check input, .pick input[type=checkbox] { width: 16px; height: 16px; }
  tbody tr.click:hover { background: var(--surface-2); }
  .todo a:hover { background: var(--surface-2); }
}
