/* Ledger - self-hosted, no CDN. Drop woff2 files in /assets/fonts to get the
   intended faces; the system fallbacks below are chosen to degrade cleanly. */

@font-face { font-family: "Instrument Sans"; src: url("fonts/InstrumentSans-Variable.woff2") format("woff2");
             font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/IBMPlexMono-Regular.woff2") format("woff2");
             font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/IBMPlexMono-Medium.woff2") format("woff2");
             font-weight: 500; font-display: swap; }

:root {
  --font-ui:  "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;

  --paper:       #F7F8F7;
  --surface:     #FFFFFF;
  --surface-sunk:#F1F3F1;
  --ink:         #14181F;
  --ink-2:       #4A525C;
  --ink-3:       #7A838D;
  --rule:        #E3E6E4;
  --rule-strong: #CBD1CD;

  --credit:      #0F7A5A;
  --credit-wash: #E8F2EE;
  --debit:       #B4462F;
  --debit-wash:  #FAEDE9;
  --flag:        #A8630C;
  --flag-wash:   #FBF0DF;

  --r:    8px;
  --r-lg: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 31, .05);
  --sidebar: 216px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F1211; --surface: #171B19; --surface-sunk: #1F2422;
    --ink: #E9ECE9; --ink-2: #A6AEA9; --ink-3: #757D78;
    --rule: #262C29; --rule-strong: #39413C;
    --credit: #4FBF95; --credit-wash: #12241D;
    --debit: #E08A70;  --debit-wash: #26160F;
    --flag: #D9A45C; --flag-wash: #241B0E;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

/* Every figure in the app is tabular so decimal points stack down a column. */
.num, td.num, .fig {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: -.01em;
}
.pos { color: var(--credit); }
.neg { color: var(--debit); }
.zero { color: var(--ink-3); }

h1, h2, h3 { font-weight: 600; letter-spacing: -.021em; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
a  { color: inherit; }

.eyebrow {
  font-size: 11px; font-weight: 500; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
}

/* ---------------------------------------------------------------- app shell */

.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.side {
  border-right: 1px solid var(--rule);
  background: var(--surface);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 18px 18px 14px; font-weight: 600; letter-spacing: -.03em; font-size: 17px;
}
.brand .mark {
  width: 22px; height: 22px; border-radius: 5px; background: var(--ink);
  color: var(--paper); display: grid; place-items: center;
  font-family: var(--font-num); font-size: 12px; font-weight: 500;
}

.hh-picker { padding: 0 12px 12px; }
.hh-picker select {
  width: 100%; font-size: 13px; padding: 7px 9px; background: var(--surface-sunk);
  border: 1px solid transparent;
}
.hh-picker select:hover { border-color: var(--rule-strong); }

.side nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 1px; flex: 1; }
.side nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--r); text-decoration: none;
  color: var(--ink-2); font-size: 14px; font-weight: 500;
}
.side nav a:hover { background: var(--surface-sunk); color: var(--ink); }
.side nav a[aria-current] { background: var(--ink); color: var(--paper); }
.side nav a[aria-current] .badge { background: rgba(255,255,255,.18); color: inherit; }
.side nav .sep { height: 1px; background: var(--rule); margin: 8px 4px; }

.side footer { padding: 12px; border-top: 1px solid var(--rule); font-size: 13px; }
.side footer .who { color: var(--ink-3); font-size: 12px; margin-bottom: 6px; }

.main { min-width: 0; padding: 0 28px 64px; }
.topline {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 26px 0 4px;
}
.topline .sub { color: var(--ink-3); font-size: 13px; }
.topline .spacer { flex: 1; }

/* --------------------------------------------------- the month spine (signature)
   Twelve months of net flow, diverging from a shared baseline. Doubles as the
   period navigation: the bar you click becomes the month everything else shows. */

.spine {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px;
  padding: 14px 0 10px; margin-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.spine .cell {
  display: block; text-decoration: none; text-align: center;
  border-radius: var(--r); padding: 6px 2px 5px; position: relative;
}
.spine .cell:hover { background: var(--surface-sunk); }
.spine .cell[aria-current] { background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule-strong); }
.spine .plot { height: 46px; display: flex; flex-direction: column; justify-content: center; }
.spine .up, .spine .down { display: block; width: 62%; margin: 0 auto; border-radius: 2px; min-height: 0; }
.spine .up   { background: var(--credit); border-radius: 2px 2px 0 0; }
.spine .down { background: var(--debit);  border-radius: 0 0 2px 2px; }
.spine .axis { height: 1px; background: var(--rule-strong); width: 100%; }
.spine .m { font-size: 10px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase;
            color: var(--ink-3); margin-top: 5px; }
.spine .cell[aria-current] .m { color: var(--ink); }
.spine .v { font-size: 10px; color: var(--ink-3); }

/* ------------------------------------------------------------------- surfaces */

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); align-items: start; }

.card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.card > header {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--rule);
}
.card > header .spacer { flex: 1; }
.card .body { padding: 16px; }
.card .body.flush { padding: 0; }

.stat { padding: 15px 16px; }
.stat .label { font-size: 12px; color: var(--ink-3); margin-bottom: 3px; }
.stat .value { font-family: var(--font-num); font-size: 26px; font-weight: 500; letter-spacing: -.03em; }
.stat .value.hero { font-size: 38px; }
.stat .meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* ---------------------------------------------------------------------- table */

table { width: 100%; border-collapse: collapse; }
thead th {
  font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); text-align: left; padding: 9px 12px;
  border-bottom: 1px solid var(--rule); white-space: nowrap;
}
thead th.num { text-align: right; }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-sunk); }
td.num { text-align: right; white-space: nowrap; }
.t-name { font-weight: 500; }
.t-sub { font-size: 12px; color: var(--ink-3); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 2px 8px; border-radius: 20px;
  background: var(--surface-sunk); color: var(--ink-2); white-space: nowrap;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge {
  font-family: var(--font-num); font-size: 11px; padding: 1px 6px;
  border-radius: 5px; background: var(--surface-sunk); color: var(--ink-3);
}

/* ------------------------------------------------------------ the pivot grid */

.pivot-wrap { overflow-x: auto; }
.pivot { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.pivot th, .pivot td { padding: 0; }
.pivot thead th {
  padding: 8px 6px; font-size: 11px; text-align: right;
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.pivot thead th:first-child { text-align: left; }
.pivot .cat {
  padding: 0 12px 0 14px; font-size: 13px; font-weight: 500; white-space: nowrap;
  position: sticky; left: 0; background: var(--surface); z-index: 1;
  border-right: 1px solid var(--rule);
}
.pivot tbody tr:hover .cat { background: var(--surface-sunk); }
.pivot .cell {
  text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums lining-nums;
  font-size: 12.5px; padding: 7px 8px; border-bottom: 1px solid var(--rule);
  position: relative;
}
.pivot .cell a { text-decoration: none; display: block; }
.pivot .cell.empty { color: var(--ink-3); }
.pivot .cell.peak::after {
  content: ""; position: absolute; left: 3px; right: 3px; bottom: 2px;
  height: 2px; background: var(--ink); border-radius: 1px; opacity: .5;
}
.pivot tfoot td {
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  text-align: right; padding: 10px 8px; border-top: 2px solid var(--rule-strong);
  font-weight: 500; font-size: 12.5px;
}
.pivot tfoot td:first-child { text-align: left; padding-left: 14px; font-family: var(--font-ui); }
.pivot .rowtot { border-left: 1px solid var(--rule); font-weight: 500; }

/* ------------------------------------------------------------------- meters */

.meter { height: 6px; border-radius: 3px; background: var(--surface-sunk); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--credit); border-radius: 3px; }
.meter.over > i { background: var(--debit); }
.meter.near > i { background: var(--flag); }

.bline { display: flex; align-items: center; gap: 10px; }
.bline .meter { flex: 1; }

/* -------------------------------------------------------------------- forms */

label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 5px; }
label .hint { font-weight: 400; color: var(--ink-3); }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: var(--r); padding: 8px 10px; appearance: none;
}
input.money { font-family: var(--font-num); font-variant-numeric: tabular-nums; text-align: right; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--surface-sunk);
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--ink); }
textarea { min-height: 70px; resize: vertical; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px;
}
.field { margin-bottom: 14px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; }
.check label { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  padding: 8px 14px; border-radius: var(--r);
  border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink);
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-sunk); }
.btn:active { transform: translateY(.5px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.primary:hover { opacity: .9; background: var(--ink); }
.btn.danger { color: var(--debit); border-color: var(--rule-strong); }
.btn.danger:hover { background: var(--debit-wash); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-sunk); }

.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--r); overflow: hidden; }
.seg a {
  padding: 6px 12px; font-size: 13px; font-weight: 500; text-decoration: none;
  color: var(--ink-2); border-left: 1px solid var(--rule);
}
.seg a:first-child { border-left: 0; }
.seg a:hover { background: var(--surface-sunk); }
.seg a[aria-current] { background: var(--ink); color: var(--paper); }

.toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .field { margin: 0; }
.toolbar .grow { flex: 1; min-width: 160px; }

/* ------------------------------------------------------------------ notices */

.flash {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: var(--r); font-size: 14px; margin: 14px 0 0;
  border: 1px solid;
}
.flash.ok    { background: var(--credit-wash); border-color: var(--credit); color: var(--credit); }
.flash.error { background: var(--debit-wash);  border-color: var(--debit);  color: var(--debit); }

.empty { text-align: center; padding: 44px 20px; color: var(--ink-3); }
.empty h3 { color: var(--ink); margin-bottom: 5px; }
.empty p { margin: 0 0 16px; font-size: 14px; }

.fx-note {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--ink-2);
  background: var(--surface-sunk); border-radius: var(--r); padding: 9px 11px; margin-top: -4px;
}
.fx-note .rate { font-family: var(--font-num); font-weight: 500; color: var(--ink); }
.fx-note button { margin-left: auto; }
.fx-note.stale { background: var(--flag-wash); color: var(--flag); }

/* --------------------------------------------------------------- auth screen */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .panel { width: 100%; max-width: 380px; }
.auth .brand { padding: 0 0 22px; font-size: 19px; }
.auth .card { padding: 22px; }
.auth .alt { text-align: center; font-size: 13px; color: var(--ink-3); margin-top: 16px; }

/* -------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static; height: auto; flex-direction: row; align-items: center;
    overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--rule); gap: 4px;
  }
  .side nav { flex-direction: row; padding: 8px; flex: 1; }
  .side nav .sep, .side footer .who { display: none; }
  .side footer { border: 0; padding: 8px; }
  .hh-picker { padding: 8px; min-width: 150px; }
  .main { padding: 0 16px 56px; }
  .g-main { grid-template-columns: 1fr; }
  .spine .v { display: none; }
  .spine .plot { height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Radio-backed segmented control (the transaction Kind picker).
   The input itself is visually hidden, so the checked state has to be styled
   on the adjacent span or every option looks identical. */
.seg-radio {
  display: flex; width: 100%;
  border: 1px solid var(--rule-strong); border-radius: var(--r); overflow: hidden;
}
.seg-radio label { flex: 1; margin: 0; cursor: pointer; }
.seg-radio span {
  display: block; padding: 8px 12px; text-align: center;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  border-left: 1px solid var(--rule); white-space: nowrap;
}
.seg-radio label:first-child span { border-left: 0; }
.seg-radio label:hover span { background: var(--surface-sunk); color: var(--ink); }
.seg-radio input:checked + span { background: var(--ink); color: var(--paper); }
.seg-radio input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: -2px; }
