/* ==========================================================================
   OCAPI · OpenCode Free 网关 — admin design system (spec §9)
   Single stylesheet, no build step, no external fonts / CDN.
   Light is the default theme; [data-theme="dark"] overrides the tokens.
   Tokens and component classes follow the Combo Gateway design system.
   ========================================================================== */

/* --- Design tokens: light (default) -------------------------------------- */
:root {
  /* colour */
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-surface-2: #f8fafb;
  --color-surface-3: #eef2f4;
  --color-border: #e2e7ec;
  --color-border-strong: #cbd4dc;
  --color-text: #161a1f;
  --color-text-soft: #4a5560;
  --color-text-muted: #7a8794;
  --color-accent: #0d9488;
  --color-accent-hover: #0b7f75;
  --color-accent-soft: #d5f0ec;
  --color-accent-fg: #ffffff;
  --color-chart-line: #d97706;
  --color-success: #15803d;
  --color-success-soft: #dcf5e4;
  --color-warning: #b45309;
  --color-warning-soft: #fbeed6;
  --color-danger: #c0392b;
  --color-danger-soft: #fbe2df;
  --color-info: #1d4ed8;
  --color-info-soft: #dfe8fd;

  /* spacing scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, .18);

  /* type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 11.5px;
  --text-sm: 12.5px;
  --text-base: 13.5px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 26px;

  --sidebar-w: 16rem;
  --transition: 140ms cubic-bezier(.4, 0, .2, 1);
}

/* --- Design tokens: dark -------------------------------------------------- */
[data-theme="dark"] {
  --color-bg: #0d1015;
  --color-surface: #151a21;
  --color-surface-2: #1a2029;
  --color-surface-3: #212933;
  --color-border: #262e39;
  --color-border-strong: #38424f;
  --color-text: #e7ebf0;
  --color-text-soft: #b3bcc7;
  --color-text-muted: #808c9a;
  --color-accent: #2dd4bf;
  --color-accent-hover: #5eead4;
  --color-accent-soft: #123b37;
  --color-accent-fg: #04211e;
  --color-chart-line: #fbbf24;
  --color-success: #4ade80;
  --color-success-soft: #10321f;
  --color-warning: #fbbf24;
  --color-warning-soft: #3a2c0d;
  --color-danger: #f87171;
  --color-danger-soft: #3a1a1a;
  --color-info: #7aa2f7;
  --color-info-soft: #16233d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
}

/* --- Reset / base --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-base); }
h4 { font-size: var(--text-sm); color: var(--color-text-soft); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0 0 var(--space-3); }
a { color: var(--color-accent); }
small { font-size: var(--text-xs); }
code, .mono { font-family: var(--font-mono); font-size: .92em; }
.num, .kpi-value, td.num, th.num, .chart-legend { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
::selection { background: var(--color-accent-soft); }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: var(--radius-sm); }

/* --- Layout --------------------------------------------------------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-3);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-2); }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  background: linear-gradient(140deg, var(--color-accent), var(--color-accent-hover));
  color: var(--color-accent-fg);
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: var(--text-base); letter-spacing: -.01em; }
.brand-text small { color: var(--color-text-muted); font-size: var(--text-xs); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--color-text-soft);
  text-decoration: none;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }
.nav-item:hover { background: var(--color-surface-3); color: var(--color-text); }
.nav-item.active { background: var(--color-accent); color: var(--color-accent-fg); box-shadow: var(--shadow-sm); }
.nav-item.active svg { opacity: 1; }

.sidebar-foot {
  margin-top: auto;
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.sidebar-foot .version {
  margin-left: auto;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-text-muted); }
.dot.ok { background: var(--color-success); box-shadow: 0 0 0 3px var(--color-success-soft); }
.dot.bad { background: var(--color-danger); box-shadow: 0 0 0 3px var(--color-danger-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: var(--space-3); }
.user-name { color: var(--color-text-soft); font-size: var(--text-sm); }
.view { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  font: inherit; font-weight: 550;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn:hover { background: var(--color-surface-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-fg); }
.btn.primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
.btn.ghost, .btn-ghost { background: transparent; border-color: transparent; color: var(--color-text-soft); }
.btn.ghost:hover, .btn-ghost:hover { background: var(--color-surface-3); color: var(--color-text); }
.btn.danger { color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 45%, var(--color-border)); }
.btn.danger:hover { background: var(--color-danger-soft); }
.btn.sm { padding: 3px var(--space-2); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent; color: var(--color-text-soft); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--color-surface-3); color: var(--color-text); }
.icon-btn svg { width: 19px; height: 19px; }
.only-mobile { display: none; }
[data-theme="light"] .icon-moon, :root:not([data-theme="dark"]) .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* --- Cards / grid --------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-head h4 { margin: 0; }
.card-title-group { display: flex; align-items: baseline; gap: var(--space-3); min-width: 0; }
.card-sub { color: var(--color-text-muted); font-size: var(--text-sm); }
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid.kpi { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--color-text-muted); }
.soft { color: var(--color-text-soft); }

/* --- KPI ------------------------------------------------------------------ */
/* Card styling applies to a KPI tile, not to a `.grid.kpi` CONTAINER (which is
   a grid of tiles). Without :not(.grid) the later .kpi rule's display:flex
   overrides .grid's display:grid and the tiles stack one-per-row. */
.kpi:not(.grid) {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-1);
}
.kpi-label { font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: var(--text-2xl); font-weight: 680; letter-spacing: -.02em; }
.kpi-value.sm { font-size: var(--text-xl); }
.kpi-foot { font-size: var(--text-xs); color: var(--color-text-muted); }
.kpi.accent { background: linear-gradient(150deg, var(--color-accent-soft), var(--color-surface-2)); }

/* --- Forms ---------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field > label, .label { font-size: var(--text-sm); font-weight: 550; color: var(--color-text-soft); }
.field .hint { font-size: var(--text-xs); color: var(--color-text-muted); }
.input, .select, textarea.input {
  font: inherit;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}
textarea.input { min-height: 84px; resize: vertical; font-family: var(--font-mono); font-size: var(--text-sm); }
.select { appearance: none; padding-right: var(--space-8); background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: right 14px center, right 9px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.inline-field { display: flex; align-items: center; gap: var(--space-2); }
input[type="number"].input { font-variant-numeric: tabular-nums; }

/* --- Toggle --------------------------------------------------------------- */
.toggle { position: relative; display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track {
  width: 40px; height: 22px; border-radius: var(--radius-pill);
  background: var(--color-border-strong);
  position: relative; transition: background var(--transition);
}
.toggle .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.toggle input:checked + .track { background: var(--color-accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 3px var(--color-accent-soft); }
.toggle input:disabled + .track { opacity: .5; }
.toggle .toggle-text { font-size: var(--text-sm); color: var(--color-text-soft); }

/* --- Badges / tags -------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 600;
  background: var(--color-surface-3); color: var(--color-text-soft);
  white-space: nowrap;
}
.badge.ok, .badge.success { background: var(--color-success-soft); color: var(--color-success); }
.badge.danger, .badge.error { background: var(--color-danger-soft); color: var(--color-danger); }
.badge.warn, .badge.warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge.info { background: var(--color-info-soft); color: var(--color-info); }
.badge.accent { background: var(--color-accent-soft); color: var(--color-accent); }
.badge.mono { font-family: var(--font-mono); }
.tag-row { display: flex; flex-wrap: wrap; gap: 4px; }

/* --- Level bar (probe states) --------------------------------------------- */
.level-bar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.level-bar .lvl { font-family: var(--font-mono); }
.badge.lvl-ok { background: var(--color-success-soft); color: var(--color-success); }
.badge.lvl-dead { background: var(--color-danger-soft); color: var(--color-danger); }
.badge.lvl-unknown { background: var(--color-warning-soft); color: var(--color-warning); }
.badge.lvl-base { outline: 1px dashed currentColor; outline-offset: -1px; font-weight: 700; }
/* blocked level chip: muted + struck through. The state colour class (lvl-ok/
   lvl-dead/lvl-unknown) is retained for the title but overridden here so a
   blocked 活档 reads as "excluded". */
.badge.lvl-blocked {
  background: var(--color-surface-3);
  color: var(--color-text-muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
/* clickable 活(supported) level chips toggle the 屏蔽 blocklist */
.badge.lvl-toggle { cursor: pointer; }
.badge.lvl-toggle:hover { box-shadow: 0 0 0 2px var(--color-accent-soft); }
/* one 档位栏 chip = state badge + a small per-level ⟳ re-probe button */
.lvl-chip { display: inline-flex; align-items: center; gap: var(--space-1); }
.lvl-reprobe {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-pill);
  background: transparent; color: var(--color-text-muted);
  font-size: 11px; line-height: 1; cursor: pointer;
  transition: color var(--transition), background var(--transition);
}
.lvl-reprobe:hover { color: var(--color-accent); background: var(--color-accent-soft); }
.lvl-reprobe:disabled { opacity: .45; cursor: default; }
.badge.lvl-probing { opacity: .7; font-style: italic; text-decoration: none; }
/* legend: explains baseline + the 活/死/未知 colour mapping once per page */
.level-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.level-legend .legend-title { font-weight: 650; color: var(--color-text-soft); text-transform: uppercase; letter-spacing: .06em; }
.level-legend .legend-item { display: inline-flex; align-items: center; gap: var(--space-2); }
.level-legend .legend-text { color: var(--color-text-muted); }
/* level cell stacks the 档位栏 chips above the probe_error summary line */
.level-cell { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.probe-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Connectivity test result --------------------------------------------- */
.test-result { font-size: var(--text-sm); color: var(--color-text-muted); word-break: break-word; }
.test-result.ok { color: var(--color-success); }
.test-result.err { color: var(--color-danger); }

/* --- Fetched model picker (multi-select) ---------------------------------- */
.fetch-state { font-size: var(--text-sm); color: var(--color-text-muted); }
.fetch-state.err { color: var(--color-danger); }
.model-pick-list {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
  max-height: 220px; overflow-y: auto;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
}
.pick-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  cursor: pointer; font-size: var(--text-sm);
}
.pick-item input { accent-color: var(--color-accent); }
.pick-group-head {
  flex-basis: 100%;
  display: flex; align-items: center; gap: var(--space-2);
  margin: var(--space-1) 0;
  font-size: var(--text-xs); font-weight: 600;
  color: var(--color-text-muted);
  text-transform: none; letter-spacing: .02em;
}
.pick-group-head:not(:first-child) { margin-top: var(--space-2); }
.pick-item.is-added { opacity: .55; cursor: default; }
.pick-item.is-added input { accent-color: var(--color-text-muted); }
.pick-badge {
  font-size: var(--text-xs); padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-3); color: var(--color-text-muted);
}

/* --- Segmented control ---------------------------------------------------- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--color-surface-3); border-radius: var(--radius); }
.segmented button {
  font: inherit; font-size: var(--text-sm); font-weight: 550;
  border: none; background: transparent; color: var(--color-text-soft);
  padding: 4px var(--space-3); border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.segmented button.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }

/* --- Tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { text-align: left; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.table th {
  height: 40px;
  padding: 10px 14px;
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.table td { padding: 11px 14px; }
.table tbody tr:not(.detail-row) td { height: 44px; }
.table tbody tr:hover { background: var(--color-surface-2); }
.table th.num, .table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
}
.table .empty-row td { text-align: center; color: var(--color-text-muted); padding: var(--space-6); }

/* Semantic value colours: success-rate scale + throughput scale. */
.rate-high { color: var(--color-success); font-weight: 600; }
.rate-mid { color: var(--color-info); font-weight: 600; }
.rate-low { color: var(--color-warning); font-weight: 600; }
.speed-tag { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.speed-tag.fast { color: var(--color-success); font-weight: 600; }
.speed-tag.mid { color: var(--color-accent); font-weight: 600; }
.speed-tag.slow { color: var(--color-text-muted); }

/* --- Usage: per-upstream accordion groups --------------------------------- */
.upstream-group-section .card-head { margin-bottom: var(--space-3); }
.upstream-groups { display: flex; flex-direction: column; gap: var(--space-3); }
.upstream-group-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.upstream-group-card:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-sm); }
.upstream-group-head {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%;
  padding: 13px var(--space-4);
  border: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
}
.upstream-group-head:hover { background: var(--color-surface-2); }
.upstream-group-head:focus-visible { outline-offset: -2px; }
.upstream-chev {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; flex: 0 0 16px;
  color: var(--color-text-muted);
  transition: transform var(--transition), color var(--transition);
}
.upstream-chev svg { width: 16px; height: 16px; }
.upstream-group-card:not(.is-collapsed) .upstream-chev { transform: rotate(90deg); }
.upstream-group-head:hover .upstream-chev { color: var(--color-accent); }
.upstream-model-count { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; }
.upstream-metrics {
  margin-left: auto;
  display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
}
.upstream-metrics .um { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.upstream-metrics .um-label { font-size: var(--text-xs); color: var(--color-text-muted); }
.upstream-metrics .um-value {
  font-size: var(--text-sm); font-weight: 600; color: var(--color-text-soft);
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
}
.upstream-group-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 220ms cubic-bezier(.4, 0, .2, 1), opacity 180ms ease;
}
.upstream-group-body-inner {
  min-height: 0;
  overflow: hidden;
  box-shadow: inset 0 1px 0 var(--color-border);
  opacity: 1;
  transition: opacity 180ms ease;
}
.upstream-group-card.is-collapsed .upstream-group-body { grid-template-rows: 0fr; }
.upstream-group-card.is-collapsed .upstream-group-body-inner { opacity: 0; }
.upstream-group-body .table th { background: var(--color-surface-2); }

/* --- Modal ---------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 14, 20, .55);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--space-6);
  overflow-y: auto;
  animation: fade-in 140ms ease;
}
.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  margin: auto;
  animation: rise 160ms cubic-bezier(.2, .8, .2, 1);
}
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); }
.modal-body { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); max-height: 68vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* --- Draggable member list ------------------------------------------------ */
.member-list { display: flex; flex-direction: column; gap: var(--space-2); }
.member-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2); border: 1px solid var(--color-border);
  border-radius: var(--radius); background: var(--color-surface-2);
}
.member-item.dragging { opacity: .45; }
.member-item.drop-target { border-color: var(--color-accent); box-shadow: 0 0 0 2px var(--color-accent-soft); }
.drag-handle { cursor: grab; color: var(--color-text-muted); display: grid; place-items: center; }
.drag-handle:active { cursor: grabbing; }
.member-item .member-ref { flex: 1; font-family: var(--font-mono); font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Chart ---------------------------------------------------------------- */
.chart-box { position: relative; width: 100%; }
.chart-box canvas { width: 100%; height: 220px; display: block; }
.chart-legend { display: flex; gap: var(--space-4); font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-2); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* --- Toasts / states ------------------------------------------------------ */
.toast-root { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 200; display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  min-width: 220px; max-width: 360px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius); border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  box-shadow: var(--shadow-lg); font-size: var(--text-sm);
  animation: rise 160ms ease;
}
.toast.ok { border-left: 3px solid var(--color-success); }
.toast.err { border-left: 3px solid var(--color-danger); }
.state { text-align: center; color: var(--color-text-muted); padding: var(--space-8) var(--space-4); }
.state .state-title { font-weight: 600; color: var(--color-text-soft); margin-bottom: var(--space-1); }
.state.error { color: var(--color-danger); }
.skeleton { background: linear-gradient(90deg, var(--color-surface-3), var(--color-surface-2), var(--color-surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); height: 14px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spin { width: 15px; height: 15px; border: 2px solid var(--color-border-strong); border-top-color: var(--color-accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius); font-size: var(--text-sm); }
.alert.error { background: var(--color-danger-soft); color: var(--color-danger); }
.alert.ok { background: var(--color-success-soft); color: var(--color-success); }
.alert.info { background: var(--color-info-soft); color: var(--color-info); }

/* --- Auth screen ---------------------------------------------------------- */
body.is-auth .sidebar, body.is-auth .topbar { display: none; }
body.is-auth .view { min-height: 100vh; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { justify-content: center; margin-bottom: var(--space-4); }
.auth-note { font-size: var(--text-sm); color: var(--color-text-muted); text-align: center; }
.plaintext-key { font-family: var(--font-mono); font-size: var(--text-sm); word-break: break-all; padding: var(--space-3); border-radius: var(--radius); background: var(--color-accent-soft); color: var(--color-accent); border: 1px dashed var(--color-accent); }

/* --- Utilities ------------------------------------------------------------ */
.hide { display: none !important; }
.w-full { width: 100%; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.divider { height: 1px; background: var(--color-border); border: 0; margin: var(--space-2) 0; }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 900px) {
  .sidebar { --sidebar-w: 13rem; }
}

@media (max-width: 640px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: 17rem; flex-basis: 17rem; height: 100vh;
    transform: translateX(-102%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(10, 14, 20, .5); z-index: 50; }
  .only-mobile { display: grid; }
  .view { padding: var(--space-4); gap: var(--space-4); }
  .topbar { padding: var(--space-3) var(--space-4); }
  .grid, .grid.kpi, .grid.cards { grid-template-columns: 1fr; }

  /* tables -> stacked cards */
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    background: var(--color-surface-2);
  }
  .table.responsive tr:hover { background: var(--color-surface-2); }
  .table.responsive td { display: flex; justify-content: space-between; gap: var(--space-3); border: 0; padding: 3px 0; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--color-text-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .05em; text-align: left; }
  .table.responsive td.num { text-align: right; }
  .table.responsive .empty-row td { justify-content: center; }
  .table.responsive .empty-row td::before { content: none; }
  /* Upstream accordion header wraps its metrics under the title on phones. */
  .upstream-group-head { flex-wrap: wrap; }
  .upstream-metrics { margin-left: 0; width: 100%; gap: var(--space-2) var(--space-4); }
  .modal-backdrop { padding: var(--space-3); }
  .modal-body { max-height: none; }
}

/* --- Recent requests: fallback path expander ------------------------------ */
/* The 回退 / 明细 cell is a toggle button: an optional ✓/— mark + chevron. */
.row-toggle {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 0; border: none; background: transparent; cursor: pointer;
  font: inherit; color: var(--color-text-soft);
}
.row-toggle:hover { color: var(--color-accent); }
.row-toggle .chev { display: inline-flex; width: 14px; height: 14px; color: var(--color-text-muted); transition: transform var(--transition); }
.row-toggle .chev svg { width: 14px; height: 14px; }
.row-toggle:hover .chev { color: var(--color-accent); }
.row-toggle.open .chev { transform: rotate(90deg); }
.row-toggle .fb-mark.yes { color: var(--color-success); font-weight: 700; }
.row-toggle .fb-mark.no { color: var(--color-text-muted); }

.table tbody tr.is-open > td { background: var(--color-surface-2); }
.table .detail-row { height: auto; }
.table .detail-row > td {
  height: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  text-align: left;
}
.trace-path {
  list-style: none;
  margin: 0;
  padding: var(--space-1) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.trace-step {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  padding: 8px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.trace-step .trace-member { color: var(--color-text-muted); font-weight: 500; }
.trace-step .trace-name { color: var(--color-text); }
.trace-step .trace-arrow { color: var(--color-text-muted); }
.trace-step .trace-reason { font-size: var(--text-xs); word-break: break-word; }
.trace-step .trace-ok { color: var(--color-success); font-weight: 700; margin-left: auto; }
.trace-step.is-skip { background: transparent; border-style: dashed; }
.trace-step.is-skip .trace-name { color: var(--color-text-muted); }
.trace-empty { font-size: var(--text-sm); }

/* In responsive stacked mode, ensure the detail row takes full width without cell labels */
@media (max-width: 640px) {
  .table.responsive .detail-row > td { display: block; text-align: left; }
  .table.responsive .detail-row > td::before { content: none; }
}

/* ==========================================================================
   OCAPI shell additions (todo 8: shell only, no real data yet)
   ========================================================================== */

/* --- Brand / chrome ------------------------------------------------------- */
.brand-text strong { white-space: nowrap; }
.sidebar-foot .dot.pending {
  background: var(--color-warning);
  box-shadow: 0 0 0 3px var(--color-warning-soft);
}
.topbar-right .btn { text-decoration: none; }
.user-name { white-space: nowrap; }

/* --- Hero / page intro ---------------------------------------------------- */
.hero {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 160% at 0% 0%, var(--color-accent-soft) 0%, transparent 58%),
    var(--color-surface);
  box-shadow: var(--shadow-sm);
}
.hero-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: var(--radius);
  background: linear-gradient(140deg, var(--color-accent), var(--color-accent-hover));
  color: var(--color-accent-fg);
  box-shadow: var(--shadow-sm);
}
.hero-mark svg { width: 24px; height: 24px; }
.hero-body { flex: 1; min-width: 0; }
.hero-body h2 { margin: 0 0 var(--space-1); font-size: var(--text-xl); }
.hero-body p { margin: 0; color: var(--color-text-soft); max-width: 68ch; }
.hero-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.page-lead { max-width: 72ch; color: var(--color-text-soft); }

/* --- Empty / placeholder surfaces ---------------------------------------- */
.chart-placeholder {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: var(--space-5);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 31px,
      color-mix(in srgb, var(--color-border) 55%, transparent) 31px,
      color-mix(in srgb, var(--color-border) 55%, transparent) 32px
    ),
    var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}
.chart-placeholder strong {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--color-text-soft);
  font-size: var(--text-base);
}
.placeholder-card { border-style: dashed; box-shadow: none; }
.placeholder-list {
  margin: 0;
  padding-left: var(--space-5);
  color: var(--color-text-soft);
  font-size: var(--text-sm);
}
.placeholder-list li + li { margin-top: var(--space-1); }
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
}
.empty-state svg { width: 30px; height: 30px; opacity: .55; }
.empty-state .empty-title { color: var(--color-text-soft); font-weight: 600; }
.empty-state .empty-text { font-size: var(--text-sm); max-width: 44ch; }

/* --- Auth / setup placeholder -------------------------------------------- */
.auth-shell { width: 100%; max-width: 440px; }
.auth-shell .card { padding: var(--space-6); }
.auth-head { text-align: center; margin-bottom: var(--space-5); }
.auth-head .brand { justify-content: center; margin-bottom: var(--space-4); }
.auth-head h2 { margin-bottom: var(--space-1); }
.auth-head p { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); }
.auth-switch { display: flex; justify-content: center; }
.auth-switch .segmented { width: 100%; }
.auth-switch .segmented button { flex: 1; }
.auth-foot { margin-top: var(--space-4); text-align: center; font-size: var(--text-sm); }
.auth-foot a { text-decoration: none; }

/* --- Small screens: hero stacks, auth card breathes ----------------------- */
@media (max-width: 640px) {
  .hero { flex-direction: column; align-items: flex-start; }
  .hero-actions { width: 100%; }
  .hero-actions .btn { flex: 1; }
  .auth-shell { max-width: 100%; }
  .auth-shell .card { padding: var(--space-5); }
}

/* ==========================================================================
   Dashboard + Playground (todo 27)
   Extends the tokens above; no new colours or one-off magic values.
   ========================================================================== */

/* --- Dashboard: meta / sparkline ----------------------------------------- */
.hero-updated {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.sparkline-wrap { display: flex; flex-direction: column; gap: var(--space-2); }
.sparkline {
  display: block;
  width: 100%;
  height: auto;
  min-height: 120px;
  color: var(--color-accent);
}
.sparkline .spark-grid line {
  stroke: var(--color-border);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}
.sparkline .spark-line {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.sparkline .spark-area { stroke: none; }
.sparkline .spark-axis,
.sparkline .spark-max {
  fill: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
}
.spark-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.spark-legend { display: inline-flex; align-items: center; gap: var(--space-2); }
.spark-swatch {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-accent);
}
.spark-empty-note { margin: 0; font-size: var(--text-xs); }
.status-code {
  margin-left: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.empty-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* --- Playground: two-column controls + output ---------------------------- */
.playground-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: var(--space-5);
  align-items: stretch;
}
.playground-controls,
.playground-output { min-width: 0; }
.playground-output { display: flex; flex-direction: column; }
.playground-output .output-pane { flex: 1 1 auto; }
.playground-form { gap: var(--space-4); }
.key-row { display: flex; align-items: center; gap: var(--space-2); }
.key-row .input,
.key-row .select { flex: 1; min-width: 0; }
.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  align-items: start;
}
.playground-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.playground-actions .btn { min-width: 120px; }
.output-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.output-pane {
  min-height: 320px;
  max-height: 560px;
  overflow: auto;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  scroll-behavior: smooth;
}
.output-pane::-webkit-scrollbar { width: 8px; height: 8px; }
.output-pane::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: var(--radius-pill);
}
.output-empty {
  padding: var(--space-10) var(--space-4);
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  text-align: center;
}
.output-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.reasoning-block {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--color-border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--color-surface-3);
  color: var(--color-text-muted);
}
.reasoning-block summary {
  cursor: pointer;
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.reasoning-block summary:hover { color: var(--color-text-soft); }
.reasoning-text {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tool-call-section {
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px dashed var(--color-border);
}
.tool-call-label {
  margin-bottom: var(--space-2);
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.tool-call-chips { display: flex; flex-direction: column; gap: var(--space-2); }
.tool-chip {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
}
.tool-name {
  flex: 0 0 auto;
  padding: 1px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: 650;
}
.tool-args {
  color: var(--color-text-soft);
  font-family: var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.field .hint.err { color: var(--color-danger); }

@media (max-width: 900px) {
  .playground-grid { grid-template-columns: 1fr; }
  .output-pane { max-height: 420px; }
}

@media (max-width: 640px) {
  .key-row { flex-wrap: wrap; }
  .key-row .btn { flex: 0 0 auto; }
  .playground-actions .btn { flex: 1; }
  .output-pane { min-height: 240px; max-height: 360px; }
}

/* ==========================================================================
   Relays + Proxy Pools (todo 28)
   Extends the tokens above; tables stack on phones via .table.responsive.
   ========================================================================== */

/* --- Warning banner / shared cells --------------------------------------- */
.alert.warning { background: var(--color-warning-soft); color: var(--color-warning); }
.warning-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  border: 1px solid color-mix(in srgb, var(--color-warning) 35%, var(--color-border));
}
.warning-banner .warning-mark {
  display: inline-flex;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}
.warning-banner .warning-mark svg { width: 18px; height: 18px; }
.warning-banner .warning-text { min-width: 0; }
.url-cell {
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-main { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.cell-error {
  max-width: 32ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-danger);
  font-size: var(--text-xs);
}
.inline-actions { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; }
.badge-row { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; }
.state .spin { margin: 0 auto var(--space-2); }

/* --- Modal form grid ------------------------------------------------------ */
.modal-form-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.form-grid .field-full { grid-column: 1 / -1; }

/* --- Worker source viewer ------------------------------------------------- */
.source-pre {
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  color: var(--color-text-soft);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.65;
  white-space: pre;
  overflow: auto;
  max-height: 56vh;
}
.source-pre code { font-size: inherit; }

/* --- Pools: list + members panel ----------------------------------------- */
.pools-layout {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(0, 1.5fr);
  gap: var(--space-5);
  align-items: start;
}
.pool-list { display: flex; flex-direction: column; gap: var(--space-2); }
.pool-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.pool-card:hover { border-color: var(--color-border-strong); background: var(--color-surface); }
.pool-card:focus-visible { outline-offset: -2px; }
.pool-card.is-selected {
  border-color: var(--color-accent);
  background: linear-gradient(140deg, var(--color-accent-soft), var(--color-surface));
  box-shadow: 0 0 0 2px var(--color-accent-soft);
}
.pool-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}
.pool-card-title { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
.pool-card-title strong { overflow-wrap: anywhere; }
.pool-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.pool-card-actions { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; }
.members-panel { min-width: 0; }
.members-panel .table-wrap { margin: 0 calc(-1 * var(--space-1)); }

@media (max-width: 900px) {
  .pools-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .url-cell { max-width: none; white-space: normal; overflow-wrap: anywhere; }
  .cell-error { max-width: none; white-space: normal; overflow-wrap: anywhere; }
  .pool-card-head { flex-direction: column; }
  .pool-card-actions .btn { flex: 1; }
}

/* ==========================================================================
   Models / API Keys / Requests / Settings + real admin auth (todo 29)
   Extends the tokens above; no new colours or external resources.
   ========================================================================== */

/* --- Auth states ---------------------------------------------------------- */
.auth-shell .alert { text-align: left; }
.auth-shell .auth-head + .alert { margin-bottom: var(--space-4); }
body.is-auth .auth-shell .stack .btn[type="submit"] { margin-top: var(--space-2); }

/* --- Filter toolbar ------------------------------------------------------- */
.filter-form { display: flex; flex-direction: column; gap: var(--space-3); }
.filter-grid {
  display: grid;
  gap: var(--space-3) var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}
.filter-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.filter-actions .btn { min-width: 96px; }
.filter-form .input[type="datetime-local"] { font-variant-numeric: tabular-nums; }

/* --- Clickable request rows ---------------------------------------------- */
.table tbody tr.row-clickable { cursor: pointer; }
.table tbody tr.row-clickable:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}
.table tbody tr.row-clickable:hover { background: var(--color-surface-2); }
.table .status-code { margin-left: 0; }

/* --- Pagination ----------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-top: var(--space-3);
  margin-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}
.pagination-info { font-size: var(--text-sm); color: var(--color-text-muted); }
.pagination-actions { display: flex; align-items: center; gap: var(--space-2); }

/* --- Request detail modal ------------------------------------------------- */
.detail-grid {
  display: grid;
  gap: var(--space-3) var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
}
.detail-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.detail-value {
  color: var(--color-text);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.detail-value code { font-size: var(--text-xs); }
.detail-section { display: flex; flex-direction: column; gap: var(--space-2); }
.detail-section h3 { font-size: var(--text-sm); color: var(--color-text-soft); }
.detail-error {
  margin: 0;
  padding: var(--space-3);
  border: 1px solid color-mix(in srgb, var(--color-danger) 35%, var(--color-border));
  border-radius: var(--radius);
  background: var(--color-danger-soft);
  color: var(--color-danger);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* --- One-time key reveal -------------------------------------------------- */
.plaintext-key {
  user-select: all;
  font-size: var(--text-base);
  line-height: 1.6;
}
.warning-banner .warning-text { line-height: 1.55; }

/* --- Settings groups ------------------------------------------------------ */
.settings-form { gap: var(--space-4); }
.settings-groups { display: flex; flex-direction: column; gap: var(--space-4); }
.settings-group {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
}
.settings-group-head {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.settings-group-head h3 { font-size: var(--text-base); }
.settings-group-head p { margin: 0; font-size: var(--text-xs); }
.settings-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-top: var(--space-2);
}
.settings-actions .btn { min-width: 120px; }
.settings-actions .muted { font-size: var(--text-xs); }

/* --- Settings read-only status ------------------------------------------- */
.grid.kpi .kpi-value .badge { font-size: var(--text-sm); }

/* --- Small screens -------------------------------------------------------- */
@media (max-width: 640px) {
  .filter-grid { grid-template-columns: 1fr; }
  .filter-actions .btn { flex: 1; }
  .pagination { align-items: stretch; }
  .pagination-actions { width: 100%; }
  .pagination-actions .btn { flex: 1; }
  .detail-grid { grid-template-columns: 1fr; }
  .settings-group { padding: var(--space-3); }
  .settings-actions .btn { width: 100%; }
}
