/* quant.kilambi.com: dark terminal theme.
   Estate design rules applied: flat backgrounds, hairline rules,
   no card grids, no decorative gradients, no layered shadows,
   radius 0 to 4px, tabular numerals, colour reserved for signal.
   Sans throughout on data surfaces; serif for the site name only
   (deviation recorded in TERMINAL-UX-SPEC.md section 5.2). */

:root {
  --bg: #0b0b0c;
  --bg-raise: #131315;
  --rule: #2c2c2f;
  --rule-soft: #1f1f22;
  --ink: #ece9e1;
  --ink-soft: #c4c0b6;
  --muted: #948f83;
  --amber: #e8a33d;
  --green: #43a56c;
  --red: #d2604f;
  --blue: #56b4e9;
  --violet: #a58fd6;
  --teal: #35b5a5;
  --grey-line: #9a968c;
  --focus: #e8a33d;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", Times, serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.num, td.num, dd, .stat-v {
  font-variant-numeric: tabular-nums;
}

.wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* ---------- site head and command bar ---------- */

.site-head {
  border-bottom: 1px solid var(--rule);
  padding: 10px 0 0;
  margin-bottom: 0;
}

.head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 24px;
}

.brand {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.brand:hover { text-decoration: none; }

.head-note {
  color: var(--muted);
  font-size: 12px;
}

.family-nav {
  margin-left: auto;
  font-size: 12.5px;
}
.family-nav a { color: var(--ink-soft); }
.family-nav .sep { color: var(--muted); padding: 0 6px; }

.cmdbar {
  position: relative;
  margin: 10px 0 0;
  padding: 8px 0 10px;
  border-top: 1px solid var(--rule-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}

.cmd-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.cmd-input-wrap { position: relative; flex: 0 1 560px; }

#cmd-input {
  width: 100%;
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  padding: 6px 8px;
}
#cmd-input::placeholder { color: var(--muted); }

#cmd-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: 2px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 40;
}
#cmd-list li {
  padding: 5px 8px;
  border-bottom: 1px solid var(--rule-soft);
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: baseline;
}
#cmd-list li:last-child { border-bottom: none; }
#cmd-list li[aria-selected="true"] { background: #1d1d20; }
#cmd-list .c-code { font-weight: 600; color: var(--ink); white-space: nowrap; }
#cmd-list .c-name { color: var(--ink-soft); }
#cmd-list .c-fam { color: var(--muted); margin-left: auto; white-space: nowrap; font-size: 12px; }

/* ---------- series header strip ---------- */

.series-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 4px 20px;
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--rule);
}

.series-id { min-width: 0; }

.series-code {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
}

.series-name {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 2px 0 0;
}

.series-family {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 2px 0 0;
}

.series-last {
  margin-left: auto;
  text-align: right;
}

.series-last .last-v {
  font-size: 21px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.series-last .last-lab,
.series-last .chg-lab {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.series-last .chg-v {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- chart and stats layout ---------- */

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 232px;
  gap: 0 20px;
  align-items: start;
  padding-top: 10px;
}

.chart-main { min-width: 0; order: 1; }
.stats-col { order: 2; }

@media (max-width: 860px) {
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .stats-col { order: 1; }
  .chart-main { order: 2; }
}

/* ---------- controls ---------- */

.controls { border-bottom: 1px solid var(--rule-soft); padding-bottom: 8px; }

.ctl-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  margin: 0 0 6px;
}
.ctl-row:last-child { margin-bottom: 0; }

.ctl-lab {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  width: 74px;
  flex: none;
}

.btn-group { display: inline-flex; flex-wrap: wrap; }

button.ctl {
  background: none;
  border: none;
  border-right: 1px solid var(--rule-soft);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 12.5px;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 0;
}
button.ctl:first-child { border-left: 1px solid var(--rule-soft); }
button.ctl:hover { color: var(--ink); }
button.ctl[aria-pressed="true"] {
  color: var(--ink);
  font-weight: 700;
  box-shadow: inset 0 -2px 0 var(--amber);
}
button.ctl:disabled { color: var(--muted); cursor: default; box-shadow: none; }

select.ctl-select {
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  padding: 3px 6px;
  margin-left: 8px;
}

.ctl-note { color: var(--muted); font-size: 12px; margin-left: 12px; }

/* ---------- studies ---------- */

.studies-box { flex: 1 1 auto; min-width: 0; }

.study-list {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
}

.study-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
  padding: 3px 0;
  border-bottom: 1px solid var(--rule-soft);
}

.study-none {
  color: var(--muted);
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px solid var(--rule-soft);
}

button.study-toggle {
  border-left: 1px solid var(--rule-soft);
  font-variant-numeric: tabular-nums;
}

.ctl-lab2 {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.study-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
}

.study-add .ctl-select { margin-left: 0; }

input.ctl-input {
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  width: 64px;
  margin-left: 4px;
}

button.ctl-bordered {
  border: 1px solid var(--rule);
  border-radius: 2px;
}
button.ctl-bordered:first-child { border-left: 1px solid var(--rule); }

.studies-box .ctl-note { margin: 4px 0 0; }

button.ctl:disabled, select.ctl-select:disabled,
input.ctl-input:disabled {
  color: var(--muted);
  cursor: default;
  box-shadow: none;
}

.sr-status {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- chart ---------- */

.chart-summary {
  color: var(--ink-soft);
  font-size: 12.5px;
  margin: 8px 0 6px;
  max-width: 110ch;
}

.chart-box {
  width: 100%;
  height: 430px;
  border-bottom: 1px solid var(--rule-soft);
}
.chart-box svg { display: block; }

.legend-line {
  color: var(--ink-soft);
  font-size: 12px;
  margin: 6px 0 0;
}
.legend-line .sw {
  display: inline-block;
  width: 14px;
  border-top: 2px solid var(--amber);
  margin: 0 6px 3px 0;
  vertical-align: middle;
}

/* ---------- stats box ---------- */

.stats {
  border-top: 1px solid var(--rule);
  margin: 0;
}

.stats .stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--rule-soft);
}

.stats dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-top: 2px;
}

.stats dd {
  margin: 0;
  text-align: right;
  font-size: 13px;
}

.stats dd .stat-sub {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
}

.stats-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 2px;
}

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

.table-wrap {
  overflow: auto;
  max-height: 520px;
  border-top: 1px solid var(--rule);
  margin-top: 14px;
}

table.data {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}

table.data th {
  position: sticky;
  top: 0;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-align: left;
  padding: 6px 10px 5px 0;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
  z-index: 2;
}

table.data td {
  padding: 4px 10px 4px 0;
  border-bottom: 1px solid var(--rule-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.data th.r, table.data td.r { text-align: right; }
table.data tbody tr:hover { background: #101012; }
table.data .flag-note { color: var(--amber); white-space: normal; }
table.data .rowlink { color: var(--ink); font-weight: 600; }

th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink); }

/* index and family pages */

.page-title {
  font-size: 17px;
  font-weight: 700;
  margin: 16px 0 2px;
}

.page-sub { color: var(--muted); margin: 0 0 10px; font-size: 12.5px; }

.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 34px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 8px 0;
  margin: 10px 0 4px;
}

.strip .strip-item .s-lab {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.strip .strip-item .s-val { font-size: 14px; font-variant-numeric: tabular-nums; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 0;
}
.filter-row label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.filter-row input {
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  padding: 5px 8px;
  flex: 0 1 420px;
}

button.watch {
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 11.5px;
  padding: 2px 8px;
  cursor: pointer;
}
button.watch[aria-pressed="true"] { color: var(--amber); border-color: var(--amber); }

h2.section {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 5px;
  margin: 22px 0 0;
}

/* ---------- source and method, related series ---------- */

.src-block {
  border-top: 1px solid var(--rule);
  margin-top: 18px;
  padding-top: 8px;
  color: var(--muted);
  font-size: 12px;
  max-width: 120ch;
}
.src-block p { margin: 0 0 5px; }
.src-block .m-label { color: var(--ink-soft); }

.depth-list { margin: 8px 0 0; }
.depth-list .stat-row {
  display: flex;
  gap: 14px;
  padding: 3px 0;
  border-bottom: 1px solid var(--rule-soft);
  max-width: 560px;
}
.depth-list dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  width: 250px;
  flex: none;
  padding-top: 1px;
}
.depth-list dd { margin: 0; font-variant-numeric: tabular-nums; }

.related {
  margin-top: 12px;
  font-size: 12.5px;
}
.related .rel-lab {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 4px;
}
.related a { color: var(--ink-soft); }
.related .sep { color: var(--muted); padding: 0 5px; }

.site-foot {
  border-top: 1px solid var(--rule);
  margin-top: 28px;
  padding-top: 8px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}
.site-foot a { color: var(--ink-soft); }
