/* Nova AI · 用量看板
   Dark-first developer dashboard. Chart colors come from a validated
   categorical palette (adjacent-pair CVD ΔE ≥ 8, all ≥ 3:1 on --surface-1). */

:root {
  color-scheme: dark;

  /* surfaces & ink */
  --page:            #0A0E17;
  --surface-1:       #121826;
  --surface-2:       #171F30;
  --surface-3:       #1E2739;
  --border:          rgba(255, 255, 255, .09);
  --border-strong:   rgba(255, 255, 255, .16);
  --text-primary:    #F1F5F9;
  --text-secondary:  #A8B3C4;
  --text-muted:      #8B96A8;

  /* categorical series (dark steps) */
  --series-1: #3987e5;  /* blue   — spend      */
  --series-2: #199e70;  /* aqua   — tokens     */
  --series-3: #d95926;  /* orange              */
  --series-4: #c98500;  /* yellow              */
  --series-5: #d55181;  /* magenta             */

  /* status — reserved, never reused as a series */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --grid:     rgba(255, 255, 255, .07);
  --axis:     rgba(255, 255, 255, .14);

  /* dense dashboard scale */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px;

  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  --ring: 0 0 0 2px var(--page), 0 0 0 4px var(--series-1);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .7);

  --font-sans: system-ui, -apple-system, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --dur: 180ms;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; }

/* Author `display` on .signin / .alert / .loading would otherwise beat the UA
   rule for [hidden]. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 520px at 12% -12%, rgba(57, 135, 229, .13), transparent 62%),
    radial-gradient(900px 460px at 92% -6%, rgba(25, 158, 112, .09), transparent 60%),
    var(--page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd, figure { margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 1em; height: 1em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

/* ── brand ─────────────────────────────────────────────────────────── */

.brand { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.brand__mark { width: 26px; height: 26px; flex: none; }
.brand__mark rect { fill: var(--surface-3); }
.brand__mark path { fill: none; stroke: var(--series-1); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand__name { font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand__divider { width: 1px; height: 16px; background: var(--border-strong); }
.brand__page { color: var(--text-secondary); font-size: 14px; }
.brand--lg { justify-content: center; margin-bottom: var(--sp-5); }
.brand--lg .brand__mark { width: 34px; height: 34px; }
.brand--lg .brand__name { font-size: 19px; }

/* ── sign in ───────────────────────────────────────────────────────── */

.signin {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--sp-5) var(--sp-4);
  padding-bottom: max(var(--sp-5), env(safe-area-inset-bottom));
}

.signin__card {
  width: 100%; max-width: 420px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
  box-shadow: var(--shadow);
}

.signin__title { font-size: 22px; font-weight: 650; letter-spacing: -.02em; text-align: center; }
.signin__sub {
  margin: var(--sp-2) 0 var(--sp-5);
  color: var(--text-secondary); font-size: 14px; text-align: center;
}
.signin__note {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  margin-top: var(--sp-4);
  color: var(--text-muted); font-size: 12.5px; line-height: 1.45;
}
.signin__note .icon { margin-top: 2px; font-size: 14px; }

/* ── form controls ─────────────────────────────────────────────────── */

.field { display: block; }
.field__label { display: block; margin-bottom: var(--sp-2); font-size: 13px; font-weight: 550; color: var(--text-secondary); }
.field__wrap { position: relative; display: block; }

.field__input {
  width: 100%;
  padding: 11px 48px 11px 12px;
  background: var(--page);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field__input::placeholder { color: var(--text-muted); }
.field__input:hover { border-color: rgba(255, 255, 255, .26); }
.field__input:focus { outline: none; border-color: var(--series-1); box-shadow: 0 0 0 3px rgba(57, 135, 229, .22); }

.field__reveal {
  position: absolute; inset-inline-end: 1px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: var(--r-sm);
  color: var(--text-muted); font-size: 17px; cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.field__reveal:hover { color: var(--text-primary); background: var(--surface-3); }

.field__help { display: block; margin-top: var(--sp-2); color: var(--text-muted); font-size: 12.5px; }

.check {
  display: flex; align-items: center; gap: var(--sp-2);
  margin: var(--sp-4) 0 var(--sp-3);
  min-height: 44px; cursor: pointer; user-select: none;
}
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check__box {
  width: 18px; height: 18px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border-strong); border-radius: 5px;
  background: var(--page); color: transparent; font-size: 13px;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.check input:checked + .check__box { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.check input:focus-visible + .check__box { box-shadow: var(--ring); }
.check__text { font-size: 13.5px; color: var(--text-secondary); }

/* ── buttons ───────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-4);
  border: 1px solid transparent; border-radius: var(--r-md);
  font: inherit; font-weight: 550; font-size: 14px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

.btn--primary { background: var(--series-1); color: #fff; }
.btn--primary:hover:not([disabled]) { background: #4b94ea; }

.btn--ghost {
  background: var(--surface-2); border-color: var(--border);
  color: var(--text-secondary);
}
.btn--ghost:hover:not([disabled]) { background: var(--surface-3); color: var(--text-primary); border-color: var(--border-strong); }

.btn--block { width: 100%; }
.btn--icon { width: 44px; min-width: 44px; padding: 0; font-size: 17px; }
.btn--sm { min-height: 44px; padding: 0 var(--sp-3); font-size: 13px; }

.btn.is-busy .btn__label { opacity: .6; }

/* ── top bar ───────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(10, 14, 23, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: 1240px; margin: 0 auto;
  padding: var(--sp-3) var(--sp-4);
  padding-inline: max(var(--sp-4), env(safe-area-inset-left)) max(var(--sp-4), env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
}
.topbar__actions { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }

/* Below 760px the controls move to their own row so the brand and the key
   chip never compete for the same line. */
@media (max-width: 760px) {
  .topbar__inner { flex-wrap: wrap; row-gap: var(--sp-2); }
  .brand__divider, .brand__page { display: none; }
  .keychip { max-width: none; }
  .topbar__actions { flex: 1 0 100%; }
  .select { flex: 1; min-width: 0; }
  .select select { width: 100%; }
}

.keychip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  margin-inline-start: auto;   /* brand left, chip + controls right */
  max-width: 46vw; padding: 5px 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; font-size: 12.5px;
}
.keychip__alias { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.keychip__mask { color: var(--text-muted); font-family: var(--font-mono); font-size: 11.5px; white-space: nowrap; }

.select { position: relative; display: inline-flex; align-items: center; }
.select__icon {
  position: absolute; inset-inline-start: 11px; font-size: 15px;
  color: var(--text-muted); pointer-events: none;
}
.select select {
  appearance: none;
  min-height: 44px; padding: 0 var(--sp-4) 0 34px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  color: var(--text-primary); font: inherit; font-size: 13.5px; cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.select select:hover { background: var(--surface-3); border-color: var(--border-strong); }

/* ── page grid ─────────────────────────────────────────────────────── */

.page {
  max-width: 1240px; margin: 0 auto;
  padding: var(--sp-5) var(--sp-4) var(--sp-6);
  padding-inline: max(var(--sp-4), env(safe-area-inset-left)) max(var(--sp-4), env(safe-area-inset-right));
  padding-bottom: max(var(--sp-6), env(safe-area-inset-bottom));
  display: grid; gap: var(--sp-4);
}

.grid { display: grid; gap: var(--sp-4); }
.grid--hero  { grid-template-columns: 1fr; }
.grid--stats { grid-template-columns: 1fr; }

@media (min-width: 640px) {
  .grid--stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 720px) {
  .grid--hero  { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
}

/* ── card ──────────────────────────────────────────────────────────── */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  min-width: 0;
}
.card__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.card__title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.card__hint  { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.card__label {
  display: flex; align-items: baseline; gap: var(--sp-2); flex-wrap: wrap;
  color: var(--text-secondary); font-size: 13px; font-weight: 550;
}
.card__range { color: var(--text-muted); font-size: 12px; font-weight: 400; }
.card__tools { display: flex; align-items: center; gap: var(--sp-2); }

/* ── hero figure ───────────────────────────────────────────────────── */

/* Label + figure only — centred so the card reads as deliberate when the
   budget card beside it stretches the row taller. */
.card--hero { display: flex; flex-direction: column; justify-content: center; }

.hero {
  margin-top: var(--sp-2);
  font-size: clamp(38px, 8vw, 54px);
  font-weight: 650; line-height: 1.05; letter-spacing: -.035em;
}

/* ── budget meter ──────────────────────────────────────────────────── */

.card--budget { display: flex; flex-direction: column; gap: var(--sp-3); }

.meter__top { display: flex; align-items: baseline; gap: var(--sp-2); margin-top: var(--sp-3); }
.meter__value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
.meter__limit { color: var(--text-muted); font-size: 13.5px; }

.meter__track {
  height: 10px; border-radius: 999px; overflow: hidden;
  background: rgba(57, 135, 229, .18);   /* lighter step of the fill's own ramp */
}
.meter__fill {
  height: 100%; border-radius: 999px; background: var(--series-1);
  transition: width 420ms var(--ease), background var(--dur) var(--ease);
}
.meter.is-warning .meter__fill  { background: var(--warning); }
.meter.is-warning .meter__track { background: rgba(250, 178, 25, .18); }
.meter.is-critical .meter__fill  { background: var(--critical); }
.meter.is-critical .meter__track { background: rgba(208, 59, 59, .2); }

.meter__foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3);
}
.meter__reset { color: var(--text-muted); font-size: 12.5px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-size: 12px; font-weight: 550; color: var(--text-secondary);
}
.tag .icon { font-size: 13px; }
.tag--good     { color: var(--good);     border-color: rgba(12, 163, 12, .4);  background: rgba(12, 163, 12, .1); }
.tag--warning  { color: var(--warning);  border-color: rgba(250, 178, 25, .4); background: rgba(250, 178, 25, .1); }
.tag--critical { color: var(--critical); border-color: rgba(208, 59, 59, .45); background: rgba(208, 59, 59, .12); }

/* ── stat tiles ────────────────────────────────────────────────────── */

.stat { display: flex; flex-direction: column; gap: var(--sp-1); }
.stat__label {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-secondary); font-size: 12.5px; font-weight: 550;
}
.stat__label .icon { font-size: 15px; color: var(--text-muted); }
.stat__value { font-size: clamp(21px, 3.4vw, 26px); font-weight: 650; letter-spacing: -.02em; }
.stat__sub   { color: var(--text-muted); font-size: 12px; }

/* ── chart ─────────────────────────────────────────────────────────── */

.card--chart { padding-bottom: var(--sp-3); }
.chart { position: relative; height: 300px; }
@media (max-width: 640px) { .chart { height: 240px; } }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
}
.segmented__btn {
  min-height: 36px; padding: 0 var(--sp-3);
  background: none; border: 0; border-radius: 7px;
  color: var(--text-secondary); font: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.segmented__btn:hover { color: var(--text-primary); }
.segmented__btn.is-active { background: var(--surface-3); color: var(--text-primary); }

/* ── tables ────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; margin-top: var(--sp-4); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td {
  padding: 9px var(--sp-3);
  text-align: start; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table th {
  color: var(--text-muted); font-weight: 550; font-size: 12px;
  position: sticky; top: 0; background: var(--surface-1);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }
.table .bar-col { width: 130px; }
@media (max-width: 640px) { .table .bar-col { display: none; } }
.table .model { font-family: var(--font-mono); font-size: 12.5px; }

.share { display: flex; align-items: center; gap: var(--sp-2); }
.share__track { flex: 1; min-width: 56px; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.share__fill  { display: block; height: 100%; border-radius: 999px; }
.share__pct   { color: var(--text-muted); font-size: 11.5px; font-variant-numeric: tabular-nums; min-width: 34px; text-align: end; }

.empty { color: var(--text-muted); font-size: 13px; padding: var(--sp-5) 0; text-align: center; }

/* ── alerts, footer, loading ───────────────────────────────────────── */

.alert {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: 10px var(--sp-3); border-radius: var(--r-md);
  font-size: 13.5px;
}
.alert .icon { margin-top: 2px; font-size: 16px; flex: none; }
.alert--error { margin-top: var(--sp-3); background: rgba(208, 59, 59, .12); border: 1px solid rgba(208, 59, 59, .38); color: #f0a1a1; }

.foot { color: var(--text-muted); font-size: 12px; }

.loading {
  position: fixed; inset-block-end: var(--sp-5); inset-inline-start: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 8px var(--sp-4);
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: 999px; box-shadow: var(--shadow);
  font-size: 13px; color: var(--text-secondary);
}
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--series-1);
  animation: spin 720ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page.is-stale { opacity: .55; transition: opacity var(--dur) var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
