/* ==========================================================================
   Usage blocks — account quotas, user consumption, GPU cluster.

   The markup comes from clove (app/api/routes/usage.py + services/codex_tracker.py)
   and lands in the overview as-is; this file is the only place its looks are
   decided. It is a port of the old standalone page's stylesheet with the
   hardcoded palette swapped for the panel's variables, so these blocks follow
   the panel's own light/dark toggle instead of the OS setting, and sit on the
   same surfaces, borders and type scale as the cards around them.

   Rule of thumb when clove's renderers change: layout and structure belong in
   the renderer's class names, colour belongs here. The only colours still
   written inline upstream are the semantic ones (green→yellow→red load ramps,
   per-series chart strokes), which read correctly on both themes.
   ========================================================================== */

:root {
  --u-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --u-soft: color-mix(in srgb, var(--surface-2) 70%, var(--surface-1));
  --u-line: var(--grid);
}

.usage-frag { font-size: 13px; color: var(--text-primary); }
.usage-loading { padding: 22px 0; text-align: center; color: var(--text-muted); font-size: 13px; }
.usage-stamp { font-size: 12px; color: var(--text-muted); transition: color .4s; white-space: nowrap; }
.usage-stamp::before {
  content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 6px;
  border-radius: 50%; background: var(--good); vertical-align: 1px;
}
.usage-stamp.is-fresh { color: var(--good-text); }
.usage-stamp.is-fresh::before { animation: uPulse .9s ease-out; }
@keyframes uPulse {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 50%, transparent); }
  to   { box-shadow: 0 0 0 7px transparent; }
}

/* ── account usage ──────────────────────────────────────────────────── */
.acct { padding: 10px 0; border-top: 1px solid var(--border); }
.usage-frag > .acct:first-child { border-top: 0; padding-top: 0; }
.acct-head { display: flex; align-items: center; gap: 6px 8px; margin-bottom: 10px; flex-wrap: wrap; }
.acct-name { font-size: 14px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.acct-empty { text-align: center; color: var(--text-muted); font-size: 13px; padding: 14px 0; }
.idx-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-secondary);
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.acct-tag {
  font-size: 11px; padding: 1px 8px; border-radius: 999px; font-weight: 500; white-space: nowrap;
  background: color-mix(in srgb, var(--series-1) 14%, transparent); color: var(--series-1);
}
.acct-tag-codex   { background: color-mix(in srgb, var(--good) 14%, transparent);   color: var(--good-text); }
.acct-tag-kimi    { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--slot-4); }
.acct-tag-claude  { background: color-mix(in srgb, var(--series-1) 14%, transparent); color: var(--series-1); }
.acct-tag-zai     { background: color-mix(in srgb, var(--slot-5) 16%, transparent);  color: var(--slot-5); }
.acct-tag-minimax { background: color-mix(in srgb, var(--series-2) 15%, transparent); color: var(--series-2); }
.acct-tag-mimo    { background: color-mix(in srgb, var(--slot-5) 14%, transparent);  color: var(--slot-5); }
.acct-tag-agy     { background: color-mix(in srgb, var(--slot-1) 14%, transparent);  color: var(--slot-1); }
.acct-state { font-size: 11px; white-space: nowrap; margin-left: auto; }
.acct-state.is-ok   { color: var(--good-text); }
.acct-state.is-warn { color: var(--warning); }
.acct-state.is-bad  { color: var(--critical); }

/* usage bars (also used by the codex block) */
.ub { margin-bottom: 9px; }
.ub:last-child { margin-bottom: 0; }
.ub-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; margin-bottom: 4px; }
.ub-label { color: var(--text-secondary); font-weight: 500; }
.ub-pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.ub-track { position: relative; height: 8px; background: var(--surface-2); border-radius: 5px; }
.ub-fill { height: 100%; border-radius: 5px; transition: width .5s ease; }
.ub-now { position: absolute; top: -3px; bottom: -3px; width: 2px; border-radius: 1px; background: color-mix(in srgb, var(--text-primary) 55%, transparent); }
.ub-now::after {
  content: ''; position: absolute; top: -4px; left: 50%; transform: translateX(-50%);
  border-left: 3px solid transparent; border-right: 3px solid transparent;
  border-top: 4px solid color-mix(in srgb, var(--text-primary) 55%, transparent);
}
.ub-cap { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); margin-top: 3px; }

/* ── stat tiles (the codex block, rendered by codex2api's tracker.py) ──── */
.cl-overview { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.cl-stat {
  flex: 1 1 110px; padding: 12px 14px; text-align: center;
  background: var(--u-soft); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.cl-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.cl-lbl { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── consumption: activity, trend, ranking ──────────────────────────── */
.cons-toggle { display: flex; gap: 6px; margin: 18px 0 14px; }
.cons-btn {
  font: inherit; font-size: 12px; padding: 4px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-secondary);
  transition: all .2s;
}
.cons-btn:hover { color: var(--text-primary); }
.cons-btn.active { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.cons-sub { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 8px;
  /* one line, shrunk to fit if need be (see fitOverflowingText) — a wrapped section
     heading pushes everything under it out of alignment with the block beside it */
  white-space: nowrap; overflow: hidden; }
.cons-pane > .cons-sub:first-child { margin-top: 0; }
.usage-frag > .cons-sub:first-child { margin-top: 0; }
.cons-empty { text-align: center; color: var(--text-muted); font-size: 13px; padding: 12px 0; }

.act-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.act-chip {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 8px 6px;
  background: var(--u-soft); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.act-chip::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--good); }
.act-user { padding-left: 8px; font-family: var(--u-mono); font-weight: 600; font-size: 12px; }
.act-model { padding-left: 8px; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-reqs { padding-left: 8px; font-size: 15px; font-weight: 700; color: var(--good-text); }
.act-reqs small { font-size: 10px; font-weight: 400; color: var(--text-muted); }
.act-empty { font-size: 12px; color: var(--text-muted); padding: 8px 0; text-align: center; }

.tg-wrap { position: relative; }
.tg-max { font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.tg-svg { width: 100%; height: 132px; display: block; overflow: hidden; border-radius: 6px; }
.tg-grid { stroke: var(--u-line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tg-axis { position: relative; height: 14px; margin-top: 4px; }
.tg-axis span { position: absolute; top: 0; font-size: 10px; line-height: 14px; color: var(--text-muted); white-space: nowrap; }
.tg-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; }
.tg-leg { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-secondary); }
.tg-leg i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; flex-shrink: 0; }
.tg-leg b { margin-left: 1px; font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.tg-plot { position: relative; }
.tg-cross { position: absolute; top: 0; bottom: 0; width: 1px; display: none; pointer-events: none; background: color-mix(in srgb, var(--text-primary) 28%, transparent); }
.tg-dot {
  position: absolute; width: 7px; height: 7px; border-radius: 50%; display: none;
  border: 2px solid var(--surface-1); transform: translate(-50%, -50%);
  pointer-events: none; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.tg-tip {
  position: absolute; z-index: 6; display: none; min-width: 118px; padding: 8px 10px;
  font-size: 11px; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); color: var(--text-primary);
}
.tg-tip-t { color: var(--text-muted); margin-bottom: 5px; font-size: 10px; }
.tg-tip-row { display: flex; align-items: center; gap: 6px; line-height: 1.7; }
.tg-tip-row i { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.tg-tip-row b { margin-left: auto; padding-left: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── codex box (collapsible) ────────────────────────────────────────── */
.cx-box { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--u-soft); overflow: hidden; }
.cx-sum {
  padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--good-text);
  display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden;
}
.cx-sum::before { content: '▍'; color: var(--good); }
.cx-hint { margin-left: auto; font-size: 10px; font-weight: 400; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.cx-body { padding: 0 12px 14px; }
.cx-body > .cons-sub:first-child { margin-top: 6px; }
.cx-curbar { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.cx-cur { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-secondary); }
.cx-cur i { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.cx-cur b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.cx-btns { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 4px; }
.cx-btn {
  font: inherit; font-size: 11px; padding: 3px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-secondary);
  transition: all .2s;
}
.cx-btn:hover { color: var(--text-primary); }
.cx-btn.active { background: var(--good); border-color: var(--good); color: #fff; }
.cx-pane[hidden] { display: none; }
/* fixed layout so the columns divide the card evenly and the last one ends at the
   right edge, instead of every column hugging its content and leaving a gap */
.cx-q { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 11px; margin: 6px 0 2px; }
.cx-q th:first-child, .cx-q td:first-child { width: 15%; }
.cx-q-win, .cx-q th:nth-child(2) { width: 8%; }
.cx-q th { text-align: left; font-weight: 600; color: var(--text-muted); padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.cx-q td { padding: 5px 8px; border-bottom: 1px solid var(--border); color: var(--text-primary); font-variant-numeric: tabular-nums; }
.cx-q tr:last-child td { border-bottom: 0; }
.cx-q-acct { font-weight: 600; vertical-align: middle; }
.cx-q-acct i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.cx-q-win { color: var(--text-secondary); }
.cx-q-pct { font-weight: 600; }
.cx-q-full { font-weight: 600; color: var(--good-text); }
.cx-q-i { color: var(--series-1); }
.cx-q-c { color: var(--slot-3); }
.cx-q-o { color: var(--good-text); }
.cx-q-comp { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cx-q-comp .cx-q-usd span + span::before,
/* three numbers in one cell read as one long run without a separator; the slash is
   the same one the header uses (输入/缓存/输出), so the mapping is obvious */
.cx-q-comp span + span::before { content: '/'; color: var(--text-muted); margin: 0 5px 0 1px; }
/* the value columns are compared down the column, so they line up on the right */
.cx-q th:nth-child(n + 3), .cx-q td:not(.cx-q-acct):not(.cx-q-win) { text-align: right; }
.cx-q-cap, .cx-q-lc { font-size: 9px; margin-left: 4px; padding: 1px 4px; border-radius: 6px; font-weight: 600; vertical-align: 1px; }
.cx-q-cap { background: color-mix(in srgb, var(--critical) 15%, transparent); color: var(--critical); }
.cx-q-lc { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--slot-4); }
.cx-q-note { font-size: 10px; color: var(--text-muted); margin: 4px 0 2px; line-height: 1.5; }
.cx-q-usd { display: block; font-size: 10px; font-weight: 400; color: var(--text-muted); margin-top: 1px; }
.cx-q-full .cx-q-usd { color: var(--good-text); font-weight: 600; }
.cx-stats { margin: 8px 0 2px; }
.cx-stats .cl-stat { flex: 1 1 132px; padding: 10px 12px; }
.cx-stats .cl-val { font-size: 17px; }
.cx-stats .cl-sub { font-size: 10px; color: var(--text-muted); margin-top: 3px; line-height: 1.35; }

@media (max-width: 640px) {
  .act-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
}

/* ── per-account × per-model breakdown ──────────────────────────────────── */
.cx-mb { margin: 8px 0 4px; }
.cx-mb-sum-line {
  cursor: pointer; font-size: 11px; font-weight: 600; color: var(--text-secondary);
  padding: 5px 0; list-style: none; display: flex; align-items: center; gap: 6px;
}
.cx-mb-sum-line::-webkit-details-marker { display: none; }
.cx-mb-sum-line::before { content: '▸'; font-size: 9px; color: var(--text-muted); }
.cx-mb[open] .cx-mb-sum-line::before { content: '▾'; }
.cx-mb-body { padding: 2px 0 6px; }
.cx-mb-acct {
  display: flex; align-items: center; gap: 6px; margin: 10px 0 2px;
  font-size: 11px; font-weight: 600;
}
.cx-mb-acct i { width: 9px; height: 9px; border-radius: 2px; }
.cx-mb-sum { margin-left: auto; font-weight: 400; color: var(--text-muted); }
.cx-mb-t th:first-child, .cx-mb-t td:first-child { width: 30%; }
.cx-mb-t th:nth-child(2), .cx-mb-t td:nth-child(2) { width: 10%; }
.cx-mb-model { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }

/* ── 当前活跃 chips ─────────────────────────────────────────────────────── */
.act-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; }
.act-chip {
  position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 2px 10px; padding: 9px 11px 9px 20px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-1); overflow: hidden;
}
/* a live dot rather than a bar: these are people making requests right now */
.act-chip::before {
  content: ''; position: absolute; left: 9px; top: 50%; width: 5px; height: 5px;
  margin-top: -2.5px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 18%, transparent);
}
.act-user {
  grid-column: 1; padding: 0; font-family: var(--u-mono); font-weight: 600; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.act-model {
  grid-column: 1; grid-row: 2; padding: 0; font-size: 10px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.act-reqs {
  grid-column: 2; grid-row: 1 / span 2; padding: 0;
  font-size: 16px; font-weight: 700; color: var(--good-text);
  font-variant-numeric: tabular-nums; line-height: 1.1; text-align: right;
}
.act-reqs small { display: block; font-size: 9px; font-weight: 400; color: var(--text-muted); }

@media (max-width: 640px) {
  .act-grid { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); }
}

/* Six columns of numbers do not fit a phone; scrolling the table beats shrinking every
   header into an ellipsis. The wrapper is emitted by codex2api around both tables. */
.cx-q-wrap { overflow-x: auto; scrollbar-width: thin; }
@media (max-width: 700px) {
  .cx-q { min-width: 560px; }
  .cx-mb-t { min-width: 520px; }
}
