  :root {
    --bg: #0b0c0f;
    --bg-1: #111319;
    --bg-2: #161922;
    --line: #222632;
    --line-2: #2c313d;
    --text: #e7ebf2;
    --muted: #98a1b3;
    --faint: #5b6475;
    --accent: #7c84ff;
    --accent-2: #3ddc97;
    --amber: #f7a13b;
    --radius: 12px;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    background: var(--bg); color: var(--text); font-family: var(--sans);
    font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
    overflow: hidden;
  }
  .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; border: 2px solid var(--bg); }
  ::-webkit-scrollbar-thumb:hover { background: #3a4150; }

  /* top bar */
  .topbar {
    height: 56px; display: flex; align-items: center; gap: 18px;
    padding: 0 20px; border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, var(--bg-1), var(--bg));
  }
  .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
  .brand .logo { display: block; width: 20px; height: 20px; flex-shrink: 0; }
  .brand .wm { display: flex; align-items: baseline; gap: 1px; }
  .brand .pf { color: var(--accent); }
  .status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); font-family: var(--mono); }
  .status .arrow { color: var(--faint); }
  .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); animation: pulse 2s infinite; }
  @keyframes pulse { 50% { opacity: 0.4; } }
  .topbar .spacer { flex: 1; }
  .kpis { display: flex; gap: 26px; }
  .kpi { text-align: right; }
  .kpi b { display: block; font-family: var(--mono); font-size: 16px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
  .kpi span { font-size: 10.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }

  /* layout */
  .app { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 56px); }
  .sidebar { border-right: 1px solid var(--line); overflow-y: auto; background: var(--bg); }
  .side-head { padding: 14px 16px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); position: sticky; top: 0; background: var(--bg); z-index: 1; }
  .call {
    display: block; width: 100%; text-align: left; cursor: pointer;
    background: none; border: 0; color: inherit; font: inherit;
    padding: 11px 16px; border-bottom: 1px solid var(--line);
    border-left: 2px solid transparent; transition: background 0.12s, border-color 0.12s;
  }
  .call:hover { background: var(--bg-1); }
  .call.active { background: var(--bg-2); border-left-color: var(--accent); }
  .call-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .call-model { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .call-cost { font-family: var(--mono); font-size: 12px; color: var(--accent-2); white-space: nowrap; }
  .call-sub { display: flex; justify-content: space-between; margin-top: 4px; font-size: 11.5px; color: var(--faint); }
  .call-sub .num { color: var(--muted); }
  .badge { display: inline-block; font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.05em; padding: 1px 6px; border-radius: 5px; background: var(--bg-2); color: var(--muted); border: 1px solid var(--line-2); }
  .wdot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); margin-right: 6px; vertical-align: middle; flex-shrink: 0; }

  /* main */
  .main { overflow-y: auto; padding: 24px 28px 60px; }
  .detail-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
  .dh-title h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
  .dh-title .meta { color: var(--muted); font-size: 12.5px; font-family: var(--mono); margin-top: 3px; }
  .dh-stats { display: flex; gap: 22px; margin-left: auto; align-items: center; }
  .stat b { display: block; font-family: var(--mono); font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
  .stat span { font-size: 10.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
  .stat.cost b { color: var(--accent-2); }

  .wgauge { display: flex; align-items: center; gap: 12px; margin: 0 0 18px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
  .wgauge .glabel { color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; font-size: 10.5px; }
  .wgauge .bar { flex: 1; max-width: 460px; height: 6px; background: var(--bg-2); border-radius: 3px; overflow: hidden; }
  .wgauge .bar i { display: block; height: 100%; border-radius: 3px; }

  .detail-head, .panel, .insight { animation: rise 0.28s cubic-bezier(0.22,1,0.36,1) both; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
  .insight {
    display: flex; align-items: center; gap: 13px; margin-bottom: 18px;
    background: linear-gradient(90deg, rgba(247,161,59,0.14), rgba(247,161,59,0.02) 60%, transparent);
    border: 1px solid var(--line); border-left: 3px solid var(--amber);
    border-radius: 10px; padding: 13px 16px;
  }
  .insight .ic { font-size: 18px; line-height: 1; }
  .insight .txt { font-size: 14px; color: var(--muted); }
  .insight .txt b { color: var(--text); }
  .insight .num { color: var(--amber); }
  .panel { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
  .panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
  .empty-note { color: var(--muted); font-size: 13px; padding: 18px 4px; text-align: center; font-family: var(--mono); }
  .crumbs { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; text-transform: none; letter-spacing: 0; }
  .crumb { color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 5px; }
  .crumb:hover { background: var(--bg-2); color: var(--text); }
  .crumb.cur { color: var(--text); }
  .crumb-sep { color: var(--faint); }

  /* flame graph */
  #flame { width: 100%; }
  #flame svg { display: block; width: 100%; height: auto; }
  .frame rect { transition: opacity 0.12s; rx: 3; }
  .frame text { font-family: var(--mono); font-size: 11px; pointer-events: none; fill: #0a0c10; font-weight: 600; }
  .frame:hover rect { opacity: 0.82; }

  .tip {
    position: fixed; z-index: 60; pointer-events: none; opacity: 0;
    background: #0a0c10; border: 1px solid var(--line-2); border-radius: 8px;
    padding: 9px 12px; font-size: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: opacity 0.1s; max-width: 280px;
  }
  .tip.on { opacity: 1; }
  .tip .t-name { font-weight: 700; margin-bottom: 4px; }
  .tip .t-row { font-family: var(--mono); color: var(--muted); font-size: 11.5px; }
  .tip .t-row b { color: var(--text); }

  /* legend / breakdown */
  .legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; }
  .leg { display: grid; grid-template-columns: 12px 1fr auto 44px 64px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
  .leg .sw { width: 11px; height: 11px; border-radius: 3px; }
  .leg .lname { font-size: 13px; }
  .leg .ltok { font-family: var(--mono); color: var(--muted); font-size: 12px; }
  .leg .lpct { font-family: var(--mono); color: var(--faint); font-size: 12px; width: 44px; text-align: right; }
  .leg .lcost { font-family: var(--mono); color: var(--accent-2); font-size: 12px; width: 64px; text-align: right; }
  .leg.dim { opacity: 0.5; }
  .leg .lname .pill { margin-left: 6px; }

  /* sidebar toolbar with custom dropdowns */
  .side-tools { display: flex; gap: 8px; padding: 6px 12px 10px; position: sticky; top: 33px; background: var(--bg); z-index: 5; }
  .dd-slot { flex: 1; min-width: 0; }
  .dd { position: relative; }
  .dd-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 6px; background: var(--bg-1); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 12.5px; cursor: pointer; transition: border-color 0.12s, background 0.12s; }
  .dd-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dd-btn:hover { border-color: #3a4150; background: var(--bg-2); }
  .dd.open .dd-btn { border-color: var(--accent); }
  .dd-caret { color: var(--faint); transition: transform 0.15s; flex-shrink: 0; }
  .dd.open .dd-caret { transform: rotate(180deg); }
  .dd-menu { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--bg-1); border: 1px solid var(--line-2); border-radius: 10px; padding: 5px; box-shadow: 0 14px 40px rgba(0,0,0,0.55); z-index: 30; opacity: 0; transform: translateY(-4px); pointer-events: none; transition: opacity 0.14s, transform 0.14s; max-height: 320px; overflow-y: auto; }
  .dd.open .dd-menu { opacity: 1; transform: none; pointer-events: auto; }
  .dd-item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--muted); font: inherit; font-size: 12.5px; padding: 7px 9px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dd-item:hover { background: var(--bg-2); color: var(--text); }
  .dd-item.sel { color: var(--accent); }
  .menu-btn { display: none; background: none; border: 1px solid var(--line-2); color: var(--text); border-radius: 8px; width: 36px; height: 34px; font-size: 16px; cursor: pointer; }

  /* sparkline */
  .spark-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
  .spark-wrap span { font-size: 9.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
  .spark { display: flex; align-items: flex-end; gap: 2px; height: 22px; }
  .spark i { width: 5px; background: var(--accent); border-radius: 1px; opacity: 0.6; }

  /* optimization panel */
  .sugg { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
  .sugg:last-child { border-bottom: 0; }
  .sugg .si { flex-shrink: 0; margin-top: 1px; }
  .sugg .stext { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
  .sugg .stext b { color: var(--text); }
  .sugg .stext .save { color: var(--accent-2); font-family: var(--mono); }
  .pill { background: var(--bg-2); border: 1px solid var(--line-2); color: var(--muted); border-radius: 10px; padding: 0 8px; font-size: 11px; font-family: var(--mono); }

  /* empty state */
  .empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; text-align: center; color: var(--muted); padding: 40px; }
  .empty h2 { font-size: 18px; color: var(--text); margin-bottom: 10px; font-weight: 700; }
  .empty code { font-family: var(--mono); background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 3px 8px; color: var(--accent-2); }
  .empty .hint { margin-top: 14px; font-size: 13px; }
  .empty .glyph { font-size: 40px; opacity: 0.5; margin-bottom: 18px; }

  /* responsive: tablet + mobile */
  @media (max-width: 860px) {
    .topbar { gap: 12px; padding: 0 14px; }
    .spark-wrap { display: none; }
    .menu-btn { display: block; order: -1; }
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; top: 56px; bottom: 0; left: 0; width: 290px; max-width: 85vw;
      transform: translateX(-100%); transition: transform 0.22s ease; z-index: 40;
      box-shadow: 0 0 50px rgba(0,0,0,0.6); }
    body.nav-open .sidebar { transform: none; }
    .scrim { display: none; position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,0.5); z-index: 39; }
    body.nav-open .scrim { display: block; }
    .main { padding: 18px 16px 56px; }
    .dh-stats { gap: 16px 18px; margin-left: 0; flex-wrap: wrap; }
    .legend { grid-template-columns: 1fr; }
  }
  @media (max-width: 620px) {
    .status { display: none; }
    .seg button { padding: 5px 10px; }
  }
  @media (max-width: 520px) {
    /* keep the view toggle and the cost KPI; the rest would overflow the bar */
    .topbar { padding: 0 10px; }
    .brand .wm { display: none; }  /* keep the logo mark, drop the wordmark */
    .kpis { gap: 12px; }
    .kpis .kpi:first-child, .kpis .kpi:nth-child(2) { display: none; }
    .seg button { padding: 5px 9px; font-size: 12px; }
    .dh-title h1 { font-size: 18px; }
    .leg { grid-template-columns: 12px 1fr auto 58px; }
    .leg .lpct { display: none; }
  }

  /* view toggle (segmented control) */
  .seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
  .seg button { background: none; border: 0; color: var(--muted); font: inherit; font-size: 12.5px; padding: 5px 14px; border-radius: 6px; cursor: pointer; transition: background 0.12s, color 0.12s; }
  .seg button:hover { color: var(--text); }
  .seg button.seg-on { background: var(--bg-1); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.4); }

  /* trends view */
  .trends-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
  .tcard { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
  .tcard .tlabel { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); }
  .tcard .tval { font-family: var(--mono); font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin: 6px 0 4px; }
  .tcard.cost .tval { color: var(--accent-2); }
  .delta { font-family: var(--mono); font-size: 12.5px; }
  .delta.up { color: #e5897a; }
  .delta.down { color: var(--accent-2); }
  .delta.flat { color: var(--faint); }
  .barchart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
  .barchart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
  .barchart .col .bar { width: 100%; max-width: 36px; background: linear-gradient(180deg, var(--accent), #5a63e0); border-radius: 4px 4px 0 0; transition: opacity 0.12s; }
  .barchart .col:hover .bar { opacity: 0.8; }
  .barchart .col .day { font-family: var(--mono); font-size: 10px; color: var(--faint); white-space: nowrap; }
  @media (max-width: 860px) { .trends-cards { grid-template-columns: 1fr; } }
  /* context timeline */
  .tl-pick { min-width: 220px; }
  .timeline-wrap { grid-template-columns: repeat(4, 1fr); }
  .tlchart { display: flex; align-items: flex-end; gap: 6px; height: 220px; padding-top: 10px; overflow-x: auto; }
  .tcol { flex: 1; min-width: 16px; display: flex; flex-direction: column; align-items: center; gap: 7px; cursor: default; }
  .tstack { width: 100%; max-width: 44px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
  .tstack:hover { outline: 1px solid var(--line-2); }
  .seg2 { width: 100%; min-height: 1px; transition: opacity 0.12s; }
  .tcol:hover .seg2 { opacity: 0.82; }
  .tnum { font-family: var(--mono); font-size: 10px; color: var(--faint); }
  .tl-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
  .tl-leg { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
  .tl-leg .sw { width: 11px; height: 11px; border-radius: 3px; }
  @media (max-width: 860px) { .timeline-wrap { grid-template-columns: repeat(2, 1fr); } }
  /* most-expensive-prompts leaderboard */
  .route { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .route:last-child { border-bottom: 0; }
  .rtop { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
  .rname { font-size: 13px; color: var(--text); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rcost { font-family: var(--mono); font-size: 13px; color: var(--accent-2); white-space: nowrap; }
  .rbar { height: 5px; background: var(--bg-2); border-radius: 3px; margin: 7px 0 5px; overflow: hidden; }
  .rbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--amber), #f4b860); border-radius: 3px; }
  .rmeta { font-family: var(--mono); font-size: 11px; color: var(--faint); }
  /* reclaimable headline + per-call footer */
  .reclaim-banner { margin-bottom: 18px; padding: 18px 22px;
    border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: var(--radius);
    background: linear-gradient(100deg, rgba(247,161,59,0.10), var(--bg-1) 60%); }
  .rb-top { display: flex; align-items: center; gap: 18px; }
  .reclaim-banner .rb-ic { flex-shrink: 0; opacity: 0.9; }
  .rb-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); }
  .rb-val { font-family: var(--mono); font-size: 30px; color: var(--amber); letter-spacing: -0.02em; margin-top: 2px; }
  .reclaim-banner.lean .rb-val { font-size: 20px; color: var(--accent-2); }
  .rb-meta { margin-left: auto; display: flex; flex-direction: column; gap: 3px; text-align: right;
    font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
  .rb-actions { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
  .rb-actions-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); margin-bottom: 8px; }
  .rb-act-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
  .rb-act { display: flex; align-items: baseline; gap: 12px; }
  .rb-act-do { color: var(--text); font-size: 13.5px; flex: 1; }
  .rb-act-meta { font-family: var(--mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
  .rb-act-meta .save { color: var(--accent-2); }
  .reclaim-call { display: flex; align-items: center; gap: 12px; margin: 0 0 18px; padding: 12px 18px;
    border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: var(--radius);
    background: linear-gradient(100deg, rgba(247,161,59,0.10), var(--bg-1) 70%); }
  .reclaim-call .rc-ic { flex-shrink: 0; }
  .reclaim-call .rc-text { font-size: 14px; color: var(--muted); }
  .reclaim-call .rc-text b { color: var(--text); }
  .reclaim-call .rc-text .save { color: var(--accent-2); font-family: var(--mono); }
  .reclaim-call .rc-pct { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--amber); white-space: nowrap; }
  @media (max-width: 620px) { .rb-top { flex-wrap: wrap; gap: 10px; } .rb-meta { margin-left: 0; text-align: left; }
    .rb-act { flex-direction: column; gap: 2px; } }
