:root { color-scheme: dark; --chart-h: 340px; }
@media (min-width: 1200px) { :root { --chart-h: 360px; } }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: #0b0d10;
  color: #e7edf3;
}

a { color: #8dc1ff; text-decoration: none; }
a:hover { color: #b6d8ff; text-decoration: underline; }

.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }

.topbar {
  backdrop-filter: blur(6px);
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand { margin: 0; padding: 14px 0; font-size: 18px; }

.card {
  background: #12161a;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
}
.card-body { padding: 16px; }

/* headers/footers inside cards */
.rowhead, .rowfoot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.rowhead h2 { margin: 0; font-size: 1.1rem; }
.muted { color: #9fb0c2; }
.small { font-size: .9rem; }
.mb { margin-bottom: 18px; }

/* ========================
   GRID LAYOUT FOR CARDS
   ======================== */
.cards {
  display: grid;
  gap: 1rem;                 /* spacing between cards */
  grid-template-columns: 1fr;
  align-items: stretch;      /* each card fills the row height */
}
@media (min-width: 1000px) {
  .cards { grid-template-columns: 1fr 1fr; }
}

/* IMPORTANT: remove sibling margin that breaks alignment with CSS Grid */
 /* .card + .card { margin-top: 18px; }  <-- DELETE/COMMENT OUT */

/* Chart cards always fill their grid track */
.card.card--chart {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* 3-row grid inside the card body: header / chart / footer */
.card.card--chart .card-body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: .75rem;
  min-height: 0;          /* allow middle row to shrink if needed */
}

/* The chart area: fixed, unified height */
.chart-box {
  position: relative;
  width: 100%;
  height: var(--chart-h);
  border-radius: .5rem;
  overflow: hidden;
  background: #0f1317;   /* dark chart surface */
}
.chart-box--sm { height: 280px; }
.chart-box--lg { height: 420px; }

/* Canvas fills its container (no extra background/padding on canvas) */
.chart-box > canvas {
  position: absolute; inset: 0;
  width: 100% !important;
  height: 100% !important;
  border-radius: 10px;
}
canvas { background: transparent; padding: 0; display: block; }

/* Stats / tables */
.stat-card {
  margin-top: .75rem;
  background: #12161a;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: .5rem;
}
.stat-card__title {
  padding: .5rem .75rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  color: #a9b3bc;
  font-size: .9rem;
}
.stats { width: 100%; border-collapse: collapse; }
.stats th, .stats td { padding: .5rem .75rem; text-align: left; font-size: .9rem; }
.stats thead th { color: #bfc8d2; font-weight: 600; }
.stats tbody tr:nth-child(even) td { background: rgba(255,255,255,.02); }

/* CPI movers list */
.movers { padding: .5rem .75rem; }
.movers-list { list-style: none; margin: .25rem 0 0; padding: 0; display: grid; gap: .25rem; }
.movers-list li { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: baseline; }
.movers-list .lbl { font-weight: 600; }
.movers-list .pct { color: #bcd0e3; }
.pos { color: #7be495; }
.neg { color: #ff8a8a; }

/* Active filter link */
a.active {
  color: #e7edf3;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Footer */
.footer { border-top: 1px solid rgba(255,255,255,.08); margin-top: 24px; }
.footer .wrap { padding: 14px 0; }

/* Footer row in chart cards (grid row #3) */
.rowfoot { display: flex; align-items: center; }
.btn-link { text-decoration: none; }
.btn-link:hover { text-decoration: underline; }

/* sortable stats table */
.stats td.num, .stats th.num { text-align: right; }
.stats--sortable th { cursor: pointer; }
.stats--sortable th[aria-sort="ascending"]::after  { content: " ▲"; opacity: .6; }
.stats--sortable th[aria-sort="descending"]::after { content: " ▼"; opacity: .6; }

.range-controls { display:flex; gap:.5rem; flex-wrap:wrap; }
.range-controls button {
  background:#0f1317; color:#e7edf3; border:1px solid rgba(255,255,255,.12);
  border-radius:.4rem; padding:.25rem .6rem; cursor:pointer; font: inherit;
}
.range-controls button:hover { border-color: rgba(255,255,255,.28); }
.range-controls button.is-active { border-color:#8dc1ff; box-shadow: 0 0 0 1px rgba(141,193,255,.35) inset; }

.norm-controls {
  display:flex; gap:.75rem; align-items:center; flex-wrap:wrap; margin:.25rem 0 .5rem;
}
.norm-controls .checkbox { display:flex; align-items:center; gap:.4rem; }
.norm-controls input[type="range"] { width: 200px; }

/* Two-handle window slider */
.range-controls { display: grid; gap: .5rem; }
.range-buttons { display:flex; gap:.5rem; flex-wrap:wrap; }
.range-buttons .is-active { text-decoration: underline; }

.range-window { position: relative; height: 36px; }
.range-window input[type="range"]{
  position: absolute; inset: 0;
  width: 100%; margin: 0;
  background: transparent;
  /* KEY TRICK: the track does not eat events; only the thumb does */
  pointer-events: none;
  -webkit-appearance: none; appearance: none;
}

/* Visual track (WebKit/Blink) */
.range-window input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; background: rgba(255,255,255,.25); border-radius: 2px;
}
/* Thumb (only the thumb accepts pointer events) */
.range-window input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  height: 14px; width: 14px; border-radius: 50%;
  background: #e7edf3; border: 2px solid #12161a;
  pointer-events: auto;
  margin-top: -5px; /* center on 4px track */
}

/* Firefox */
.range-window input[type="range"]::-moz-range-track {
  height: 4px; background: rgba(255,255,255,.25); border-radius: 2px;
}
.range-window input[type="range"]::-moz-range-thumb {
  height: 14px; width: 14px; border-radius: 50%;
  background: #e7edf3; border: 2px solid #12161a;
  pointer-events: auto;
}

/* Color-coding so you can see both handles */
.range-window input[type="range"]:not(.is-end)::-webkit-slider-thumb { background: #7be495; } /* start = green */
.range-window input[type="range"].is-end::-webkit-slider-thumb       { background: #8dc1ff; } /* end   = blue  */
.range-window input[type="range"]:not(.is-end)::-moz-range-thumb     { background: #7be495; }
.range-window input[type="range"].is-end::-moz-range-thumb           { background: #8dc1ff; }

/* Make the right handle feel like it lives on the right */
.range-window input[type="range"].is-end { z-index: 2; }
.range-window input[type="range"]:not(.is-end) { z-index: 1; }

.range-labels { display:flex; justify-content:space-between; font-size:.85rem; color:#9fb0c2; }

.pill-list { list-style:none; margin:.25rem 0 0; padding:0; display:flex; gap:.5rem; flex-wrap:wrap; }
.pill-list li { background:#0f1317; border:1px solid rgba(255,255,255,.12); border-radius:.5rem; padding:.2rem .5rem; }
.pos { color:#7be495; } .neg { color:#ff8a8a; }
