/* BuildLedger. Dense, financial, light + dark. No external assets. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --border-strong: #c3cad3;
  --text: #16202c;
  --text-dim: #5b6875;
  --text-faint: #8a94a0;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --good: #1a7f4b;
  --good-soft: #e6f4ec;
  --warn: #a15c00;
  --warn-soft: #fdf1dc;
  --bad: #c02626;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #161b23;
    --surface-2: #1d232d;
    --border: #2a323e;
    --border-strong: #3b4553;
    --text: #e6eaf0;
    --text-dim: #9aa6b4;
    --text-faint: #6b7684;
    --accent: #5b9dff;
    --accent-soft: #16233a;
    --good: #4ac585;
    --good-soft: #12291d;
    --warn: #e0a63a;
    --warn-soft: #2b2312;
    --bad: #f06d6d;
    --bad-soft: #2d1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px; height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; }
.brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 800; letter-spacing: .5px;
}
.brand-name { letter-spacing: -.2px; }
.brand-lg { font-size: 20px; justify-content: center; }
.brand-lg .brand-mark { width: 34px; height: 34px; font-size: 14px; }

.project-picker { display: flex; align-items: center; gap: 6px; }
.project-picker select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 13px; font-weight: 600; max-width: 220px;
}

.tabs { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; }
.tab {
  padding: 6px 11px; border-radius: 6px; font-size: 13px;
  color: var(--text-dim); white-space: nowrap;
}
.tab:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.version { font: 11px var(--mono); color: var(--text-faint); }

/* ---------- layout ---------- */

.stage { padding: 20px; max-width: 1560px; margin: 0 auto; }
.loading { color: var(--text-faint); padding: 40px; text-align: center; }

.view-head {
  display: flex; align-items: flex-start; gap: 14px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.view-head h1 { margin: 0; font-size: 19px; letter-spacing: -.3px; }
.view-head .sub { color: var(--text-dim); font-size: 13px; margin: 3px 0 0; }
.view-head .spacer { flex: 1; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 15px; margin-bottom: 14px;
}
.card > h2 {
  margin: 0 0 3px; font-size: 14px; font-weight: 650;
  display: flex; align-items: center; gap: 8px;
}
.card > .card-sub {
  margin: 0 0 12px; font-size: 12px; color: var(--text-dim);
}
.card-flush { padding: 0; overflow: hidden; }
.card-flush > h2, .card-flush > .card-sub { padding: 15px 15px 0; }
.card-flush > .card-sub { padding-bottom: 12px; }

/* ---------- stat tiles ---------- */

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px;
}
.stat .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .55px;
  color: var(--text-faint); font-weight: 650; margin-bottom: 5px;
}
.stat .value { font-size: 21px; font-weight: 660; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat .value.sm { font-size: 17px; }
.stat .foot { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.stat.good .value { color: var(--good); }
.stat.bad .value { color: var(--bad); }
.stat.warn .value { color: var(--warn); }

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

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-faint); font-weight: 650;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); position: sticky; top: 0; white-space: nowrap;
}
table.data td {
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.is-group td {
  background: var(--surface-2); font-weight: 660; font-size: 12px;
  text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim);
}
table.data tr.is-total td {
  font-weight: 700; border-top: 2px solid var(--border-strong);
  background: var(--surface-2);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums;
                 font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
td.neg { color: var(--bad); }
td.pos { color: var(--good); }
td.dim { color: var(--text-faint); }
td.wrap { white-space: normal; min-width: 200px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.empty {
  padding: 34px 20px; text-align: center; color: var(--text-faint);
  font-size: 13px;
}

/* ---------- pills & badges ---------- */

.pill {
  display: inline-block; padding: 2px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 640; white-space: nowrap;
  background: var(--surface-2); color: var(--text-dim);
  border: 1px solid var(--border);
}
.pill.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad  { background: var(--bad-soft);  color: var(--bad);  border-color: transparent; }
.pill.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.tag-missed {
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
  color: var(--warn); text-transform: uppercase;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); line-height: 1.3;
}
.btn:hover { background: var(--surface-2); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-block { width: 100%; padding: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

label { display: block; font-size: 12px; font-weight: 620; color: var(--text-dim); }
input, select, textarea {
  font: inherit; font-size: 13px; width: 100%;
  padding: 6px 9px; margin-top: 4px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
textarea { min-height: 64px; resize: vertical; }
input[type=checkbox] { width: auto; margin: 0 6px 0 0; }
.check-row { display: flex; align-items: center; gap: 4px; font-size: 13px;
             color: var(--text); font-weight: 500; margin-top: 8px; }
.field-hint { font-size: 11px; color: var(--text-faint); margin-top: 3px; font-weight: 400; }

.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 12px;
}
.filters label { font-size: 11px; }
.filters input, .filters select { min-width: 130px; }
.filters .grow { flex: 1; min-width: 200px; }

/* ---------- modal ---------- */

.modal-back {
  position: fixed; inset: 0; background: rgba(10, 14, 20, .55);
  display: grid; place-items: center; z-index: 200; padding: 20px;
  overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 10px; box-shadow: var(--shadow);
  width: min(720px, 100%); max-height: 90vh; display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.modal-wide { width: min(1020px, 100%); }
.modal header {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal header h3 { margin: 0; font-size: 15px; }
.modal .body { padding: 18px; overflow-y: auto; }
.modal footer {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end; align-items: center;
}
.modal footer .spacer { flex: 1; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } }

.fieldset-title {
  grid-column: 1 / -1; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-faint); font-weight: 700;
  border-bottom: 1px solid var(--border); padding-bottom: 5px; margin-top: 6px;
}

/* ---------- toast ---------- */

.toast-root {
  position: fixed; bottom: 18px; right: 18px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px; box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 13px; max-width: 380px;
}
.toast.error { border-left-color: var(--bad); }
.toast.success { border-left-color: var(--good); }

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

.notice {
  border-radius: 6px; padding: 10px 13px; font-size: 13px;
  margin-bottom: 12px; border: 1px solid transparent;
}
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-bad { background: var(--bad-soft); color: var(--bad); }
.notice-info { background: var(--accent-soft); color: var(--accent); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

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

/* Categorical slots 1-3, validated against this app's own surfaces
   (#ffffff light, #161b23 dark) with scripts/validate_palette.js --pairs all.
   Light: worst CVD dE 9.2, normal-vision 24.0. Dark: 9.4 / 20.9.
   Light-mode aqua sits at 2.82:1 on white, so every chart using slot 3 ships
   direct end labels AND a table view. Do not add a 4th slot: yellow beside
   orange fails the all-pairs floor. Fold extra series into "Other" or facet. */
.viz {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --viz-grid: #e1e0d9;
  --viz-axis: #c3c2b7;
  --viz-ink: #52514e;
  --viz-muted: #898781;
  --viz-surface: #ffffff;
  --viz-pos: #2a78d6;
  --viz-neg: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  .viz {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --viz-grid: #2c2c2a;
    --viz-axis: #383835;
    --viz-ink: #c3c2b7;
    --viz-muted: #898781;
    --viz-surface: #161b23;
    --viz-pos: #3987e5;
    --viz-neg: #d03b3b;
  }
}

.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font-family: inherit; }
.chart .tick-label { font-size: 10.5px; fill: var(--viz-muted);
                     font-variant-numeric: tabular-nums; }
.chart .end-label { font-size: 11px; font-weight: 650; fill: var(--viz-ink); }
.chart .grid-line { stroke: var(--viz-grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--viz-axis); stroke-width: 1; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round;
                      stroke-linecap: round; }
.chart .crosshair { stroke: var(--viz-axis); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .dot { stroke: var(--viz-surface); stroke-width: 2; }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 20;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; box-shadow: var(--shadow); padding: 8px 10px;
  font-size: 12px; min-width: 150px; opacity: 0; transition: opacity .1s;
}
.chart-tip.on { opacity: 1; }
.chart-tip .tip-date { font-weight: 700; margin-bottom: 5px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px;
                      justify-content: space-between; }
.chart-tip .tip-row b { font-variant-numeric: tabular-nums; font-weight: 620; }

.chart-legend {
  display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px;
  color: var(--text-dim); margin-top: 10px;
}
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ---------- misc ---------- */

.bar-track {
  height: 6px; background: var(--surface-2); border-radius: 4px;
  overflow: hidden; margin-top: 6px;
}
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bar-fill.over { background: var(--bad); }
.bar-fill.good { background: var(--good); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 12px; }
.mb0 { margin-bottom: 0; }

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

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 30px; width: min(360px, 100%); display: grid; gap: 14px;
}
.login-sub { margin: -6px 0 4px; text-align: center; color: var(--text-dim); font-size: 13px; }
.login-version { text-align: center; margin: 0; font: 11px var(--mono); color: var(--text-faint); }
.flash { padding: 9px 12px; border-radius: 6px; font-size: 13px; }
.flash-error { background: var(--bad-soft); color: var(--bad); }

@media (max-width: 900px) {
  .topbar { height: auto; padding: 10px 14px; }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .topbar-right { margin-left: auto; }
  .stage { padding: 14px; }
}
