:root {
  --paper:   #E7EAEE;
  --panel:   #FBFCFD;
  --ink:     #12171D;
  --ink-2:   #4A5763;
  --rule:    #C2CAD3;
  --rule-2:  #DCE1E7;
  --accent:  #0E6B62;
  --signal:  #9A5B12;
  --bar:     #C3D0DD;
  --row-h:   30px;

  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --display: "Space Grotesk", var(--sans);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10151A;
    --panel: #161C23;
    --ink:   #DFE6ED;
    --ink-2: #8E9DAB;
    --rule:  #2A343E;
    --rule-2:#212A33;
    --accent:#4FC3B4;
    --signal:#D69B4A;
    --bar:   #253340;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
}

body {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}

/* ------------------------------------------------------------- masthead */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 20px;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}

.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: -0.02em;
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.wordmark .mark { color: var(--ink); }
.wordmark .mark.alt { color: var(--accent); }
.rule-tick {
  display: inline-block;
  width: 26px;
  height: 7px;
  margin-left: 8px;
  border: 1px solid var(--rule);
  border-top: 0;
  border-image: repeating-linear-gradient(90deg, var(--rule) 0 1px, transparent 1px 6px) 1;
  border-bottom: 1px solid var(--rule);
  transform: translateY(-2px);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-left: auto;
}

.field { display: grid; gap: 3px; }
.field > span {
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-2);
}

select, .ghost, input {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 5px 8px;
  height: 28px;
}
select { min-width: 160px; }

.ghost { cursor: pointer; }
.ghost:hover { border-color: var(--accent); color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------- query strip */

.querystrip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  height: 40px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.prompt {
  font-family: var(--display);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

#query {
  flex: 1;
  height: 26px;
  border: 0;
  border-bottom: 1px dashed var(--rule);
  border-radius: 0;
  background: transparent;
  padding-left: 0;
  letter-spacing: 0.01em;
}
#query::placeholder { color: var(--ink-2); opacity: 0.6; }

.readout {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  white-space: nowrap;
}
.readout b { color: var(--ink); font-weight: 600; }

/* -------------------------------------------------------- column picker */

.columns-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  max-height: 34vh;
  overflow: auto;
}
.columns-panel label {
  display: flex;
  gap: 6px;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  width: 210px;
}
.columns-panel .group-title {
  width: 100%;
  font-family: var(--display);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 6px;
}

/* --------------------------------------------------------------- sheet */

.sheet {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  position: relative;
}

.head, .filters, .row {
  display: grid;
  grid-template-columns: var(--cols);
  align-items: stretch;
}

.head {
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 3;
}

.head .cell {
  font-family: var(--display);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 8px 8px 6px;
  cursor: pointer;
  user-select: none;
  border-right: 1px solid var(--rule-2);
  line-height: 1.2;
  display: flex;
  align-items: flex-end;
  gap: 4px;
}
.head .cell:hover { color: var(--accent); }
.head .cell.sorted { color: var(--accent); }
.head .cell .unit {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.75;
}
.head .cell .arrow { margin-left: auto; font-size: 10px; }

.filters {
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
}
.filters input {
  width: 100%;
  height: 24px;
  border: 0;
  border-right: 1px solid var(--rule-2);
  border-radius: 0;
  background: transparent;
  font-size: 11px;
  padding: 2px 8px;
}
.filters input.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.filters input::placeholder { color: var(--ink-2); opacity: 0.45; }

.scroller { overflow: auto; position: relative; }
.canvas { position: relative; }

.row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--row-h);
  border-bottom: 1px solid var(--rule-2);
  contain: strict;
}
.row:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.row.odd { background: color-mix(in srgb, var(--ink) 3%, transparent); }
.row.odd:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }

.row .cell {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--rule-2);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  position: relative;
}
.cell.num { justify-content: flex-end; font-variant-numeric: tabular-nums; }
.cell.name { font-weight: 600; }
.cell.null { color: var(--ink-2); opacity: 0.45; }
.cell.money { color: var(--ink); }
.cell.flag-on { color: var(--accent); }
.cell.flag-off { color: var(--ink-2); opacity: 0.4; }

/* Signature: magnitude rule behind numeric values. Reads the column's own
   maximum, so scale is always relative to what is on screen. */
.mag {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: var(--bar);
}

.empty {
  position: absolute;
  inset: auto 0 0 0;
  top: 90px;
  display: grid;
  place-content: center;
  gap: 4px;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
}
.muted { color: var(--ink-2); }

/* ------------------------------------------------------------ colophon */

.colophon {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 18px;
  border-top: 1px solid var(--rule);
  background: var(--panel);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-2);
}
.colophon .sep { opacity: 0.4; }

@media (max-width: 720px) {
  .masthead { gap: 10px; }
  .controls { margin-left: 0; width: 100%; }
  select { min-width: 0; flex: 1; }
  .querystrip { padding: 0 10px; }
  .readout { display: none; }
}

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