/* === Macro Market Dashboard === */
:root {
  --bg: oklch(0.16 0.01 250);
  --bg-2: oklch(0.20 0.012 250);
  --bg-3: oklch(0.24 0.014 250);
  --fg: oklch(0.96 0.005 250);
  --fg-dim: oklch(0.70 0.01 250);
  --fg-faint: oklch(0.50 0.012 250);
  --line: oklch(0.30 0.012 250);
  --line-soft: oklch(0.26 0.011 250);
  --up: oklch(0.78 0.17 145);
  --down: oklch(0.68 0.21 25);
  --neutral: oklch(0.78 0.08 230);
  --accent: oklch(0.78 0.13 230);

  --curve-now: oklch(0.82 0.16 230);
  --curve-1m: oklch(0.78 0.14 80);
  --curve-1y: oklch(0.62 0.04 250);

  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: oklch(0.985 0.003 250);
  --bg-2: oklch(0.96 0.005 250);
  --bg-3: oklch(0.93 0.006 250);
  --fg: oklch(0.20 0.012 250);
  --fg-dim: oklch(0.45 0.01 250);
  --fg-faint: oklch(0.62 0.008 250);
  --line: oklch(0.85 0.008 250);
  --line-soft: oklch(0.90 0.006 250);
  --up: oklch(0.55 0.16 145);
  --down: oklch(0.55 0.20 25);
  --accent: oklch(0.50 0.13 230);

  --curve-now: oklch(0.50 0.16 230);
  --curve-1m: oklch(0.55 0.14 60);
  --curve-1y: oklch(0.65 0.02 250);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  font-family: var(--sans);
  font-feature-settings: "ss01", "cv11", "tnum";
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.up { color: var(--up); }
.down { color: var(--down); }

/* ─── Layout ─────────────────────────────── */
.dash {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 32px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 48px; height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 28px; color: var(--accent);
  background: transparent; cursor: pointer;
  padding: 0; line-height: 1;
  transition: border-color 0.15s, background 0.15s;
}
.brand-mark:hover {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--accent) 10%, transparent);
}
.brand-title {
  font-size: clamp(20px, 3vw, 26px);
  font-weight: 700; letter-spacing: -0.5px;
  margin: 0;
}
.brand-sub { font-size: 12px; color: var(--fg-dim); }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stamp {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 11px; color: var(--fg-dim);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.stamp-dot {
  width: 6px; height: 6px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--up);
  box-shadow: 0 0 0 0 var(--up);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--up) 70%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}
.stamp-info { display: flex; flex-direction: column; gap: 3px; }
.stamp-date { font-size: 11px; color: var(--fg-dim); }
.stamp-tzrow { display: flex; align-items: center; gap: 7px; }
.stamp-tz { display: flex; align-items: center; gap: 4px; }
.tz-label {
  font-size: 9px; letter-spacing: 0.8px; color: var(--fg-faint);
  text-transform: uppercase;
}
.tz-time { font-size: 12px; font-weight: 600; color: var(--fg); }
.stamp-sep { color: var(--fg-faint); }

/* ── Refresh button ─────────────────────────────── */
.refresh-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.refresh-btn:hover:not(:disabled) {
  background: var(--bg-3);
  border-color: var(--accent);
  color: var(--accent);
}
.refresh-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.refresh-btn.spinning { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Period range selector ───────────────────────── */
.period-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.period-bar-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--fg-faint);
  flex-shrink: 0;
}
.period-btns {
  display: flex;
  gap: 3px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}
.period-btn {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  line-height: 1.4;
}
.period-btn:hover:not(.active) {
  background: var(--bg-3);
  color: var(--fg);
}
.period-btn.active {
  background: color-mix(in oklab, var(--accent) 18%, transparent);
  color: var(--accent);
  font-weight: 700;
}

.sec-label {
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  color: var(--fg-dim); text-transform: uppercase;
  margin: 32px 0 14px;
}

/* ─── Cards ──────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  display: flex; flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease;
}
.card:hover { border-color: color-mix(in oklab, var(--line) 50%, var(--fg-dim)); }
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.card-label { font-size: 14px; font-weight: 600; }
.card-sub { font-size: 11px; color: var(--fg-faint); margin-top: 2px; }
.card-price {
  font-family: var(--mono); font-weight: 600;
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: -0.5px;
  line-height: 1.05;
  margin-top: 4px;
}
.card-fed-range { color: var(--accent); }
.card-unit { font-size: 14px; color: var(--fg-dim); }
.card-abs {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--fg-dim);
}
.card-spark { margin-top: 6px; }

/* ── Sparkline axis labels ───────────────────────── */
.spark-wrap { position: relative; }
.spark-axis {
  position: relative;
  height: 14px;
  margin-top: 3px;
  overflow: hidden;
}
.spark-tick {
  position: absolute;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--fg-faint);
  white-space: nowrap;
  line-height: 14px;
  top: 0;
}
.spark-tick--start { left: 0; }
.spark-tick--mid   { transform: translateX(-50%); }
.spark-tick--end   { right: 0; }

/* ── Period change label below sparkline ── */
.spark-period-label {
  font-family: var(--mono); font-size: 10px; font-weight: 500;
  margin-top: 3px; text-align: right;
}
.spark-period-label.up   { color: var(--up); }
.spark-period-label.down { color: var(--down); }

.chip {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip.up   { background: color-mix(in oklab, var(--up)   15%, transparent); color: var(--up); }
.chip.down { background: color-mix(in oklab, var(--down) 15%, transparent); color: var(--down); }

.pill-neutral {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1px;
  color: var(--fg-dim);
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 999px;
}

/* ─── Fed card ───────────────────────────── */
.fed-row-wrap { margin-top: 24px; }
.card-fed { max-width: calc(33.333% - 10px); }
.fed-meta { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.fed-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line-soft);
  font-size: 12px;
}
.fed-row:last-child { border-bottom: none; }
.fed-k { color: var(--fg-dim); }
.fed-v { font-family: var(--mono); }
.fed-cd .fed-big {
  font-size: 20px; font-weight: 600; color: var(--accent);
}

/* ─── Section grids ─────────────────────── */
.grid-row1 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.grid-row2 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 0;
}
.mag-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}

/* ─── Mag 7 mini ─────────────────────────── */
.mini {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  display: flex; flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.mini-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.mini-sym { font-weight: 700; font-size: 13px; }
.mini-name { font-size: 11px; color: var(--fg-faint); }
.mini-price { font-family: var(--mono); font-size: 18px; font-weight: 600; margin-top: 4px; }
.mini-abs { font-family: var(--mono); font-size: 10px; }
.mini-spark { margin-top: 4px; }

/* ─── Yield Curve ────────────────────────── */
.card-curve { padding: 24px; }
.yc { display: flex; flex-direction: column; gap: 14px; }
.yc-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 12px;
}
.yc-title { font-size: 16px; font-weight: 600; }
.yc-sub { font-size: 11px; color: var(--fg-faint); margin-top: 2px; font-family: var(--mono); }
.yc-legend { display: flex; gap: 6px; flex-wrap: wrap; }
.yc-leg {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11px;
  background: transparent; color: var(--fg);
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
.yc-leg.off { opacity: 0.4; }
.yc-leg.on:hover { background: var(--bg-3); }
.yc-swatch {
  width: 14px; height: 2px; background: var(--leg-color); border-radius: 2px;
  display: inline-block;
}
.yc-swatch.dashed { background: linear-gradient(to right, var(--leg-color) 50%, transparent 50%); background-size: 6px 100%; }
.yc-swatch.dotted { background: linear-gradient(to right, var(--leg-color) 50%, transparent 50%); background-size: 4px 100%; }

.yc-chartwrap {
  position: relative;
  width: 100%;
}
.yc-chart {
  width: 100%; height: auto; display: block;
  touch-action: none;
}
.yc-grid { stroke: var(--line-soft); stroke-width: 1; stroke-dasharray: 2 3; }
.yc-axis-lab {
  fill: var(--fg-faint);
  font-family: var(--mono); font-size: 10px;
}
.yc-hover-line { stroke: var(--fg-faint); stroke-width: 1; stroke-dasharray: 2 3; }
.yc-tip {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  font-family: var(--mono);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.yc-tip-tenor { font-weight: 700; margin-bottom: 4px; }
.yc-tip-row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.yc-tip-dot { width: 6px; height: 6px; border-radius: 50%; }
.yc-tip-lab { color: var(--fg-dim); min-width: 50px; }
.yc-tip-val { font-weight: 600; margin-left: auto; }

.yc-spreads {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}
.yc-sp { padding: 4px 0; }
.yc-sp-lab {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 1px; color: var(--fg-faint);
  text-transform: uppercase;
}
.yc-sp-val {
  font-family: var(--mono); font-size: 18px; font-weight: 600;
  margin-top: 4px;
}
.yc-sp-val.inv { color: var(--down); }
.yc-sp-delta {
  font-family: var(--mono); font-size: 10px;
  margin-top: 2px;
}

/* ─── Footer ────────────────────────────── */
.dash-footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 10px; color: var(--fg-faint);
}

/* ─── Loading / error states ────────────── */
.state {
  max-width: 600px; margin: 80px auto;
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--bg-2);
}
.state-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.state-sub { color: var(--fg-dim); font-size: 13px; line-height: 1.6; }
.state code {
  font-family: var(--mono);
  background: var(--bg-3);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

/* ───────────────────────────────────────────
   RESPONSIVE
   ─────────────────────────────────────────── */

/* Tablet — 2 col benchmarks, 4 col mag */
@media (max-width: 1100px) {
  .grid-row1 { grid-template-columns: repeat(2, 1fr); }
  .grid-row2 { grid-template-columns: 1fr 1fr; }   /* spreads 2+2 */
  .mag-grid { grid-template-columns: repeat(4, 1fr); }
  .card-fed { max-width: 100%; }
}

/* Small tablet */
@media (max-width: 820px) {
  .dash { padding: 20px 18px 40px; }
  .grid-row2 { grid-template-columns: 1fr; }  /* all cards stacked */
  .mag-grid { grid-template-columns: repeat(3, 1fr); }
  .card-fed { max-width: 100%; }
  .card { padding: 20px; }
  .yc-spreads { grid-template-columns: repeat(3, 1fr); }
  .card-curve { padding: 18px; }
}

/* Phone */
@media (max-width: 600px) {
  .dash { padding: 16px 14px 32px; }
  .dash-header { flex-direction: column; align-items: flex-start; }
  .grid-row1 { grid-template-columns: 1fr; }
  .mag-grid { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 16px; }
  .card-fed { max-width: 100%; }
  .card-curve { padding: 14px; }
  .yc-head { flex-direction: column; }
  .sec-label { margin: 24px 0 10px; }
  .yc-spreads { grid-template-columns: 1fr; gap: 12px; }
  .mini { padding: 12px; }
  .mini-price { font-size: 16px; }
  /* On narrow mini cards (2-col grid ≈ 160px), hide axis to prevent crowding */
  .mini .spark-axis { display: none; }
  /* Period bar: let buttons scroll horizontally if needed */
  .period-bar { gap: 8px; }
  .period-btns { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-shrink: 1; }
  .period-btn { padding: 4px 9px; }
}

/* Very small */
@media (max-width: 380px) {
  .mag-grid { grid-template-columns: 1fr; }
}
