/* Tally — household ledger theme.
   Warm paper, ink text, one terracotta accent. Serif display headings,
   system sans body. Light by default, warm dark via prefers-color-scheme.
   No external fonts or assets (privacy rule, ADR-0002). */

:root {
  --paper: #f4efe4;
  --card: #fdfbf4;
  --card-2: #ece5d3;
  --ink: #2b2723;
  --muted: #7a7264;
  --line: #ddd3bd;
  --accent: #b4552d;
  --accent-ink: #fdfbf4;
  --good: #4f7350;
  --bad: #9c3f34;
  /* Soft "flagged, not terminal" tone — missed tasks (ADR-0040 phase 1)
     stay completable, so deliberately not --bad (reserved for genuinely
     bad/terminal outcomes). */
  --warn: #a67c1f;
  --radius: 8px;
  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #221e19;
    --card: #2c2721;
    --card-2: #3a332a;
    --ink: #e9e2d2;
    --muted: #a2988a;
    --line: #453d31;
    --accent: #cf6a3c;
    --accent-ink: #221e19;
    --good: #7fa080;
    --bad: #c96a5e;
    --warn: #d9a441;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 640px; margin: 0 auto; padding: 20px 16px 96px; }

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0.5em 0 0.4em;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 {
  font-family: var(--sans);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.wordmark {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 4px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}

button {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 16px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.06); }
button.danger {
  background: transparent;
  border-color: var(--bad);
  color: var(--bad);
}
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--ink); border-color: transparent; }
button:disabled { opacity: 0.5; cursor: default; }

input, select {
  font: inherit;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  width: 100%;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 0.9rem; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.error { color: var(--bad); margin: 8px 0; min-height: 1.2em; }
.muted { color: var(--muted); }
.step-counter {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 2px;
}
.pill {
  display: inline-block;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 1px 10px;
  font-size: 0.78rem;
  color: var(--muted);
}
.pill.boost {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 0.7rem;
  line-height: 1.4;
  padding: 0 8px;
  white-space: nowrap;
}
.pill.expired { border-color: var(--bad); color: var(--bad); }
.pill.missed { border-color: var(--warn); color: var(--warn); }

/* Language switcher (ADR-0032) */
.lang-switch { display: inline-flex; gap: 4px; }
.lang-switch button.lang {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.75rem;
}
.lang-switch button.lang.active { color: var(--accent); border-color: var(--accent); }

/* Today board (ADR-0033) */
.today-grid { display: grid; gap: 4px; margin-top: 12px; align-items: start; }
.today-head {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  min-width: 0;
}
.today-name {
  font-size: 0.8rem;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tally { color: var(--ink); }
.tally line { stroke: currentColor; }
.tally line.cross { stroke: var(--accent); }
.today-chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 0.8rem;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.today-chip.done {
  color: var(--muted);
  border-style: dashed;
  text-decoration: line-through;
}

/* Profile picker */
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.profile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 20px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.profile:hover { border-color: var(--accent); }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--card-2);
  color: #fdfbf4;
  font-family: var(--serif);
  font-weight: 600;
  flex: none;
}
.profile .avatar { width: 56px; height: 56px; font-size: 1.5rem; }

/* Tab bar */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center; gap: 2px;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 8px max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom));
}
nav.tabs button {
  flex: 1; max-width: 140px;
  background: transparent; border: 0;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 4px;
  border-radius: var(--radius);
}
nav.tabs button.active { color: var(--accent); font-weight: 600; }

/* Task list */
.task {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.task:last-child { border-bottom: 0; }
/* .card already contributes 16px of padding; .task only wants 12px of
   space to whatever's above/below it (matching the 12px+12px either side
   of the border between two rows), so the first/last row pulls back the
   extra 4px rather than stacking 16+12=28px at the list's outer edge. */
.task:first-child { margin-top: -4px; }
.task:last-child { margin-bottom: -4px; }
.task-body { flex: 1 1 auto; min-width: 0; align-self: flex-start; }
.task .title { font-weight: 600; }
.task .meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 0.85rem; }

/* Icon-only task actions: won't-do / not-needed / done / more, a grid
   that's 2 columns wide but never taller than it needs to be —
   grid-auto-rows (not a fixed grid-template-rows) means a 1-2 button row
   (e.g. production today, before won't-do/more are wired up — see
   PENDING.md) sizes to one 44px row instead of reserving a second, empty
   one beneath it. "More" opens a menu of extra actions (currently just
   complete-as-another-member — see renderTaskMenu); won't-do/not-needed
   stay on the row as their own buttons. The body sizes to whatever's
   left (min-width: 0 lets long titles wrap instead of pushing the
   buttons out). 44x44 CSS px meets the WCAG 2.5.8 (AAA) /
   platform-standard minimum touch target so they're comfortable to tap
   on a phone, not just click with a mouse. Row uses
   align-items: flex-end so the button grid stays pinned to the bottom of
   the row when the body wraps taller than it. */
.task-actions {
  display: grid;
  grid-template-columns: repeat(2, 44px);
  grid-auto-rows: 44px;
  gap: 8px;
  flex: none;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
.icon-btn:hover { background: var(--card-2); }
.icon-btn.primary { background: var(--good); border-color: var(--good); color: var(--accent-ink); }
.icon-btn.primary:hover { filter: brightness(1.06); }
.icon-btn .icon { display: flex; }

/* Leaderboard */
.board-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.board-row .bar-wrap {
  flex: 1;
  background: var(--card-2);
  border-radius: 4px;
  height: 18px;
  overflow: hidden;
}
.board-row .bar { height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.board-row .value { min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }

.balance-big {
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--accent);
}

table.ledger { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.ledger td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.ledger td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta-pos { color: var(--good); }
.delta-neg { color: var(--bad); }

ul { margin: 8px 0; padding-left: 20px; }
li { margin: 3px 0; }

/* Modal (native <dialog>) */
dialog {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  width: min(480px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(20, 16, 12, 0.55); }
dialog h2 { margin-top: 0; }
dialog select[multiple] { height: auto; }

/* Task "more" menu: complete-as-member list, a divider, then won't-do /
   not-needed (renderTaskMenu in tasks.ts). Narrower than the general
   <dialog> width since it's a menu, not a form. */
#task-menu-dialog, .task-menu-static { width: min(260px, calc(100vw - 32px)); padding: 12px; }
/* Overrides the global h3 (small uppercase "section label" style) — here
   it's the menu's task title, which should read like a normal heading. */
.task-menu-title { margin: 0 0 4px; font-size: 0.95rem; font-weight: 600; text-transform: none; letter-spacing: normal; color: var(--ink); font-family: var(--sans); }
.task-menu-section-label { margin: 8px 4px 4px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius);
  background: transparent; border: none; color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--card-2); }
.menu-divider { border: none; border-top: 1px solid var(--line); margin: 8px 0; }

/* Chain-authoring + eligibility picker (ADR-0040 phase 3 follow-up) */
.elig-picker { position: relative; }
.elig-field {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 5px 8px; min-height: 40px; cursor: text;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.elig-field:focus-within { border-color: var(--muted); }
.elig-input {
  flex: 1 1 90px; min-width: 90px; border: none; background: transparent;
  color: var(--ink); font: inherit; padding: 4px 2px; outline: none;
}
.elig-everyone { color: var(--muted); font-style: italic; padding: 4px 2px; }
.elig-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 4px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card-2);
  font-size: 0.85rem; line-height: 1;
}
.elig-chip .elig-name { padding-right: 2px; }
.elig-chip .avatar { flex: 0 0 auto; }
.elig-group-disc {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
}
.elig-group-disc .icon svg { width: 13px; height: 13px; }
.elig-x {
  border: none; background: transparent; color: inherit; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0 2px; opacity: 0.6;
  min-width: 20px; min-height: 20px; border-radius: 999px;
}
.elig-x:hover { opacity: 1; border-color: transparent; }
.elig-menu {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 220px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
}
.elig-menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border: none; background: transparent; color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.elig-menu-item:hover { background: var(--card-2); }
.elig-menu-item .elig-kind { font-size: 0.78rem; }
.elig-menu-empty { padding: 8px 10px; }

/* Add-task composer */
.composer-row { display: flex; gap: 8px; align-items: flex-start; }
.composer-name-row { margin-bottom: 8px; }
.composer-action-row { align-items: center; }
.composer-input-wrap { position: relative; flex: 1 1 auto; }
.composer-input { width: 100%; }
.composer-menu {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 260px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
}
.composer-menu-item {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 8px 10px; border: none; background: transparent; color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.composer-menu-item:hover { background: var(--card-2); }
.composer-menu-kicker { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.composer-menu-title { font-weight: 600; }
.composer-menu-min { margin-left: auto; font-size: 0.8rem; white-space: nowrap; }
.composer-more { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 4px; }
.composer-field { margin: 12px 0; }
.composer-field > label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.composer-tpl-hint { font-size: 0.78rem; font-style: italic; }
.composer-worth-wrap { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.composer-worth { width: 70px; }
.composer-more-btn { white-space: nowrap; }
.composer-fu-list { display: flex; flex-direction: column; gap: 12px; }
.composer-fu-r1 select { width: 100%; }
.composer-fu-r2 { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.composer-fu-add { align-self: flex-start; padding-left: 0; margin-top: 8px; }
