:root {
  color-scheme: light dark;
  --bg: #f1efe9;
  --surface: #fbfaf6;
  --surface-raised: #fffefb;
  --ink: #1b2522;
  --muted: #68716d;
  --line: #d7d7cf;
  --accent: #0c6b59;
  --accent-soft: #d9eee8;
  --credit: #b42335;
  --shadow: 0 18px 48px rgb(31 42 38 / 8%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 82% 0%, rgb(12 107 89 / 10%), transparent 28rem),
    var(--bg);
}

button, input, select { font: inherit; }

button, select, input {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
}

button {
  min-height: 2.65rem;
  padding: 0.62rem 1rem;
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

button:hover { filter: brightness(0.94); }
button:disabled { cursor: wait; opacity: 0.58; }

input, select {
  min-height: 2.65rem;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.58rem 0.7rem;
  color: var(--ink);
  background: var(--surface-raised);
}

label { color: var(--muted); font-size: 0.76rem; font-weight: 750; letter-spacing: 0.035em; }

.shell { width: min(1180px, calc(100% - 2rem)); margin-inline: auto; }

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding-block: 3.25rem 2rem;
}

.back { color: var(--accent); font-weight: 750; text-decoration: none; }
.back::before { content: "← "; }

h1, h2, p { margin-top: 0; }
h1 { max-width: 12ch; margin-bottom: 0.4rem; font-family: Georgia, serif; font-size: clamp(2.6rem, 7vw, 5rem); font-weight: 500; line-height: 0.94; letter-spacing: -0.045em; }
h2 { margin-bottom: 0; font-size: 1.18rem; }
.lede, .status, .empty p { color: var(--muted); }
.eyebrow { margin: 1.25rem 0 0.45rem; color: var(--accent); font-size: 0.7rem; font-weight: 850; letter-spacing: 0.15em; text-transform: uppercase; }

.entity-control { width: min(22rem, 100%); padding: 1rem; border-left: 3px solid var(--accent); }
.entity-control small { display: block; margin-top: 0.55rem; color: var(--muted); line-height: 1.35; }

.panel {
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.controls { padding: clamp(1rem, 3vw, 1.6rem); }
.control-heading, .action-row { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.control-heading .eyebrow { margin-top: 0; }
.preset-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
button.quiet { min-height: 2.2rem; padding: 0.4rem 0.7rem; color: var(--accent); background: transparent; }

.range-grid { display: grid; grid-template-columns: 1fr 1fr minmax(13rem, 1.35fr) auto; gap: 0.8rem; align-items: end; margin-top: 1.2rem; }
.action-row { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.filter { width: min(38rem, 100%); }
.status { min-height: 1.2em; margin: 0.8rem 0 0; font-size: 0.84rem; }
.status.error { color: var(--credit); }

.freshness { display: grid; gap: 0.55rem; margin-block: 1rem; }
.freshness-row { display: grid; grid-template-columns: 6rem minmax(11rem, auto) 1fr; gap: 0.75rem; align-items: baseline; padding: 0.7rem 0.9rem; border: 1px solid var(--line); border-radius: 0.65rem; color: var(--muted); background: rgb(255 255 255 / 36%); font-size: 0.78rem; }
.freshness-row strong { color: var(--ink); }
.hash { overflow-wrap: anywhere; color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.72rem; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; margin-block: 1rem; }
.metric { padding: 1rem 1.1rem; border-top: 3px solid var(--accent); background: var(--surface); }
.metric span { display: block; color: var(--muted); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.metric strong { display: block; margin-top: 0.3rem; font-family: Georgia, serif; font-size: 1.75rem; font-weight: 500; }

.category-strip { display: flex; gap: 0.6rem; overflow-x: auto; margin-block: 1rem 1.35rem; padding-bottom: 0.3rem; }
.category-card { min-width: 10rem; padding: 0.75rem 0.85rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--accent-soft); }
.category-card span { display: block; color: var(--muted); font-size: 0.72rem; }
.category-card strong { display: block; margin-top: 0.2rem; }

.ledger { display: grid; gap: 1rem; padding-bottom: 4rem; }
.gl-section { overflow: hidden; }
.gl-head { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.gl-head p { margin: 0.22rem 0 0; color: var(--muted); font-size: 0.78rem; }
.gl-subtotal { text-align: right; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th { color: var(--muted); background: rgb(0 0 0 / 2.5%); font-size: 0.67rem; letter-spacing: 0.09em; text-align: left; text-transform: uppercase; }
th, td { padding: 0.72rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
td.amount, th.amount { text-align: right; white-space: nowrap; }
.credit { color: var(--credit); font-weight: 750; }
.memo { max-width: 27rem; color: var(--muted); }
.source { white-space: nowrap; color: var(--muted); font-size: 0.75rem; }
.empty { padding: 2rem; text-align: center; }
.empty .eyebrow { margin-top: 0; }

@media (max-width: 820px) {
  .masthead, .control-heading, .action-row { align-items: stretch; flex-direction: column; }
  .range-grid { grid-template-columns: 1fr 1fr; }
  .range-grid label:nth-child(3), .range-grid button { grid-column: 1 / -1; }
  .filter, .entity-control { width: 100%; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 1rem, 1180px); }
  .masthead { padding-top: 1.5rem; }
  .range-grid, .summary-grid { grid-template-columns: 1fr; }
  .range-grid label, .range-grid label:nth-child(3), .range-grid button { grid-column: auto; }
  .freshness-row { grid-template-columns: 1fr; gap: 0.2rem; }
  .gl-head { align-items: start; flex-direction: column; }
  .gl-subtotal { text-align: left; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111815;
    --surface: #18211e;
    --surface-raised: #202a27;
    --ink: #edf4ef;
    --muted: #a2ada8;
    --line: #34423d;
    --accent: #68cfb6;
    --accent-soft: #203e36;
    --credit: #ff8793;
    --shadow: 0 18px 48px rgb(0 0 0 / 20%);
  }
  button { color: #0c2a23; }
  button.quiet { color: var(--accent); }
  .freshness-row { background: rgb(0 0 0 / 12%); }
  th { background: rgb(255 255 255 / 3%); }
}

@media print {
  body { background: #fff; color: #111; }
  .controls, .back, .refresh { display: none; }
  .panel { box-shadow: none; }
  .ledger { display: block; }
  .gl-section { break-inside: avoid; margin-bottom: 1rem; }
}
