/* MagicRouter dashboard — dark data-dense UI.
   Palette: Developer Tool / IDE (slate + run-green), Inter + JetBrains Mono. */

:root {
  --bg: #0b1220;
  --bg-soft: #111a2e;
  --panel: #151f33;
  --panel-2: #1c2841;
  --card: #1b2336;
  --border: #2a3a57;
  --border-soft: #22304a;
  --text: #f8fafc;
  --muted: #94a3b8;
  --muted-2: #6b7a90;
  --primary: #22c55e;
  --primary-2: #4ade80;
  --on-primary: #052e16;
  --info: #5b8cff;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a78bfa;
  --radius: 12px;
  --shadow: 0 12px 32px rgba(2, 6, 23, 0.45);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(900px 480px at 12% -12%, rgba(34, 197, 94, 0.08), transparent 60%),
    radial-gradient(1000px 520px at 108% -8%, rgba(91, 140, 255, 0.1), transparent 58%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.app { display: flex; min-height: 100vh; }

/* ------------------------------------------------------------------ sidebar */
.sidebar {
  width: 236px;
  flex: 0 0 236px;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid var(--border-soft);
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px; color: var(--on-primary);
  background: linear-gradient(135deg, #4ade80, #22c55e 55%, #16a34a);
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14.5px; letter-spacing: -0.2px; }
.brand-text span { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 9px;
  border: 1px solid transparent; background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 500;
  cursor: pointer; text-align: left; transition: background 0.14s ease, color 0.14s ease;
}
.nav-item:hover { color: var(--text); background: rgba(148, 163, 184, 0.08); }
.nav-item.active {
  color: var(--text);
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.3);
}
.nav-item.active .ico { color: var(--primary); }
.nav-item .ico { font-size: 14px; width: 18px; text-align: center; opacity: 0.95; }
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; gap: 8px;
  padding: 9px 11px; border: 1px solid var(--border-soft); border-radius: 9px;
  font-size: 11.5px; color: var(--muted); background: rgba(255, 255, 255, 0.02);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 8px currentColor; flex: 0 0 auto; }
.status-dot.ok { background: var(--green); }
.status-dot.bad { background: var(--red); }

/* --------------------------------------------------------------------- main */
.main { flex: 1; min-width: 0; padding: 22px 28px 64px; max-width: 1600px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border-soft);
}
.topbar-left { display: flex; flex-direction: column; gap: 2px; }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -0.5px; font-weight: 700; line-height: 1.2; }
.topbar p { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.userchip {
  font-size: 11.5px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px; border-radius: 8px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border-soft);
}
.userchip::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px var(--green); flex: 0 0 auto;
}

.view { display: none; animation: fade 0.18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ buttons */
.btn {
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  padding: 7px 14px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
  white-space: nowrap; font-family: inherit; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: #3b4d6e; background: #1e2e4a; }
.btn:active { transform: translateY(0.5px); opacity: 0.9; }
.btn.primary {
  background: var(--primary); border-color: var(--primary);
  color: var(--on-primary); font-weight: 700;
  box-shadow: 0 3px 12px rgba(34, 197, 94, 0.25);
}
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); box-shadow: 0 4px 18px rgba(74, 222, 128, 0.3); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: rgba(148, 163, 184, 0.07); border-color: rgba(148,163,184,0.3); }
.btn.danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.07); }
.btn.danger:hover { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.55); }
.btn.tiny { padding: 4px 10px; font-size: 11.5px; border-radius: 7px; }
.btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 17px; cursor: pointer; padding: 4px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: rgba(148,163,184,0.1); }

/* -------------------------------------------------------------------- cards */
.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 14px 16px 13px; position: relative; overflow: hidden;
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.stat-card:hover { border-color: rgba(148,163,184,0.25); transform: translateY(-1px); }
.stat-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent, var(--primary)) 0%, transparent 80%);
  border-radius: var(--radius) var(--radius) 0 0;
}
.stat-card .label { font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted-2); font-weight: 700; margin-top: 2px; }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.8px; font-variant-numeric: tabular-nums; line-height: 1; }
.stat-card .sub { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* ------------------------------------------------------------------- panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 13.5px; letter-spacing: -0.2px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: 1.55fr 1fr; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ------------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border-radius: 9px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
thead th {
  text-align: left; padding: 9px 12px; color: var(--muted-2);
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid var(--border-soft); font-weight: 700; white-space: nowrap;
  position: sticky; top: 0; z-index: 1; user-select: none;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid rgba(34, 48, 74, 0.55); vertical-align: middle; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover td { background: rgba(34, 197, 94, 0.04); }
tbody tr:last-child td { border-bottom: none; }
.mono { font-family: var(--mono); font-size: 11.5px; }
.email { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 650;
  border: 1px solid transparent; white-space: nowrap; line-height: 1.5;
}
.badge.green { color: #86efac; background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.32); }
.badge.amber { color: #fcd34d; background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.32); }
.badge.red { color: #fca5a5; background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.32); }
.badge.blue { color: #a8c1ff; background: rgba(91, 140, 255, 0.12); border-color: rgba(91, 140, 255, 0.32); }
.badge.purple { color: #c4b5fd; background: rgba(167, 139, 250, 0.12); border-color: rgba(167, 139, 250, 0.32); }
.badge.gray { color: var(--muted); background: rgba(148, 163, 184, 0.1); border-color: var(--border); }

.quota-bar { height: 5px; border-radius: 999px; background: rgba(148, 163, 184, 0.18); overflow: hidden; min-width: 60px; }
.quota-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.quota-bar.low > span { background: var(--red); }

/* ---------------------------------------------------------- toolbar / inputs */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }
.input {
  background: var(--bg-soft); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 7px 10px; font-size: 12.5px;
  outline: none; transition: border-color 0.14s ease, box-shadow 0.14s ease;
  min-width: 0; font-family: inherit;
}
.input::placeholder { color: var(--muted-2); }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14); }
textarea.input { resize: vertical; width: 100%; }
select.input { cursor: pointer; }
/* Native dropdown lists ignore the page theme on Windows; force readable colors. */
select, select option, select optgroup {
  color-scheme: dark;
  background-color: #0d1626;
  color: #e6edf9;
}
select option:checked, select option:hover { background-color: #17304a; color: #ffffff; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--primary); width: 15px; height: 15px; }

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

/* ---------------------------------------------------------------- breakdown */
.breakdown { display: flex; flex-direction: column; gap: 12px; }
.breakdown-row { display: grid; grid-template-columns: 120px 1fr 90px; align-items: center; gap: 12px; }
.breakdown-row .name { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.breakdown-row .bar { height: 7px; border-radius: 999px; background: rgba(148, 163, 184, 0.14); overflow: hidden; }
.breakdown-row .bar > span { display: block; height: 100%; border-radius: 999px; background: var(--info); }
.breakdown-row .val { text-align: right; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ provider cards */
.provider-card { background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px; }
.provider-card h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 9px; }
.provider-card .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 12px; }
.model-chip {
  display: inline-block; padding: 2px 7px; margin: 3px 4px 0 0; border-radius: 6px;
  font-size: 10.5px; background: rgba(91, 140, 255, 0.1);
  border: 1px solid rgba(91, 140, 255, 0.22); color: #b9ccff; font-family: var(--mono);
}

/* -------------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field > span { font-weight: 500; }
.form-actions { display: flex; gap: 8px; }
.kv { display: flex; flex-direction: column; gap: 10px; }
.kv > div { display: flex; flex-direction: column; gap: 4px; }
.kv span { font-size: 11.5px; color: var(--muted-2); }
.kv code {
  font-family: var(--mono); font-size: 11.5px; background: var(--bg-soft);
  border: 1px solid var(--border-soft); padding: 6px 9px; border-radius: 7px;
  color: #a8c1ff; user-select: all; word-break: break-all;
}

/* -------------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%; max-width: 660px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  max-height: 88vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 14px; font-weight: 650; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

/* -------------------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 80;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 16px; border-radius: 11px; font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px) scale(0.97);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none; max-width: 360px; line-height: 1.5;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.toast.ok { border-color: rgba(34, 197, 94, 0.45); background: rgba(21, 31, 51, 0.97); }
.toast.err { border-color: rgba(239, 68, 68, 0.45); }

canvas { width: 100%; display: block; }

.empty { padding: 26px; text-align: center; color: var(--muted-2); font-size: 12.5px; }

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 40; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: none; }
  .main { padding: 16px; }
  .cards { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ------------------------------------------------------- connect modal tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--border-soft); padding-bottom: 9px; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 550;
  font-family: inherit;
}
.tab:hover { color: var(--text); background: rgba(148, 163, 184, 0.08); }
.tab.active { color: var(--text); background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.3); }
.tabpane { display: none; flex-direction: column; gap: 12px; }
.tabpane.active { display: flex; }
.steps { display: flex; flex-direction: column; gap: 9px; margin-bottom: 4px; }
.step { display: flex; gap: 10px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.step .n {
  flex: 0 0 20px; height: 20px; border-radius: 50%;
  background: rgba(34, 197, 94, 0.14); border: 1px solid rgba(34, 197, 94, 0.32);
  color: var(--primary-2); font-size: 10.5px; display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.step code { background: rgba(255, 255, 255, 0.06); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 11px; }
.device-box {
  margin-top: 14px; padding: 16px; border: 1px solid var(--border); border-radius: 11px;
  background: rgba(255, 255, 255, 0.02); display: flex; flex-direction: column; gap: 7px;
  align-items: center; text-align: center;
}
.code-big { font-family: var(--mono); font-size: 25px; letter-spacing: 5px; font-weight: 700; color: var(--primary-2); }

/* --------------------------------------------------- quota cards (cockpit) */
.qcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 9px; }
.qcards.inline { display: flex; flex-direction: column; gap: 6px; min-width: 268px; }
.qcard {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
  padding: 8px 10px; border: 1px solid var(--border-soft); border-radius: 9px;
  background: rgba(255, 255, 255, 0.02);
}
.qcard.compact { padding: 4px 6px; border-radius: 7px; background: transparent; border-color: transparent; }
.qcard.compact:hover { background: rgba(255, 255, 255, 0.035); border-color: var(--border-soft); }
.qcard-label { font-size: 10.5px; font-weight: 700; color: var(--muted); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qcard-meter { display: flex; align-items: center; gap: 8px; }
.qcard-track { flex: 1 1 auto; min-width: 0; height: 4px; border-radius: 999px; background: rgba(148, 163, 184, 0.2); overflow: hidden; }
.qcard-bar { height: 100%; border-radius: inherit; transition: width 0.25s ease; }
.qcard-bar.high { background: var(--green); }
.qcard-bar.medium { background: var(--amber); }
.qcard-bar.low { background: var(--red); }
.qcard-pct { flex: 0 0 auto; font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.qcard-pct.high { color: #86efac; }
.qcard-pct.medium { color: #fcd34d; }
.qcard-pct.low { color: #fca5a5; }
.qcard-reset { font-size: 9.5px; color: var(--muted-2); }
.qmore { font-size: 10px; color: var(--muted-2); }
.qmore-btn {
  font-size: 10px; font-weight: 700; color: var(--primary-2);
  background: none; border: 0; padding: 0; cursor: pointer; text-align: left;
}
.qmore-btn:hover { text-decoration: underline; }
.qbreakdown { margin-top: 16px; }
.qbreakdown h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-2); margin-bottom: 8px; }
.client-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.05em;
  padding: 1px 6px; border-radius: 999px; color: var(--info, #5b8cff);
  border: 1px solid rgba(91, 140, 255, 0.32); background: rgba(91, 140, 255, 0.1);
}

.provider-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 1px 6px; border-radius: 999px; color: var(--muted);
  border: 1px solid var(--border-soft); background: rgba(255, 255, 255, 0.03);
}

/* ------------------------------------------------------- test panel + chat */
.testpanel { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.testpanel > .btn {
  align-self: flex-start; width: auto; flex: 0 0 auto;
  padding: 8px 22px; margin-top: 2px;
}
.testpanel .field { display: flex; flex-direction: column; gap: 6px; }
.testpanel .field > span { font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.test-result { display: flex; flex-direction: column; gap: 8px; }
.test-meta { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.test-text {
  padding: 11px 13px; border-radius: 9px; font-size: 12.5px; line-height: 1.6;
  background: rgba(148, 163, 184, 0.06); border: 1px solid var(--border-soft);
  white-space: pre-wrap; word-break: break-word;
}
.test-err { color: #fca5a5; font-size: 12px; }

/* ------------------------------------------------------------- playground */
#view-playground.active { display: flex; }
.view#view-playground { height: calc(100vh - 120px); min-height: 520px; }
.pg {
  display: flex; flex-direction: column; width: 100%; height: 100%;
  border: 1px solid var(--border-soft); border-radius: 16px; overflow: hidden;
  background: radial-gradient(1200px 420px at 50% -180px, rgba(34, 197, 94, 0.07), transparent 70%),
              rgba(13, 21, 36, 0.6);
}
.pg-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 18, 32, 0.55); backdrop-filter: blur(8px);
}
.pg-head-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pg-logo {
  width: 28px; height: 28px; border-radius: 9px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 13px; font-weight: 800; color: #04120a;
  background: linear-gradient(160deg, #34d399, #22c55e);
}
.pg-head-left strong { display: block; font-size: 13px; line-height: 1.2; }
.pg-status { font-size: 11px; color: var(--muted-2); }
.pg-status.busy { color: #7dd3a0; }
.pg-status.err { color: #fca5a5; }
.pg-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pg-select {
  height: 32px; padding: 0 30px 0 10px; border-radius: 9px; font-size: 12px;
  color: var(--text); background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-soft); appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center;
  max-width: 240px;
}
.pg-select:hover { border-color: rgba(34, 197, 94, 0.35); }
.pg-select:focus { outline: none; border-color: rgba(34, 197, 94, 0.55); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12); }
.pg-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border-radius: 9px; font-size: 11.5px; color: var(--muted); cursor: pointer;
  border: 1px solid var(--border-soft); background: rgba(148, 163, 184, 0.06);
  white-space: nowrap; user-select: none;
}
.pg-toggle input { accent-color: #22c55e; width: 13px; height: 13px; cursor: pointer; }
.pg-toggle:has(input:checked) { color: var(--text); border-color: rgba(34, 197, 94, 0.35); }
.pg-icon {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  color: var(--muted); background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-soft); cursor: pointer;
}
.pg-icon:hover { color: var(--text); border-color: rgba(34, 197, 94, 0.35); }

.pg-scroll { flex: 1 1 auto; overflow-y: auto; scroll-behavior: smooth; }
.pg-thread {
  max-width: 760px; margin: 0 auto; padding: 26px 20px 8px;
  display: flex; flex-direction: column; gap: 22px;
}

/* empty state */
.pg-hero { text-align: center; padding: 40px 10px 10px; }
.pg-hero h3 {
  margin: 0 0 8px; font-size: 24px; font-weight: 600; letter-spacing: -0.02em;
  background: linear-gradient(90deg, #e8eefc, #86efac);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.pg-hero p { margin: 0 0 22px; color: var(--muted-2); font-size: 12.5px; }
.pg-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pg-chip {
  padding: 8px 13px; border-radius: 11px; font-size: 12px; cursor: pointer;
  color: var(--text); background: rgba(148, 163, 184, 0.06);
  border: 1px solid var(--border-soft); transition: border-color 0.15s ease, background 0.15s ease;
}
.pg-chip:hover { border-color: rgba(34, 197, 94, 0.4); background: rgba(34, 197, 94, 0.08); }

/* messages */
.msg { display: flex; gap: 12px; animation: fade 0.18s ease; }
.msg.user { justify-content: flex-end; }
.msg-body { min-width: 0; max-width: 100%; }
.msg.user .msg-body { max-width: 78%; }
.msg-avatar {
  width: 26px; height: 26px; border-radius: 8px; flex: 0 0 auto; margin-top: 2px;
  display: grid; place-items: center; font-size: 11px; font-weight: 800;
}
.msg-avatar.bot { background: linear-gradient(160deg, #34d399, #22c55e); color: #04120a; }
.msg-avatar.err { background: rgba(239, 68, 68, 0.2); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }
.msg-who { font-size: 11px; font-weight: 650; color: var(--muted); margin-bottom: 5px; }
.msg-text {
  font-size: 13.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; color: #e6edf9;
}
.msg.user .msg-text {
  padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  background: rgba(34, 197, 94, 0.13); border: 1px solid rgba(34, 197, 94, 0.26);
}
.msg.err .msg-text {
  padding: 10px 14px; border-radius: 12px; color: #fca5a5;
  background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.28);
}
.msg-meta {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px;
  font-size: 10px; color: var(--muted-2); letter-spacing: 0.02em;
}
.msg-meta span { display: inline-flex; align-items: center; gap: 4px; }
.msg-meta .pill {
  padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border-soft);
  background: rgba(148, 163, 184, 0.06);
}
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 6px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #86efac; opacity: 0.35;
  animation: blink 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 100% { opacity: 0.25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }

/* composer */
.pg-composer { padding: 10px 20px 16px; background: linear-gradient(180deg, transparent, rgba(11, 18, 32, 0.85) 40%); }
.pg-box {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 14px; border-radius: 16px;
  background: rgba(20, 30, 48, 0.9); border: 1px solid var(--border-soft);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.3);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.pg-box:focus-within { border-color: rgba(34, 197, 94, 0.45); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1), 0 12px 34px rgba(0, 0, 0, 0.3); }
.pg-attach {
  width: 30px; height: 30px; flex: 0 0 auto; border: none; border-radius: 9px; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); background: transparent; margin-bottom: 2px;
}
.pg-attach:hover { color: #86efac; background: rgba(34, 197, 94, 0.1); }
.pg-box.drop { border-color: rgba(34, 197, 94, 0.7); background: rgba(34, 197, 94, 0.07); }
.pg-attachments { max-width: 760px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.pg-attach-item {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 28px 6px 8px;
  border-radius: 10px; background: rgba(20, 30, 48, 0.95); border: 1px solid var(--border-soft);
  font-size: 11px; max-width: 230px;
}
.pg-attach-item img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; flex: 0 0 auto; }
.pg-attach-item .fi {
  width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; flex: 0 0 auto;
  font-size: 9px; font-weight: 700; letter-spacing: 0.03em; color: #86efac; background: rgba(34, 197, 94, 0.12);
}
.pg-attach-item .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-attach-item .fx {
  position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border: none; border-radius: 5px;
  display: grid; place-items: center; cursor: pointer; font-size: 11px; line-height: 1;
  color: var(--muted-2); background: transparent;
}
.pg-attach-item .fx:hover { color: #fca5a5; background: rgba(239, 68, 68, 0.12); }
.msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-imgs img { max-width: 220px; max-height: 160px; border-radius: 10px; border: 1px solid var(--border-soft); }
.msg.user .msg-imgs img { max-width: 180px; }
.pg-box textarea {
  flex: 1 1 auto; min-height: 24px; max-height: 180px; resize: none; border: none; outline: none;
  background: transparent; color: var(--text); font: inherit; font-size: 13.5px; line-height: 1.6;
  padding: 5px 0;
}
.pg-box textarea::placeholder { color: var(--muted-2); }
.pg-send {
  width: 34px; height: 34px; border-radius: 11px; flex: 0 0 auto; border: none; cursor: pointer;
  display: grid; place-items: center; color: #04120a;
  background: linear-gradient(160deg, #4ade80, #22c55e);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.pg-send:disabled { opacity: 0.35; cursor: default; }
.pg-send:not(:disabled):hover { transform: translateY(-1px); }
.pg-hint { max-width: 760px; margin: 8px auto 0; text-align: center; font-size: 10.5px; color: var(--muted-2); }
@media (max-width: 900px) {
  .pg-select { max-width: 150px; }
  .view#view-playground { height: calc(100vh - 90px); }
}
.tier-chip {
  display: inline-flex; align-items: center;
  font-size: 9.5px; font-weight: 650; letter-spacing: 0.02em;
  padding: 1px 6px; border-radius: 999px; color: #a8c1ff;
  border: 1px solid rgba(91, 140, 255, 0.28); background: rgba(91, 140, 255, 0.1);
}

/* ------------------------------------------------- account cards (accounts) */
.acc-list-head {
  display: flex; align-items: center; gap: 14px;
  padding: 2px 4px 12px;
}
.acc-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: stretch; }
@media (max-width: 1320px) { .acc-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 980px) { .acc-list { grid-template-columns: minmax(0, 1fr); } }
.acc-card {
  display: flex; flex-direction: column; height: 100%;
  border: 1px solid var(--border-soft); border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.012));
  padding: 14px 15px 15px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  /* Off-screen cards skip layout and paint, so a long account list stays smooth. */
  content-visibility: auto;
  contain-intrinsic-size: auto 560px;
}
.qsec-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 7px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-2);
}
.quota-queue {
  font-size: 11px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.quota-queue.busy { color: var(--info, #5b8cff); }
.quota-queue.busy::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.acc-card:hover {
  border-color: rgba(34, 197, 94, 0.3);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
}
.acc-card.off { opacity: 0.62; }
.acc-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.acc-id { min-width: 0; display: flex; flex-direction: column; gap: 3px; flex: 1 1 150px; }
.acc-id .email { font-size: 13.5px; font-weight: 600; max-width: 100%; }
.acc-sub { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.acc-head .spacer { display: none; }
.acc-actions { width: 100%; flex-wrap: wrap; justify-content: flex-start; margin-top: 10px; gap: 5px; }
.acc-card .acc-actions .btn.tiny { padding: 3px 6px; font-size: 10.5px; }
.acc-meta {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 12px;
  margin: 12px 0 4px; padding: 9px 11px; border-radius: 9px;
  background: rgba(148, 163, 184, 0.05); border: 1px solid rgba(148, 163, 184, 0.1);
}
.acc-stat { display: inline-flex; align-items: baseline; gap: 6px; font-size: 11.5px; color: var(--text); font-variant-numeric: tabular-nums; }
.acc-stat b { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-2); }
.acc-quota { margin-top: 10px; padding-top: 12px; border-top: 1px dashed rgba(148, 163, 184, 0.16); flex: 1 1 auto; }
.acc-note {
  margin-top: 8px; padding: 6px 9px; border-radius: 8px; font-size: 11px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.acc-note.err { color: #fca5a5; background: rgba(239, 68, 68, 0.09); border: 1px solid rgba(239, 68, 68, 0.25); }

/* ------------------------------------------------------------------ models */
.mdl-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 0 4px 4px; }
.mdl-form .field { display: flex; flex-direction: column; gap: 5px; min-width: 140px; }
.mdl-form .field.grow { flex: 1 1 200px; }
.mdl-form .field span { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-2); }
#modelsTable td, #modelsTable th { padding: 8px 10px; }
#modelsTable tbody tr:hover { background: rgba(148, 163, 184, 0.05); }
.chip {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 10px;
  border: 1px solid var(--border-soft); background: rgba(148, 163, 184, 0.08); color: var(--muted);
  text-transform: capitalize;
}
.acc-card .qcards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 7px; }
.acc-card .qcard { padding: 7px 9px; }
.acc-card .qmcards { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 6px; }
.acc-card .qmcard { padding: 6px 8px 5px; gap: 5px; }
.acc-card .qmcard-reset { font-size: 9px; }
.acc-card .qmcard-name { font-size: 10.5px; }
.acc-card .qcards { gap: 6px; }
.acc-card .qcard { padding: 6px 8px; }
.qempty { font-size: 11.5px; color: var(--muted-2); padding: 4px 0; }

/* per-model cards */
.qmcards-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 14px 0 8px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-2);
}
.qmcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 8px; }
.qmcard {
  --accent: var(--green);
  position: relative; min-width: 0;
  padding: 8px 10px 7px; border-radius: 9px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.022);
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.qmcard::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px;
  border-radius: 2px; background: var(--accent); opacity: 0.85;
}
.qmcard.medium { --accent: var(--amber); }
.qmcard.low { --accent: var(--red); }
.qmcard:hover { border-color: rgba(148, 163, 184, 0.34); background: rgba(255, 255, 255, 0.038); }
.qmcard-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.qmcard-name {
  font-size: 11px; font-weight: 600; color: var(--text); line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qmcard-pct { flex: 0 0 auto; font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.qmcard-pct.high { color: #86efac; }
.qmcard-pct.medium { color: #fcd34d; }
.qmcard-pct.low { color: #fca5a5; }
.qmcard-track { height: 3px; border-radius: 999px; background: rgba(148, 163, 184, 0.2); overflow: hidden; }
.qmcard-track > i { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.qmcard-track > i.medium { background: var(--amber); }
.qmcard-track > i.low { background: var(--red); }
.qmcard-reset { font-size: 9.5px; color: var(--muted-2); }
.quota-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.quota-head-right { display: flex; align-items: center; gap: 10px; }
.qsummary { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }

/* ---------------------------------------------------------------- api keys */
.keycell {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  max-width: 460px;
}
.keycell code {
  background: var(--bg-soft); border: 1px solid var(--border-soft); border-radius: 7px;
  padding: 4px 9px; font-size: 10.5px; word-break: break-all; user-select: all;
  font-family: var(--mono); color: #a8c1ff; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 340px; display: block;
}

/* -------------------------------------------------------------------- auth */
.hidden { display: none !important; }
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(800px 500px at 40% -10%, rgba(34, 197, 94, 0.12), transparent 60%),
    radial-gradient(700px 450px at 85% 110%, rgba(91, 140, 255, 0.1), transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 18px; padding: 30px 28px 26px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
}
.auth-brand {
  display: flex; align-items: center; gap: 12px; margin-bottom: 4px;
}
.auth-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.auth-brand-text strong { font-size: 15px; letter-spacing: -0.3px; font-weight: 700; }
.auth-brand-text span { font-size: 11.5px; color: var(--muted); }
.auth-divider { height: 1px; background: var(--border-soft); margin: 6px 0 4px; }
.auth-card h2 { margin: 0; font-size: 19px; letter-spacing: -0.4px; font-weight: 700; }
.auth-card p.muted { margin: 0; }
.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.auth-form .btn { width: 100%; justify-content: center; margin-top: 4px; padding: 9px; font-size: 13.5px; border-radius: 10px; }
.auth-error { color: #fca5a5; min-height: 16px; font-size: 12px; }

/* --------------------------------------------------------------- refinements */
tbody td { font-variant-numeric: tabular-nums; }
::selection { background: rgba(34, 197, 94, 0.28); color: #fff; }
* { scrollbar-width: thin; scrollbar-color: #2a3a57 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #2a3a57; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #3b4d6e; background-clip: padding-box; }
.panel > .table-wrap { margin: 0 -4px; }
.qcards.inline .qcard-label { color: var(--muted-2); }

/* --------------------------------------------------------- extra polish */
tbody td:first-child, thead th:first-child { width: 36px; padding-left: 14px; }
.row-actions .btn.tiny { padding: 3px 8px; font-size: 11px; }
td div.small.muted { display: block; line-height: 1.3; margin-top: 1px; }
td span.small.muted { display: inline; }
tbody td { white-space: nowrap; }
tbody td .email, tbody td .keycell { white-space: normal; }
.topbar { 
  position: sticky; top: 0; z-index: 10; 
  background: rgba(11,18,32,0.92); backdrop-filter: blur(12px); 
  margin: -22px -28px 20px; padding: 14px 28px 14px; 
}
input[type=checkbox] { accent-color: var(--primary); width: 14px; height: 14px; cursor: pointer; }
.badge.green::before { content: ""; margin-right: -2px; }
.table-wrap { max-height: 72vh; overflow-y: auto; border-radius: 9px; }
#accountsTable { overflow: visible; max-height: none; }
.empty { padding: 40px 20px; }
.kv code:hover { background: var(--panel-2); }