/* ═══════════════════════════════════════════════════════════════
   llmesh portal stylesheet
   App shell: fixed sidebar navigation + content column.
   Theming via CSS custom properties; dark is the default,
   [data-theme="light"] overrides.
   ═══════════════════════════════════════════════════════════════ */

/* ─── Reset ─────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }

/* ─── Theme tokens ──────────────────────────────────────────── */

:root {
  --bg:            #0c0f15;
  --surface-1:     #12161f;
  --surface-2:     #171c27;
  --surface-3:     #1e2431;
  --border:        #242b3a;
  --border-strong: #303a4e;
  --text:          #dee4ee;
  --text-muted:    #8b94a7;
  --text-faint:    #626b7d;
  --accent:        #7aa2f7;
  --accent-strong: #5d8bef;
  --accent-soft:   rgba(122, 162, 247, 0.14);
  --danger:        #f47067;
  --danger-soft:   rgba(244, 112, 103, 0.12);
  --success:       #56d364;
  --success-soft:  rgba(86, 211, 100, 0.12);
  --warning:       #e3b341;
  --warning-soft:  rgba(227, 179, 65, 0.14);
  --shadow:        0 1px 2px rgba(0,0,0,.25), 0 4px 16px rgba(0,0,0,.18);
  --radius:        10px;
  --radius-sm:     7px;
  --sidebar-w:     218px;
  --chart-1: #7aa2f7; --chart-2: #9ece6a; --chart-3: #e0af68;
  --chart-4: #bb9af7; --chart-5: #7dcfff; --chart-6: #f7768e;
  --chart-7: #73daca; --chart-8: #ff9e64; --chart-9: #c0caf5;
  --chart-10: #565f89; --chart-other: #414868;
}

[data-theme="light"] {
  --bg:            #f4f6f9;
  --surface-1:     #ffffff;
  --surface-2:     #f8f9fb;
  --surface-3:     #eef1f5;
  --border:        #e2e6ec;
  --border-strong: #cfd6df;
  --text:          #1c2430;
  --text-muted:    #5b6472;
  --text-faint:    #8a93a2;
  --accent:        #3568d4;
  --accent-strong: #2b56b4;
  --accent-soft:   rgba(53, 104, 212, 0.10);
  --danger:        #d1362b;
  --danger-soft:   rgba(209, 54, 43, 0.09);
  --success:       #1a7f37;
  --success-soft:  rgba(26, 127, 55, 0.10);
  --warning:       #9a6700;
  --warning-soft:  rgba(154, 103, 0, 0.12);
  --shadow:        0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.05);
  --chart-1: #3568d4; --chart-2: #2e9e44; --chart-3: #c78a1b;
  --chart-4: #7c5cd6; --chart-5: #1193c2; --chart-6: #d4507a;
  --chart-7: #159e8c; --chart-8: #d97a2b; --chart-9: #5b6472;
  --chart-10: #8a93a2; --chart-other: #b9c1cc;
}

/* ─── Base ──────────────────────────────────────────────────── */

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
}

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

code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}

h1, h2, h3 { line-height: 1.25; font-weight: 650; }

::selection { background: var(--accent-soft); }

/* ─── App shell ─────────────────────────────────────────────── */

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

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 10px 16px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.sidebar-brand .brand-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  flex: none;
}

.sidebar-brand .brand-host {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-faint);
  margin-top: 1px;
  word-break: break-all;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.navlink {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.navlink:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.navlink.active { background: var(--accent-soft); color: var(--accent); }
.navlink .nav-ico { width: 17px; text-align: center; opacity: .85; flex: none; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  color: var(--text-muted);
  font-size: 13px;
}
.sidebar-user .user-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-version {
  padding: 0 10px;
  font-size: 11px;
  color: var(--text-faint);
}

.nav-icon-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 8px;
  font-size: 14px;
  line-height: 1.4;
}
.nav-icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* Mobile topbar (hidden on desktop) */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.mobile-topbar .brand { font-weight: 700; }
.hamburger { display: none; }

/* Content column */
.content-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

main {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 26px 28px 40px;
  flex: 1;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-title { font-size: 19px; font-weight: 650; }
.page-sub { color: var(--text-muted); font-size: 13px; }

.site-footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 11.5px;
  padding: 10px 0 18px;
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .mobile-topbar { display: flex; }
  .hamburger { display: inline-block; }
  .sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    height: 100vh;
    box-shadow: var(--shadow);
  }
  .sidebar.open { display: flex; }
  main { padding: 18px 14px 32px; }
}

/* ─── Flash messages ────────────────────────────────────────── */

.flash {
  max-width: 1104px;
  margin: 14px auto -6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 13.5px;
  width: calc(100% - 56px);
}
.flash.success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.flash.error   { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
@media (max-width: 860px) { .flash { width: calc(100% - 28px); } }

/* ─── Auth pages (login / setup) ────────────────────────────── */

.auth-body {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.auth-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 34px 32px 30px;
  width: 100%;
  max-width: 360px;
}
.auth-card .brand {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.auth-card .brand::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.auth-card h1 { font-size: 15px; color: var(--text-muted); font-weight: 500; margin-bottom: 20px; }
.auth-card .form-group { margin-bottom: 14px; }
.auth-card button[type="submit"] { width: 100%; margin-top: 6px; }
.auth-card .form-error { margin-bottom: 12px; }
.auth-notice {
  background: var(--success-soft);
  border: 1px solid var(--success);
  color: var(--success);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.45;
}
.auth-hint { color: var(--text-faint); font-size: 12px; margin-top: 8px; line-height: 1.45; }

/* Separator between the password form and the alternative sign-in methods. */
.auth-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 14px;
  color: var(--text-faint);
  font-size: 12px;
}
.auth-sep::before, .auth-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-alt-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 0;
  padding: 9px 12px;
  /* The GitHub button is an anchor, so it needs what a button gets for free. */
  text-decoration: none;
  font-family: inherit;
}
.auth-alt-form { margin-top: 12px; }
.auth-alt-form .form-group { margin-bottom: 10px; }
.auth-card .auth-alt-form button[type="submit"] { margin-top: 0; }

/* Sign-in methods on the settings page. */
.identity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ─── Cards & sections ──────────────────────────────────────── */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.card-title {
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 0 10px;
  flex-wrap: wrap;
}
.section-title { font-size: 15px; font-weight: 650; }

/* ─── Stat cards ────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat-label {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}
.stat-sub { color: var(--text-faint); font-size: 11px; margin-top: 1px; }

.last-updated, .log-updated {
  color: var(--text-faint);
  font-size: 11.5px;
  text-align: right;
  margin: 4px 2px 14px;
  min-height: 14px;
}

/* ─── Usage panel ───────────────────────────────────────────── */

.usage-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface-1); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.18); }

.usage-metric-toggle { margin-left: auto; }

.usage-chart-wrap { position: relative; margin-top: 14px; }
.usage-chart { width: 100%; height: 240px; display: block; }
.usage-chart .grid-line { stroke: var(--border); stroke-width: 1; }
.usage-chart .axis-label {
  fill: var(--text-faint);
  font-size: 10.5px;
  font-family: inherit;
}
.usage-chart .bar { shape-rendering: crispEdges; }
.usage-chart .bar:hover { opacity: .85; }
/* Rate metrics (tok/s, TTFT) draw as overlaid lines instead of stacked bars —
   speeds do not sum — so they want smoothing rather than crisp pixel edges. */
.usage-chart .perf-line,
.usage-chart .perf-point { shape-rendering: geometricPrecision; }
.usage-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 13px;
  pointer-events: none;
}

.usage-tip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 8px 11px;
  font-size: 12px;
  max-width: 300px;
  display: none;
}
.usage-tip .tip-title { font-weight: 650; margin-bottom: 4px; }
.usage-tip .tip-row { display: flex; justify-content: space-between; gap: 14px; }
.usage-tip .tip-row .tip-name { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.usage-tip .tip-swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.usage-tip .tip-val { font-variant-numeric: tabular-nums; }

.usage-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.usage-legend .legend-item { display: inline-flex; align-items: center; gap: 6px; }
.usage-legend .legend-swatch { width: 9px; height: 9px; border-radius: 2.5px; }
.usage-legend .legend-val { color: var(--text-faint); font-variant-numeric: tabular-nums; }

.usage-totals {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
}
.usage-totals b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 650; }

/* ─── Tables ────────────────────────────────────────────────── */

.table-scroll { overflow-x: auto; }

.data-table, .stats-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13.5px;
}
.data-table th, .stats-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td, .stats-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td,
.stats-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.empty-row td {
  color: var(--text-faint);
  text-align: center;
  padding: 18px 12px !important;
}
.row-dim td { opacity: .62; }
.cell-actions { text-align: right; white-space: nowrap; }
.table-hint { color: var(--text-faint); font-size: 12px; margin-top: 6px; }

.stats-panels { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.stats-panel-half { flex: 1 1 320px; min-width: 0; }
.stats-panel-label {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 7px;
}
.stats-mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }

/* ─── Badges ────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-sm { padding: 1px 7px; font-size: 10.5px; }

.badge.connected, .badge.multi_connected, .badge-ok, .badge.active, .badge.admin {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
}
.badge.offline {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
}
.badge.never_connected, .badge.muted-badge, .badge.normal, .badge.disabled, .badge.member {
  background: var(--surface-3);
  color: var(--text-muted);
  border-color: var(--border-strong);
}
.badge.high {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
.badge.low {
  background: var(--surface-3);
  color: var(--text-faint);
  border-color: var(--border);
}
.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
}

/* ─── Buttons ───────────────────────────────────────────────── */

.btn,
button[type="submit"]:not(.seg-btn):not(.tab-btn):not(.alias-add-btn):not(.alias-badge-del):not(.btn-secondary):not(.btn-danger):not(.btn-copy):not(.btn-xs):not(.chip-remove) {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent-strong);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: filter .12s ease;
}
.btn:hover,
button[type="submit"]:not(.seg-btn):not(.tab-btn):not(.alias-add-btn):not(.alias-badge-del):not(.btn-secondary):not(.btn-danger):not(.btn-copy):not(.btn-xs):not(.chip-remove):hover { filter: brightness(1.08); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-weight: 550;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-secondary:hover { background: var(--surface-3); text-decoration: none; }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-xs { padding: 2px 8px !important; font-size: 12px !important; }
.icon-btn { line-height: 1.2; }

.btn-copy {
  background: none !important;
  border: none !important;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 0 4px !important;
}
.btn-copy:hover { color: var(--accent); }

.btn-download { text-decoration: none; }
.btn-priority-save { margin-left: 4px; }

/* ─── Forms ─────────────────────────────────────────────────── */

input[type="text"], input[type="password"], input[type="number"],
input[type="url"], input:not([type]), select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13.5px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-faint); }
select { cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 4px; }

.form-group { display: flex; flex-direction: column; }
.form-group input, .form-group select { width: 100%; }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row .form-group { flex: 1 1 160px; }
.form-inline { display: inline-flex; align-items: center; gap: 6px; }
.inline-form { display: inline; }
.inline-flex { display: inline-flex; }
.inline-input { width: auto; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.field-desc { color: var(--text-faint); font-size: 12px; margin-top: 3px; font-weight: 400; }

.priority-inline { padding: 3px 6px; font-size: 12.5px; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}
.filter-bar input { flex: 1 1 220px; }

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── New key/token banner ──────────────────────────────────── */

.new-key-banner {
  background: var(--warning-soft);
  border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.new-key-banner code {
  display: inline-block;
  background: var(--surface-1);
  border-color: var(--border-strong);
  padding: 5px 10px;
  margin: 8px 0;
  word-break: break-all;
  user-select: all;
}
.new-key-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* ─── Endpoint display ──────────────────────────────────────── */

.endpoint-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  max-width: 100%;
}
.endpoint-url {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Model list (dashboard) ────────────────────────────────── */

.model-list { display: flex; flex-direction: column; }
.model-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.model-row:last-child { border-bottom: none; padding-bottom: 0; }
.model-row:first-child { padding-top: 0; }
.model-name {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  font-weight: 600;
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-aliases { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.alias-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11.5px;
  font-weight: 600;
}
.alias-badge-del {
  background: none;
  border: none;
  color: inherit;
  opacity: .65;
  cursor: pointer;
  font-size: 10px;
  padding: 0 1px;
}
.alias-badge-del:hover { opacity: 1; }
.model-add-alias { display: inline-flex; align-items: center; gap: 4px; }
.model-add-alias input { padding: 2px 8px; font-size: 12px; }
.alias-add-btn {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 1px 7px;
}
.alias-add-btn:hover { color: var(--text); }

/* ─── Alias fallback chains ─────────────────────────────────── */

.alias-chain-list { display: flex; flex-direction: column; gap: 14px; }
.alias-chain {
  display: grid;
  grid-template-columns: minmax(90px, 160px) 1fr;
  gap: 10px 14px;
  align-items: start;
}
.alias-chain-name { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.alias-chain-targets { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.alias-tier {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
/* The tier number is the load-bearing element here: position in the list only
   implies preference when tiers differ, so the number is what the eye should
   land on. */
.alias-tier-num {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.alias-tier-model {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.alias-tier-actions { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; }

@media (max-width: 620px) {
  .alias-chain { grid-template-columns: 1fr; gap: 6px; }
}
/* Flags a cost total that is missing traffic, so an incomplete figure does not
   read as authoritative. */
.usage-total-warn { color: var(--warning); }
.usage-total-warn b { color: var(--warning); }

/* ─── Collapsible sections ──────────────────────────────────── */

.collapsible { margin-bottom: 18px; }
.collapsible-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 650;
  font-size: 14px;
  user-select: none;
  padding: 4px 0;
}
.collapsible-header:hover { color: var(--accent); }
.toggle-arrow { font-size: 11px; color: var(--text-faint); }
.collapsible-body { display: none; }
.collapsible-body.open { display: block; }
.queue-header .queue-count { margin-left: 2px; }

/* ─── Client groups & connections ───────────────────────────── */

.user-group {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.user-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 650;
}
.user-group-name { font-size: 13.5px; }
.user-group .data-table, .user-group .table-scroll .data-table { border: none; border-radius: 0; }

.client-connections {
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  padding: 8px 14px;
}
/* The connections row is always rendered so a client connecting later has
   somewhere to be inserted. With nothing in it there is nothing to show, and
   its padding and border would otherwise read as an empty band under every
   disconnected token. */
.client-connections:empty { display: none; }
.conn-subrow:has(.client-connections:empty) { display: none; }
.conn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 5px 0;
  font-size: 12.5px;
}
.conn-row-router { opacity: .8; }
.conn-name { font-weight: 600; }
.conn-version, .conn-capacity { color: var(--text-muted); }
.conn-jobs { width: 100%; padding-left: 12px; }

/* Performance tiles sit inside a card, which already provides the bottom gap. */
.perf-stat-grid { margin-bottom: 0; margin-top: 10px; }

/* ─── Client performance sub-row ─────────────────────────────── */

.perf-block { padding: 8px 14px 10px; }
.perf-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  margin-bottom: 6px;
}
.perf-title { font-weight: 650; }
.perf-window { font-size: 11.5px; }
.perf-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
.perf-metric {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 9px;
}
.perf-metric-value {
  font-size: 14px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.perf-metric-label { color: var(--text-faint); font-size: 11px; }
.client-model-table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 11.5px;
}
.client-model-table th {
  text-align: left;
  color: var(--text-faint);
  font-weight: 600;
  padding: 3px 8px 3px 0;
  border-bottom: 1px solid var(--border);
}
.client-model-table td {
  padding: 3px 8px 3px 0;
  font-variant-numeric: tabular-nums;
}
.client-model-table td:first-child {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--text-muted);
}

/* ─── Client models sub-row ──────────────────────────────────── */

/* The table used to sit inside the performance block and borrow its padding.
   It is its own sub-row now, so it carries its own. */
.client-models-block { padding: 6px 14px 10px; }
.client-models-block .client-model-table { margin-top: 0; }
/* Each row's slot control is a form in a cell; keep it from adding row height. */
.client-model-table .form-inline { margin: 0; gap: 4px; }
.client-model-table td { vertical-align: middle; }

.job-row { display: flex; flex-direction: column; gap: 1px; padding: 4px 0; font-size: 12px; }
.job-row-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.job-phase-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: none; }
.job-processing .job-phase-dot { background: var(--warning); animation: pulse 1.4s ease-in-out infinite; }
.job-generating .job-phase-dot { background: var(--success); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.job-owner { font-weight: 600; }
.job-model { color: var(--text-muted); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; }
.job-elapsed { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.job-row-stats { color: var(--text-muted); padding-left: 15px; }
.job-badge-priority { margin-left: 2px; }
.job-badge-retry { margin-left: 2px; }
.job-stats-live { color: var(--text-faint); }

/* ─── Tabs ──────────────────────────────────────────────────── */

.tab-container {}
.tab-bar {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  width: fit-content;
  max-width: 100%;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 5px 13px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 550;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--surface-1); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.18); }

.tab-bar.underline {
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  gap: 14px;
  width: 100%;
}
.tab-bar.underline .tab-btn {
  border-radius: 0;
  padding: 7px 2px;
  box-shadow: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-bar.underline .tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Settings ──────────────────────────────────────────────── */

.settings-narrow { max-width: 460px; }

/* ─── Logs viewer ───────────────────────────────────────────── */

.logs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.logs-container {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.8px;
  line-height: 1.7;
  max-height: 460px;
  overflow-y: auto;
  padding: 10px 12px;
}
.logs-empty { color: var(--text-faint); text-align: center; padding: 20px; font-family: inherit; }
.log-row { display: flex; gap: 10px; align-items: baseline; white-space: nowrap; }
.log-time { color: var(--text-faint); flex: none; }
.log-level { flex: none; width: 44px; font-weight: 700; font-size: 10.5px; }
.log-level.INFO { color: var(--accent); }
.log-level.WARN { color: var(--warning); }
.log-level.ERROR { color: var(--danger); }
.log-level.DEBUG { color: var(--text-faint); }
.log-msg { flex: none; }
.log-attrs { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }

/* ─── Help / docs pages ─────────────────────────────────────── */

.docs-layout { display: flex; gap: 26px; align-items: flex-start; }
.docs-nav {
  flex: 0 0 200px;
  position: sticky;
  top: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
}
.docs-nav-header { display: none; font-weight: 650; cursor: pointer; padding: 2px 6px; }
.docs-nav-items { display: block; }
.docs-nav-section {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 12px 6px 4px;
}
.docs-nav-section:first-child { margin-top: 0; }
.docs-link {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-muted);
}
.docs-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.docs-link.active { background: var(--accent-soft); color: var(--accent); }

.docs-content { flex: 1; min-width: 0; }
.docs-section { display: none; }
.docs-section.active { display: block; }
.docs-title { font-size: 20px; margin-bottom: 6px; }
.docs-subtitle { font-size: 15px; font-weight: 650; margin: 22px 0 8px; }
.docs-p { color: var(--text-muted); margin-bottom: 10px; max-width: 74ch; }
.docs-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 16px 0 5px;
}
.docs-code-wrap { position: relative; margin-bottom: 12px; }
.docs-code {
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 40px 12px 14px;
  overflow-x: auto;
  white-space: pre;
  font-size: 12.2px;
  line-height: 1.6;
}
.btn-code-copy {
  position: absolute;
  top: 7px; right: 7px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 1px 7px;
}
.btn-code-copy:hover { color: var(--text); }
.docs-xref { font-size: 12.5px; color: var(--text-faint); }
.flow-prose { max-width: 74ch; }

.mermaid-diagram { margin: 14px 0; }
.mermaid-label { font-size: 12px; color: var(--text-faint); margin-bottom: 4px; }
.mermaid {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

@media (max-width: 860px) {
  .docs-layout { flex-direction: column; }
  .docs-nav { position: static; flex: none; width: 100%; }
  .docs-nav-header { display: flex; justify-content: space-between; }
  .docs-nav-items { display: none; }
  .docs-nav-items.open { display: block; }
}

/* ─── Utilities ─────────────────────────────────────────────── */

.muted { color: var(--text-muted); }
.link-muted { color: var(--text-muted); }
.text-mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.text-xs { font-size: 11.5px; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-2 { flex: 2; }
.items-center { align-items: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; } .mt-5 { margin-top: 20px; } .mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.prefix-wrap { display: flex; align-items: center; }
.prefix {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding: 6px 8px;
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}
.prefix-wrap input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; flex: 1; }

/* Responsive tables: stack cells on small screens */
@media (max-width: 640px) {
  .data-table thead { display: none; }
  .data-table tbody tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .data-table tbody td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: none;
    padding: 3px 12px;
  }
  .data-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-faint);
    font-size: 11.5px;
  }
  .data-table tbody td:not([data-label]) { justify-content: flex-end; }
}

/* Access management: role chips, the role editor's permission grid. */
.role-chips { flex-wrap: wrap; }
.role-chips .badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-3); color: var(--text-muted); border-color: var(--border-strong);
}
.role-chips .badge.owner, .role-chips .badge.admin {
  background: var(--accent-soft); color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
.role-chips .badge.operator, .role-chips .badge.auditor {
  background: var(--success-soft); color: var(--success);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
}
.role-chips form { display: inline; }
.chip-remove { background: none; border: 0; padding: 0 2px; cursor: pointer; color: inherit; opacity: .6; font-size: 11px; line-height: 1; }
.chip-remove:hover { opacity: 1; }
.select-xs { font-size: 12px; padding: 2px 4px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.perm-group { border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; }
.perm-group legend { font-weight: 600; font-size: 12px; padding: 0 4px; }
.perm-item { display: block; font-size: 12px; }
/* Client sharing sub-row. */
.sharing-block { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.sharing-block .seg form { display: inline; }
.sharing-advanced { flex-basis: 100%; }

/* Policy editor and simulator. */
.code-input { width: 100%; font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; line-height: 1.45; }
.sim-result { border-top: 1px solid var(--border); padding-top: 10px; }
