/* usage dashboard — opencode + baton, dark-glow data UI
   shape rule: interactive = pill, containers = 18px, data bars = 6px */

:root {
  --bg: #04060c;
  --panel: rgba(255, 255, 255, 0.03);
  --ink: #e8f0f6;
  --dim: #93a7b4;
  --faint: #5c6c78;
  --signal: #3ce0ff;
  --signal-dim: rgba(60, 224, 255, 0.14);
  --signal-line: rgba(60, 224, 255, 0.35);
  --red: #ff5d5d;
  --line: rgba(232, 240, 246, 0.08);
  --line-soft: rgba(232, 240, 246, 0.05);
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scrollbar-gutter: stable; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ---------- ambient depth: two drifting glows + grain, fixed ---------- */
.glow { position: fixed; border-radius: 50%; filter: blur(110px); pointer-events: none; z-index: 0; }
.glow-a { width: 46vw; height: 46vw; left: -12vw; top: -18vw; background: rgba(79, 68, 197, 0.20); animation: drift-a 46s ease-in-out infinite alternate; }
.glow-b { width: 38vw; height: 38vw; right: -14vw; top: 12vh; background: rgba(13, 148, 136, 0.13); animation: drift-b 38s ease-in-out infinite alternate; }
.noise {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes drift-a {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(6vw, 7vh, 0) scale(1.12); }
}
@keyframes drift-b {
  from { transform: translate3d(0, 0, 0) scale(1.08); }
  to   { transform: translate3d(-7vw, 9vh, 0) scale(1); }
}

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(16px, 4vw, 40px);
  height: 64px;
  background: rgba(4, 6, 12, 0.55);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.mark { width: 18px; height: 18px; align-self: center; flex: none; fill: var(--signal); }
.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.wordsub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.status { display: flex; align-items: center; gap: 14px; flex: none; }

.live-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--signal);
  padding: 7px 13px;
  border: 1px solid var(--signal-line);
  border-radius: 999px;
  background: rgba(60, 224, 255, 0.05);
}
.live-pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 10px rgba(60, 224, 255, 0.9);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}
.ago {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  min-width: 120px;
  text-align: right;
}

/* ---------- layout ---------- */
.wrap {
  position: relative; z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px) 64px;
}

/* ---------- period tabs ---------- */
.periods {
  display: flex; position: relative;
  margin: 40px auto 8px;
  padding: 5px;
  width: max-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}
.tab {
  position: relative;
  appearance: none; border: 0; background: none; cursor: pointer;
  font-family: var(--font-display);
  font-size: 13.5px; font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--dim);
  padding: 9px 18px;
  border-radius: 999px;
  transition: color 220ms cubic-bezier(0.22, 1, 0.36, 1);
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab:active { transform: translateY(1px); }
.tab[aria-selected="true"] { color: var(--signal); }
.tab:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.thumb {
  position: absolute; top: 5px; left: 0;
  height: calc(100% - 10px);
  border: 1px solid var(--signal-line);
  background: var(--signal-dim);
  border-radius: 999px;
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1),
              width 420ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform, width;
  z-index: 0;
}

/* ---------- combined hero ---------- */
.hero {
  position: relative;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: clamp(24px, 4vw, 56px);
  padding: clamp(40px, 6vh, 72px) 0 44px;
  overflow: hidden;
}
.ghost {
  position: absolute;
  right: -1.5vw; bottom: -9vw;
  font-size: 19vw;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 0.8;
  color: rgba(232, 240, 246, 0.025);
  user-select: none;
  pointer-events: none;
  z-index: 0;
}
.stat { position: relative; z-index: 1; min-width: 0; }
.stat-cost { padding-left: clamp(24px, 4vw, 56px); border-left: 1px solid var(--line-soft); }

.stat-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px; font-weight: 500;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 14px;
}
.big {
  font-size: clamp(3.5rem, 9.5vw, 7.2rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  display: flex; align-items: baseline;
  min-width: 0;
}
.big .prefix { font-size: 0.42em; color: var(--dim); margin-right: 0.08em; }
.big .unit { font-size: 0.4em; font-weight: 600; color: var(--dim); margin-left: 0.14em; letter-spacing: 0; }
.big .val { min-width: 0; }
.tick { animation: tick-flash 650ms ease-out; }
@keyframes tick-flash {
  0% { color: var(--signal); text-shadow: 0 0 26px rgba(60, 224, 255, 0.45); }
  100% { color: var(--ink); text-shadow: none; }
}

.stat-exact {
  margin-top: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
}
.stat-meta {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
}

/* ---------- timeline chart ---------- */
.tl-section { margin-top: 56px; position: relative; }
.tl-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.tl-title {
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink);
  padding: 0 0 2px;
}
.tl-tools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.tl-legend {
  font-family: var(--font-mono); font-size: 10px; color: var(--dim);
  display: inline-flex; align-items: center; gap: 6px; letter-spacing: 0.06em;
}
.lg {
  display: inline-block; width: 9px; height: 9px; border-radius: 3px;
  margin: 0 4px 0 0; vertical-align: -1px;
}
.lg.lg-oc { background: linear-gradient(90deg, #2b7fff, var(--signal)); }
.lg.lg-bt { background: #6a5fd8; }

.mini-tabs {
  display: inline-flex; gap: 2px; padding: 3px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
}
.mini-tabs button {
  appearance: none; border: 0; background: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: 0.08em; color: var(--dim);
  padding: 5px 13px; border-radius: 999px;
  transition: color 180ms ease, background 180ms ease;
}
.mini-tabs button[aria-pressed="true"] { color: var(--signal); background: var(--signal-dim); }
.mini-tabs button:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.tl-crumb {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 14px 0 18px;
  font-family: var(--font-mono); font-size: 11px;
}
.crumb {
  appearance: none; background: none; border: 0; cursor: pointer;
  font: inherit; color: var(--dim);
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent;
  transition: color 160ms ease, border-color 160ms ease;
}
.crumb:hover { color: var(--ink); border-color: var(--line); }
.crumb:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.crumb-now { color: var(--signal); border-color: var(--signal-line); background: rgba(60, 224, 255, 0.05); cursor: default; }
.crumb-sep { color: var(--faint); }

.tl-wrap { position: relative; }
.tl-chart {
  display: flex; align-items: stretch; gap: 3px;
  height: 200px;
  padding: 8px 2px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin;
}
.tl-chart:focus-visible { outline: none; }
.tl-bar {
  appearance: none; background: none; border: 0; cursor: pointer;
  flex: 1 1 0; min-width: 9px; max-width: 64px;
  display: flex; flex-direction: column;
  font: inherit; color: inherit; padding: 0;
}
.tl-bar:focus-visible { outline: none; }
.tl-bar:focus-visible .tl-fill { box-shadow: 0 0 0 2px var(--signal-line); border-radius: 4px; }
.tl-fill {
  position: relative; flex: 1 1 auto;
  border-radius: 4px 4px 0 0;
}
.seg { position: absolute; left: 0; right: 0; }
.seg-oc {
  bottom: 0;
  height: calc(var(--h) * var(--oc) / 100);
  background: linear-gradient(180deg, var(--signal), #2b7fff);
  opacity: 0.92;
  transition: height 450ms cubic-bezier(0.22, 1, 0.36, 1), bottom 450ms cubic-bezier(0.22, 1, 0.36, 1);
}
.seg-bt {
  bottom: calc(var(--h) * var(--oc) / 100);
  height: calc(var(--h) * (100 - var(--oc)) / 100);
  background: #6a5fd8;
  opacity: 0.9;
  border-radius: 4px 4px 0 0;
  transition: height 450ms cubic-bezier(0.22, 1, 0.36, 1), bottom 450ms cubic-bezier(0.22, 1, 0.36, 1);
}
.tl-bar:hover .seg { filter: brightness(1.18); }
.tl-lab {
  flex: none;
  font-family: var(--font-mono); font-size: 9.5px; color: var(--faint);
  text-align: center; padding-top: 8px;
  white-space: nowrap;
}
.tl-lab-hide { opacity: 0; }

.tl-empty {
  font-family: var(--font-mono); font-size: 12px; color: var(--dim);
  padding: 28px 0;
}

.tl-tooltip {
  position: absolute; bottom: calc(100% + 10px); left: 0;
  z-index: 20;
  pointer-events: none;
  min-width: 190px; max-width: 300px;
  background: rgba(7, 10, 18, 0.95);
  border: 1px solid var(--signal-line);
  border-radius: 10px;
  padding: 11px 14px;
  font-family: var(--font-mono); font-size: 11px; color: var(--dim);
  display: flex; flex-direction: column; gap: 5px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.55), 0 0 22px rgba(60, 224, 255, 0.08);
}
.tl-tooltip[hidden] { display: none; }
.tl-tooltip b { color: var(--ink); font-weight: 600; font-size: 12px; }
.tl-tooltip .tip-split { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

/* ---------- device groups ---------- */
.device { margin-top: 68px; }
.device-head {
  display: flex; align-items: baseline; gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.device-name {
  font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
}
.device-status {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em;
  padding: 4px 11px; border-radius: 999px;
  margin-left: auto;
}
.device-status.on { color: var(--signal); border: 1px solid var(--signal-line); background: rgba(60, 224, 255, 0.05); }
.device-status.off { color: var(--faint); border: 1px solid var(--line); }
.device-body { margin-left: clamp(0px, 2vw, 26px); }

.waiting-note {
  margin: 26px 4px;
  font-family: var(--font-mono); font-size: 11.5px; line-height: 1.7;
  color: var(--faint);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  max-width: 68ch;
}
.src-waiting .sec-hero, .src-waiting .sec-title { display: none; }

/* ---------- per-source sections ---------- */
.src-section { margin-top: 68px; }
.src-section.enter {
  opacity: 0; transform: translateY(14px);
  animation: row-in 600ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.src-head {
  display: flex; align-items: baseline; gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.src-index {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--signal);
  letter-spacing: 0.14em;
}
.src-name { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; }
.src-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  letter-spacing: 0.06em;
  margin-left: auto;
  white-space: nowrap;
}

.sec-hero {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: clamp(18px, 3vw, 40px);
  padding: 26px 0 8px;
}
.sec-hero .stat-cost { padding-left: clamp(18px, 3vw, 40px); border-left: 1px solid var(--line-soft); }
.sec-hero .big { font-size: clamp(2.3rem, 5.2vw, 3.9rem); }
.sec-hero .stat-label { margin-bottom: 10px; }
.sec-hero .stat-exact { margin-top: 10px; font-size: 11px; }
.sec-hero .stat-meta { margin-top: 6px; font-size: 10.5px; }

/* ---------- model rows ---------- */
.models { position: relative; }
.sec-title {
  font-size: 14px; font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--dim);
  padding: 20px 4px 6px;
}
.rows { border-top: 1px solid var(--line-soft); }

.row {
  display: grid;
  grid-template-columns: minmax(190px, 1.1fr) 2.2fr max-content;
  gap: 20px;
  align-items: center;
  padding: 15px 6px;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 10px;
  transition: background 200ms ease;
}
.row:hover { background: rgba(255, 255, 255, 0.025); }
.row.enter {
  opacity: 0; transform: translateY(10px);
  animation: row-in 480ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes row-in {
  to { opacity: 1; transform: none; }
}

.m-id { min-width: 0; }
.m-top { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.m-name { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.chip {
  font-family: var(--font-mono);
  font-size: 9px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px 2px;
  white-space: nowrap;
}
.m-sub {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.m-bar { min-width: 0; }
.track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2b7fff, var(--signal));
  box-shadow: 0 0 14px rgba(60, 224, 255, 0.28);
  transition: width 620ms cubic-bezier(0.22, 1, 0.36, 1);
}
.m-share {
  margin-top: 7px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.04em;
}

.m-cost {
  font-family: var(--font-mono);
  font-size: 16px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 96px;
}
.m-cost .c-val { color: var(--ink); }
.m-cost.dim .c-val { color: var(--faint); font-weight: 500; }

/* empty + loading */
.empty {
  padding: 48px 0 40px;
  text-align: center;
  color: var(--dim);
}
.empty svg { width: 30px; height: 30px; stroke: var(--faint); margin-bottom: 14px; }
.empty-title { font-size: 14px; font-weight: 600; color: var(--dim); }
.empty-sub { margin-top: 6px; font-size: 12px; color: var(--faint); font-family: var(--font-mono); }

.shimmer-row {
  height: 52px;
  margin: 12px 0;
  border-radius: 10px;
  background: linear-gradient(100deg, rgba(255,255,255,0.02) 40%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.02) 60%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

/* ---------- footer ---------- */
.foot {
  margin-top: 56px;
  padding-top: 22px;
  border-top: 1px solid var(--line-soft);
}
.foot p {
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.7;
  color: var(--faint);
  max-width: 82ch;
}
.foot p + p { margin-top: 6px; }
.foot em { font-style: normal; color: var(--dim); }
.kbd {
  font-family: var(--font-mono);
  color: var(--dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  top: 76px; right: clamp(16px, 4vw, 40px);
  z-index: 30;
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--ink);
  background: rgba(7, 10, 18, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  opacity: 0; transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 260ms ease, transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.show { opacity: 1; transform: none; }
.toast-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--red);
  flex: none;
}

/* ---------- error card ---------- */
.errorcard {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(4, 6, 12, 0.85);
  backdrop-filter: blur(8px);
  padding: 24px;
}
.errorcard[hidden] { display: none; }
.errorcard-inner {
  text-align: center;
  max-width: 440px;
  padding: 40px 36px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
}
.errorcard-inner svg { width: 34px; height: 34px; stroke: var(--dim); margin-bottom: 16px; }
.errorcard-inner h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.errorcard-inner p { margin-top: 10px; font-size: 13px; line-height: 1.65; color: var(--dim); font-family: var(--font-mono); }
.retry {
  margin-top: 24px;
  appearance: none; cursor: pointer;
  font-family: var(--font-display);
  font-size: 14px; font-weight: 600;
  color: var(--signal);
  background: var(--signal-dim);
  border: 1px solid var(--signal-line);
  border-radius: 999px;
  padding: 11px 30px;
  transition: transform 140ms ease, background 200ms ease;
}
.retry:hover { background: rgba(60, 224, 255, 0.2); }
.retry:active { transform: scale(0.97); }
.retry:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .row { grid-template-columns: 1fr max-content; grid-template-areas: "id cost" "bar bar"; row-gap: 12px; }
  .m-id { grid-area: id; }
  .m-cost { grid-area: cost; align-self: start; margin-top: 3px; }
  .m-bar { grid-area: bar; }
}
@media (max-width: 768px) {
  .hero, .sec-hero { grid-template-columns: 1fr; }
  .tl-chart { height: 150px; }
  .tl-tooltip { max-width: 240px; }
  .stat-cost, .sec-hero .stat-cost { padding-left: 0; border-left: 0; padding-top: 8px; }
  .ghost { font-size: 34vw; bottom: auto; top: -6vw; right: -8vw; }
  .wordsub { display: none; }
  .ago { min-width: 0; }
  .big { font-size: clamp(3.2rem, 17vw, 5rem); }
  .sec-hero .big { font-size: clamp(2.2rem, 11vw, 3rem); }
  .tab { padding: 9px 13px; font-size: 12.5px; }
  .periods { margin-top: 24px; }
  .src-name { font-size: 18px; }
  .src-sub { display: none; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .glow-a, .glow-b, .live-pill .dot, .shimmer-row, .tick { animation: none !important; }
  .thumb, .fill, .seg-oc, .seg-bt { transition: none !important; }
  .row.enter, .src-section.enter { animation: none; opacity: 1; transform: none; }
  * { scroll-behavior: auto !important; }
}
