/*
 * Kira — the look of a set of accounts, not an admin panel.
 *
 * The audience is someone checking figures: an accountant, an auditor, an owner
 * who wants to know where the money went. So the page is built like a printed
 * statement rather than a dashboard — quiet paper, hairline rules, and typography
 * that makes a column of numbers scannable.
 *
 * Two choices carry most of the weight:
 *   · tabular figures everywhere money appears, so digits line up in a column
 *   · the faint green banding on ledger listings, after the green-bar analysis
 *     paper accountants read on for a century before screens
 *
 * Hand written rather than generated from a utility framework: statement
 * typography needs rules a utility class set does not have, and the result
 * should not look like every other admin screen.
 */

:root {
  --paper: #faf8f4;
  --paper-raised: #ffffff;
  --ink: #1c1c19;
  --ink-soft: #55524a;
  --ink-faint: #8b877c;
  --rule: #ddd7c9;
  --rule-strong: #b4ad9c;

  /* Ledger green — the banding colour of analysis paper. */
  --ledger: #2f5d50;
  --ledger-tint: #f0f4f1;
  --ledger-band: #f6f8f5;

  --negative: #8c2f22;
  --warn-bg: #fdf6e6;
  --warn-rule: #d8b768;
  --ok: #2f5d50;

  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16171a;
    --paper-raised: #1d1f23;
    --ink: #ece9e2;
    --ink-soft: #a9a49a;
    --ink-faint: #7c7871;
    --rule: #34373d;
    --rule-strong: #4c5058;
    --ledger: #7fbfa9;
    --ledger-tint: #1b2622;
    --ledger-band: #191d1c;
    --negative: #e08a7a;
    --warn-bg: #2a2415;
    --warn-rule: #7a6428;
    --ok: #7fbfa9;
  }
}

:root[data-theme="dark"] {
  --paper: #16171a;
  --paper-raised: #1d1f23;
  --ink: #ece9e2;
  --ink-soft: #a9a49a;
  --ink-faint: #7c7871;
  --rule: #34373d;
  --rule-strong: #4c5058;
  --ledger: #7fbfa9;
  --ledger-tint: #1b2622;
  --ledger-band: #191d1c;
  --negative: #e08a7a;
  --warn-bg: #2a2415;
  --warn-rule: #7a6428;
  --ok: #7fbfa9;
}

:root[data-theme="light"] {
  --paper: #faf8f4;
  --paper-raised: #ffffff;
  --ink: #1c1c19;
  --ink-soft: #55524a;
  --ink-faint: #8b877c;
  --rule: #ddd7c9;
  --rule-strong: #b4ad9c;
  --ledger: #2f5d50;
  --ledger-tint: #f0f4f1;
  --ledger-band: #f6f8f5;
  --negative: #8c2f22;
  --warn-bg: #fdf6e6;
  --warn-rule: #d8b768;
  --ok: #2f5d50;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ledger); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Masthead ──────────────────────────────────────────────── */

.masthead {
  border-bottom: 1px solid var(--rule);
  background: var(--paper-raised);
}

.masthead-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem 1.5rem 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem 1.25rem;
}

.wordmark {
  font-family: var(--serif);
  font-size: 1.35rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  font-weight: 600;
}
.wordmark span { color: var(--ledger); }

.entity {
  font-size: 0.9rem;
  color: var(--ink-soft);
  border-left: 1px solid var(--rule);
  padding-left: 1.25rem;
}
.entity strong { color: var(--ink); font-weight: 600; }

.masthead-spacer { flex: 1 1 auto; }

.theme-toggle {
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--rule-strong); color: var(--ink); }

/* Navigation reads as tabs on a folder of statements. */
.nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  gap: 1.4rem;
  overflow-x: auto;
}

.nav a {
  display: block;
  padding: 0.7rem 0 0.55rem;
  font-size: 0.86rem;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.nav a:hover { color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--ledger);
  font-weight: 600;
}

/* ── Page ──────────────────────────────────────────────────── */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem 1.5rem 5rem;
}

.statement-head { margin-bottom: 1.5rem; }

.statement-head h1 {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 600;
  margin: 0 0 0.2rem;
  letter-spacing: -0.01em;
}

.statement-head .period {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.sheet {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 1.6rem 1.75rem;
  margin-bottom: 1.5rem;
}

.sheet > h2 {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

/* ── Figures ───────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 0.42rem 0.5rem;
  text-align: left;
  vertical-align: baseline;
}
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }

thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
  font-weight: 600;
  border-bottom: 1px solid var(--rule-strong);
  padding-bottom: 0.5rem;
}

/* Money: tabular figures so digits stack, and the mono face for the code
   column so account numbers align as a block. */
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
}
.code {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.neg { color: var(--negative); }
.muted { color: var(--ink-faint); }

tbody tr.section-head td {
  font-weight: 600;
  padding-top: 1.1rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

tbody tr.subtotal td {
  border-top: 1px solid var(--rule);
  font-weight: 600;
  padding-top: 0.55rem;
}

/* A double rule under a final total — the printed convention for "this is the
   figure the statement was built to produce". */
tbody tr.total td {
  border-top: 1px solid var(--rule-strong);
  border-bottom: 3px double var(--rule-strong);
  font-weight: 700;
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}

tbody tr.indent td:first-child { padding-left: 1.25rem; }

/* Ledger listings band like analysis paper. */
table.banded tbody tr:nth-child(even) { background: var(--ledger-band); }
table.banded tbody tr:hover { background: var(--ledger-tint); }

tr.voided td { color: var(--ink-faint); text-decoration: line-through; }

/* ── Verdicts and notices ──────────────────────────────────── */

.verdict {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}
.verdict::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
}
.verdict.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.verdict.ok::before { background: var(--ok); }
.verdict.bad { color: var(--negative); border-color: color-mix(in srgb, var(--negative) 35%, transparent); }
.verdict.bad::before { background: var(--negative); }

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-rule);
  border-left-width: 3px;
  border-radius: 2px;
  padding: 0.8rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.88rem;
}
.notice h3 {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.notice ul { margin: 0; padding-left: 1.1rem; }
.notice li + li { margin-top: 0.25rem; }

/* ── Summary tiles ─────────────────────────────────────────── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.tile {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 1rem 1.1rem;
}
.tile .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
  margin-bottom: 0.35rem;
}
.tile .figure {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.tile .sub { font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.2rem; }

/* ── Misc ──────────────────────────────────────────────────── */

.tree-depth-1 td:first-child { padding-left: 1.1rem; }
.tree-depth-2 td:first-child { padding-left: 2.2rem; }
.tree-depth-3 td:first-child { padding-left: 3.3rem; }

.pill {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink-faint);
}

.empty {
  padding: 2.5rem 0;
  text-align: center;
  color: var(--ink-faint);
  font-style: italic;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 1.25rem;
  font-size: 0.86rem;
}
.toolbar input, .toolbar select {
  font: inherit;
  padding: 0.32rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-raised);
  color: var(--ink);
}
.toolbar button {
  font: inherit;
  padding: 0.34rem 0.9rem;
  border: 1px solid var(--ledger);
  background: var(--ledger);
  color: #fff;
  border-radius: 2px;
  cursor: pointer;
}
.toolbar button:hover { filter: brightness(1.08); }

/* Wide tables scroll inside their own box; the page never does. */
.scroll-x { overflow-x: auto; }

footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  color: var(--ink-faint);
  font-size: 0.78rem;
}

/* ── Print ─────────────────────────────────────────────────── */

@media print {
  :root { --paper: #fff; --paper-raised: #fff; --ink: #000; }
  .masthead, .nav, .toolbar, .theme-toggle, footer { display: none; }
  main { max-width: none; padding: 0; }
  .sheet { border: none; padding: 0; margin-bottom: 1.5rem; break-inside: avoid; }
  table.banded tbody tr:nth-child(even) { background: none; }
  a { color: #000; text-decoration: none; }
}

@media (max-width: 640px) {
  main { padding: 1.25rem 1rem 4rem; }
  .sheet { padding: 1.1rem 1rem; }
  .masthead-inner { padding: 0.85rem 1rem 0; }
  .nav { padding: 0 1rem; }
  .entity { border-left: none; padding-left: 0; }
}
