/* Palette roles come from the data-viz reference instance; dark steps are
   selected for the dark surface, not flipped from light. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, .05), 0 8px 24px rgba(11, 11, 11, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.wrap { width: min(1180px, 100% - 3rem); margin-inline: auto; }
@media (max-width: 620px) { .wrap { width: min(1180px, 100% - 1.75rem); } }

/* ---------- top bar ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  width: min(1180px, 100% - 3rem); margin-inline: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 0;
}
.brand { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--series-1), var(--series-3));
}
h1 { font-size: 1.02rem; margin: 0; letter-spacing: -.01em; }
.brand-sub { margin: .1rem 0 0; font-size: .76rem; color: var(--text-muted); }
.ghost-btn {
  font: inherit; font-size: .8rem; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border);
  border-radius: 7px; padding: .35rem .7rem; cursor: pointer; flex: none;
}
.ghost-btn:hover { color: var(--text-primary); border-color: var(--axis); }

/* ---------- structure ---------- */
main { padding: 1.75rem 0 1rem; }
.loading { color: var(--text-muted); padding: 3rem 0; }
section { margin-bottom: 2.25rem; }
.sec-head { margin: 0 0 .2rem; font-size: .95rem; letter-spacing: -.01em; }
.sec-sub { margin: 0 0 1rem; font-size: .82rem; color: var(--text-muted); max-width: 68ch; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
}

/* ---------- coverage callout ---------- */
.callout {
  display: flex; gap: .85rem; padding: 1rem 1.15rem; margin-bottom: 1.75rem;
  border-left: 3px solid var(--status-warning);
}
.callout-icon { flex: none; font-size: 1rem; line-height: 1.4; }
.callout h2 { font-size: .87rem; margin: 0 0 .3rem; }
.callout p { margin: 0 0 .5rem; font-size: .83rem; color: var(--text-secondary); max-width: 82ch; }
.callout p:last-child { margin-bottom: 0; }
.callout code { font-size: .93em; color: var(--text-primary); }

/* ---------- KPI row ---------- */
.kpis { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
.kpi { padding: .95rem 1.05rem; }
.kpi-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); margin: 0 0 .35rem;
}
.kpi-value { font-size: 1.6rem; line-height: 1.1; margin: 0; letter-spacing: -.02em; }
.kpi-value.muted { color: var(--text-muted); }
.kpi-note { margin: .35rem 0 0; font-size: .74rem; color: var(--text-muted); }

/* ---------- charts ---------- */
.chart-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.chart-card { padding: 1.1rem 1.2rem 1.25rem; }
.chart-title { font-size: .85rem; margin: 0 0 .15rem; }
.chart-sub { font-size: .75rem; color: var(--text-muted); margin: 0 0 .9rem; }
.bars { display: flex; flex-direction: column; gap: .5rem; }
.bar-row { display: grid; grid-template-columns: 8.5rem 1fr auto; gap: .7rem; align-items: center; }
.bar-name {
  font-size: .78rem; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-track { background: var(--grid); border-radius: 3px; height: 10px; position: relative; }
.bar-fill {
  height: 10px; background: var(--series-1);
  border-radius: 0 4px 4px 0; min-width: 2px;
}
.bar-val { font-size: .78rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* coverage strip */
.strip { display: flex; gap: 2px; flex-wrap: wrap; }
.strip-cell {
  width: 20px; height: 26px; border-radius: 3px;
  background: var(--grid); position: relative; cursor: default;
}
.strip-cell[data-funded="true"] { background: var(--series-1); }
.strip-legend {
  display: flex; gap: 1.1rem; margin-top: .85rem;
  font-size: .74rem; color: var(--text-muted); align-items: center;
}
.swatch {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 2px; margin-right: .35rem; vertical-align: -1px;
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .82rem; }
caption { text-align: left; padding: 1rem 1.15rem .1rem; font-size: .85rem; font-weight: 600; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .045em;
  color: var(--text-muted); font-weight: 600;
}
th:first-child, td:first-child { padding-left: 1.15rem; }
th:last-child, td:last-child { padding-right: 1.15rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--plane); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.dim { color: var(--text-muted); }

.pill {
  display: inline-block; font-size: .69rem; padding: .12rem .45rem;
  border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary);
}
.pill.funded { border-color: transparent; background: color-mix(in srgb, var(--status-good) 15%, transparent); color: var(--status-good); }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; padding: 0 1.15rem 1rem; }
.filters input, .filters select {
  font: inherit; font-size: .8rem; padding: .35rem .55rem;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--plane); color: var(--text-primary);
}
.filters input { min-width: 190px; }
.empty-row td { color: var(--text-muted); font-style: italic; }

.foot { padding: 1.5rem 0 3rem; font-size: .76rem; color: var(--text-muted); }
.foot p { margin: 0; max-width: 74ch; }

/* ---------- buttons ---------- */
.topbar-actions { display: flex; gap: .5rem; align-items: center; flex: none; }
.primary-btn {
  font: inherit; font-size: .8rem; font-weight: 500;
  background: var(--series-1); color: #fff; border: 1px solid transparent;
  border-radius: 7px; padding: .38rem .8rem; cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: .55; cursor: progress; }
.link-btn {
  font: inherit; font-size: .78rem; background: none; border: 0; padding: .1rem .25rem;
  color: var(--series-1); cursor: pointer; border-radius: 4px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--status-critical); }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* ---------- lock screen ---------- */
.lock-card { padding: 1.6rem 1.5rem; max-width: 30rem; margin: 3rem auto; }
.lock-card h2 { font-size: 1rem; margin: 0 0 .4rem; }
.lock-form { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.lock-form input {
  font: inherit; font-size: .85rem; flex: 1 1 12rem; padding: .45rem .6rem;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--plane); color: var(--text-primary);
}
.setup-cmd {
  background: var(--plane); border: 1px solid var(--border); border-radius: 8px;
  padding: .7rem .85rem; font-size: .76rem; overflow-x: auto; margin: .2rem 0 .7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre;
}

/* ---------- entry dialog ---------- */
#entry-dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface-1); color: var(--text-primary);
  width: min(46rem, calc(100vw - 2rem)); box-shadow: var(--shadow);
}
#entry-dialog::backdrop { background: rgba(0, 0, 0, .45); }
#entry-form { padding: 1.35rem 1.45rem 1.2rem; }
#entry-form h2 { font-size: .98rem; margin: 0 0 .2rem; }
.dialog-sub { font-size: .78rem; color: var(--text-muted); margin: 0 0 1.1rem; }
.field-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
.field-grid label {
  display: flex; flex-direction: column; gap: .28rem;
  font-size: .74rem; color: var(--text-secondary);
}
.field-grid .lbl { display: block; }
.field-grid label.wide { grid-column: 1 / -1; }
.field-grid input {
  font: inherit; font-size: .85rem; padding: .42rem .55rem;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--plane); color: var(--text-primary);
}
.field-grid input:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.req { color: var(--status-critical); margin-left: .15rem; }
.form-preview {
  margin: 1rem 0 0; font-size: .8rem; color: var(--text-secondary);
  background: var(--plane); border: 1px solid var(--border);
  border-radius: 8px; padding: .55rem .7rem; font-variant-numeric: tabular-nums;
}
.form-error {
  margin: .7rem 0 0; font-size: .8rem; color: var(--status-critical);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }

.note-cell {
  max-width: 16rem; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-muted); font-size: .78rem;
}
.empty-note { font-size: .8rem; color: var(--text-muted); margin: .4rem 0 0; }

/* Gains and losses. The arrow-free colour is backed by the sign in the number
   itself, so the hue is never the only carrier of meaning. */
.up { color: var(--status-good); }
.down { color: var(--status-critical); }
.kpi-value.up, .kpi-value.down { letter-spacing: -.02em; }
.closed-row td { opacity: .62; }
.dupe-list { margin: .4rem 0 0; padding-left: 1.1rem; font-size: .8rem; color: var(--text-secondary); }
.dupe-list li { margin-bottom: .2rem; }

.picker { display: flex; flex-direction: column; gap: .28rem; margin-bottom: 1rem;
  font-size: .74rem; color: var(--text-secondary); }
.picker select {
  font: inherit; font-size: .85rem; padding: .42rem .55rem;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--plane); color: var(--text-primary);
}
.callout.suspect { border-left-color: var(--status-critical); }

.table-actions {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  padding: 1rem 1.15rem .2rem; font-size: .78rem;
}
.onchain-fields {
  margin-top: 1rem; border: 1px solid var(--border); border-radius: 9px;
  padding: .6rem .8rem; background: var(--plane);
}
.onchain-fields > summary {
  cursor: pointer; font-size: .78rem; color: var(--text-secondary); list-style: revert;
}
.onchain-fields[open] > summary { margin-bottom: .8rem; }
.onchain-fields .field-grid { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
.onchain-fields select {
  font: inherit; font-size: .85rem; padding: .42rem .55rem;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface-1); color: var(--text-primary);
}

.form-hint { margin: .8rem 0 0; font-size: .78rem; color: var(--text-muted); }

#withdraw-dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface-1); color: var(--text-primary);
  width: min(38rem, calc(100vw - 2rem)); box-shadow: var(--shadow);
}
#withdraw-dialog::backdrop { background: rgba(0, 0, 0, .45); }
#withdraw-form { padding: 1.35rem 1.45rem 1.2rem; }
#withdraw-form h2 { font-size: .98rem; margin: 0 0 .2rem; }
#withdraw-form .field-grid input {
  font: inherit; font-size: .85rem; padding: .42rem .55rem;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--plane); color: var(--text-primary);
}
#withdraw-form .field-grid label {
  display: flex; flex-direction: column; gap: .28rem;
  font-size: .74rem; color: var(--text-secondary);
}
/* An author `display` beats the UA stylesheet's [hidden] rule, so hiding a
   field needs saying explicitly or it stays on screen. Must outrank both
   label rules above, hence the extra specificity. */
.field-grid label[hidden], #withdraw-form .field-grid label[hidden] { display: none !important; }

@media (max-width: 560px) {
  .bar-row { grid-template-columns: 6.5rem 1fr auto; gap: .55rem; }
  .topbar-actions { gap: .35rem; }
  .field-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.4rem; }
  .topbar-inner { width: min(1180px, 100% - 1.75rem); }
}
