/* Mobile-first. Two users, one phone each, thumbs at the kitchen counter. */

:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #14181d;
  --ink-soft: #5b6472;
  --ink-faint: #8b95a3;
  --line: #e2e6eb;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --neg: #b3261e;
  --warn: #8a6100;
  --warn-bg: #fdf3d8;
  --radius: 12px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #191d23;
    --ink: #e8ecf1;
    --ink-soft: #a3adba;
    --ink-faint: #6f7986;
    --line: #272d35;
    --accent: #6fbf8e;
    --accent-ink: #10231a;
    --neg: #ff8b82;
    --warn: #f0c674;
    --warn-bg: #2e2611;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

main { padding: 12px 12px 64px; max-width: 720px; margin: 0 auto; }
html, body { overflow-x: hidden; }

/* --- top bar ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 650; color: var(--ink); text-decoration: none;
  letter-spacing: -0.01em; font-size: 15px; flex: 0 0 auto;
}
.topbar nav { display: flex; gap: 2px; align-items: center; min-width: 0; }
.topbar nav a {
  color: var(--ink-soft); text-decoration: none; font-size: 13.5px;
  padding: 7px 8px; border-radius: 8px; white-space: nowrap;
}
.topbar nav a.cta { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* --- period header ------------------------------------------------------ */
.period-head {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.period-nav { display: flex; align-items: center; gap: 8px; }
.period-title { flex: 1; text-align: center; }
.period-title h1 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.sub { margin: 6px 0 0; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

.chev {
  min-width: var(--tap); min-height: var(--tap);
  display: grid; place-items: center;
  font-size: 26px; text-decoration: none; color: var(--ink-soft);
  border-radius: 10px;
}
.chev.disabled { color: var(--line); }

.pill {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 999px;
  background: var(--bg); color: var(--ink-soft); border: 1px solid var(--line);
}
.pill-anchor { color: var(--accent); border-color: var(--accent); }
.pill-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill-closed { opacity: 0.65; }

/* --- ledger ------------------------------------------------------------- */
.ledger { margin-top: 14px; border-top: 1px solid var(--line); }
.ledger-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.ledger-row.muted { color: var(--ink-soft); }
.ledger-row.total { font-weight: 680; font-size: 19px; border-bottom: none; }
.ledger-row.total.negative { color: var(--neg); }

.amt { font-variant-numeric: tabular-nums; text-align: right; }
.amt.big { font-size: 17px; font-weight: 600; }

.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form .amt { width: 110px; }

/* --- lines -------------------------------------------------------------- */
.lines { list-style: none; margin: 0; padding: 0; }
.line {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 6px; padding: 8px 10px;
}
.line.confirmed { opacity: 0.72; }
.line-main {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 76px 76px 18px;
  align-items: center; gap: 5px;
}
.line-body { min-width: 0; }
.line-name { font-weight: 560; font-size: 14.5px; line-height: 1.25; }
.line-raw, .line-note, .line-deadline { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.line-note { color: var(--ink-soft); }
.line-deadline { color: var(--warn); }
.line-deadline.past { color: var(--neg); font-weight: 600; }

.who {
  font-size: 11px; color: var(--ink-soft); background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; margin-left: 6px;
}
.flag {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--warn); background: var(--warn-bg);
  border-radius: 4px; padding: 1px 5px; margin-left: 6px;
}

.tick {
  width: 28px; height: 28px; padding: 0; border-radius: 50%;
  min-height: 0; display: grid; place-items: center;
  border: 1.5px solid var(--line); background: transparent;
  color: var(--line); font-size: 14px; cursor: pointer; line-height: 1;
}
.tick.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* plan and actual sit side by side; stacking them made each row ~180px tall,
   which is far too much for a 14-line list on a phone. The column labels live
   in a single header row rather than being repeated on all 14 lines, which
   is what was squeezing the category names into two lines at 375px. */
.lines-head {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 76px 76px 18px;
  gap: 5px; padding: 0 10px 4px;
}
.lines-head span {
  grid-column: span 1; text-align: center;
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-faint);
}
.lines-head span:first-child { grid-column: 3; }

.line-amounts { display: contents; }
.line-amounts .amt {
  width: 100%; padding: 5px 6px; min-height: 32px; font-size: 13.5px;
}
.line-amounts .actual { font-weight: 600; }

.line-del button { font-size: 19px; line-height: 1; padding: 2px 4px; }

/* The generate preview reuses .line but has no tick, inputs or delete button,
   so it must not inherit the period view's five-column grid. */
.lines.preview .line-main {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.lines.preview .line-amounts { display: block; }
.lines.preview .line-raw { white-space: normal; }

/* --- inputs ------------------------------------------------------------- */
input, select, textarea, button {
  font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input.saved { border-color: var(--accent); transition: border-color 1s; }
input.failed { border-color: var(--neg); }

button { cursor: pointer; }
button.primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600; width: 100%; min-height: var(--tap);
}
button.ghost { background: transparent; border: none; color: var(--ink-soft); padding: 4px 6px; min-height: 0; }
button.ghost.danger { color: var(--neg); }

/* --- sub-items ---------------------------------------------------------- */
.subs { margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 8px; }
.subs summary { font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.subs ul { list-style: none; margin: 8px 0; padding: 0; }
.subs li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px;
  align-items: center; font-size: 14px; padding: 3px 0;
}
.subs em { color: var(--ink-faint); font-style: normal; font-size: 12px; }
.remainder { color: var(--warn); font-weight: 600; margin-left: 6px; }
.sub-add { display: grid; grid-template-columns: 1fr 90px; gap: 6px; margin-top: 6px; }
.sub-add select, .sub-add button { grid-column: 1 / -1; }

/* --- cards, lists ------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 4px; font-size: 15px; letter-spacing: -0.01em; }
.hint { color: var(--ink-faint); font-size: 12.5px; margin: 0 0 10px; }
.lede { color: var(--ink-soft); font-size: 14px; margin: 0 0 12px; }
.section-head { font-size: 15px; margin: 18px 0 8px; color: var(--ink-soft); }

.banner { border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }

.suggestions, .skipped, .deadlines { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.suggestions li, .deadlines li a {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px;
  align-items: center; padding: 7px 0; border-top: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
}
.deadlines li.past a { color: var(--neg); }
.skipped li { padding: 4px 0; color: var(--ink-soft); font-size: 13px; }
.conf.low { color: var(--warn); }

/* --- runway ------------------------------------------------------------- */
.runway { list-style: none; margin: 0; padding: 0; }
.runway li a {
  display: grid; grid-template-columns: 106px 1fr 80px; gap: 8px;
  align-items: center; padding: 6px 0; text-decoration: none; color: var(--ink);
  font-size: 12.5px; white-space: nowrap;
}
.rw-bar { background: var(--bg); border-radius: 4px; height: 10px; overflow: hidden; }
.rw-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.rw-fill.negative { background: var(--neg); }
.rw-amt { text-align: right; font-variant-numeric: tabular-nums; }
.rw-amt.negative, .negative { color: var(--neg); }

/* --- period list -------------------------------------------------------- */
.period-list { list-style: none; margin: 0; padding: 0; }
.period-list li a {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 6px; text-decoration: none; color: var(--ink);
  min-height: var(--tap);
}
.pl-date { font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pl-nums { display: flex; gap: 10px; font-variant-numeric: tabular-nums; font-size: 13px; }
.pl-nums .in { color: var(--ink-soft); }
.pl-nums .out { color: var(--ink-faint); }
.pl-nums .left { font-weight: 650; min-width: 68px; text-align: right; }

/* --- misc --------------------------------------------------------------- */
.add-line, .period-meta { margin-top: 14px; }
.add-line summary, .period-meta summary { color: var(--ink-soft); font-size: 14px; padding: 8px 0; cursor: pointer; }
.add-line form, .period-meta form, .commit { display: grid; gap: 8px; }
.commit { margin: 16px 0; }
.empty { color: var(--ink-faint); text-align: center; padding: 24px; }
textarea { width: 100%; resize: vertical; }

@media (min-width: 560px) {
  .sub-add { grid-template-columns: 1fr 100px 1fr auto; }
  .sub-add select, .sub-add button { grid-column: auto; }
  .add-line form { grid-template-columns: 1fr 1fr 110px 1fr auto; align-items: center; }
}

/* --- auth --------------------------------------------------------------- */
.logout-form { display: inline; }
/* Needs to out-specify `button.ghost`, which sets border: none. */
.topbar .who-btn {
  font-size: 13px; color: var(--ink-soft); padding: 6px 8px;
  border-radius: 8px; background: var(--bg); border: 1px solid var(--line);
  min-height: 0; max-width: 70px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.login-page { display: grid; min-height: 100vh; place-items: center; }
main.login {
  width: min(100%, 340px); padding: 24px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius);
}
main.login h1 { margin: 0 0 20px; font-size: 22px; text-align: center; }
main.login form { display: grid; gap: 6px; }
main.login label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-faint); margin-top: 8px;
}
main.login input { min-height: var(--tap); font-size: 16px; }
main.login button { margin-top: 18px; }
.banner.error {
  background: var(--warn-bg); color: var(--neg);
  border: 1px solid var(--neg); margin-bottom: 4px;
}

/* --- inline note on a line ---------------------------------------------- */
/* Quiet until it has something to say: an empty note is a faint prompt, a
   filled one reads as text. Keeps 14 rows from growing a visible form each. */
.note-row { display: flex; gap: 4px; align-items: center; margin-top: 2px; }
.note-input {
  flex: 1; min-height: 26px; padding: 2px 4px; font-size: 12.5px;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--ink-soft);
}
.note-input::placeholder { color: var(--line); }
.note-input:hover { border-color: var(--line); }
.note-input:focus {
  background: var(--bg); border-color: var(--accent);
  color: var(--ink); outline: none;
}
.note-input.has-note { color: var(--ink-soft); }
/* The explicit save button is only needed without JavaScript. */
.note-save { display: none; font-size: 11px; }
.no-js .note-save { display: inline; }

.line-due {
  font-size: 12px; color: var(--accent); margin-top: 2px; font-weight: 560;
}
.in-period { color: var(--ink-faint); font-style: normal; font-size: 11.5px; display: block; }

/* --- schedule page ------------------------------------------------------- */
.sched-list { list-style: none; margin: 0 0 14px; padding: 0; }
.sched {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 6px;
}
.sched.incomplete { border-color: var(--warn); }
.sched.off { opacity: 0.6; }
.sched > details > summary {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 10px 12px; cursor: pointer; min-height: var(--tap);
}
.sched-name { font-weight: 560; font-size: 14.5px; }
.sched-when {
  font-size: 12.5px; color: var(--ink-soft); text-align: right; flex: 0 1 auto;
}
.sched-when em { color: var(--ink-faint); font-style: normal; display: block; }
.sched-when .needs { color: var(--warn); font-weight: 600; }

.sched-form { padding: 0 12px 12px; display: grid; gap: 10px; min-width: 0; }
.sched-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-width: 0; }
/* Grid items are min-width:auto by default, so a long value in an input makes
   the column refuse to shrink and the whole page scrolls sideways. */
.sched-form label { display: grid; gap: 3px; min-width: 0; }
.sched-form input, .sched-form select { min-width: 0; width: 100%; }
.sched-form label.wide { grid-column: 1 / -1; }
.sched-form label > span {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-faint);
}
.sched-form label[hidden] { display: none; }
.sched-form label.check {
  grid-auto-flow: column; justify-content: start; align-items: center; gap: 8px;
}
.sched-form label.check span { text-transform: none; letter-spacing: 0;
  font-size: 13px; color: var(--ink-soft); }
.sched-form label.check input { width: 18px; height: 18px; min-height: 0; }
.evidence { margin: 0; }
.sched-actions { display: grid; }
.sched-del { padding: 0 12px 10px; text-align: right; }
.sched-del button { font-size: 12px; }
.add-rule summary { cursor: pointer; color: var(--ink-soft); font-size: 14px; }
.add-rule .sched-form { padding: 12px 0 0; }

@media (min-width: 560px) {
  .sched-grid { grid-template-columns: repeat(3, 1fr); }
}
