:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #e2e6ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 14px;
  /* Chart series (validated categorical slots 1-3) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --card: #182027;
    --text: #e6eaee;
    --muted: #93a0ad;
    --line: #2a343d;
    --accent: #2dd4bf;
    --accent-ink: #062a26;
    --warn: #f59e0b;
    --bad: #f87171;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0 0 .75rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.neg { color: var(--bad); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--accent); text-decoration: none; }
.tabs { display: flex; gap: .25rem; }
.tabs a {
  padding: .4rem .8rem; border-radius: 999px;
  color: var(--text); text-decoration: none;
}
.tabs a.on { background: var(--accent); color: var(--accent-ink); }
.who { margin-left: auto; display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .9rem; }
.who a { color: var(--muted); text-decoration: none; }
.who a:hover, .who a.on { color: var(--text); text-decoration: underline; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

.wrap { max-width: 720px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
/* Grid items default to min-width:auto, which lets a wide table stretch the page; keep it inside its scroller. */
.wrap > * { min-width: 0; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem;
}
.flash {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  background: color-mix(in srgb, var(--accent) 15%, var(--card));
  border: 1px solid var(--accent); border-radius: var(--radius); padding: .6rem 1rem;
}
.flash form { margin: 0; }
.flash button.link { font-weight: 600; }
a { color: var(--accent); }
.crumbs { margin: 0; }

/* Summary card */
.summary-head { display: flex; justify-content: space-between; align-items: flex-start; }
.summary .label { color: var(--muted); font-size: .9rem; }
.summary .big { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary .month { color: var(--muted); font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: .15rem; white-space: nowrap; }
.summary .step {
  display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border-radius: 999px; font-size: 1.4rem; line-height: 1; color: var(--text); text-decoration: none;
}
.summary a.step:hover { background: var(--line); }
.summary .step.off { color: var(--line); }
.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: .6rem 0 .9rem; }
.bar span { display: block; height: 100%; background: var(--accent); }
.summary.warn .bar span { background: var(--warn); }
.summary.over .bar span { background: var(--bad); }
.summary.over .big { color: var(--bad); }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .5rem; margin: 0; }
.figures dt { color: var(--muted); font-size: .8rem; }
.figures dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Forms */
form label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, select {
  width: 100%; font: inherit; color: var(--text);
  padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[aria-invalid="true"] { border-color: var(--bad); }
button.primary, .button, button.danger {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  padding: .7rem 1.2rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text);
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { background: none; border-color: var(--bad); color: var(--bad); width: 100%; }
.danger-text { color: var(--bad) !important; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.danger-zone p { margin: 0 0 .9rem; }
form label.check { display: flex; align-items: center; gap: .5rem; cursor: pointer; color: var(--text); }
form label.check input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--accent); flex: none; }
.stack { display: grid; gap: .9rem; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.inline-form { display: grid; gap: .8rem; margin-top: 1rem; }
.inline-form .full { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .inline-form { grid-template-columns: 9rem 11rem 1fr auto; align-items: end; }
  .inline-form:not(:has(.grow)) { grid-template-columns: 11rem 11rem auto 1fr; }
  .inline-form button { height: 2.75rem; }
}
.start-form { display: flex; flex-wrap: wrap; align-items: end; gap: .6rem .8rem; margin-bottom: 1rem; }
.start-form label { flex: 0 1 12rem; }
.start-form .button { height: 2.75rem; padding-block: 0; }
.start-form .full { flex-basis: 100%; }
.person-picker label { display: flex; align-items: center; gap: .6rem; color: var(--muted); }
.person-picker select { width: auto; min-width: 12rem; }
.entry { display: grid; gap: .8rem; }
@media (min-width: 640px) {
  .entry { grid-template-columns: 1fr 8rem 10rem auto; align-items: end; }
  .entry button { height: 2.75rem; }
  .entry label.check { grid-column: 1 / -1; grid-row: 2; }
}
.login { max-width: 380px; width: 100%; margin: 12vh auto 0; }
.login form { display: grid; gap: .9rem; }

/* Lists & tables */
.expenses { list-style: none; margin: 0; padding: 0; }
.expenses li { border-top: 1px solid var(--line); }
.expenses li:first-child { border-top: 0; }
.expenses a {
  display: grid; grid-template-columns: 3.5rem 1fr auto; gap: .6rem;
  padding: .65rem .4rem; margin: 0 -.4rem; border-radius: 8px;
  color: inherit; text-decoration: none;
}
.expenses a:hover { background: var(--bg); }
.expenses .when { color: var(--muted); font-size: .9rem; }
.expenses .what { overflow-wrap: anywhere; }
.expenses .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.expenses .amt.in { color: var(--accent); }
.small { font-size: .85rem; margin: .5rem 0 0; }

/* Reports */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.seg a { padding: .3rem .75rem; border-radius: 999px; color: var(--text); text-decoration: none; font-size: .9rem; }
.seg a.on { background: var(--accent); color: var(--accent-ink); }
.chart-box { position: relative; height: 300px; }
@media (min-width: 640px) { .chart-box { height: 340px; } }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .5rem .4rem; border-top: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .85rem; border-top: 0; }
tr.muted td { color: var(--muted); }
td.row-action { text-align: right; width: 1%; }
td.row-action form { margin: 0; }
td.wrap-cell { white-space: normal; min-width: 10rem; }
