/* Cost Ledger — cost.taset.app
   Dark-only by design: it lives on the same navy starfield as the booking app. */

.viz-root {
  color-scheme: dark;

  /* surfaces */
  --page:           #0a1729;
  --surface-1:      #16315a;   /* the chart surface every mark is validated against */
  --surface-2:      #0f2452;
  --hairline:       rgba(255, 255, 255, 0.10);
  --grid:           rgba(255, 255, 255, 0.08);

  /* text tokens — marks carry color, text never does */
  --text-primary:   #ffffff;
  --text-secondary: #cfe3ff;
  --text-muted:     #8fa8cc;

  /* categorical slots, dark steps, validated on --surface-1
     (adjacent CVD ΔE 8.4 worst pair, normal-vision 19.8, all ≥3:1 contrast) */
  --series-1:       #3987e5;   /* cache read  */
  --series-2:       #d95926;   /* cache write */
  --series-3:       #199e70;   /* output      */
  --series-4:       #c98500;   /* input       */

  --accent:         #0ed2da;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: #0a1729;
  color: #fff;
  font-family: 'Noto Serif Khmer', Georgia, serif;
  min-height: 100dvh;
}

/* Figures always use the sans stack with tabular numerals so columns line up. */
.num, .hero-value, th, td, .tile-value, .axis text, tspan {
  font-family: ui-sans-serif, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

.viz-root {
  position: relative;
  z-index: 1;
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 44px) clamp(14px, 3vw, 28px) 72px;
}

.loading { color: var(--text-muted); text-align: center; padding: 22vh 0; }

/* ---------- header ---------- */
.masthead { margin-bottom: clamp(20px, 3vw, 32px); }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-secondary);
}
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), var(--series-1));
  box-shadow: 0 0 12px rgba(14, 210, 218, 0.6);
}
.masthead h1 {
  margin: 12px 0 6px;
  font-size: clamp(28px, 5.2vw, 46px);
  line-height: 1.1;
  font-weight: 600;
}
.masthead .sub { margin: 0; color: var(--text-muted); font-size: 15px; line-height: 1.6; }
.rate-chip {
  display: inline-block; margin-top: 14px;
  padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--hairline);
  background: rgba(57, 135, 229, 0.14);
  color: var(--text-secondary);
  font-size: 13px; letter-spacing: 0.02em;
}

/* ---------- cards ---------- */
.card {
  border-radius: 18px;
  background:
    radial-gradient(135% 90% at 86% 0%, rgba(255, 255, 255, 0.07), transparent 55%),
    linear-gradient(160deg, #274a7e 0%, #16315a 48%, #0c1c34 100%);
  border: 1px solid var(--hairline);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  padding: clamp(16px, 2.6vw, 26px);
}

section { margin-top: clamp(18px, 2.6vw, 28px); }
section > h2 {
  margin: 0 0 4px;
  font-size: 19px; font-weight: 600; letter-spacing: 0.01em;
}
section > .note { margin: 0 0 18px; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; }

/* ---------- hero figure ---------- */
.hero { text-align: center; padding: clamp(26px, 5vw, 44px) clamp(16px, 3vw, 28px); }
.hero-label { color: var(--text-muted); font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; }
.hero-value {
  display: block;
  margin: 10px 0 2px;
  font-size: clamp(40px, 11vw, 92px);
  font-weight: 700; line-height: 1;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff 30%, #9dc6ff 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.hero-cents { font-size: 0.44em; letter-spacing: 0; color: var(--text-secondary); -webkit-text-fill-color: currentColor; }
.hero-tokens { margin: 12px 0 0; color: var(--text-secondary); font-size: clamp(15px, 2.4vw, 18px); }
.hero-meta { margin: 16px 0 0; color: var(--text-muted); font-size: 13.5px; line-height: 1.7; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.tile { display: flex; flex-direction: column; gap: 6px; }
.tile-head { display: flex; align-items: center; gap: 8px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tile-label { color: var(--text-secondary); font-size: 13.5px; }
.tile-value { font-size: clamp(22px, 3.4vw, 28px); font-weight: 700; letter-spacing: -0.01em; }
.tile-sub { color: var(--text-muted); font-size: 13px; }
.meter { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.10); overflow: hidden; margin-top: 2px; }
.meter > i { display: block; height: 100%; border-radius: 999px; }

.facts { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-top: 12px; }
.fact { padding: 14px 16px; }
.fact .k { color: var(--text-muted); font-size: 12.5px; }
.fact .v { font-size: 20px; font-weight: 600; margin-top: 4px; }

/* ---------- charts ---------- */
.chart-wrap { overflow-x: auto; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11.5px; }
.chart .lbl-value { fill: var(--text-secondary); font-weight: 600; }
.chart .lbl-cat { fill: var(--text-secondary); font-size: 12.5px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--hairline); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .mark, .chart .mark.is-hot { filter: brightness(1.22); }
.chart .crosshair { stroke: rgba(255, 255, 255, 0.30); stroke-width: 1; pointer-events: none; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 0 0 14px; padding: 0; list-style: none; }
.legend li { display: inline-flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 13px; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  padding: 9px 12px; border-radius: 10px;
  background: #0b1c33; border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6);
  color: #fff; font-size: 12.5px; line-height: 1.5;
  opacity: 0; transition: opacity 0.12s ease;
  max-width: 260px;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 3px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); }
.tooltip .tt-row b { color: #fff; font-weight: 600; }

/* ---------- table ---------- */
.table-toggle {
  appearance: none; cursor: pointer;
  margin-bottom: 14px; padding: 8px 15px; border-radius: 999px;
  border: 1px solid var(--hairline); background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary); font-size: 13px;
  font-family: inherit;
}
.table-toggle:hover { background: rgba(255, 255, 255, 0.11); color: #fff; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
caption { text-align: left; color: var(--text-muted); font-size: 13px; padding-bottom: 10px; }
th, td { padding: 9px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--text-secondary); font-weight: 600; border-bottom: 1px solid var(--hairline); }
tbody tr + tr td { border-top: 1px solid rgba(255, 255, 255, 0.06); }
tbody td { color: var(--text-secondary); }
tbody td:first-child, tfoot td { color: #fff; }
tfoot td { border-top: 1px solid var(--hairline); font-weight: 700; padding-top: 11px; }
[hidden] { display: none !important; }

/* ---------- footer ---------- */
.colophon { margin-top: 30px; color: var(--text-muted); font-size: 12.5px; line-height: 1.75; }
.colophon h2 { color: var(--text-secondary); font-size: 15px; margin: 0 0 8px; }
.colophon code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-secondary); }
.colophon a { color: var(--accent); }

/* ---------- count module ---------- */
.counters { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(216px, 1fr)); }
.counter {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 5px;
  padding-top: calc(clamp(16px, 2.6vw, 26px) + 3px);
}
.counter-rule { position: absolute; top: 0; left: 0; width: 100%; height: 3px; opacity: 0.9; }
.counter-value {
  display: inline-block;                    /* so the reserved width holds while the digits run */
  font-size: clamp(23px, 3.5vw, 31px); font-weight: 700;
  letter-spacing: -0.015em; line-height: 1.15;
}
.counter-label { color: var(--text-secondary); font-size: 13.5px; }

/* ---------- featured detail list ---------- */
section h3 { margin: clamp(22px, 3vw, 30px) 0 4px; font-size: 16px; font-weight: 600; }
section h3 + .note { margin: 0 0 16px; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; }
.feature-list { list-style: none; display: grid; gap: 10px; margin: 0; padding: 0; }
.feature { padding: 0; overflow: hidden; }
.feature.is-featured { border-color: rgba(14, 210, 218, 0.34); }
.feature summary {
  display: block; list-style: none; cursor: pointer;
  padding: clamp(14px, 2.2vw, 19px);
}
.feature summary::-webkit-details-marker { display: none; }
.feature summary:hover .feature-title { color: #fff; }
.feature summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.feature-head { display: flex; align-items: baseline; gap: 12px; }
.feature-rank { flex: none; color: var(--text-muted); font-size: 12px; letter-spacing: 0.1em; }
.feature-main { flex: 1 1 auto; min-width: 0; }
.feature-title { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.35; }
.feature-meta { margin: 4px 0 0; color: var(--text-muted); font-size: 12.5px; line-height: 1.55; }
.feature-fig { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.feature-value { font-size: clamp(17px, 2.6vw, 21px); font-weight: 700; letter-spacing: -0.01em; }
.feature-share { color: var(--text-muted); font-size: 11.5px; white-space: nowrap; }
.feature-chev {
  flex: none; align-self: center; width: 8px; height: 8px; margin-left: 2px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: translateY(-2px) rotate(45deg); transition: transform 0.18s ease;
}
.feature details[open] .feature-chev { transform: translateY(2px) rotate(-135deg); }
.feature-meter { margin-top: 13px; }
.feature.is-featured .feature-title { font-size: 17px; }
.feature.is-featured .feature-value { font-size: clamp(21px, 3.6vw, 28px); }
.feature-more {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0 22px; margin: 0;
  padding: 4px clamp(14px, 2.2vw, 19px) clamp(12px, 2vw, 16px);
}
.feature-more > div {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  padding: 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.feature-more dt { color: var(--text-muted); font-size: 12.5px; }
.feature-more dd { margin: 0; color: #fff; font-size: 12.5px; font-weight: 600; }

@media (max-width: 560px) {
  /* Eight figures single-file is a long scroll; two-up keeps the module glanceable. */
  .counters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .counter { padding-left: 14px; padding-right: 14px; }
  .counter-value { font-size: clamp(16px, 5.2vw, 23px); }

  /* Rank, headline and figure stack in one column so no entry wraps differently
     from its neighbours; the chevron leaves the flow entirely. */
  .feature summary { position: relative; padding-right: 34px; }
  .feature-head { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: baseline; }
  .feature-main { grid-column: 2; }
  .feature-fig { grid-column: 2; align-items: flex-start; margin-top: 9px; }
  .feature-chev { position: absolute; right: 15px; top: 21px; align-self: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .starfield, .stars, .stars2, .stars3 { animation: none !important; }
  * { transition: none !important; }
}

/* Print / forced-colors: the table is the fallback, so never hide it there. */
@media print {
  body { background: #fff; color: #000; }
  .starfield, .tooltip, .table-toggle { display: none !important; }
  #daily-table, #detail-tables { display: block !important; }
  .feature-chev, .counter-rule { display: none !important; }
  .feature, .counter { break-inside: avoid; }
}
