/* Matters — "paper & ink" (SPEC §7): dense ledger tables, 14 px IBM Plex Sans, tabular figures,
   one rust accent, warm greys everywhere else, category colors as tints. Flat, no gradients. */

/* ---------- tokens ---------- */
:root {
  --paper: #faf8f4;
  --paper-2: #f2eee7;
  --paper-3: #e8e2d8;
  --field: #fffdfa;
  --ink: #1f1b16;
  --ink-2: #5d5548;
  --ink-3: #9b9285;
  --rule: #e3dcd1;
  --rule-2: #cbc2b4;
  --accent: #b5451b;
  --accent-2: #93340f;
  --accent-fg: #fffaf5;
  --accent-soft: color-mix(in srgb, #b5451b 11%, transparent);
  --danger: #a12b2b;
  --tint-pct: 20%;
  --radius: 3px;
  --nav-height: 52px;
  --control-h: 32px;
  --input-font: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16130f;
    --paper-2: #1e1a15;
    --paper-3: #2b251e;
    --field: #110f0c;
    --ink: #ece6db;
    --ink-2: #ada395;
    --ink-3: #75695c;
    --rule: #2d2721;
    --rule-2: #463e33;
    --accent: #e0784a;
    --accent-2: #f09068;
    --accent-fg: #1a0d06;
    --accent-soft: color-mix(in srgb, #e0784a 14%, transparent);
    --danger: #e06666;
    --tint-pct: 13%;
  }
}
@media (max-width: 640px) {
  :root { --control-h: 40px; --input-font: 16px; }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { color-scheme: light dark; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.45;
  font-variant-numeric: tabular-nums;
  background: var(--paper);
  color: var(--ink);
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 20px 40px; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.page-title { font-size: 20px; }
h2 {
  display: flex; align-items: center; gap: 10px;
  margin: 24px 0 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2);
}
h2::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
h3 { font-size: 13px; margin-top: 14px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.page-head .page-title { margin: 0; }
.muted { color: var(--ink-2); }
.empty { margin: 16px 0; padding: 22px; border: 1px dashed var(--rule-2); border-radius: var(--radius); text-align: center; color: var(--ink-3); font-style: italic; }
[x-cloak] { display: none !important; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
::selection { background: var(--accent); color: var(--accent-fg); }

/* ---------- masthead nav ---------- */
.nav {
  display: flex; align-items: stretch; gap: 0;
  height: var(--nav-height); padding: 0 20px;
  background: var(--paper); border-bottom: 1px solid var(--ink);
  position: sticky; top: 0; z-index: 20;
}
.nav-brand { display: flex; align-items: center; margin-right: 28px; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.brand-dot { color: var(--accent); }
.nav-spacer { flex: 1; }
.nav-link {
  display: flex; align-items: center; padding: 0 12px; margin-bottom: -1px;
  color: var(--ink-2); text-decoration: none; font-size: 12px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--ink); }
.nav-link.current { color: var(--ink); border-bottom-color: var(--accent); }
@media (max-width: 640px) {
  .nav {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 20;
    height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    border-bottom: 0; border-top: 1px solid var(--ink); background: var(--paper);
  }
  .nav-brand, .nav-spacer { display: none; }
  .nav-link { flex: 1; justify-content: center; margin: 0; padding: 0; font-size: 11px; border-bottom: 0; border-top: 2px solid transparent; }
  .nav-link.current { border-top-color: var(--accent); color: var(--accent); }
  main { padding: 14px 14px calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 24px); }
}

/* ---------- feedback ---------- */
.busy-bar { position: fixed; top: 0; left: 0; right: 0; height: 2px; background: var(--accent); opacity: 0; transition: opacity 0.15s; z-index: 30; }
.busy-bar.htmx-request { opacity: 1; }
button.htmx-request { opacity: 0.6; pointer-events: none; }
.toast {
  position: fixed; left: 50%; top: calc(var(--nav-height) + 12px); transform: translateX(-50%); z-index: 25;
  max-width: min(92vw, 480px); padding: 9px 16px; border-radius: var(--radius);
  background: var(--ink); color: var(--paper); font-weight: 500; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  animation: toast-out 0.4s ease 4s forwards;
}
@media (max-width: 640px) { .toast { top: 12px; } }
@keyframes toast-out { to { opacity: 0; visibility: hidden; } }
.flash { margin: 0 0 12px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--paper-2); }
.warn { margin: 0 0 12px; padding: 8px 12px; border: 1px solid color-mix(in srgb, #c9a227 60%, var(--rule)); background: color-mix(in srgb, #e6b800 14%, transparent); border-radius: var(--radius); }
.notice { padding: 0 2px; color: var(--ink-2); font-size: 12px; font-style: italic; }
.notice:not(:empty) { padding: 5px 2px 0; }

/* ---------- controls ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  height: var(--control-h); padding: 0 12px;
  font: inherit; font-size: 13px; font-weight: 500; line-height: 1;
  color: var(--ink); background: var(--field); border: 1px solid var(--rule-2); border-radius: var(--radius);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--ink); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.primary:hover, .btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.current { background: var(--ink); border-color: var(--ink); color: var(--paper); }
button.small, .btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
button:focus-visible, .btn:focus-visible, input:focus, select:focus, textarea:focus, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, select, textarea {
  font: inherit; font-size: var(--input-font);
  height: var(--control-h); padding: 0 10px;
  color: var(--ink); background: var(--field); border: 1px solid var(--rule-2); border-radius: var(--radius);
  min-width: 0; max-width: 100%;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
textarea { height: auto; min-height: 66px; padding: 8px 10px; line-height: 1.4; }
input[type="checkbox"], input[type="radio"] { height: auto; width: auto; margin: 0; accent-color: var(--accent); }
input[type="file"] { border: 0; padding: 0; height: auto; background: none; }
input[type="color"] { width: 44px; padding: 2px; }
input.short { width: 84px; }
input.num { text-align: right; }
::placeholder { color: var(--ink-3); }
details > summary { cursor: pointer; color: var(--ink-2); list-style: none; font-size: 12px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "+ "; color: var(--accent); }
details[open] > summary::before { content: "− "; }

/* forms */
.field-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; margin-bottom: 10px; }
.field-row label, .stack > label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.field-row label > input, .field-row label > select, .stack > label > textarea, .stack > label > input { color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 400; }
.field-row label.grow, label.grow { flex: 1 1 260px; }
.field-row .check-label, .check-label { flex-direction: row; align-items: center; gap: 6px; height: var(--control-h); color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 13px; }
.inline-pair { display: inline-flex; align-items: center; gap: 6px; }
.inline-form { display: flex; gap: 6px; align-items: flex-end; }
.field-label { font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); display: block; margin-bottom: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 14px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.toolbar form { display: flex; gap: 6px; align-items: center; }
.toolbar strong { margin-left: 6px; font-size: 15px; letter-spacing: -0.01em; }
@media (max-width: 640px) {
  .field-row label { flex: 1 1 140px; }
  .field-row label > input, .field-row label > select { width: 100%; }
}

/* chips: filter links and radio/checkbox labels that look like ledger tags */
.chips { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 4px;
  height: 26px; padding: 0 9px; border-radius: var(--radius);
  border: 1px solid var(--rule-2); background: var(--field); color: var(--ink-2);
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; text-decoration: none; cursor: pointer; user-select: none;
}
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip.current, .chip:has(input:checked) { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.chip[style*="--cat"].current, .chip[style*="--cat"]:has(input:checked) { border-color: var(--cat); background: var(--cat); color: #fff; }
.chip-gap { width: 8px; }
@media (max-width: 640px) { .chip { height: 32px; font-size: 12px; } }

/* ---------- ledger tables ---------- */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 5px 8px; border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; vertical-align: middle; }
table.grid thead th { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); border-bottom: 1px solid var(--ink); background: var(--paper); position: sticky; top: 0; }
table.grid tbody tr:hover td { background: var(--paper-2); }
table.grid .num { text-align: right; }
table.grid tfoot td { font-weight: 600; border-top: 3px double var(--ink); border-bottom: 0; }
table.grid td.zero { color: var(--rule-2); }
table.grid tr.today td { background: var(--accent-soft); }
table.grid tr.archived td { color: var(--ink-3); }
table.grid td.actions { white-space: nowrap; text-align: right; }
table.grid td.actions form { display: inline; }
table.grid input, table.grid select { min-width: 64px; }
table.grid input.short { width: 72px; min-width: 0; }
table.grid a.day-link { color: var(--ink); text-decoration: none; font-weight: 500; }
table.grid a.day-link:hover { color: var(--accent); }
table.grid .plus-mark { color: var(--accent); font-weight: 700; margin-left: 2px; }
/* a plus day you set by hand (birthday, trip) reads differently from one the weekday rule gave you */
table.grid .plus-mark.manual { padding: 0 4px; border: 1px solid var(--accent); border-radius: 2px; margin-left: 4px; }
.plus-day { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 14px; padding: 8px 10px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); }
.plus-day form { display: inline; }
.plus-badge { padding: 1px 8px; border: 1px solid var(--rule-2); border-radius: 2px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.plus-badge.on { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
table.grid tr.editor td { background: var(--accent-soft); }
.tint, table.grid thead th.tint { background: color-mix(in srgb, var(--cat) var(--tint-pct), var(--paper)); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--cat); vertical-align: middle; margin-right: 4px; }
.badge { display: inline-block; padding: 0 5px; border: 1px solid var(--rule-2); border-radius: 2px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); margin-left: 3px; vertical-align: 1px; }
/* the month grid keeps the day column while scrolling sideways */
table.month-grid th:first-child, table.month-grid td:first-child { position: sticky; left: 0; z-index: 2; background: var(--paper); }
table.month-grid thead th:first-child { z-index: 3; }
table.month-grid tr.today td:first-child { background: color-mix(in srgb, var(--accent) 11%, var(--paper)); }
table.month-grid tbody tr:hover td:first-child { background: var(--paper-2); }
/* Compact toggle (feedback round, 2026-09-19): last 5 days + today + next 3, everything else hidden. */
.grid-toggle { margin-bottom: 8px; }
table.month-grid.compact-days tbody tr:not(.near-today) { display: none; }
/* phone: labelled cards instead of columns */
@media (max-width: 640px) {
  table.grid.cards, table.grid.cards tbody, table.grid.cards tr, table.grid.cards td { display: block; width: 100%; }
  table.grid.cards thead { display: none; }
  table.grid.cards tr { border: 1px solid var(--rule); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; background: var(--paper-2); }
  table.grid.cards tbody tr:hover td { background: transparent; }
  table.grid.cards td { display: flex; align-items: center; gap: 8px; border: 0; padding: 4px 0; white-space: normal; text-align: left; }
  table.grid.cards td.num { text-align: left; }
  table.grid.cards td[data-label]::before { content: attr(data-label); flex: 0 0 88px; font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
  table.grid.cards td:not([data-label]):not(.actions) { padding: 0; }
  table.grid.cards td.actions { justify-content: flex-end; gap: 6px; padding-top: 6px; }
  table.grid.cards td input, table.grid.cards td select { flex: 1; width: auto; min-width: 0; }
  table.grid.cards td input.short { flex: 0 0 96px; }
  table.grid.cards tfoot, table.grid.cards tfoot tr, table.grid.cards tfoot td { display: block; border: 0; }
}

/* ---------- stats & surfaces ---------- */
.card { max-width: 380px; margin: 56px auto; padding: 24px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); }
.card .page-title { font-size: 26px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-bottom: 16px; }
.stat { flex: 0 1 auto; min-width: 120px; padding: 6px 0 0; border-top: 2px solid var(--ink); }
.stat .label { display: block; font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.stat .value { display: block; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.stat .value.negative, .negative { color: var(--danger); }
.copy-offer { margin: 0 0 14px; padding: 12px 14px; border: 1px dashed var(--rule-2); border-radius: var(--radius); background: var(--paper-2); }
.copy-offer table { width: auto; margin: 8px 0; }
.changed { font-weight: 600; color: var(--accent); }
.settings-links { columns: 2; column-gap: 40px; max-width: 680px; }
.settings-links h2 { margin-top: 0; break-after: avoid; }
.settings-links ul { margin: 0 0 18px; padding: 0; list-style: none; break-inside: avoid; }
.settings-links li { padding: 5px 0; border-bottom: 1px solid var(--rule); }
.settings-links li a { color: var(--ink); text-decoration: none; }
.settings-links li a:hover { color: var(--accent); }
@media (max-width: 640px) { .settings-links { columns: 1; } }
pre.preview { max-height: 240px; overflow: auto; background: var(--paper-2); padding: 8px; font-size: 12px; }

/* ---------- finance ---------- */
.finance-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; padding: 10px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); }
.finance-add input[name="amount"] { width: 140px; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; text-align: right; }
.finance-add input[name="comment"] { flex: 1 1 160px; }
.finance-add input[type="date"] { width: 150px; }
.finance-add .cat-buttons { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.cat-btn { border-color: color-mix(in srgb, var(--cat) 55%, var(--rule-2)); background: color-mix(in srgb, var(--cat) var(--tint-pct), var(--field)); color: var(--ink); font-weight: 600; }
.cat-btn:hover { background: var(--cat); border-color: var(--cat); color: #fff; }
@media (max-width: 640px) {
  .finance-add input[name="amount"] { flex: 1 1 120px; }
  .finance-add input[name="comment"] { flex: 1 1 100%; }
  .finance-add .cat-btn { flex: 1 1 calc(25% - 6px); }
}
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 480px; }
.calendar .dow { font-size: 10px; letter-spacing: 0.08em; color: var(--ink-3); text-align: center; text-transform: uppercase; }
.calendar form { display: contents; }
.calendar button { width: 100%; padding: 0; height: 36px; }
.calendar button.plus { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.calendar button.override { outline: 2px solid var(--ink); outline-offset: -2px; }
.calendar .blank { visibility: hidden; }
.mom { display: flex; flex-wrap: wrap; gap: 12px 32px; }
.mom-group { min-width: 240px; flex: 1; max-width: 360px; }
.mom-name { font-weight: 600; margin-bottom: 2px; }
.mom-row { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.mom-label { width: 30px; color: var(--ink-3); text-transform: uppercase; font-size: 10px; letter-spacing: 0.06em; }
.mom-track { flex: 1; height: 8px; background: var(--paper-3); overflow: hidden; }
.mom-bar { height: 100%; background: var(--accent); }
.mom-value { min-width: 64px; text-align: right; }

/* ---------- todo ---------- */
.quick-add { margin-bottom: 14px; padding: 10px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); }
.quick-add-row { display: flex; gap: 6px; }
.quick-add-row input { flex: 1; font-size: max(15px, var(--input-font)); }
.quick-add .chips { margin-top: 8px; }
.quick-add .more { margin-top: 8px; }
.quick-add .more .field-row { margin: 8px 0 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 0; margin: 4px 0 10px; border-bottom: 1px solid var(--rule-2); }
.tabs a { display: inline-flex; align-items: baseline; gap: 5px; padding: 8px 12px 6px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--ink-2); text-decoration: none; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.tabs a:hover { color: var(--ink); }
.tabs a.current { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a .count { font-size: 11px; font-weight: 500; color: var(--ink-3); letter-spacing: 0; }
.tabs a.current .count { color: var(--accent); }
@media (max-width: 640px) { .tabs { overflow-x: auto; flex-wrap: nowrap; } .tabs a { flex: 0 0 auto; padding: 10px 10px 8px; } }
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.search-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.search-row input[type="search"] { flex: 1 1 160px; }
.search-row label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-list > li { border-bottom: 1px solid var(--rule); }
.todo-list > li.group-head { padding: 16px 0 4px; border: 0; font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); }
.todo-row { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 4px 2px; }
.todo-row .done-btn { width: 22px; height: 22px; padding: 0; border-radius: 2px; border: 1.5px solid var(--ink-2); background: var(--field); color: transparent; flex: 0 0 auto; font-size: 13px; }
.todo-row .done-btn:hover { border-color: var(--accent); color: var(--accent); }
.todo-row .title-btn { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 4px 0; color: var(--ink); text-decoration: none; font: inherit; font-size: 14px; }
.todo-row .title-btn:hover { color: var(--accent); }
.todo-row .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--ink-2); align-items: center; }
.todo-row .meta .area { padding: 1px 6px; border-radius: 2px; background: color-mix(in srgb, var(--cat) var(--tint-pct), transparent); color: var(--ink); font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.todo-row .meta .overdue { color: var(--danger); font-weight: 600; }
.todo-row .meta .priority { padding: 1px 6px; border-radius: 2px; border: 1px solid var(--rule-2); color: var(--ink-2); font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.todo-row .meta .priority-top { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.todo-row.is-done .title-btn { text-decoration: line-through; color: var(--ink-3); }
.todo-row.is-done .done-btn { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.todo-panel { margin: 0 0 12px 34px; padding: 14px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); }
.todo-panel textarea { width: 100%; }
.todo-panel > label, .todo-panel form > label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 8px; }
.todo-panel .actions-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.todo-panel .actions-row form { display: inline; }
.todo-panel h3 { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); }
.checklist { list-style: none; margin: 6px 0; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.checklist li span { flex: 1; }
.checklist li.is-done span { text-decoration: line-through; color: var(--ink-3); }
.checklist form { display: inline; }
.checklist .done-btn { width: 20px; height: 20px; padding: 0; border-radius: 2px; font-size: 12px; }
.checklist .add-child { display: flex; gap: 6px; margin-top: 6px; }
.checklist .add-child input { flex: 1; }
@media (max-width: 640px) {
  .todo-row { flex-wrap: wrap; }
  .todo-row .meta { width: 100%; padding-left: 34px; }
  .todo-panel { margin-left: 0; }
}

/* ---------- gym ---------- */
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 2px; border: 1px solid var(--rule-2); vertical-align: middle; }
.thumb.large { width: 120px; height: 120px; }
.media-grid { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.media-grid figure { margin: 0; text-align: center; font-size: 11px; color: var(--ink-2); max-width: 100%; }
.media-grid form { display: inline; }
.video { width: 320px; max-width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: var(--radius); background: #000; }
.video-toggle { margin: 4px 0 8px; }
.video-toggle .video { margin-top: 6px; }
.session-block { margin-bottom: 14px; padding: 10px 12px 12px; border: 1px solid var(--rule-2); border-radius: var(--radius); background: var(--paper-2); }
.session-block h2 { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin: 0 0 8px; font-size: 16px; text-transform: none; letter-spacing: -0.01em; color: var(--ink); }
.session-block h2::after { content: none; }
.session-block h2 .muted { font-size: 12px; font-weight: 400; }
.session-block table.grid thead th { background: var(--paper-2); }
.set-table td form { display: inline; }
.set-table input.num { width: 72px; }
.set-table select { width: auto; max-width: 160px; }
.stepper { display: inline-flex; align-items: center; gap: 2px; }
.stepper input { width: 64px; }
.stepper .step { width: 30px; padding: 0; height: var(--control-h); font-size: 16px; }
.pr { display: inline-block; padding: 1px 5px 0; border-radius: 2px; background: var(--accent); color: var(--accent-fg); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; margin-left: 4px; vertical-align: 1px; }
.unit-abbrev { font-size: 11px; color: var(--ink-2); margin-left: 3px; }
.rest-timer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: 12px; align-items: center; justify-content: center;
  padding: 8px 12px; background: var(--ink); color: var(--paper);
}
.rest-timer .muted { color: var(--ink-3); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
.rest-timer .clock { font-size: 24px; font-weight: 700; min-width: 68px; text-align: center; letter-spacing: -0.02em; }
.rest-timer.done .clock { color: var(--accent-2); }
.rest-timer button { background: transparent; color: var(--paper); border-color: var(--ink-3); }
.rest-timer button:hover { border-color: var(--paper); }
.timer-spacer { height: 60px; }
@media (max-width: 640px) { .rest-timer { bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px)); } }
.template-list li, .session-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.template-list form, .session-list form { display: inline; }
.next-up { font-size: 10px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.1em; }
.exercise-groups h2 { margin-top: 16px; }
.with-map { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: flex-start; }
.with-map-main { flex: 1 1 420px; min-width: 0; }
.body-map { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.body-map svg { width: 120px; height: auto; }
.body-map .silhouette { fill: var(--paper-3); stroke: var(--rule-2); stroke-width: 1; }
.body-map .region { fill: var(--rule-2); opacity: 0.6; }
.body-map .region.hit { fill: var(--accent); opacity: 1; }
.body-map .region.hit-secondary { fill: var(--accent); opacity: 0.38; }
.body-map-caption { width: 100%; margin: 0; font-size: 11px; }
.secondary { margin-bottom: 10px; }
.open-rows { margin: 8px 0 0; align-items: center; }
.open-rows label { flex: 0 0 auto; flex-direction: row; align-items: center; gap: 6px; }
.open-rows label input { width: 64px; }

/* phone: set tables become block rows; the editor row is a full-width grid so nothing overflows */
@media (max-width: 640px) {
  .set-table, .set-table tbody { display: block; width: 100%; }
  .set-table thead { display: none; }
  .set-table tbody tr { display: flex; align-items: center; gap: 6px; padding: 5px 2px; border-bottom: 1px solid var(--rule); }
  .set-table tbody tr:hover td { background: transparent; }
  .set-table tbody tr td { display: block; padding: 0; border: 0; white-space: nowrap; }
  .set-table tbody tr td:nth-child(1) { flex: 0 0 22px; color: var(--ink-3); font-size: 12px; }
  .set-table tbody tr td:nth-child(2) { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .set-table tbody tr td:nth-child(3), .set-table tbody tr td:nth-child(4) { flex: 0 0 auto; min-width: 58px; text-align: right; }
  .set-table tbody tr:not(.editor) td:nth-child(3)::after { content: " kg"; color: var(--ink-3); font-size: 11px; }
  .set-table tbody tr td:nth-child(5) { flex: 0 0 auto; margin-left: auto; }
  .set-table tbody tr td[colspan] { flex: 1 1 100%; }
  .set-table tbody tr.editor { display: grid; grid-template-columns: 28px 1fr 1fr; gap: 6px 8px; padding: 8px 4px; align-items: center; background: var(--accent-soft); border-radius: var(--radius); }
  .set-table tbody tr.editor td { min-width: 0; text-align: left; margin: 0; }
  .set-table tbody tr.editor td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .set-table tbody tr.editor td:nth-child(2) { grid-column: 2 / 4; grid-row: 1; overflow: visible; }
  .set-table tbody tr.editor td:nth-child(2) select { width: 100%; max-width: none; }
  .set-table tbody tr.editor td:nth-child(3) { grid-column: 1 / 3; grid-row: 2; }
  .set-table tbody tr.editor td:nth-child(4) { grid-column: 3; grid-row: 2; }
  .set-table tbody tr.editor td:nth-child(4) input { width: 100%; }
  .set-table tbody tr.editor td:nth-child(5) { grid-column: 1 / 4; grid-row: 3; }
  .set-table tbody tr.editor td:nth-child(5) button { width: 100%; }
  .set-table tbody tr.editor .stepper { display: flex; width: 100%; }
  .set-table tbody tr.editor .stepper input { flex: 1; width: auto; min-width: 0; }
  .set-table tbody tr.editor .thumb { display: none; }
}

/* Keyboard access and persistent request feedback. */
[hidden] { display: none !important; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 50; padding: 10px 16px; background: var(--paper); transform: translateY(-200%); }
.skip-link:focus { transform: translateY(0); }
.request-error { animation: none; border: 2px solid var(--danger); }
.request-error a { color: inherit; text-decoration: underline; }
.request-error button { margin-left: 8px; }
@media (prefers-reduced-motion: reduce) {
  .busy-bar { transition: none; }
  .toast { animation-duration: 0.01ms; }
}

/* Module landing pages: agenda, ledger and training desk. */
.module-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 0 26px; }
.module-heading h1 { font-size: clamp(28px, 4vw, 44px); letter-spacing: -.045em; line-height: 1.08; max-width: 780px; }
.eyebrow { display: block; margin: 0 0 10px; font-size: 11px; letter-spacing: .09em; color: var(--ink-2); font-weight: 600; }
.module-intro { margin: 10px 0 0; color: var(--ink-2); font-size: 15px; }
.date-stamp { white-space: nowrap; border-left: 2px solid var(--accent); padding: 12px 0 12px 18px; font-weight: 500; }
.text-action { font-weight: 500; text-underline-offset: 4px; }
.quick-add, .finance-add { background: var(--paper-2); padding: 18px; border: 1px solid var(--rule); border-radius: 6px; }
.quick-add-row input[name=title] { font-size: 17px; }
.agenda-overview { display: grid; grid-template-columns: 1fr 1fr 1.2fr; border-bottom: 1px solid var(--rule-2); padding: 22px 0; margin-bottom: 20px; gap: 24px; }
.agenda-overview strong { display: block; font-size: 32px; letter-spacing: -.04em; font-weight: 500; line-height: 1.25; }
.agenda-overview small { font-size: 14px; font-weight: 400; letter-spacing: 0; color: var(--ink-2); }
.agenda-link { display: block; align-self: center; background: var(--accent-soft); padding: 16px 18px; border-radius: 4px; text-decoration: none; font-size: 16px; font-weight: 600; }
.agenda-link span { float: right; }
.agenda-link small { display: block; margin-top: 5px; }
#todo-list .todo-row { border-left: 3px solid var(--area-color, var(--rule)); padding: 14px 12px; margin: 5px 0; background: var(--field); }
#todo-list .title-btn { font-size: 16px; }
#todo-list .is-done { opacity: .65; background: transparent; }
#todo-list .group-head { font-size: 16px; text-transform: none; letter-spacing: -.01em; padding-top: 22px; color: var(--ink); }
.balance-hero { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 26px 0; margin: 4px 0 20px; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule-2); }
.balance-number { display: block; font-size: clamp(36px, 6vw, 64px); font-weight: 500; letter-spacing: -.055em; line-height: 1.15; overflow-wrap: anywhere; }
.balance-number small { font-size: 16px; letter-spacing: 0; color: var(--ink-2); }
.balance-hero p:last-child { margin-bottom: 0; }
.budget-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 18px 0 24px; }
.budget-card { padding: 16px; border: 1px solid var(--rule); background: var(--field); border-radius: 4px; }
.budget-card h3 { font-size: 14px; margin: 0 0 14px; }
.budget-card strong { display: block; font-size: 24px; font-weight: 500; overflow-wrap: anywhere; }
.budget-card small { font-size: 12px; color: var(--ink-2); }
.budget-card p { margin: 8px 0 0; font-size: 12px; color: var(--ink-2); }
.budget-track { margin-top: 14px; height: 5px; background: var(--paper-3); overflow: hidden; }
.budget-track span { display: block; height: 100%; background: var(--accent); }
.over-budget .budget-track span { background: var(--danger); }
.budget-warning { display: block; margin-top: 6px; color: var(--danger); font-size: 12px; font-weight: 600; }
.section-title { text-transform: none; letter-spacing: -.02em; font-size: 21px; color: var(--ink); margin: 26px 0 16px; }
.month-grid .today td:first-child { border-left: 3px solid var(--accent); font-weight: 700; }
.workout-hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; padding: 32px; margin: 22px 0 30px; background: var(--paper-2); border: 1px solid var(--rule); border-left: 4px solid var(--accent); }
.workout-copy { align-self: center; }
.workout-copy h2 { display: block; font-size: clamp(32px, 5vw, 52px); letter-spacing: -.04em; text-transform: none; color: var(--ink); margin: 0 0 12px; overflow-wrap: anywhere; }
.workout-copy h2::after { display: none; }
.workout-copy p { color: var(--ink-2); }
.workout-start { min-height: 48px; font-size: 16px; padding: 10px 24px; margin: 12px 0 16px; }
.workout-start span { padding-left: 16px; }
.workout-hero .body-map { margin: 0; max-width: 300px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0 0 18px; }
.routine-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; list-style: none; padding: 0; }
.routine-card { position: relative; border-top: 2px solid var(--rule-2); background: var(--field); padding: 20px; }
.routine-card > strong { display: block; margin: 0 65px 14px 0; font-size: 20px; }
.routine-card > form { float: right; }
.routine-card > .muted { display: block; margin-top: 6px; }
@media (max-width: 640px) {
  .module-heading { align-items: flex-start; flex-direction: column; gap: 14px; padding-top: 10px; }
  .date-stamp { padding: 0; border: 0; font-size: 12px; }
  .quick-add, .finance-add { padding: 12px; }
  .agenda-overview { grid-template-columns: 1fr 1fr; gap: 18px; }
  .agenda-link { grid-column: 1 / -1; }
  .balance-hero { flex-direction: column; align-items: flex-start; }
  .budget-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .budget-card { padding: 12px; }
  .budget-card strong { font-size: 21px; }
  .workout-hero { grid-template-columns: 1fr; padding: 20px; }
  .workout-hero .body-map { justify-self: center; }
  .workout-hero .body-map svg { width: 80px; height: 167px; }
  .section-heading { flex-wrap: wrap; }
}
.budget-details { margin: 20px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 12px 0; }
.budget-details summary { cursor: pointer; font-weight: 500; color: var(--ink-2); }
.budget-details[open] summary { margin-bottom: 14px; }

/* Less chrome, more room for the task at hand. Native disclosures also work without JS. */
.entry-options, .filter-options { margin: 10px 0 0; }
.entry-options > summary, .filter-options > summary { cursor: pointer; padding: 10px 0; font-weight: 500; }
.entry-options > summary .muted { font-weight: 400; margin-left: 6px; font-size: 12px; }
.entry-options .field-row { margin-top: 12px; }
.filter-options { border-bottom: 1px solid var(--rule); margin-bottom: 16px; }
.filter-options[open] > summary { margin-bottom: 10px; }
.filter-active { margin-left: 8px; padding: 3px 7px; font-size: 12px; background: var(--accent-soft); color: var(--accent); border-radius: 3px; }
.finance-options { flex-basis: 100%; margin: 0; }
.finance-options .field-row { margin-top: 4px; }
.entry-hint { flex-basis: 100%; margin: 2px 0 6px; color: var(--ink-2); font-size: 12px; }
@media (max-width: 640px) {
  :root { --control-h: 44px; }
  html { scroll-padding-bottom: calc(var(--nav-height) + 90px + env(safe-area-inset-bottom, 0px)); }
  main { padding-left: 12px; padding-right: 12px; }
  input, select, textarea { max-width: 100%; min-width: 0; }
  button, .btn, summary, .chip, .done-btn, .cat-btn { min-height: 44px; }
  button.small, .btn.small { min-height: 44px; }
  .chip { height: auto; padding: 8px 10px; }
  .chips { gap: 8px; }
  .quick-add-row input { min-width: 0; }
  .module-heading { padding: 4px 0 16px; gap: 8px; }
  .module-heading h1 { font-size: 26px; }
  .module-heading .module-intro { display: none; }
  .module-heading .eyebrow { margin-bottom: 6px; }
  .module-heading .text-action { padding: 8px 0; min-height: 44px; display: inline-flex; align-items: center; }
  .agenda-overview { padding: 12px 0; gap: 12px; margin-bottom: 10px; }
  .agenda-overview strong { font-size: 26px; }
  .agenda-link { padding: 12px; }
  .entry-options > summary .muted { display: block; margin: 2px 0 0 16px; }
  .finance-add input[name=amount] { width: 100%; flex-basis: 100%; font-size: 24px; text-align: left; }
  .finance-add .cat-btn { flex: 1 1 calc(50% - 6px); }
  .finance-options .field-row > input, .finance-options .field-row > select { flex: 1 1 100%; width: 100%; }
  .search-row { flex-wrap: wrap; }
  .search-row > input[type=search] { flex-basis: 100%; width: 100%; }
  .search-row > label { flex-wrap: wrap; }
  .tabs a { min-height: 44px; align-items: center; }
  .set-table tbody tr.editor { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 12px; padding: 14px 10px; }
  .set-table tbody tr.editor td:nth-child(1) { grid-column: 1 / -1; grid-row: 1; }
  .set-table tbody tr.editor td:nth-child(1)::before { content: "Set "; }
  .set-table tbody tr.editor td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .set-table tbody tr.editor td:nth-child(3) { grid-column: 1; grid-row: 3; }
  .set-table tbody tr.editor td:nth-child(4) { grid-column: 2; grid-row: 3; align-self: start; }
  .set-table tbody tr.editor td:nth-child(3)::before { content: "Weight"; display: block; margin-bottom: 6px; color: var(--ink-2); font-size: 12px; }
  .set-table tbody tr.editor td:nth-child(4)::before { content: attr(data-label); display: block; margin-bottom: 6px; color: var(--ink-2); font-size: 12px; }
  .set-table tbody tr.editor td:nth-child(5) { grid-column: 1 / -1; grid-row: 4; }
  .set-table tbody tr.editor input.num { height: 48px; font-size: 20px; }
  .set-table .stepper .step { width: 44px; min-width: 44px; height: 48px; }
  .set-table tbody tr:not(.editor) td:nth-child(3)::after { content: none; }
  .session-block h2 { flex-wrap: wrap; gap: 8px; text-transform: none; letter-spacing: 0; }
  .session-block .block-name { font-size: 20px; flex-basis: 100%; }
  .rest-timer { padding: 10px 12px; gap: 8px; }
  .rest-timer .clock { min-width: 60px; }
  .workout-hero .body-map svg { width: 64px; height: 134px; }
  .workout-start { width: 100%; }
}
@media (max-width: 640px) {
  .done-btn, .checklist .done-btn { min-width: 44px; width: 44px; }
  .todo-row .meta { padding-left: 52px; }
  .set-table tbody tr.editor { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .set-table tbody tr.editor td:nth-child(3) { grid-column: 1 / -1; grid-row: 3; }
  .set-table tbody tr.editor td:nth-child(4) { grid-column: 1; grid-row: 4; }
  .set-table tbody tr.editor td:nth-child(5) { grid-column: 2; grid-row: 4; align-self: end; }
  .set-table tbody tr.editor td:nth-child(5) button { min-height: 48px; }
}
@media (max-width: 640px) {
  button, .btn { min-width: 44px; }
}

/* Daily allowance balance is the primary Finance signal. */
.daily-adjustment { --signal: var(--accent); margin: 8px 0 20px; padding: 24px; border: 1px solid color-mix(in srgb, var(--signal) 35%, var(--rule)); border-left: 5px solid var(--signal); background: color-mix(in srgb, var(--signal) 9%, var(--paper)); border-radius: 5px; }
.daily-adjustment.is-negative { --signal: var(--danger); }
.adjustment-heading { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.adjustment-heading h2 { margin: 0; color: var(--ink); font-size: 19px; text-transform: none; letter-spacing: 0; }
.adjustment-heading h2::after { display: none; }
.adjustment-heading > span { color: var(--ink-2); font-size: 12px; }
.adjustment-value { display: block; margin: 12px 0; color: var(--signal); font-size: clamp(40px, 7vw, 76px); font-weight: 600; line-height: 1.1; letter-spacing: -.045em; overflow-wrap: anywhere; }
.adjustment-value small { font-size: 16px; font-weight: 500; letter-spacing: 0; }
.daily-adjustment p { margin: 0; color: var(--ink-2); font-size: 13px; }
.adjustment-status { display: inline-block; color: var(--signal); font-weight: 600; margin-right: 10px; }
.balance-hero .balance-number { font-size: clamp(26px, 4vw, 38px); }
@media (max-width: 640px) {
  .daily-adjustment { padding: 18px 14px; }
  .adjustment-status { display: block; margin-bottom: 4px; }
}
