/* === Admin Page — additional styles ===
   Reuses base theme (--bg-base, --text, --primary, --card, etc.) from style.css
*/

.admin-layout { display: flex; min-height: 100vh; align-items: stretch; }
.admin-layout .sidebar { position: relative; top: auto; flex-shrink: 0; }
.admin-main {
  flex: 1 1 0;
  padding: 24px 32px 48px;
  min-width: 0;
  max-width: 1280px;
}

/* Header */
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px; flex-wrap: wrap;
}
.admin-title { display: flex; align-items: center; gap: 12px; }
.admin-title h1 {
  font-size: 22px; font-weight: 700; margin: 0;
  letter-spacing: -0.01em;
}
.admin-title .sub {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.12em;
}
.admin-role-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.18), rgba(6, 182, 212, 0.18));
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: var(--text); font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.admin-role-badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: #8b5cf6; box-shadow: 0 0 8px #8b5cf6;
}

/* Action bar */
.admin-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px;
}
.admin-actions .right { margin-left: auto; }

/* Search input */
.admin-search {
  flex: 1; max-width: 360px;
}

/* Model table */
.mtable-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  max-width: 100%;
}
.mtable {
  width: 100%;
  min-width: 920px;
  border-collapse: separate; border-spacing: 0;
  table-layout: auto;
}
.mtable th.tier-col, .mtable td.tier-col { min-width: 88px; }  /* Bug fix:
  4-char Chinese labels like "高价旗舰" / "便宜轻量" need ~80px pill width;
  without min-width, the column auto-sizes to the th text "档位" (28px) and
  the pill gets clipped, forcing text to wrap one char per line. */
.mtable th.caps-col, .mtable td.caps-col { min-width: 84px; }  /* Bug fix:
  capability cells like "工具/推理" (4 chars) need ≥70px; default ~40px forces
  the text to wrap one char per line. */
.mtable th.status-col, .mtable td.status-col { min-width: 78px; }  /* Bug fix:
  "● 启用" / "○ 禁用" badges (4 chars + dot) need ≥70px; default ~54px wraps. */
.mtable thead th:first-child { border-top-left-radius: var(--radius); }
.mtable thead th:last-child { border-top-right-radius: var(--radius); }
.mtable tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
.mtable tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
.mtable thead th {
  text-align: left;
  padding: 12px 14px;
  font-size: 10.5px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  background: rgba(8, 9, 13, 0.35);
  border-bottom: 1px solid var(--border);
}
.mtable tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
.mtable tbody tr:last-child td { border-bottom: none; }
.mtable tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.mtable .mono { font-size: 12.5px; color: var(--text); }
.mtable .muted { color: var(--text-muted); font-size: 12px; }
.mtable .tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10.5px;
  background: rgba(139, 92, 246, 0.12);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.2);
  margin-right: 4px;
}
.mtable .toggle-on, .mtable .toggle-off {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  white-space: nowrap;  /* Bug fix: same as tier-pill — 3-4 char Chinese
    labels like "● 启用" / "○ 已停用" would otherwise wrap to one char per line. */
  min-width: 56px; justify-content: center;
}
.mtable .toggle-on { background: rgba(34, 197, 94, 0.12); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.25); }
.mtable .toggle-off { background: rgba(239, 68, 68, 0.10); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.22); }
.mtable .row-actions { display: flex; gap: 6px; }
.mtable .row-actions .btn { padding: 4px 10px; font-size: 11.5px; }

/* Tier badge colors (use the same scheme as WorkBuddy portal) */
.tier-flagship { background: linear-gradient(135deg, #f59e0b, #d97706); color: #1a1100; }
.tier-pro      { background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #f5f3ff; }
.tier-fast     { background: linear-gradient(135deg, #06b6d4, #0891b2); color: #ecfeff; }
.tier-standard { background: rgba(139, 148, 158, 0.18); color: #cbd5e1; }
.tier-entry    { background: rgba(34, 197, 94, 0.16); color: #4ade80; }
.tier-budget   { background: rgba(107, 114, 128, 0.18); color: #9ca3af; }
.mtable .tier-pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  white-space: nowrap;  /* Bug fix: without this, 4-char Chinese labels like
    "高价旗舰" / "便宜轻量" would wrap character-by-character when the cell
    width is constrained, producing a vertical stack of single chars. */
  min-width: 32px;      /* ensure even 2-char labels like "标准" have a balanced pill */
  text-align: center;
}
.mtable .tpc-cell {
  display: inline-flex; align-items: baseline; gap: 2px;
  font-family: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  font-size: 12.5px; font-weight: 600;
  color: #f5f3ff;
  padding: 2px 8px;
  background: rgba(139, 92, 246, 0.10);
  border: 1px solid rgba(139, 92, 246, 0.18);
  border-radius: 6px;
  white-space: nowrap;
}
.mtable .tpc-cell .muted { color: var(--text-faint); font-weight: 500; }

/* Bound channels (new-api) */
.channel-pills {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
}
.channel-pill {
  display: inline-flex; flex-direction: column; gap: 1px;
  padding: 4px 9px; border-radius: 6px;
  background: rgba(99, 102, 241, 0.14);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.25);
  cursor: help;
  white-space: nowrap;
  transition: background 0.15s;
  min-width: 80px;
}
.channel-pill:hover {
  background: rgba(99, 102, 241, 0.24);
}
.channel-pill .cp-name {
  font-size: 11.5px; font-weight: 600;
  display: inline-flex; align-items: baseline; gap: 4px;
}
.channel-pill .cp-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; font-weight: 500;
  color: rgba(165, 180, 252, 0.7);
}
.channel-pill .cp-host {
  font-family: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  font-size: 9.5px; font-weight: 500;
  color: rgba(165, 180, 252, 0.6);
}
.channel-pill.disabled {
  background: rgba(107, 114, 128, 0.14);
  color: #6b7280;
  border-color: rgba(107, 114, 128, 0.25);
}
.channel-pill.disabled .cp-id,
.channel-pill.disabled .cp-host { color: rgba(107, 114, 128, 0.7); }
.channel-pill.unbound {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.28);
  font-weight: 500;
}
.channel-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 16px; padding: 0 5px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  border-radius: 999px;
  font-size: 10px; font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}

/* Make channel pills clickable */
.channel-pill[data-channel-id] {
  cursor: pointer;
}
.channel-pill[data-channel-id]:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.18);
}

/* Channel detail modal */
.cd-id-badge {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 6px;
  background: rgba(99, 102, 241, 0.16);
  color: #a5b4fc;
  margin-left: 6px; vertical-align: middle;
}
.cd-sub {
  font-size: 11.5px; color: var(--text-muted); margin-top: 4px;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.cd-status-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 0; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.cd-status { font-size: 13px; }
.cd-meta-pills {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.cd-meta-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11px; color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}
.cd-meta-pill strong { color: var(--text); font-weight: 600; }
.cd-section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.cd-section:last-of-type { border-bottom: none; }
.cd-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 8px;
}
.cd-host-full {
  font-family: 'JetBrains Mono', monospace; font-size: 12.5px;
  color: var(--text); padding: 8px 10px;
  background: rgba(0, 0, 0, 0.25); border-radius: 6px;
  word-break: break-all;
}
.cd-host-short { font-size: 11.5px; margin-top: 4px; }
.cd-models-grid {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.cd-model-tag {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  padding: 3px 9px; border-radius: 5px;
  background: rgba(139, 92, 246, 0.10);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.20);
}
.cd-quota {
  font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 600;
  color: var(--text);
}

/* API key masked display */
.cd-key-masked {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.30);
  border: 1px solid var(--border);
}
.cd-key-text {
  font-family: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  font-size: 13px; font-weight: 600;
  color: #fbbf24;  /* amber — stands out as a secret */
  letter-spacing: 0.02em;
}
.cd-key-len {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}
.cd-key-cell {
  display: inline-block;
  padding: 2px 6px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
  color: #fbbf24;
  font-size: 11.5px; font-weight: 500;
  letter-spacing: 0.02em;
  cursor: help;
  border: 1px solid var(--border);
  white-space: nowrap;  /* Bug fix: API key text "sk-***X0" was wrapping on
    the c-tbody row when the cell got too narrow (e.g. 80px). With nowrap
    the cell grows the column instead of wrapping mid-token, keeping the
    key on one line and easier to copy. */
  max-width: 220px;
  overflow: hidden; text-overflow: ellipsis;
}

/* Routing topology card */
.routing-card {
  background: var(--bg-surface);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 18px;
}
.routing-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.routing-title {
  font-size: 14px; font-weight: 700; letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.routing-sub { font-size: 11.5px; }
.routing-stats {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.routing-stat {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11.5px; color: var(--text-muted);
}
.routing-stat-n {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700; color: var(--text); font-size: 12.5px;
}

.rt-flow {
  display: flex; flex-direction: column; gap: 0;
}
.rt-level {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.rt-level:last-of-type { border-bottom: none; }
.rt-level-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.rt-level-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 22px; padding: 0 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-weight: 700; font-size: 11px;
  border-radius: 6px; letter-spacing: 0.04em;
  font-family: 'JetBrains Mono', monospace;
}
.rt-prio-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px; color: var(--text-muted);
}
.rt-role-pill {
  font-size: 10.5px; padding: 2px 8px; border-radius: 999px;
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80; font-weight: 600;
  margin-left: auto;
}
.rt-role-pill.alt {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}
.rt-groups {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.rt-group {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch;
  padding: 6px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.06);
}
.rt-channel {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 110px; padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}
.rt-channel:hover {
  transform: translateY(-1px);
  border-color: rgba(99, 102, 241, 0.4);
}
.rt-ch-name {
  font-size: 12.5px; font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 160px;
}
.rt-ch-meta {
  display: flex; align-items: center; gap: 4px;
}
.rt-mode-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 16px; padding: 0 4px;
  font-size: 9.5px; font-weight: 700;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
}
.rt-mode-load_balance {
  background: rgba(139, 92, 246, 0.20);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.35);
}
.rt-mode-standalone {
  background: rgba(107, 114, 128, 0.18);
  color: #9ca3af;
  border: 1px solid rgba(107, 114, 128, 0.28);
}
.rt-pct {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px; font-weight: 600;
  color: #c4b5fd;
}

.rt-arrow {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 32px;
  color: var(--text-faint);
}
.rt-arrow-icon {
  font-size: 16px; font-weight: 700;
  color: rgba(251, 191, 36, 0.7);
  line-height: 1;
}
.rt-arrow-label {
  font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.08em; font-weight: 600;
  color: rgba(251, 191, 36, 0.7);
}

/* Danger button */
.btn.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}
.btn.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
}

/* Channel form modal (create / edit) */
.cf-models-row {
  grid-column: 1 / -1;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.cf-models-row > label {
  display: block;
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600; margin-bottom: 8px;
}
.cf-models-toolbar {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}
.cf-models-toolbar .btn-sm { font-size: 11px; padding: 3px 8px; }
.cf-models-grid {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 240px; overflow-y: auto;
  padding: 8px;
  background: rgba(0, 0, 0, 0.20);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.cf-model-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px 4px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
}
.cf-model-chip:hover { background: rgba(255, 255, 255, 0.07); }
.cf-model-chip.on {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(99, 102, 241, 0.45);
}
.cf-model-chip input[type=checkbox] {
  appearance: none;
  width: 12px; height: 12px;
  border: 1.5px solid var(--text-faint);
  border-radius: 3px;
  margin: 0;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.cf-model-chip input[type=checkbox]:checked {
  background: #6366f1;
  border-color: #6366f1;
}
.cf-model-chip input[type=checkbox]:checked::after {
  content: '✓';
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: #fff; font-size: 10px; line-height: 1; font-weight: 700;
}
.cf-mc-name {
  font-size: 11.5px; color: var(--text); font-weight: 500;
}
.cf-mc-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--text-faint);
}

/* Empty state */
.admin-empty {
  padding: 56px 24px;
  text-align: center; color: var(--text-muted);
}
.admin-empty .icon { margin-bottom: 8px; opacity: 0.4; }
.admin-empty h3 { color: var(--text); margin: 8px 0 4px; font-size: 16px; font-weight: 600; }

/* Modal */
.modal-mask {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: fadeIn 0.18s ease;
}
.modal-card {
  width: 100%; max-width: 560px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(139, 92, 246, 0.08);
  max-height: 90vh; overflow: auto;
  animation: scaleIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-card.lg { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 22px; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 16px 22px; border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
}

/* Form grid */
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 11.5px; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em; }
.form-grid .input, .form-grid .select, .form-grid .textarea {
  width: 100%; box-sizing: border-box;
}
.form-grid .textarea { min-height: 64px; resize: vertical; font-family: inherit; }
.form-grid .row-checks {
  display: flex; gap: 14px; flex-wrap: wrap; padding: 4px 0;
}
.form-grid .row-checks label {
  display: flex; align-items: center; gap: 6px;
  text-transform: none; letter-spacing: 0;
  font-size: 12.5px; color: var(--text); cursor: pointer;
  margin-bottom: 0;
}
.form-grid .row-checks input[type=checkbox] { accent-color: var(--primary); }
.form-grid .hint { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* Toast (reuse from style.css if available, fallback inline) */
.toast-host {
  position: fixed; top: 24px; right: 24px; z-index: 1500;
  display: flex; flex-direction: column; gap: 8px;
  /* Bug fix: pointer-events on the host must be none so the host container
   * doesn't intercept clicks meant for elements below it (e.g. a modal's
   * X close button at top-right). Each .toast below re-enables pointer
   * events for itself so users can still click to dismiss. */
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 10px; min-width: 220px; max-width: 360px;
  font-size: 13px; color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; gap: 10px;
  animation: slideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  cursor: pointer;
}
.toast.ok { border-color: rgba(34, 197, 94, 0.4); }
.toast.err { border-color: rgba(239, 68, 68, 0.4); }
.toast .icon { flex-shrink: 0; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* Auth gate */
.auth-gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; padding: 24px; text-align: center;
}
.auth-gate h2 { margin: 0; font-size: 22px; }
.auth-gate p { color: var(--text-muted); max-width: 460px; }
.auth-gate .btn { margin-top: 8px; }

/* Loading state */
.loading-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 9, 13, 0.4); backdrop-filter: blur(2px);
  border-radius: var(--radius);
}

/* Responsive */
@media (max-width: 880px) {
  .admin-layout { flex-direction: column; }
  .admin-main { padding: 16px 18px 32px; max-width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .mtable { font-size: 12px; }
  .mtable thead th, .mtable tbody td { padding: 8px 10px; }
  .mtable .hide-sm { display: none; }
  .admin-search { max-width: 100%; }
}

/* Coding Plan / per-model usage sections removed (data sources were unreliable) */

.admin-table th, .admin-table td { vertical-align: middle; }
.stat-pill { display:inline-flex; align-items:center; gap:4px; padding:4px 10px; background:rgba(255,255,255,0.04); border:1px solid rgba(255,255,255,0.06); border-radius:14px; font-size:12px; color:var(--text-muted); }
.stat-pill strong { color:var(--text-primary); font-size:13px; }
.stat-pill.ok { color:#86efac; border-color:rgba(34,197,94,0.20); background:rgba(34,197,94,0.06); }
.stat-pill.ok strong { color:#86efac; }
.stat-pill.warn { color:#fcd34d; border-color:rgba(245,158,11,0.20); background:rgba(245,158,11,0.06); }
.stat-pill.warn strong { color:#fcd34d; }

.badge { display:inline-block; padding:2px 8px; border-radius:10px; font-size:11px; font-weight:500; line-height:1.4; white-space:nowrap; }
.badge-ok { background:rgba(34,197,94,0.12); color:#86efac; border:1px solid rgba(34,197,94,0.25); }
.badge-err { background:rgba(239,68,68,0.12); color:#fca5a5; border:1px solid rgba(239,68,68,0.25); }
.badge-warn { background:rgba(245,158,11,0.12); color:#fcd34d; border:1px solid rgba(245,158,11,0.25); }
.badge-muted { background:rgba(255,255,255,0.06); color:var(--text-muted); border:1px solid rgba(255,255,255,0.08); }
.badge-purple { background:rgba(168,85,247,0.12); color:#d8b4fe; border:1px solid rgba(168,85,247,0.25); }

.user-link { color:#67e8f9; text-decoration:none; cursor:pointer; border-bottom:1px dashed rgba(103,232,249,0.4); }
.user-link:hover { color:#a5f3fc; border-bottom-color:rgba(103,232,249,0.9); }

.codes-toolbar, .users-toolbar { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; gap:12px; flex-wrap:wrap; }
.codes-stats, .users-stats { display:flex; gap:6px; flex-wrap:wrap; }
.codes-actions, .users-actions { display:flex; gap:8px; align-items:center; }

.codes-table-wrap, .users-table-wrap { background:rgba(255,255,255,0.02); border:1px solid rgba(255,255,255,0.06); border-radius:8px; overflow:hidden; }
.codes-table, .users-table { width:100%; }
.codes-table tr:hover, .users-table tr:hover { background:rgba(255,255,255,0.025); }
.codes-table th, .users-table th { background:rgba(255,255,255,0.03); }
.codes-table .center, .users-table .center { text-align:center; }

.nested-table { width:100%; font-size:12px; }
.nested-table th, .nested-table td { padding:6px 10px; }
.nested-table th { background:rgba(255,255,255,0.02); font-weight:500; color:var(--text-muted); }

.ud-section { display:flex; flex-direction:column; gap:10px; margin-bottom:14px; }
.ud-stats { display:grid; grid-template-columns:repeat(4, 1fr); gap:10px; }
.ud-stat { background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.06); border-radius:6px; padding:8px 10px; }
.ud-stat-label { font-size:11px; color:var(--text-muted); margin-bottom:2px; }
.ud-stat-value { font-size:18px; font-weight:600; color:var(--text-primary); }
.ud-stat-unit { font-size:11px; color:var(--text-muted); font-weight:400; }
.ud-stat-value.muted { color:var(--text-muted); }
.ud-meta { display:flex; flex-wrap:wrap; gap:12px; font-size:12px; color:var(--text-muted); padding:8px 10px; background:rgba(255,255,255,0.02); border-radius:6px; }
.ud-meta strong { color:var(--text-primary); font-weight:500; }
.ud-actions { display:flex; gap:8px; margin-bottom:14px; padding-bottom:12px; border-bottom:1px dashed rgba(255,255,255,0.08); }

.form-grid > .full { grid-column: 1 / -1; }
.input, .select, .textarea { width:100%; padding:8px 10px; background:rgba(255,255,255,0.04); border:1px solid rgba(255,255,255,0.10); border-radius:6px; color:var(--text-primary); font-size:13px; box-sizing:border-box; font-family:inherit; }
.input:focus, .select:focus, .textarea:focus { outline:none; border-color:#10b981; background:rgba(255,255,255,0.06); }
.textarea { font-family:ui-monospace, 'Cascadia Code', 'Consolas', monospace; resize:vertical; min-height:60px; }
.hint { font-size:11px; color:var(--text-muted); margin-top:3px; line-height:1.4; }
.row-checks { display:flex; gap:14px; flex-wrap:wrap; font-size:12px; }
.row-checks label { display:inline-flex; align-items:center; gap:5px; cursor:pointer; }
