/* ==========================================================================
   CodeBuddy Proxy — UI stylesheet

   Hand-written, no framework and no build step. Organised as:
     1. tokens        design variables + light/dark themes
     2. reset         normalisation + utilities
     3. layout        shell / sidebar / topbar / view / stacks and grids
     4. components    cards, buttons, forms, pills, tables, menus, pagers,
                      callouts, toasts, modal
     5. features      dashboard, accounts, pool, auth files, models, logs,
                      playground, settings
     6. responsive    tablet drawer + phone
   ========================================================================== */

/* 1. tokens ------------------------------------------------------------- */
:root {
  --brand: #006eff;
  --brand-ink: #ffffff;
  --brand-soft: color-mix(in oklab, var(--brand) 11%, transparent);
  --brand-line: color-mix(in oklab, var(--brand) 32%, transparent);

  --ok: #17935b;
  --warn: #b0740b;
  --err: #d33a3a;
  --info: #5b5bd6;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --control-h: 34px;
  --control-h-sm: 28px;

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

  --shadow-1: 0 1px 2px rgb(16 24 40 / 0.05);
  --shadow-2: 0 8px 24px rgb(16 24 40 / 0.1), 0 2px 6px rgb(16 24 40 / 0.05);
  --shadow-3: 0 20px 56px rgb(16 24 40 / 0.22);

  --sidebar-w: 224px;
  --topbar-h: 60px;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a909a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* light */
:root,
[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-sunken: #eef0f3;
  --bg-hover: #f1f3f6;
  --border: #e3e6eb;
  --border-strong: #d0d5dd;
  --ink: #16181d;
  --ink-soft: #525964;
  --ink-faint: #868c96;
  --surface: var(--bg-elevated);
  --line: var(--border);
  color-scheme: light;
}

/* dark */
[data-theme="dark"] {
  --bg: #0e1014;
  --bg-elevated: #161920;
  --bg-sunken: #0b0d11;
  --bg-hover: #1e222a;
  --border: #252a33;
  --border-strong: #343a45;
  --ink: #e8ebf0;
  --ink-soft: #a3aab6;
  --ink-faint: #6e7784;
  --surface: var(--bg-elevated);
  --line: var(--border);
  --brand-soft: color-mix(in oklab, var(--brand) 20%, transparent);
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-2: 0 8px 24px rgb(0 0 0 / 0.5);
  --shadow-3: 0 20px 60px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0e1014;
    --bg-elevated: #161920;
    --bg-sunken: #0b0d11;
    --bg-hover: #1e222a;
    --border: #252a33;
    --border-strong: #343a45;
    --ink: #e8ebf0;
    --ink-soft: #a3aab6;
    --ink-faint: #6e7784;
    --surface: var(--bg-elevated);
    --line: var(--border);
    --brand-soft: color-mix(in oklab, var(--brand) 20%, transparent);
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 8px 24px rgb(0 0 0 / 0.5);
    --shadow-3: 0 20px 60px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

/* 2. reset -------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 18px;
}
h2 {
  font-size: 16px;
}
h3 {
  font-size: 14px;
}

p {
  margin: 0;
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code,
kbd,
pre {
  font-family: var(--mono);
  font-size: 12.5px;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

svg {
  flex: none;
}

.muted {
  color: var(--ink-soft);
}
.faint {
  color: var(--ink-faint);
}
.small {
  font-size: 12px;
}
.mono {
  font-family: var(--mono);
}
.right {
  text-align: right;
}
.nowrap {
  white-space: nowrap;
}
.ellipsis {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grow {
  flex: 1 1 auto;
  min-width: 0;
}
.hidden {
  display: none !important;
}
.ok {
  color: var(--ok);
}
.warn {
  color: var(--warn);
}
.err {
  color: var(--err);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 3. layout ------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-3);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px var(--space-2);
  color: var(--ink);
  text-decoration: none;
}
.brand:hover {
  text-decoration: none;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(140deg, var(--brand), color-mix(in oklab, var(--brand) 55%, #7b5bff));
  box-shadow: var(--shadow-1);
  flex: none;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-text strong {
  font-size: 14px;
}
.brand-text small {
  color: var(--ink-faint);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-group-label {
  padding: 0 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav a:hover {
  background: var(--bg-hover);
  color: var(--ink);
  text-decoration: none;
}
.nav a.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
.nav-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: none;
}
.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--err);
  background: color-mix(in oklab, var(--err) 13%, transparent);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: var(--space-3) var(--space-1) 0;
  border-top: 1px solid var(--border);
}
.sidebar-foot .version {
  margin-left: auto;
  padding-right: var(--space-1);
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.scrim {
  display: none;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-h);
  padding: 10px var(--space-5);
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg-elevated) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
}
.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.topbar-title p {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}
/* `.btn` sets display later in the file, so this needs the extra class. */
.btn.menu-toggle {
  display: none;
}

.view {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: var(--ink-faint);
  padding: var(--space-6);
}

/* stacks, rows, grids */
.col,
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.stack {
  gap: var(--space-4);
}
.col.tight {
  gap: 2px;
}
.row,
.row-between,
.row-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.row-between {
  justify-content: space-between;
}
.row-wrap {
  flex-wrap: wrap;
  gap: 6px;
}
.row.row-wrap {
  gap: var(--space-2);
}

.grid {
  display: grid;
  gap: var(--space-4);
  align-items: start;
}
.grid > * {
  min-width: 0;
}
.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-auto {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.grid.stretch {
  align-items: stretch;
}

/* Main / side split: a wide column to watch and a narrow one to act on. */
.split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.split-main,
.split-side {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

/* Two independent stacks: cards keep their own height, no holes. */
.columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  align-items: start;
}
.columns > .stack {
  min-width: 0;
}

/* A labelled band of the page: a small heading over a group of cards. */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 2px 0;
}
.section-head h2 {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
}
.section-head p {
  font-size: 12px;
  color: var(--ink-faint);
}

/* 4. components --------------------------------------------------------- */

/* cards */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  min-height: 50px;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
}
.card-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.card-title > strong {
  font-size: 14px;
  font-weight: 650;
}
.card-title > span {
  font-size: 12px;
  color: var(--ink-faint);
}
.card-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-left: auto;
}
.card-body {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}
.card-body.tight {
  gap: var(--space-2);
}
.card-body.flush {
  padding: 0;
  gap: 0;
}
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 10px var(--space-4);
  border-top: 1px solid var(--border);
}

/* stat tiles */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px var(--space-4);
  background: var(--bg-elevated);
  min-width: 0;
}
.stat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 550;
}
.stat-label svg {
  color: var(--ink-faint);
}
.stat-value {
  font-size: 24px;
  font-weight: 660;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-hint {
  color: var(--ink-faint);
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-hint.is-wrapped {
  white-space: normal;
  overflow-wrap: anywhere;
}
.stat-cell.is-alert .stat-value {
  color: var(--err);
}
.stat-cell.is-good .stat-value {
  color: var(--ok);
}

/* disclosure: useful-but-not-glanceable content */
.disclosure > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px var(--space-4);
  font-weight: 600;
  color: var(--ink-soft);
  user-select: none;
  border-radius: var(--radius);
}
.disclosure > summary::-webkit-details-marker {
  display: none;
}
.disclosure > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
  flex: none;
}
.disclosure[open] > summary::before {
  transform: rotate(90deg);
}
.disclosure > summary:hover {
  color: var(--ink);
}
.disclosure[open] > summary {
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}
.disclosure.plain > summary {
  padding: 6px 0;
}
.disclosure.plain[open] > summary {
  border-bottom: none;
}
.disclosure .summary-extra {
  margin-left: auto;
  font-weight: 400;
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 12px;
  font: inherit;
  font-weight: 550;
  font-size: 13px;
  line-height: 1;
  color: var(--ink);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
  flex: none;
}
.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  text-decoration: none;
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in oklab, var(--brand) 88%, black);
}
.btn-danger {
  color: var(--err);
  border-color: color-mix(in oklab, var(--err) 40%, var(--border));
}
.btn-danger:hover:not(:disabled) {
  background: color-mix(in oklab, var(--err) 9%, transparent);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--ink);
}
.btn-sm {
  height: var(--control-h-sm);
  padding: 0 9px;
  font-size: 12.5px;
  gap: 5px;
}
.btn-icon {
  width: var(--control-h);
  padding: 0;
}
.btn-icon.btn-sm {
  width: var(--control-h-sm);
}
.btn-block {
  width: 100%;
}
.btn.is-live {
  color: var(--ok);
  border-color: color-mix(in oklab, var(--ok) 45%, var(--border));
  background: color-mix(in oklab, var(--ok) 9%, transparent);
}
.btn.is-live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s ease-in-out infinite;
}

/* pills / chips */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  line-height: 1;
  border: 1px solid transparent;
  white-space: nowrap;
  flex: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.pill-plain::before,
.pill.no-dot::before {
  display: none;
}
.pill-ok {
  color: var(--ok);
  background: color-mix(in oklab, var(--ok) 12%, transparent);
}
.pill-warn {
  color: var(--warn);
  background: color-mix(in oklab, var(--warn) 14%, transparent);
}
.pill-err {
  color: var(--err);
  background: color-mix(in oklab, var(--err) 12%, transparent);
}
.pill-info {
  color: var(--info);
  background: color-mix(in oklab, var(--info) 12%, transparent);
}
.pill-brand {
  color: var(--brand);
  background: var(--brand-soft);
}
.pill-muted {
  color: var(--ink-soft);
  background: var(--bg-sunken);
}
.pill-plain {
  color: var(--ink-soft);
  border-color: var(--border);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  font-size: 11px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-family: var(--mono);
  white-space: nowrap;
}

/* inline facts separated by dots: "2 of 3 · 0 in flight · 0 queued" */
.facts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--ink-faint);
  min-width: 0;
}
.facts > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.facts b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* tables */
.table-wrap {
  overflow-x: auto;
  min-width: 0;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th,
td {
  text-align: left;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 550;
  background: var(--bg-sunken);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
th.num,
td.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}
td.actions {
  text-align: right;
  white-space: nowrap;
}
td.actions > .row {
  justify-content: flex-end;
}
tbody tr:hover {
  background: var(--bg-hover);
}
tbody tr:last-child td {
  border-bottom: none;
}

/* forms */
label.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-soft);
}
input,
select,
textarea {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  width: 100%;
  min-width: 0;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input,
select {
  height: var(--control-h);
}
input:hover,
select:hover,
textarea:hover {
  border-color: color-mix(in oklab, var(--ink-faint) 60%, var(--border-strong));
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
input[readonly] {
  background: var(--bg-sunken);
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 15px;
  cursor: pointer;
}
input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  accent-color: var(--brand);
  flex: none;
  cursor: pointer;
}
input[type="number"] {
  font-variant-numeric: tabular-nums;
}
textarea {
  padding: 8px 10px;
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}
textarea.mono,
textarea.af-json {
  font-family: var(--mono);
}
.field-hint {
  font-weight: 400;
  color: var(--ink-faint);
  font-size: 12px;
  line-height: 1.5;
}
.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3) var(--space-4);
}

/* Toggle switch: a checkbox restyled as a track. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  min-width: 0;
}
.switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  border: none;
  background: var(--border-strong);
  transition: background 0.15s ease;
}
.switch input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.15s ease;
}
.switch input[type="checkbox"]:checked {
  background: var(--brand);
}
.switch input[type="checkbox"]:checked::after {
  transform: translateX(14px);
}
.switch input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  box-shadow: none;
}
/* A switch with its explanation underneath, used on the settings page. */
.switch-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.switch-field .field-hint {
  padding-left: 42px;
}

/* search box with a leading icon */
.search {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.search svg {
  position: absolute;
  left: 10px;
  color: var(--ink-faint);
  pointer-events: none;
}
.search input {
  padding-left: 32px;
}

/* segmented control */
.seg {
  display: inline-flex;
  align-items: center;
  height: var(--control-h);
  padding: 3px;
  gap: 2px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex: none;
  max-width: 100%;
  overflow-x: auto;
}
.seg button {
  height: 100%;
  padding: 0 10px;
  border: none;
  border-radius: 4px;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.seg button:hover {
  color: var(--ink);
}
.seg button[aria-pressed="true"] {
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

/*
 * Toolbar: one row of filters and actions. Controls keep their natural width
 * instead of the form default of 100%, and wrap as a group on small screens.
 */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-width: 0;
}
.toolbar > select,
.toolbar .toolbar-group > select {
  width: auto;
  min-width: 120px;
}
.toolbar > .search {
  flex: 1 1 240px;
}
.toolbar > .spacer {
  flex: 1 1 auto;
}
.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  min-width: 0;
}
.toolbar-sep {
  width: 1px;
  align-self: stretch;
  margin: 4px 2px;
  background: var(--border);
}
.toolbar label.field.field-inline > span {
  white-space: nowrap;
}

/* A label and its control on one line. */
label.field.field-inline {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}
label.field.field-inline > span {
  margin: 0;
  white-space: nowrap;
}
label.field.field-inline > select,
label.field.field-inline > input {
  width: auto;
}

/* key / value grid */
.account-meta,
.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: var(--space-3) var(--space-3);
  margin: 0;
  font-size: 12.5px;
}
.account-meta > div,
.kv-grid > div {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.account-meta .k,
.kv-grid .k {
  color: var(--ink-faint);
  font-size: 11.5px;
}
.account-meta .v,
.kv-grid .v {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* key / value list: label left, value right */
.kv-list {
  display: flex;
  flex-direction: column;
  margin: 0;
}
.kv-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
  min-width: 0;
}
.kv-list > div:last-child {
  border-bottom: none;
}
.kv-list .k {
  color: var(--ink-soft);
  white-space: nowrap;
}
.kv-list .v {
  min-width: 0;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* bars */
.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 0.3s ease;
}
.bar.is-warn > span {
  background: var(--warn);
}
.bar.is-full > span {
  background: var(--err);
}

/* Stacked health bar: ready / cooling / re-login / disabled. */
.hbar {
  display: flex;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-sunken);
  gap: 2px;
}
.hbar > span {
  display: block;
  height: 100%;
  min-width: 4px;
}
.hbar .ok {
  background: var(--ok);
}
.hbar .warn {
  background: var(--warn);
}
.hbar .err {
  background: var(--err);
}
.hbar .muted {
  background: var(--border-strong);
}

/* callouts */
.callout {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid color-mix(in oklab, var(--info) 30%, var(--border));
  background: color-mix(in oklab, var(--info) 6%, var(--bg-elevated));
  font-size: 13px;
}
.callout > svg {
  margin-top: 1px;
  color: var(--info);
}
.callout-warn {
  border-color: color-mix(in oklab, var(--warn) 35%, var(--border));
  background: color-mix(in oklab, var(--warn) 7%, var(--bg-elevated));
}
.callout-warn > svg {
  color: var(--warn);
}
.callout-err {
  border-color: color-mix(in oklab, var(--err) 35%, var(--border));
  background: color-mix(in oklab, var(--err) 6%, var(--bg-elevated));
}
.callout-err > svg {
  color: var(--err);
}
.callout-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
}
.callout-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.callout-item strong {
  font-weight: 600;
}
.callout-item a {
  font-size: 12.5px;
  font-weight: 550;
  white-space: nowrap;
}
.error-line {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--err) 8%, transparent);
  color: var(--err);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* dropdown menu */
.menu {
  position: relative;
  display: inline-flex;
  flex: none;
}
.menu-pop {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 40;
  min-width: 180px;
  display: none;
  flex-direction: column;
  padding: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}
.menu.is-open .menu-pop {
  display: flex;
}
.menu.is-up .menu-pop {
  top: auto;
  bottom: calc(100% + 4px);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  background: var(--bg-hover);
  outline: none;
}
.menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.menu-item svg {
  color: var(--ink-faint);
}
.menu-item.is-danger {
  color: var(--err);
}
.menu-item.is-danger svg {
  color: currentColor;
}
.menu-sep {
  height: 1px;
  margin: 4px 2px;
  background: var(--border);
}

/* pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  font-size: 12.5px;
  color: var(--ink-faint);
}
.pager-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.pager-nav .btn {
  min-width: var(--control-h-sm);
  padding: 0 7px;
}
.pager-gap {
  color: var(--ink-faint);
  padding: 0 2px;
}
.pager-size select {
  height: var(--control-h-sm);
  min-width: 68px;
  font-size: 12.5px;
}

/* empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--ink-soft);
}
.empty-icon {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-1);
  border-radius: 12px;
  color: var(--ink-faint);
  background: var(--bg-sunken);
}
.empty h3 {
  color: var(--ink);
}
.empty > p {
  max-width: 460px;
}
.empty > .row,
.empty > .row-wrap,
.empty > .btn {
  margin-top: var(--space-2);
}

/* code block */
pre.code {
  margin: 0;
  padding: var(--space-3);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 60vh;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.copy-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
}
.copy-row input {
  font-family: var(--mono);
  font-size: 12px;
}

/* spinner */
.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid color-mix(in oklab, currentColor 30%, transparent);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex: none;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* toasts */
.toasts {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 100;
  max-width: min(400px, calc(100vw - 32px));
}
.toast {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: 8px 8px 8px 12px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  box-shadow: var(--shadow-2);
  animation: toast-in 0.16s ease;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.toast.ok {
  border-left-color: var(--ok);
}
.toast.err {
  border-left-color: var(--err);
}
.toast.warn {
  border-left-color: var(--warn);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  width: min(520px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 48px);
  overflow: visible;
}
.modal.is-wide {
  width: min(780px, calc(100vw - 32px));
}
.modal::backdrop {
  background: rgb(10 12 16 / 0.5);
  backdrop-filter: blur(2px);
}
.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}
.modal-card > h2 {
  padding: var(--space-4) var(--space-5) 0;
}
#modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  overflow-y: auto;
  min-height: 0;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* 5. features ----------------------------------------------------------- */

/* dashboard: per-provider pool health */
.provider-health {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.provider-health:first-child {
  padding-top: 0;
}
.provider-health:last-child {
  padding-bottom: 0;
  border-bottom: none;
}
.provider-health-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
}
.provider-health-head strong {
  font-size: 13.5px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 12px;
  color: var(--ink-soft);
}
.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.legend i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
  background: var(--border-strong);
}
.legend i.ok {
  background: var(--ok);
}
.legend i.warn {
  background: var(--warn);
}
.legend i.err {
  background: var(--err);
}
.legend b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.endpoint {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.endpoint > span {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 550;
}

/* logs */
.log-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.log-stream {
  max-height: calc(100vh - 230px);
  min-height: 160px;
  overflow-y: auto;
}
.log-row {
  display: grid;
  grid-template-columns: 72px 70px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: 8px var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  cursor: pointer;
}
.log-row:last-child {
  border-bottom: none;
}
.log-row:hover,
.log-row:focus-visible {
  background: var(--bg-hover);
  outline: none;
}
.log-row.is-error {
  background: color-mix(in oklab, var(--err) 4%, transparent);
}
.log-row.is-error:hover {
  background: color-mix(in oklab, var(--err) 8%, transparent);
}
.log-row > .pill {
  justify-self: start;
}
.log-head {
  cursor: default;
  padding-top: 7px;
  padding-bottom: 7px;
  background: var(--bg-sunken);
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}
.log-head:hover {
  background: var(--bg-sunken);
}
.log-time {
  font-family: var(--mono);
  color: var(--ink-faint);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.log-main {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.log-main > * {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
  max-width: 100%;
}
.log-main > .log-path {
  font-weight: 550;
  color: var(--ink);
}
.log-main > .log-model {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.log-main > .log-account {
  color: var(--ink-faint);
}
.log-main > .log-error {
  color: var(--err);
  flex: 1 1 auto;
}
.log-main > .log-message {
  flex: 1 1 auto;
}
.log-side {
  color: var(--ink-faint);
  font-size: 12px;
  min-width: 0;
  max-width: 240px;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* accounts: link bar */
.link-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.link-bar .label-input {
  flex: 0 1 240px;
  min-width: 160px;
}
.link-bar .spacer {
  flex: 1 1 auto;
}

/* accounts: cards */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr));
  gap: var(--space-4);
  align-items: start;
}
.account-grid > .empty,
.account-grid > .loading {
  grid-column: 1 / -1;
}
.account {
  display: flex;
  flex-direction: column;
}
.account.is-off {
  background: color-mix(in oklab, var(--bg-sunken) 45%, var(--bg-elevated));
}
.account-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-3);
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-weight: 650;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-soft);
}
.account.is-off .avatar {
  color: var(--ink-faint);
  background: var(--bg-sunken);
}
.account-id {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1 1 auto;
}
.account-id strong {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-id span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  max-width: 50%;
  min-width: 0;
}
.account-status .pill {
  max-width: 100%;
}
.pill.no-dot {
  display: inline-block;
  line-height: 20px;
}
.account-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4);
}
.account-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding: 10px var(--space-4);
  border-top: 1px solid var(--border);
}

/* quota summary */
.quota {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
}
.quota-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--ink-soft);
}
.quota-head strong {
  font-size: 16px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.quota-head .of {
  color: var(--ink-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.quota-foot {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px var(--space-3);
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.quota.is-empty .quota-head strong {
  color: var(--err);
}

/* accounts: rotation pool */
.pool-slot {
  display: flex;
  flex-direction: column;
}
.pool-provider {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.pool-provider + .pool-provider {
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.pool-provider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
}
.pool-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.pool-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: 12px;
}
.pool-list-head strong {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
}
.pool-queue {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.pool-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 38px;
  padding: 6px var(--space-3);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  min-width: 0;
}
.pool-row:last-child {
  border-bottom: 0;
}
.pool-row.is-next {
  background: var(--brand-soft);
}
.pool-row.is-parked {
  color: var(--ink-soft);
}
.pool-pos {
  width: 22px;
  flex: none;
  text-align: right;
  color: var(--ink-faint);
  font-size: 11.5px;
}
.pool-who {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}
.pool-who strong {
  font-weight: 550;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pool-who span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pool-facts {
  flex: none;
  white-space: nowrap;
}
.pool-parked .disclosure > summary,
.pool-parked > summary {
  padding: 4px 0;
}

/* auth files */
.af-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.af-list {
  display: flex;
  flex-direction: column;
}
.af-listhead {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 12px;
  color: var(--ink-faint);
  border-radius: var(--radius) var(--radius) 0 0;
}
.af-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.af-row:last-child {
  border-bottom: none;
}
.af-row:hover {
  background: color-mix(in oklab, var(--bg-hover) 60%, transparent);
}
.af-row.is-selected {
  background: var(--brand-soft);
}
.af-top {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}
.af-check {
  display: flex;
  align-items: center;
  flex: none;
}
.af-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1 1 auto;
}
.af-name strong {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.af-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.af-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}
.af-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.af-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-left: 28px;
}
.af-row.is-compact {
  padding-top: 8px;
  padding-bottom: 8px;
}
.af-row.is-compact .af-detail {
  display: none;
}
.batch-bar {
  position: sticky;
  top: calc(var(--topbar-h) + 8px);
  z-index: 12;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--brand-line);
  background: color-mix(in oklab, var(--brand) 7%, var(--bg-elevated));
  box-shadow: var(--shadow-2);
}
.batch-bar strong {
  padding: 0 var(--space-2) 0 2px;
  font-size: 13px;
}
textarea.af-json {
  min-height: 260px;
  font-size: 12px;
}

/* models */
.model-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
}
.model-stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: 14px var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.model-stat-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}
.model-stat-head strong {
  font-size: 14px;
}
.model-stat-count {
  font-size: 22px;
  font-weight: 660;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.model-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}
.model-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
}
.route-id {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  justify-content: flex-start;
}
.model-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 140px;
}
.alias-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 12.5px;
}
.alias-row:last-child {
  border-bottom: none;
}
.rule-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* keys */
.secret {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* playground */
.playground {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.playground-side {
  position: sticky;
  top: calc(var(--topbar-h) + var(--space-5));
}
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.transcript {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 360px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
  padding: var(--space-4);
}
.composer {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.composer textarea {
  min-height: 72px;
  font-family: var(--font);
  font-size: 13.5px;
}
.bubble {
  padding: 10px 12px;
  border-radius: var(--radius);
  max-width: 88%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.user {
  align-self: flex-end;
  background: var(--brand-soft);
  border: 1px solid var(--brand-line);
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}
.bubble.thinking {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-family: var(--mono);
}
.bubble-role {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 4px;
}

/* settings */
.settings-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.save-bar {
  position: sticky;
  bottom: var(--space-4);
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  padding: 10px var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-2);
}
.save-bar-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}
.save-bar-state::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}
.save-bar.is-dirty {
  border-color: var(--brand-line);
}
.save-bar.is-dirty .save-bar-state {
  color: var(--ink);
  font-weight: 550;
}
.save-bar.is-dirty .save-bar-state::before {
  background: var(--brand);
  animation: pulse 1.4s ease-in-out infinite;
}
.alias-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.alias-editor .row > * {
  flex: 1 1 0;
}
.alias-editor .row > .btn {
  flex: none;
}

/* 6. responsive --------------------------------------------------------- */

@media (min-width: 1680px) {
  .view {
    max-width: 1560px;
  }
  .split {
    grid-template-columns: minmax(0, 2.2fr) minmax(340px, 1fr);
  }
}

@media (max-width: 1240px) {
  .stat-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .stat-strip > .stat-cell:nth-child(4),
  .stat-strip > .stat-cell:nth-child(5) {
    grid-column: span 1;
  }
}

@media (max-width: 1080px) {
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .split,
  .columns,
  .playground {
    grid-template-columns: minmax(0, 1fr);
  }
  .playground-side {
    position: static;
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(270px, 84vw);
    height: 100%;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-3);
  }
  .shell.nav-open .sidebar {
    transform: none;
  }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgb(10 12 16 / 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .shell.nav-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }
  .btn.menu-toggle {
    display: inline-flex;
  }
}

@media (max-width: 680px) {
  .view {
    padding: var(--space-3);
    gap: var(--space-3);
  }
  .topbar {
    padding: 8px var(--space-3);
    gap: var(--space-2);
  }
  .topbar-title p {
    display: none;
  }
  #health {
    max-width: 96px;
  }
  .grid-2,
  .grid-3,
  .grid-4,
  .field-row,
  .model-form {
    grid-template-columns: minmax(0, 1fr);
  }
  .stat-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat-strip > .stat-cell:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  .card-head,
  .card-body,
  .card-foot {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
  .log-row {
    grid-template-columns: 62px minmax(0, 1fr);
    row-gap: 4px;
    padding: 8px var(--space-3);
  }
  .log-row > .pill {
    grid-row: 2;
    grid-column: 1;
  }
  .log-row > .log-main {
    grid-column: 2;
    grid-row: 1 / span 2;
    flex-wrap: wrap;
    white-space: normal;
    row-gap: 2px;
  }
  .log-row > .log-side {
    grid-column: 2;
    max-width: none;
    text-align: left;
  }
  .log-head {
    display: none;
  }
  .pool-facts {
    display: none;
  }
  .account-status {
    max-width: 100%;
  }
  .af-top {
    flex-wrap: wrap;
  }
  .af-tags {
    justify-content: flex-start;
    order: 3;
    width: 100%;
    padding-left: 28px;
  }
  .af-detail {
    padding-left: 0;
  }
  .toolbar > select,
  .toolbar .toolbar-group > select {
    flex: 1 1 140px;
  }
  .link-bar .label-input {
    flex: 1 1 100%;
  }
  .link-bar > .btn {
    flex: 1 1 auto;
  }
  .modal-card > h2,
  #modal-body,
  .modal-actions {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
  .bubble {
    max-width: 96%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
