/* Zen Ledger — design tokens and layout.
   Palette values are the validated data-viz reference instance: every
   categorical pair used here cleared the lightness band, chroma floor, CVD
   separation, normal-vision floor and 3:1 surface contrast in BOTH modes. */

:root {
  color-scheme: light;

  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f3f2ee;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --grid:         #e1e0d9;
  --baseline:     #c3c2b7;
  --border:       rgba(11, 11, 11, 0.10);
  --shadow:       0 1px 2px rgba(11,11,11,.04), 0 8px 24px rgba(11,11,11,.05);

  --series-1:     #2a78d6;   /* personal */
  --series-2:     #eb6834;   /* zen */

  --good:         #0ca30c;
  --good-text:    #006300;
  --warning:      #fab219;
  --serious:      #ec835a;
  --critical:     #d03b3b;

  --radius:       12px;
  --radius-sm:    8px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:      #0d0d0d;
    --surface:    #1a1a19;
    --surface-2:  #232322;
    --ink:        #ffffff;
    --ink-2:      #c3c2b7;
    --muted:      #898781;
    --grid:       #2c2c2a;
    --baseline:   #383835;
    --border:     rgba(255, 255, 255, 0.10);
    --shadow:     none;
    --series-1:   #3987e5;
    --series-2:   #d95926;
    --good-text:  #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:      #0d0d0d;
  --surface:    #1a1a19;
  --surface-2:  #232322;
  --ink:        #ffffff;
  --ink-2:      #c3c2b7;
  --muted:      #898781;
  --grid:       #2c2c2a;
  --baseline:   #383835;
  --border:     rgba(255, 255, 255, 0.10);
  --shadow:     none;
  --series-1:   #3987e5;
  --series-2:   #d95926;
  --good-text:  #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- header */

header.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 1.5rem;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.wordmark { display: flex; align-items: center; gap: .55rem; font-weight: 650; letter-spacing: -.015em; }
.wordmark .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--series-1); }
.wordmark small { font-weight: 450; color: var(--muted); letter-spacing: 0; }

.topbar .spacer { flex: 1; }

.control {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .35rem .6rem;
  color: var(--ink); font: inherit; font-size: 13.5px; cursor: pointer;
}
.control:hover { background: var(--surface-2); }
select.control { padding-right: .4rem; }

button.primary {
  background: var(--ink); color: var(--plane); border: 1px solid var(--ink);
  border-radius: var(--radius-sm); padding: .4rem .85rem;
  font: inherit; font-size: 13.5px; font-weight: 550; cursor: pointer;
}
button.primary:hover { opacity: .88; }
button.primary:disabled { opacity: .45; cursor: default; }

button.ghost {
  background: none; border: 1px solid var(--border); color: var(--ink-2);
  border-radius: var(--radius-sm); padding: .3rem .6rem;
  font: inherit; font-size: 12.5px; cursor: pointer;
}
button.ghost:hover { background: var(--surface-2); color: var(--ink); }
button.danger:hover { border-color: var(--critical); color: var(--critical); }

/* ------------------------------------------------------------------ tabs */

nav.tabs { display: flex; gap: .25rem; padding: 0 1.5rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
nav.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: .7rem .85rem; margin-bottom: -1px;
  color: var(--ink-2); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
nav.tabs button:hover { color: var(--ink); }
nav.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--series-1); font-weight: 600; }

main { padding: 1.5rem; max-width: 1320px; margin: 0 auto; }
section[hidden] { display: none; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow);
}
.card > h2 {
  margin: 0 0 .15rem; font-size: 14px; font-weight: 600; letter-spacing: -.005em;
}
.card > p.sub { margin: 0 0 1rem; color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 1rem; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.two-up { grid-template-columns: 1.5fr 1fr; }
@media (max-width: 900px) { .two-up { grid-template-columns: 1fr; } }

/* stat tile — the value is a hero figure, proportional numerals */
.tile .label { color: var(--muted); font-size: 12px; font-weight: 550; letter-spacing: .02em; text-transform: uppercase; }
.tile .value { font-size: 30px; font-weight: 620; letter-spacing: -.025em; margin-top: .2rem; }
.tile .value.sm { font-size: 23px; }
.tile .note { color: var(--ink-2); font-size: 12.5px; margin-top: .15rem; }
.tile .note.good { color: var(--good-text); }
.tile .note.bad { color: var(--critical); }

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

.notice {
  display: flex; gap: .7rem; align-items: flex-start;
  border: 1px solid var(--border); border-left: 3px solid var(--muted);
  background: var(--surface); border-radius: var(--radius-sm);
  padding: .8rem 1rem; font-size: 13.5px; color: var(--ink-2);
}
.notice strong { color: var(--ink); }
.notice.warn { border-left-color: var(--warning); }
.notice.crit { border-left-color: var(--critical); }
.notice .icon { flex: none; font-size: 15px; line-height: 1.4; }

/* ------------------------------------------------------------- charts */

.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; font-size: 12.5px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

svg.chart { width: 100%; display: block; overflow: visible; }
svg.chart .gridline { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { stroke: var(--baseline); stroke-width: 1; }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
svg.chart text.value { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .bar { transition: opacity .12s; }
svg.chart .hit { fill: transparent; cursor: pointer; }
svg.chart.dim .bar { opacity: .35; }
svg.chart.dim .bar.on { opacity: 1; }

.tooltip {
  position: fixed; z-index: 60; pointer-events: none; opacity: 0;
  transition: opacity .1s;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0,0,0,.16);
  padding: .55rem .7rem; font-size: 12.5px; min-width: 140px;
}
.tooltip .t-title { font-weight: 600; margin-bottom: .3rem; }
.tooltip .t-row { display: flex; align-items: center; gap: .45rem; justify-content: space-between; }
.tooltip .t-row i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.tooltip .t-row b { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: .8rem; }

/* ------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .03em;
  text-transform: uppercase; color: var(--muted);
  padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: .5rem .6rem; border-bottom: 1px solid var(--grid); vertical-align: top; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.date { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block; padding: .08rem .45rem; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border); color: var(--ink-2);
}
.pill.personal { color: var(--series-1); border-color: color-mix(in srgb, var(--series-1) 40%, transparent); }
.pill.zen { color: var(--series-2); border-color: color-mix(in srgb, var(--series-2) 40%, transparent); }
.pill.pending { color: var(--serious); border-color: color-mix(in srgb, var(--serious) 45%, transparent); }
.pill.out { color: var(--critical); }
.pill.in { color: var(--good-text); }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: .4rem; }
.status-dot.ok { background: var(--good); }
.status-dot.error { background: var(--critical); }
.status-dot.login_required { background: var(--warning); }

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

input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="password"] {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .45rem .65rem; font: inherit; font-size: 13.5px; width: 100%;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.field.grow { flex: 1; min-width: 220px; }

.empty { color: var(--muted); font-size: 13.5px; padding: 2rem 0; text-align: center; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--ink-2); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- login page */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 360px; }
.login-card .wordmark { font-size: 18px; margin-bottom: .3rem; }
.login-card p.sub { margin: 0 0 1.25rem; }
.login-card .err { color: var(--critical); font-size: 13px; min-height: 1.2em; margin-top: .6rem; }
