:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f2321;
  --muted: #69706c;
  --border: #e2e0d8;
  --accent: #2e6b5a;
  --accent-text: #ffffff;
  --accent-weak: #e4efe9;
  --neg: #b42318;
  --late: #a15c00;
  --partial: #fbf3e2;
  --edited: #fff8db;
  /* Meters: fill and a lighter track of the same hue (checked for contrast and colour blindness). */
  --meter-ok: #1a8560;
  --meter-ok-track: #dcece4;
  --meter-late: #a15c00;
  --meter-late-track: #f5e6cf;
  --radius: 10px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Dark: the system setting, unless the theme button chose light; or the button chose dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #131615;
    --surface: #1c201e;
    --text: #e7e9e6;
    --muted: #9aa29d;
    --border: #2d3330;
    --accent: #79c2a9;
    --accent-text: #0f1513;
    --accent-weak: #1d2e28;
    --neg: #ff8b7e;
    --late: #f0b45c;
    --partial: #2b2618;
    --edited: #2e2a17;
    --meter-ok: #3aa97f;
    --meter-ok-track: #22362e;
    --meter-late: #c7842a;
    --meter-late-track: #3a2f1c;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #131615;
  --surface: #1c201e;
  --text: #e7e9e6;
  --muted: #9aa29d;
  --border: #2d3330;
  --accent: #79c2a9;
  --accent-text: #0f1513;
  --accent-weak: #1d2e28;
  --neg: #ff8b7e;
  --late: #f0b45c;
  --partial: #2b2618;
  --edited: #2e2a17;
  --meter-ok: #3aa97f;
  --meter-ok-track: #22362e;
  --meter-late: #c7842a;
  --meter-late-track: #3a2f1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}

a { color: var(--accent); }

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 32px 0 12px; }
.card h2 { margin-top: 0; }

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; gap: 8px; align-items: center; font-weight: 700; color: var(--text); text-decoration: none; }
.brand img { display: block; }
.top nav { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.who { color: var(--muted); }
.theme-toggle { color: var(--muted); text-decoration: none; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.label { display: block; color: var(--muted); font-size: 0.85rem; }
.big { font-size: 1.3rem; font-weight: 600; margin: 4px 0; }
.status { font-weight: 600; margin: 8px 0 0; }
.state-ok { color: var(--accent); }
.state-late { color: var(--late); }
.state-muted { color: var(--muted); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.ledger-card { color: inherit; text-decoration: none; }
.ledger-card:hover { border-color: var(--accent); }
.ledger-card h2 { font-size: 1.1rem; }
.ledger-card p { margin: 6px 0; }
.ledger-card p.status { margin-top: 12px; }
.cards.compact { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.cards.compact .card p { margin: 4px 0 0; }

.meter { display: block; overflow: visible; }
.meter .track { fill: var(--meter-ok-track); }
.meter .fill { fill: var(--meter-ok); }
.meter.late .track { fill: var(--meter-late-track); }
.meter.late .fill { fill: var(--meter-late); }
.meter .due, .due-key .due { stroke: var(--text); stroke-width: 2; }
.due-key { vertical-align: -2px; }
.meter-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin: 0 0 4px; }
.meter-head .num { margin-left: auto; }
.year-meters { display: grid; gap: 16px; }
.year-meter p { margin: 4px 0 0; }
.card-meter { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.card-meter p { margin: 4px 0 0; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: middle;
}

.years { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; }
.years a {
  padding: 4px 12px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface);
}
.years a.current { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.section-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.section-head h2 { margin-bottom: 12px; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot th, tfoot td { border-top: 2px solid var(--border); border-bottom: 0; font-size: inherit; font-weight: 600; color: var(--text); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--neg); }
.ccy { color: var(--muted); font-size: 0.8rem; }
.account { color: var(--muted); }
.note { color: var(--muted); min-width: 160px; }
tr.pending td { font-style: italic; opacity: 0.75; }
tr.covered td:first-child { box-shadow: inset 3px 0 var(--accent); }
tr.partial td { background: var(--partial); }
tr.target-row td { vertical-align: middle; }
tr.this-month td:first-child { font-weight: 600; }
tr.dirty td { background: var(--edited); }
.amount-input { width: 7.5em; text-align: right; font-variant-numeric: tabular-nums; padding: 4px 6px; }
td.note input { min-width: 14em; padding: 4px 6px; }
.row-actions { display: flex; gap: 12px; align-items: center; }
.js .target-row:not(.dirty) .save { display: none; }

form.inline { display: inline; }
.stack { display: grid; gap: 12px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}
.wide { grid-column: 1 / -1; }
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
label.check { display: inline-flex; gap: 6px; align-items: center; color: var(--text); font-size: 0.95rem; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 12px 0; }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
}
input:disabled, input[readonly] { color: var(--muted); }
input[type='checkbox'] { width: auto; }
.ccy-input { text-transform: uppercase; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 16px 0; padding: 12px 16px 16px; }
legend { font-weight: 600; padding: 0 6px; }
.tx-form > .wide { margin: 8px 0 16px; }
details.card { margin-top: 12px; }
summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 12px; }

button, .button {
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.small-button { padding: 3px 10px; font-size: 0.85rem; }
button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-weight: 400;
  text-decoration: underline;
}
button.danger { background: var(--neg); border-color: var(--neg); color: #fff; }
button.link.danger { background: none; color: var(--neg); }
.actions { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.danger-zone { margin: 24px 0; }

.alert {
  border: 1px solid var(--late);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  background: var(--partial);
}
.alert ul { margin: 0; padding-left: 18px; }
[hidden] { display: none !important; }

.login { max-width: 400px; margin: 56px auto; padding: 32px 24px; text-align: center; }
.login h1 { margin: 0 0 6px; font-size: 1.75rem; }
.login > p { margin: 0 0 24px; }
.login-logo { display: block; margin: 0 auto 16px; }
/* The Google button lives in a light iframe: a matching color-scheme keeps it
   transparent, instead of the opaque box browsers paint behind a mismatched one. */
#google-signin { display: flex; justify-content: center; min-height: 44px; color-scheme: light; }
.login .alert { margin: 16px 0 0; text-align: left; }
.dev-login { margin-top: 28px; padding-top: 20px; border-top: 1px dashed var(--border); text-align: left; }
.dev-login h2 { margin: 0; font-size: 1rem; }

@media (max-width: 600px) {
  main { padding-top: 16px; }
  h1 { font-size: 1.35rem; }
  th, td { padding: 7px 9px; }
  .opt { display: none; }
}
