/* =============== design tokens =============== */
/* Default: LIGHT theme (warm off-white, never pure white) */
:root, [data-theme="light"] {
  --bg:           #f6f3ee;
  --bg-elev:      #efeae2;
  --bg-card:      #fdfbf7;
  --bg-card-2:    #f5f1ea;
  --bg-input:     #fbf8f2;
  --border:       #e3ddd2;
  --border-2:     #d4cdbe;
  --fg:           #2a2825;
  --fg-2:         #555148;
  --muted:        #8a8478;
  --accent:       #c66a3c;        /* deeper coral that pops on cream */
  --accent-2:     #d68259;
  --accent-soft:  rgba(198,106,60,.10);
  --success:      #4e9e6e;
  --warning:      #b88a2a;
  --danger:       #c4524b;
  --shadow-sm:    0 1px 2px rgba(80,60,40,.06);
  --shadow:       0 4px 16px rgba(80,60,40,.08);
  --shadow-lg:    0 16px 44px rgba(80,60,40,.14);
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    14px;
  --sidebar-w:    232px;
  --ease:         cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
  --bg:           #0c0d10;
  --bg-elev:      #131418;
  --bg-card:      #16181d;
  --bg-card-2:    #1b1d23;
  --bg-input:     #101115;
  --border:       #22252c;
  --border-2:     #2c3038;
  --fg:           #e2e4ea;
  --fg-2:         #a8acb5;
  --muted:        #6a6e78;
  --accent:       #cf8254;
  --accent-2:     #e3996a;
  --accent-soft:  rgba(207,130,84,.12);
  --success:      #6ec78b;
  --warning:      #d6b56b;
  --danger:       #d97777;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.3);
  --shadow:       0 6px 18px rgba(0,0,0,.28);
  --shadow-lg:    0 18px 52px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body { display: flex; min-height: 100vh; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: "SF Mono", Menlo, Consolas, "JetBrains Mono", monospace; }
button { font: inherit; background: none; color: inherit; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--fg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.warn-text { color: var(--warning); }

/* =============== sidebar =============== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent) 0%, #9a5b39 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
  letter-spacing: -.5px;
  box-shadow: 0 4px 10px rgba(207,130,84,.25);
}
.brand-title { font-weight: 600; font-size: 13.5px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--fg-2);
  font-size: 13px; font-weight: 500;
  text-align: left;
  position: relative;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-item svg { color: var(--muted); transition: color .12s; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.03); color: var(--fg); }
.nav-item:hover svg { color: var(--fg-2); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-2);
}
.nav-item.active svg { color: var(--accent); }
.nav-count {
  margin-left: auto;
  font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  padding: 1px 8px;
  color: var(--fg-2);
}
.nav-item.active .nav-count {
  background: rgba(255,113,68,.2);
  color: var(--accent-2);
}

.sidebar-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
}
.foot-actions { display: flex; align-items: center; gap: 12px; }
.icon-btn { color: var(--muted); padding: 0; line-height: 0;
  display: inline-flex; align-items: center; }
.icon-btn:hover { color: var(--accent); }
.who { display: inline-flex; align-items: center; gap: 7px; color: var(--fg-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.dot.off { background: var(--danger); }
.dot.warn { background: var(--warning); }
.dot.unknown { background: var(--muted); }
.link {
  color: var(--muted); font-size: 12px;
  background: none; border: none; cursor: pointer;
  padding: 0;
}
.link:hover { color: var(--accent-2); }

/* =============== main =============== */
.main {
  flex: 1; min-width: 0;
  padding: 28px 36px 80px;
  overflow-y: auto;
}
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 22px; gap: 12px; flex-wrap: wrap;
}
.page-head h1 { font-size: 20px; font-weight: 600; letter-spacing: -.2px; }
.page-actions { display: flex; gap: 8px; align-items: center; }
.refresh-tag {
  font-size: 11.5px; color: var(--muted);
  padding: 4px 10px; border-radius: 999px;
  background: var(--bg-card); border: 1px solid var(--border);
}

/* =============== buttons =============== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: var(--bg-card);
  color: var(--fg);
  font-size: 13px; font-weight: 500;
  transition: all .14s;
  cursor: pointer;
}
.btn:hover { background: var(--bg-card-2); border-color: #38415a; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent); color: #1a1a1a; border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover {
  background: var(--accent-2); border-color: var(--accent-2);
  box-shadow: 0 4px 12px rgba(207,130,84,.25);
}
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(255,255,255,.04); }
.btn.danger { color: var(--danger); border-color: rgba(248,113,113,.3); }
.btn.danger:hover { background: rgba(248,113,113,.08); border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 11.5px; }
.btn.icon-only { padding: 4px 8px; font-size: 18px; line-height: 1; }

/* segment control */
.seg {
  display: inline-flex; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 3px; gap: 2px;
}
.seg-btn {
  padding: 5px 12px; border-radius: 6px;
  font-size: 12.5px; color: var(--fg-2);
  transition: all .14s;
}
.seg-btn:hover { color: var(--fg); }
.seg-btn.active {
  background: var(--bg-card-2);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}

.link-arrow {
  color: var(--accent-2); font-size: 12.5px; font-weight: 500;
  cursor: pointer;
}
.link-arrow:hover { color: var(--accent); }

/* =============== panels =============== */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.panel-head h2, .panel-h2 {
  font-size: 14px; font-weight: 600; color: var(--fg);
  letter-spacing: -.1px;
}
.panel-h2 { margin-bottom: 14px; }
.panel p { color: var(--fg-2); }
.panel p + p { margin-top: 8px; }
.panel pre {
  background: var(--bg-input); border: 1px solid var(--border);
  padding: 12px 14px; border-radius: 8px;
  font-size: 12px; color: var(--fg-2);
  overflow-x: auto; margin-top: 8px;
}
.panel code {
  background: var(--bg-input); padding: 2px 6px; border-radius: 4px;
  font-size: 12px; color: var(--accent-2);
}
.panel pre code { background: none; padding: 0; color: var(--fg-2); }

/* =============== KPI grid (overview) =============== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color .2s var(--ease);
  position: relative;
  overflow: hidden;
}
.kpi.pulse::after {
  content: ""; position: absolute; inset: 0;
  background: var(--accent);
  opacity: 0; pointer-events: none;
  animation: pulseFlash .8s ease-out;
}
@keyframes pulseFlash {
  0% { opacity: 0; }
  20% { opacity: .07; }
  100% { opacity: 0; }
}
.kpi-label {
  font-size: 10.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; font-weight: 600;
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 22px; font-weight: 600; letter-spacing: -.5px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.kpi-sub .ok { color: var(--success); }
.kpi-sub .warn { color: var(--warning); }
.kpi-sub .err { color: var(--danger); }
.kpi-spark { margin-top: 6px; height: 24px; }
.kpi-spark svg { width: 100%; height: 100%; display: block; }
.kpi-spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.kpi-spark .area { fill: var(--accent); opacity: .14; stroke: none; }

/* =============== cards (upstream) =============== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 14px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  transition: border-color .2s var(--ease), transform .2s var(--ease),
              box-shadow .2s var(--ease);
  display: flex; flex-direction: column;
  position: relative;
  animation: cardIn .25s var(--ease);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.card:hover {
  border-color: var(--border-2);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.card.live::before {
  content: ""; position: absolute; left: -1px; top: -1px;
  width: 4px; height: 12px; background: var(--accent);
  border-radius: 4px 0 0 4px;
  animation: livePulse 2.4s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: .25; }
  50% { opacity: 1; }
}
.card-disabled { opacity: .6; }

.card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-bottom: 4px;
}
.card-name {
  font-size: 14.5px; font-weight: 600; color: var(--fg);
  display: flex; align-items: center; gap: 8px;
}
.card-meta {
  font-size: 11.5px; color: var(--muted);
  display: flex; flex-direction: column; gap: 2px;
  margin: 6px 0 10px;
}
.card-meta code {
  background: rgba(255,255,255,.04); padding: 1px 6px; border-radius: 4px;
  color: var(--fg-2); font-size: 11px;
}
.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  font-size: 10.5px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(255,255,255,.05);
  color: var(--fg-2);
  border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 4px;
}
.badge .dot { width: 6px; height: 6px; }
.badge.ok { color: var(--success); border-color: rgba(74,222,128,.3); background: rgba(74,222,128,.08); }
.badge.warn { color: var(--warning); border-color: rgba(250,204,21,.3); background: rgba(250,204,21,.08); }
.badge.err { color: var(--danger); border-color: rgba(248,113,113,.3); background: rgba(248,113,113,.08); }
.badge.proxy { color: #a5b4fc; border-color: rgba(165,180,252,.3); background: rgba(165,180,252,.08); }
.badge.muted { color: var(--muted); }

/* class block w/ gauges */
.class-block { margin-top: 12px; }
.class-block:first-of-type { margin-top: 4px; }
.class-row {
  display: grid;
  grid-template-columns: 56px 1fr 1fr 1fr;
  gap: 8px; align-items: center;
  padding: 7px 0;
}
.class-label {
  font-size: 11px; font-weight: 600; color: var(--fg-2);
  text-transform: uppercase; letter-spacing: .5px;
}
.gauge {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s var(--ease);
}
.gauge::before {
  content: ""; position: absolute; left: 0; bottom: 0; top: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: .18;
  transition: width .5s var(--ease), opacity .25s var(--ease);
  width: var(--pct, 0%);
}
.gauge.warn::before {
  background: linear-gradient(90deg, var(--warning), #e5c98c);
  opacity: .22;
}
.gauge.over::before {
  background: linear-gradient(90deg, var(--danger), #e89a9a);
  opacity: .28;
}
.gauge-key { font-size: 10px; color: var(--muted); position: relative; z-index: 1; }
.gauge-val { font-size: 12px; font-weight: 600; color: var(--fg);
             font-variant-numeric: tabular-nums; position: relative; z-index: 1; }

/* card actions */
.card-foot {
  margin-top: auto; padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
}
.card-foot-actions { display: flex; gap: 6px; }
.card-foot-meta { font-size: 11.5px; color: var(--muted); }

/* test status pill on cards */
.test-pill {
  font-size: 10.5px; padding: 2px 8px; border-radius: 999px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; gap: 4px;
  animation: fadeIn .25s var(--ease);
}
@keyframes fadeIn { from {opacity:0} to {opacity:1} }
.test-pill.ok { color: var(--success); background: rgba(110,199,139,.1); }
.test-pill.err { color: var(--danger); background: rgba(217,119,119,.1); }
.test-pill.loading {
  color: var(--fg-2); background: rgba(255,255,255,.05);
}
.test-pill.loading::before {
  content: ""; width: 7px; height: 7px;
  border: 1.5px solid var(--fg-2); border-radius: 50%;
  border-top-color: transparent;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.test-stale {
  display: inline-block; font-size: 10px; color: var(--muted);
  margin-left: 4px;
}

/* mini-cards for overview */
.mini-cards { display: grid; gap: 8px; }
.mini-card {
  display: grid; grid-template-columns: 1fr auto auto auto;
  align-items: center; gap: 18px;
  padding: 10px 14px; background: var(--bg-card-2);
  border-radius: 8px; cursor: pointer;
  transition: background .12s;
}
.mini-card:hover { background: #1f2638; }
.mini-card-name { font-weight: 500; font-size: 13px; }
.mini-card-stat { font-size: 11.5px; color: var(--muted); }
.mini-card-stat strong { color: var(--fg); font-weight: 600; }

/* =============== tables =============== */
.table {
  width: 100%; border-collapse: collapse;
  font-size: 12.5px;
}
.table th {
  text-align: left; font-weight: 500;
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.table th.right { text-align: right; }
.table td.right { text-align: right; font-variant-numeric: tabular-nums; }
.table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(35,41,56,.5);
  color: var(--fg-2);
}
.table tbody tr:hover { background: rgba(255,255,255,.02); }
.table tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.pager {
  display: flex; gap: 10px; align-items: center; justify-content: center;
  margin-top: 14px;
}

/* status badges in tables */
.st { display: inline-block; padding: 1px 8px; border-radius: 999px;
      font-size: 10.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.st-2 { background: rgba(110,199,139,.1); color: var(--success); }
.st-4, .st-5 { background: rgba(217,119,119,.1); color: var(--danger); }

/* downstream table extras */
.ds-rpm {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-variant-numeric: tabular-nums;
}
.ds-rpm .num { font-size: 14px; font-weight: 600; color: var(--fg); }
.ds-rpm .unit { font-size: 10.5px; color: var(--muted); }
.ds-rpm.active .num { color: var(--accent); }
.spark { width: 64px; height: 18px; vertical-align: middle; }
.spark .bar { fill: var(--accent); opacity: .7; }
.cm-tag {
  font-size: 10.5px; padding: 1px 7px; border-radius: 999px;
  background: rgba(168,172,181,.1); color: var(--fg-2);
  border: 1px solid var(--border);
}
.cm-tag.system { background: rgba(207,130,84,.1); color: var(--accent-2); border-color: rgba(207,130,84,.3); }
.cm-tag.none { background: rgba(214,181,107,.1); color: var(--warning); border-color: rgba(214,181,107,.3); }

/* proxy table */
.proxy-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.proxy-status.ok { color: var(--success); background: rgba(110,199,139,.1); }
.proxy-status.err { color: var(--danger); background: rgba(217,119,119,.1); }
.proxy-status.untested { color: var(--muted); background: rgba(168,172,181,.08); }
.proxy-status.testing { color: var(--fg-2); background: rgba(168,172,181,.1); }
.proxy-status.testing::before {
  content: ""; width: 7px; height: 7px;
  border: 1.5px solid var(--fg-2); border-radius: 50%;
  border-top-color: transparent;
  animation: spin .8s linear infinite;
}
.refs-pill {
  display: inline-block; min-width: 20px; text-align: center;
  padding: 1px 8px; border-radius: 999px;
  background: var(--bg-card-2);
  color: var(--fg-2); font-size: 11.5px;
}
.refs-pill.used { color: var(--accent); background: var(--accent-soft); }
.bulk-result {
  margin-top: 12px; padding: 10px 14px; border-radius: 8px;
  background: var(--bg-card-2); font-size: 12.5px;
}
.bulk-result .lines {
  margin-top: 6px; max-height: 200px; overflow-y: auto;
  font-family: monospace; font-size: 11.5px; color: var(--muted);
  background: var(--bg-input); padding: 8px; border-radius: 6px;
}

/* =============== chart =============== */
.chart-box { width: 100%; height: 180px; }
.chart-box svg { display: block; width: 100%; height: 100%; }
.chart-bar { fill: var(--accent); transition: fill .12s; }
.chart-bar:hover { fill: var(--accent-2); }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 10px; }
.chart-tooltip {
  position: absolute;
  background: var(--bg-elev);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--fg);
  pointer-events: none;
  box-shadow: var(--shadow);
  white-space: nowrap;
  z-index: 50;
}

/* key value rows for settings */
.kv { display: grid; gap: 10px; }
.kv > div {
  display: grid; grid-template-columns: 140px 1fr;
  gap: 16px; font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(35,41,56,.4);
}
.kv > div:last-child { border-bottom: none; }

/* forms */
.form-tight label {
  display: block; font-size: 12.5px; color: var(--fg-2);
  margin-bottom: 12px;
}
.form-tight input:not([type=checkbox]), .form-tight select, .form-tight textarea {
  display: block; width: 100%;
  padding: 9px 12px; margin-top: 5px;
  background: var(--bg-input);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color .12s, background .12s;
}
.form-tight input:focus, .form-tight select:focus, .form-tight textarea:focus {
  border-color: var(--accent);
  background: var(--bg-card);
}
.form-tight select[multiple] { padding: 6px; min-height: 130px; }
.form-tight label.check {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px;
}
.form-tight label.check input { width: auto; margin: 0; }
.form-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 14px;
}

/* =============== modal & drawer =============== */
.modal { position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; padding: 24px; z-index: 100;
  animation: modalIn .18s var(--ease); }
@keyframes modalIn { from {opacity: 0;} to {opacity: 1;} }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px); }
.modal-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 26px 26px 22px;
  max-width: 540px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-card h3 { margin-bottom: 18px; font-size: 16px; font-weight: 600; }
.key-display {
  background: var(--bg-input);
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--success);
  font-size: 13px;
  word-break: break-all;
  user-select: all;
  margin: 14px 0;
}

.drawer { position: fixed; inset: 0; z-index: 90; display: flex; }
.drawer-mask { flex: 1; background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.drawer-card {
  width: min(640px, 90vw);
  background: var(--bg-card);
  border-left: 1px solid var(--border-2);
  display: flex; flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,.5);
  animation: slideInRight .2s ease-out;
}
@keyframes slideInRight {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.drawer-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px;
}
.drawer-head h2 { font-size: 16px; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 24px 28px; }
.drawer-content { margin-top: 16px; }

/* =============== toasts =============== */
.toast-root {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 240px; max-width: 380px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border-2);
  font-size: 13px;
  color: var(--fg);
  box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 10px;
  animation: toastIn .2s ease-out;
}
@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.toast-icon { flex-shrink: 0; width: 16px; height: 16px; margin-top: 1px; }
.toast.success { border-color: rgba(74,222,128,.4); }
.toast.success .toast-icon { color: var(--success); }
.toast.warn { border-color: rgba(250,204,21,.4); }
.toast.warn .toast-icon { color: var(--warning); }
.toast.err { border-color: rgba(248,113,113,.4); }
.toast.err .toast-icon { color: var(--danger); }
.toast-msg { flex: 1; word-break: break-word; }
.toast-x {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 16px; line-height: 1;
  padding: 0 2px;
}

/* drawer overview small stats */
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.stat-tile {
  background: var(--bg-card-2);
  border-radius: 8px;
  padding: 10px 14px;
}
.stat-tile-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat-tile-value { font-size: 17px; font-weight: 600; margin-top: 3px; }

/* login page */
.login-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 30px 34px;
  max-width: 400px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 18px; margin-bottom: 4px; font-weight: 600; }
.login-card p.muted { font-size: 12.5px; margin-bottom: 20px; }
.login-card label { display: block; margin-top: 14px; font-size: 12.5px; color: var(--fg-2); }
.login-card input {
  width: 100%; margin-top: 5px;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.login-card .btn.primary { width: 100%; margin-top: 18px; padding: 9px; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 4px; }
.alert.error { background: rgba(248,113,113,.1); color: var(--danger); border: 1px solid rgba(248,113,113,.3); }

/* models page */
.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.calc-grid label { display: block; font-size: 12.5px; color: var(--fg-2); }
.calc-grid input, .calc-grid select {
  width: 100%; padding: 8px 10px; margin-top: 5px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 6px; color: var(--fg);
}
.calc-result {
  display: grid; gap: 4px;
  background: var(--bg-card-2);
  padding: 12px 14px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.calc-row { display: flex; justify-content: space-between;
  font-size: 12.5px; color: var(--fg-2); padding: 2px 0; }
.calc-row.total {
  border-top: 1px solid var(--border);
  margin-top: 6px; padding-top: 8px;
  color: var(--fg); font-weight: 600; font-size: 14px;
}
#models-table .price-cell { font-variant-numeric: tabular-nums; font-weight: 500; color: var(--fg); }
#models-table tr.family-opus td:first-child { border-left: 3px solid #c66a3c; padding-left: 12px; }
#models-table tr.family-sonnet td:first-child { border-left: 3px solid #4e9e6e; padding-left: 12px; }
#models-table tr.family-haiku td:first-child { border-left: 3px solid #5b8def; padding-left: 12px; }

/* password strength */
.pw-strength { margin-top: 6px; }
.pw-bar {
  height: 4px; background: var(--bg-input); border-radius: 999px;
  overflow: hidden;
}
.pw-fill {
  height: 100%; width: 0;
  background: var(--danger);
  transition: width .3s var(--ease), background .3s var(--ease);
}
.pw-fill.s1 { width: 20%; background: var(--danger); }
.pw-fill.s2 { width: 40%; background: #d97742; }
.pw-fill.s3 { width: 60%; background: var(--warning); }
.pw-fill.s4 { width: 80%; background: #8fb262; }
.pw-fill.s5 { width: 100%; background: var(--success); }
.pw-text { margin-top: 4px; }

/* tier badge */
.badge.tier {
  background: rgba(91,141,239,.08);
  color: #5b8def;
  border-color: rgba(91,141,239,.3);
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .badge.tier { background: rgba(125,170,255,.1); color: #7daaff; }

/* code/keyboard color in light theme should be sub for light theme */
[data-theme="light"] .panel pre { color: #4a4a4a; background: #f8f4ec; }

/* responsive */
@media (max-width: 880px) {
  .sidebar { width: 64px; }
  .brand-text, .nav-item span:not(.nav-count), .sidebar-foot .who span:not(.dot) { display: none; }
  .nav-item { justify-content: center; }
  .main { padding: 20px; }
}

/* ============= Health card (homepage uptime widget) ============= */
.health-card {
  padding: 22px 24px 18px;
}
.hp-row { display: flex; align-items: center; }
.hp-row-top {
  justify-content: space-between;
  gap: 16px;
}
.hp-title { display: flex; align-items: center; gap: 14px; min-width: 0; }
.hp-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, #e6f9ec, #d2efde);
  color: #1f7a3d; font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
[data-theme="dark"] .hp-icon {
  background: linear-gradient(135deg, #1f3a2a, #15321f);
  color: #6fd99a;
}
.hp-name { font-size: 18px; font-weight: 600; }
.hp-sub { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: 12px; }
.hp-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  background: rgba(46, 166, 95, .12);
  color: #2ea65f;
  font-size: 11px;
  font-weight: 600;
}
.hp-status {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid;
}
.hp-status.hp-ok   { color: #2ea65f; background: rgba(46,166,95,.10); border-color: rgba(46,166,95,.35); }
.hp-status.hp-warn { color: #d97742; background: rgba(217,119,66,.10); border-color: rgba(217,119,66,.35); }
.hp-status.hp-err  { color: #d44; background: rgba(220,68,68,.10); border-color: rgba(220,68,68,.35); }

.hp-tiles {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.hp-tiles-3 { grid-template-columns: 1fr 1fr 1fr; }
.hp-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg-card-2);
  min-width: 0;  /* allow shrink in 3-col layout */
}
.hp-tile-lbl { font-size: 11px; color: var(--muted); }
.hp-tile-val { font-size: 20px; font-weight: 700; margin-top: 3px;
               font-variant-numeric: tabular-nums; white-space: nowrap; }
.hp-rpm-live { color: var(--accent); }   /* highlight when traffic flowing */
.hp-unit { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.hp-divider { height: 1px; background: var(--border); margin: 16px 0 12px; }
.hp-avail-row { justify-content: space-between; }
.hp-avail { font-size: 28px; font-weight: 700; color: #2ea65f; font-variant-numeric: tabular-nums; }

.hp-meta { display: flex; justify-content: space-between; margin: 12px 0 6px; }
.hp-bars-wrap {
  /* contain everything bar-related so axis labels stay flush */
  width: 100%;
  overflow: hidden;
}
.hp-bars {
  display: flex;
  gap: 2px;
  height: 36px;
  align-items: flex-end;
  width: 100%;
  overflow: hidden;
}
.hp-bar {
  flex: 1 1 0;
  height: 100%;
  border-radius: 2px;
  min-width: 0;   /* let bars shrink so they never overflow the card */
}
.hp-empty { background: var(--border); opacity: .45; }
.hp-ok    { background: #2ea65f; }
.hp-slow  { background: #f0b250; }
.hp-slow2 { background: #d97742; }
.hp-err   { background: #d44; }
.hp-axis {
  display: flex; justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .04em;
  padding: 0 1px;
}

/* ============= Cache hit-rate table ============= */
.cache-table th, .cache-table td { padding: 10px 14px; }
.cache-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.cache-table .hr-ok   { color: #2ea65f; }
.cache-table .hr-mid  { color: #f0b250; }
.cache-table .hr-low  { color: #d44; }

/* window switcher segment */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
}
.seg-btn {
  background: transparent;
  border: none;
  padding: 4px 12px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
}
.seg-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ============= Spend / cost card ============= */
.spend-card { padding: 22px 24px 18px; }
.sp-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.sp-row-top { margin-bottom: 16px; }
.sp-title { font-size: 18px; font-weight: 600; }
.sp-sub { margin-top: 2px; }

.sp-burn { text-align: right; }
.sp-burn-lbl { margin-bottom: 2px; }
.sp-burn-val { font-size: 22px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.sp-burn-proj { margin-top: 4px; }

.sp-tiles {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.sp-tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg-card-2);
  text-align: center;
}
.sp-tile-lbl { font-size: 11px; color: var(--muted); }
.sp-tile-val { font-size: 18px; font-weight: 700; margin-top: 3px;
               font-variant-numeric: tabular-nums; }

.sp-divider { height: 1px; background: var(--border); margin: 16px 0 12px; }
.sp-section-head {
  display: flex; justify-content: space-between;
  font-size: 13px; font-weight: 600; margin-bottom: 8px;
}
.sp-bar {
  height: 14px;
  border-radius: 7px;
  background: var(--border);
  display: flex;
  overflow: hidden;
}
.sp-seg { height: 100%; transition: width .3s ease; }
.sp-seg.sp-empty { background: var(--border); opacity: .3; }

.sp-legend {
  display: flex; flex-wrap: wrap; gap: 14px 18px;
  margin-top: 10px;
  font-size: 12px;
  align-items: center;
}
.sp-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.sp-legend-item strong { font-variant-numeric: tabular-nums; }
.sp-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }

.sp-ds {
  display: flex; flex-direction: column; gap: 6px;
}
.sp-ds-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card-2);
  font-size: 13px;
  align-items: center;
}
.sp-ds-name { font-weight: 600; }
.sp-ds-row strong { font-variant-numeric: tabular-nums; color: var(--accent); }

@media (max-width: 720px) {
  .sp-tiles { grid-template-columns: repeat(2, 1fr); }
  .sp-row { flex-direction: column; }
  .sp-burn { text-align: left; }
}

/* ============= per-upstream health grid ============= */
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
  position: relative;
}
.hp-countdown {
  grid-column: 1 / -1;
  text-align: right;
  padding: 0 6px;
}
.hp-tier {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(91,141,239,.10);
  color: #5b8def;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  margin-left: 2px;
}

/* ============= failures panel ============= */
.fail-empty {
  display: flex; align-items: center; gap: 10px;
  padding: 16px;
  color: #2ea65f;
  font-size: 14px;
}
.fail-empty-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(46,166,95,.15); color: #2ea65f;
  border-radius: 50%;
  font-weight: 700;
}
.fail-summary { padding: 8px 4px 16px; }
.fail-bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--border);
}
.fail-seg { height: 100%; }
.fail-4xx { background: #f0b250; }
.fail-5xx { background: #d44; }
.fail-other { background: #888; }
.fail-counters {
  display: flex; gap: 10px;
  margin-top: 10px;
  font-size: 12px;
  flex-wrap: wrap;
}
.fail-chip {
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.fail-chip.fail-4xx { color: #b06520; background: rgba(240,178,80,.15); }
.fail-chip.fail-5xx { color: #b81e1e; background: rgba(212,68,68,.15); }
.fail-chip.fail-other { color: #555; background: rgba(136,136,136,.15); }
.status-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}
.status-chip.fail-4xx { color: #b06520; background: rgba(240,178,80,.15); }
.status-chip.fail-5xx { color: #b81e1e; background: rgba(212,68,68,.15); }
.status-chip.fail-other { color: #555; background: rgba(136,136,136,.15); }
.fail-cols {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
}
.fail-col-h {
  font-weight: 600; font-size: 13px;
  margin-bottom: 6px;
}
.fail-col table { width: 100%; }
.data-table.compact td, .data-table.compact th { padding: 6px 10px; font-size: 12px; }
@media (max-width: 760px) {
  .fail-cols { grid-template-columns: 1fr; }
}

/* ============= quota panel ============= */
.quota-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--bg-card-2);
  transition: border-color .15s, background .15s;
}
.quota-row:hover {
  border-color: var(--accent);
  background: var(--bg-card);
}
.quota-row-head {
  display: flex; justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}
.quota-name { font-weight: 600; }
.quota-amt { font-variant-numeric: tabular-nums; }
.qb-tripped-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(212,68,68,.15);
  color: #d44;
  font-size: 10px;
  font-weight: 700;
  margin-left: 6px;
}
.quota-bar {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}
.quota-bar-fill {
  height: 100%;
  background: #2ea65f;
  transition: width .35s ease, background .2s;
}
.quota-bar.qb-mid     .quota-bar-fill { background: #5b8def; }
.quota-bar.qb-warn    .quota-bar-fill { background: #f0b250; }
.quota-bar.qb-tripped .quota-bar-fill { background: #d44; width: 100% !important; }
.quota-bar-alert {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  background: var(--muted);
  opacity: .5;
}

/* ============= modal additions (label + input style used by quota / show-key) ============= */
.modal-card .lbl {
  display: block;
  font-size: 12px;
  margin: 14px 0 4px;
  color: var(--muted);
}
.modal-card input[type="number"],
.modal-card input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: inherit;
  box-sizing: border-box;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 18px;
}
.key-copy-row {
  display: flex; gap: 8px;
  margin-top: 8px;
  align-items: center;
}
.key-copy-row .btn { white-space: nowrap; }
.copy-status {
  font-size: 12px;
  color: #2ea65f;
  opacity: 0;
  transition: opacity .2s;
}
.copy-status.shown { opacity: 1; }
