/* ============================================================================
   SGLang Manager — unified design system
   Single dark theme for the ROCm / 2× MI210 inference dashboard.

   All design tokens live under :root. The JS emits inline styles that
   reference a few legacy token names (--dim, --yellow, --panel, …), so those
   are aliased to the canonical set below — do not remove the aliases.
   ========================================================================== */

:root {
  /* Palette */
  --bg: #0a0d14;
  --bg-2: #0d111d;
  --surface: #121828;
  --surface-2: #192136;
  --surface-3: #232c46;
  --border: #26304a;
  --border-strong: #35436a;
  --text: #e9edf6;
  --text-2: #99a3bb;
  --text-3: #636d85;

  --accent: #6d7cff;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(109, 124, 255, 0.14);
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --purple: #a78bfa;
  --cyan: #22d3ee;

  /* Legacy aliases — JS inline styles + old markup depend on these. */
  --panel: var(--surface);
  --panel2: var(--surface-2);
  --panel3: var(--surface-3);
  --border2: var(--border-strong);
  --muted: var(--text-2);
  --dim: var(--text-3);
  --yellow: var(--amber);

  /* Shape + type */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas, monospace;

  /* Layout */
  --topbar-h: 54px;
  --status-h: 50px;
  --sidebar-w: 288px;
  --sidebar-w-collapsed: 62px;
  --telemetry-w: 384px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.42);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

/* Thin dark scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-3); border-radius: 6px;
  border: 2px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* ============================================================================
   App shell
   ========================================================================== */
#app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease;
}
#sidebar.collapsed {
  width: var(--sidebar-w-collapsed);
  min-width: var(--sidebar-w-collapsed);
}

.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 12px; flex-shrink: 0;
}
.logo-mark {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px; color: #fff;
  box-shadow: 0 4px 16px rgba(124, 110, 255, 0.42);
}
.logo-text { font-weight: 700; font-size: 14.5px; letter-spacing: 0.2px; white-space: nowrap; }
.logo-text small { display: block; color: var(--text-3); font-weight: 500; font-size: 11px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 26px; height: 26px;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  color: var(--text-3); cursor: pointer; font-size: 14px; line-height: 1;
  transition: all 0.14s; margin-left: auto; flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); background: var(--surface); border-color: var(--border); }
#sidebar-toggle { transition: transform 0.2s ease; }
#sidebar.collapsed #sidebar-toggle { transform: rotate(180deg); }

.gpu-mini {
  margin: 6px 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.gpu-mini-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); margin-bottom: 7px; }
.gpu-mini-head b { color: var(--text); font-weight: 600; }
.gpu-mini .bar { margin-bottom: 6px; }
.gpu-mini-stats { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-3); font-family: var(--mono); }

.sidebar-section { padding: 14px 12px 8px; flex: 1; overflow-y: auto; }
.sidebar-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: 1.2px;
  color: var(--text-3); margin-bottom: 8px; text-transform: uppercase; white-space: nowrap;
}
.engine-meta {
  display: flex; flex-direction: column; gap: 6px;
  margin: 0 0 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface);
}
.engine-meta-row {
  display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.engine-meta-row span {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-3);
}
.engine-meta-row b {
  font-size: 12px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.engine-profile-switch { display: flex; gap: 6px; align-items: center; }
.engine-profile-switch select {
  flex: 1; min-width: 0; font-size: 11.5px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 6px;
}
.server-mini {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  margin-bottom: 6px; cursor: pointer; transition: border-color 0.15s;
}
.server-mini:hover { border-color: var(--border-strong); }
.server-mini .name { flex: 1; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-mini .port { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }

.sidebar-footer {
  padding: 12px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.sidebar-footer .dim-hint { font-size: 11px; color: var(--text-3); }

/* Collapsed sidebar */
#sidebar.collapsed .logo { flex-direction: column; gap: 8px; padding: 14px 0 12px; }
#sidebar.collapsed .logo-text { display: none; }
#sidebar.collapsed #sidebar-toggle { margin-left: 0; }
#sidebar.collapsed #gpu-mini-panel { display: none; }
#sidebar.collapsed .sidebar-title,
#sidebar.collapsed .engine-meta { display: none; }
#sidebar.collapsed .sidebar-section { padding: 8px; }
#sidebar.collapsed .server-mini { justify-content: center; padding: 8px 0; border: none; background: transparent; }
#sidebar.collapsed .server-mini .pill { font-size: 0; gap: 0; padding: 4px; }
#sidebar.collapsed .server-mini .name,
#sidebar.collapsed .server-mini .port { display: none; }
#sidebar.collapsed .sidebar-footer { justify-content: center; }
#sidebar.collapsed .sidebar-footer .dim-hint { display: none; }

/* ---------- Main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  height: var(--topbar-h); padding: 0 16px; flex-shrink: 0;
  border-bottom: 1px solid var(--border); background: var(--bg-2);
}
#tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; border: 1px solid transparent; color: var(--text-2);
  font: 600 13px var(--font); padding: 7px 13px; border-radius: 8px;
  cursor: pointer; transition: all 0.14s; white-space: nowrap; flex-shrink: 0;
}
.tab .ico { width: 16px; text-align: center; font-size: 13px; }
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active {
  color: var(--accent-2); background: var(--accent-soft);
  border-color: rgba(109, 124, 255, 0.3);
}
.tab .count { color: var(--text-3); font-size: 11px; margin-left: 1px; }

#topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

#content { flex: 1; overflow: hidden; position: relative; min-height: 0; }
.tab-panel { display: none; }
.tab-panel.active { display: block; height: 100%; }
.tab-panel.scroll.active { overflow-y: auto; padding: 18px 22px 28px; }
.tab-panel.chat-panel.active { display: flex; overflow: hidden; padding: 0; }

/* ============================================================================
   Status strip (persistent, all tabs)
   ========================================================================== */
.status-strip {
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
  min-height: var(--status-h); padding: 8px 16px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-2) 100%);
  border-bottom: 1px solid var(--border);
}
.status-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.status-model {
  font-weight: 600; font-size: 13px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 360px;
}
.status-sub { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.status-spacer { flex: 1; }
.status-metrics { display: flex; align-items: center; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.status-metrics::-webkit-scrollbar { display: none; }

.s-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 8px; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border);
}
.s-chip .k {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-3);
}
.s-chip .v { font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text); }
.s-chip.tone-green .v { color: var(--green); }
.s-chip.tone-amber .v { color: var(--amber); }
.s-chip.tone-red .v { color: var(--red); }
.s-chip.tone-purple .v { color: var(--purple); }
.s-chip.tone-blue .v { color: var(--blue); }

/* Connection indicator */
.conn { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.conn .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); }
.conn.online { color: var(--green); }
.conn.online .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.conn.offline { color: var(--red); }
.conn.offline .dot { background: var(--red); }
.conn.degraded { color: var(--amber); }
.conn.degraded .dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }

.kernel-chip {
  font-size: 11px; font-weight: 700; letter-spacing: 0.4px;
  padding: 4px 11px; border-radius: 999px; white-space: nowrap;
  background: linear-gradient(135deg, rgba(109, 124, 255, 0.22), rgba(139, 92, 246, 0.22));
  border: 1px solid #3a4570; color: #c9ceff;
}
.model-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 13px; border-radius: 50px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 12.5px; color: var(--text-2); max-width: 380px;
}
.model-chip strong { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================================
   Pills, badges, buttons
   ========================================================================== */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; padding: 3px 10px;
  border-radius: 999px; border: 1px solid var(--border-strong);
  color: var(--text-2); background: var(--surface-2); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--green); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.08); }
.pill.loading { color: var(--amber); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }
.pill.loading .dot { animation: pulse 1.2s infinite; }
.pill.err { color: var(--red); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.08); }
.pill.info { color: var(--blue); border-color: rgba(96, 165, 250, 0.35); background: rgba(96, 165, 250, 0.08); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 5px;
  font-family: var(--mono); letter-spacing: 0.3px;
}
.badge.quant { background: var(--accent-soft); color: #aab4ff; border: 1px solid rgba(109, 124, 255, 0.3); }
.badge.kind-image { background: rgba(96, 165, 250, 0.12); color: var(--blue); border: 1px solid rgba(96, 165, 250, 0.3); }
.badge.kind-audio { background: rgba(251, 191, 36, 0.1); color: var(--amber); border: 1px solid rgba(251, 191, 36, 0.3); }
.badge.kind-text { background: rgba(52, 211, 153, 0.1); color: var(--green); border: 1px solid rgba(52, 211, 153, 0.3); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--font); color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  transition: all 0.14s; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; color: #fff; box-shadow: 0 4px 14px rgba(124, 110, 255, 0.32);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn-green { background: var(--green); color: #04210f; border-color: transparent; }
.btn-green:hover:not(:disabled) { filter: brightness(1.1); }
.btn-red { background: var(--red); color: #2a0606; border-color: transparent; }
.btn-red:hover:not(:disabled) { filter: brightness(1.1); }
.btn-accent { background: var(--accent); color: #fff; border-color: transparent; }
.btn-accent:hover:not(:disabled) { background: var(--accent-2); }
.btn-danger { color: var(--red); border-color: rgba(248, 113, 113, 0.35); background: transparent; }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.1); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 7px; }
.btn-icon { padding: 6px 9px; }

/* ============================================================================
   Forms
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label {
  font-size: 11px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.field input[type="text"], .field input[type="number"], .field input[type="password"],
.field select, .field textarea {
  width: 100%; padding: 8px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: 13px var(--font); outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field select { cursor: pointer; }
.field textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
.field input[type="number"] { font-variant-numeric: tabular-nums; }
.field input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.field input:disabled { opacity: 0.5; cursor: not-allowed; }
.field .hint { font-size: 10.5px; color: var(--text-3); }

.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }

.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.subsection-title {
  font-size: 11.5px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.05em; margin: 18px 0 10px;
  border-top: 1px solid var(--border); padding-top: 16px;
}
.subsection-title:first-child { margin-top: 0; border-top: none; padding-top: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }

input[type="range"] {
  -webkit-appearance: none; height: 4px; border-radius: 2px;
  background: var(--surface-3); padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--surface);
}
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row output { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); width: 44px; text-align: right; }

/* ============================================================================
   Bars, gauges, sparklines, stat boxes
   ========================================================================== */
.bar { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width 0.4s ease; }
.bar.green > i { background: var(--green); }
.bar.amber > i { background: var(--amber); }
.bar.red > i { background: var(--red); }
.bar .bar-fill { height: 100%; border-radius: 4px; background: var(--accent); transition: width 0.4s ease; }
.bar-fill.green { background: var(--green); }
.bar-fill.yellow { background: var(--amber); }
.bar-fill.red { background: var(--red); }
.bar-fill.purple { background: var(--purple); }
.bar-fill.cyan { background: var(--cyan); }

.gauge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; }
.gauge {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 14px;
  position: relative; overflow: hidden;
  transition: border-color 0.15s;
}
.gauge:hover { border-color: var(--border-strong); }
.gauge .label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-3);
}
.gauge .value {
  font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 3px;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.gauge .unit { font-size: 12px; font-weight: 500; color: var(--text-3); margin-left: 2px; }
.gauge .sub { font-size: 11px; color: var(--text-3); margin-top: 3px; }
.gauge .bar { height: 5px; background: var(--surface-3); border-radius: 3px; margin-top: 10px; overflow: hidden; }

.spark-card { margin-bottom: 14px; }
.spark-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.spark-head .label { font-size: 11px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
.spark-head .cur { font-size: 12.5px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 56px; display: block; }
.spark svg { width: 100%; height: 100%; display: block; }

.stat-box { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; }
.stat-box .k { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-box .v { font-family: var(--mono); font-size: 15px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

.system-row { display: flex; flex-wrap: wrap; gap: 12px 28px; font-size: 13px; color: var(--text-2); }
.system-row b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ============================================================================
   Panels + cards
   ========================================================================== */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.panel-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; cursor: pointer; user-select: none;
}
.panel-header:hover { background: var(--surface-2); }
.panel-header .ptitle {
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-2);
  display: flex; align-items: center; gap: 8px;
}
.panel-header .ptitle .ico { font-size: 14px; }
.panel-header .chev { margin-left: auto; color: var(--text-3); transition: transform 0.2s; font-size: 12px; }
.panel.collapsed .chev { transform: rotate(-90deg); }
.panel-header .hint { font-size: 11.5px; color: var(--text-3); font-weight: 400; }
.panel-body { padding: 16px; border-top: 1px solid var(--border); }
.panel.collapsed .panel-body { display: none; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.card h2 {
  font-size: 13px; font-weight: 700; margin-bottom: 14px; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.05em;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.card h2 .hint { font-size: 11.5px; font-weight: 400; text-transform: none; color: var(--text-3); }

.section-title { font-size: 10.5px; font-weight: 700; letter-spacing: 1.1px; color: var(--text-3); text-transform: uppercase; }
.dim-hint { font-size: 12px; color: var(--text-3); line-height: 1.6; }
.dim-hint code { font-family: var(--mono); font-size: 11px; color: var(--accent); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.empty-hint {
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 34px 20px; text-align: center; color: var(--text-3); background: var(--surface);
}

/* ============================================================================
   Server tab — live server + config + telemetry
   ========================================================================== */
.live-server-wrap { padding: 0 0 16px; }
.dash-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--telemetry-w);
  gap: 16px; align-items: start;
}

.server-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.server-card-head {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.server-card-head .meta { flex: 1; min-width: 0; }
.server-card-head .meta b { font-size: 14px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-card-head .meta .sub { font-size: 11.5px; color: var(--text-3); font-family: var(--mono); }
.server-card-actions { display: flex; gap: 6px; }
.server-card-body { padding: 14px 16px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.server-card-body .stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }

.ctx-bar-wrap { margin-top: 8px; }
.ctx-bar-wrap .lbl { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-3); margin-bottom: 4px; font-family: var(--mono); }

/* ============================================================================
   Tables
   ========================================================================== */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--border); }
.data-table th {
  color: var(--text-3); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 700;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.data-table .big { font-size: 14px; font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }

.slots-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.slots-table th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--text-3); padding: 6px 8px; border-bottom: 1px solid var(--border); font-weight: 700;
}
.slots-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 11.5px; }
.slots-table tr:last-child td { border-bottom: none; }
.slot-state { display: inline-flex; align-items: center; gap: 6px; }
.slot-state .dot { width: 7px; height: 7px; border-radius: 50%; }
.slot-state.idle .dot { background: var(--text-3); }
.slot-state.processing .dot { background: var(--blue); animation: pulse 1s infinite; }
.slot-state.generating .dot { background: var(--green); animation: pulse 0.8s infinite; }
.slot-state.error .dot { background: var(--red); }
.slot-user-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-user-chip .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.slot-user { max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-none { color: var(--text-3); }

.usage-log-wrap { max-height: 420px; overflow: auto; margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.live-dot { color: var(--green); animation: pulse 0.9s infinite; }
tr.row-live td { background: rgba(52, 211, 153, 0.06); }
.token-inflight { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.inflight-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-2); font-size: 12px; font-family: var(--mono);
}

/* ============================================================================
   GPU tab
   ========================================================================== */
.gpu-wrap {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px; margin-bottom: 16px;
}
.gpu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.gpu-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; transition: border-color 0.15s; }
.gpu-card:hover { border-color: var(--border-strong); }
.gpu-card h3 { font-size: 14px; margin-bottom: 4px; }
.gpu-card .sub { font-size: 11px; color: var(--text-3); font-family: var(--mono); margin-bottom: 14px; }
.gpu-big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.gpu-big .stat-box { text-align: center; }
.gpu-big .stat-box .v { font-size: 21px; }
.gpu-big .stat-box .k { display: block; margin-bottom: 2px; }
.gpu-name { font-weight: 600; font-size: 13px; margin-bottom: 9px; }
.gpu-bar { height: 6px; background: var(--surface-3); border-radius: 3px; margin: 6px 0; overflow: hidden; }
.gpu-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s; }
.gpu-bar-fill.mem { background: var(--accent); }
.gpu-bar-fill.util { background: var(--green); }
.gpu-stat { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin: 3px 0; }
.gpu-stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.kv-est-grid { display: grid; grid-template-columns: 1fr auto; gap: 3px 18px; font-family: var(--mono); font-size: 11px; }
.kv-est-grid b { color: var(--text); text-align: right; }

/* ============================================================================
   Models tab
   ========================================================================== */
.model-list { display: flex; flex-direction: column; gap: 10px; }
.model-option {
  display: flex; align-items: center; gap: 13px; padding: 13px 15px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  transition: all 0.14s; background: var(--surface-2);
}
.model-option:hover { border-color: var(--accent); }
.model-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.model-option input[type="radio"] { accent-color: var(--accent); transform: scale(1.15); }
.model-info { flex: 1; min-width: 0; }
.model-name { font-weight: 600; font-size: 14px; }
.model-meta { font-size: 12px; color: var(--text-2); display: flex; gap: 7px; margin-top: 3px; flex-wrap: wrap; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.tag.quant { color: var(--purple); border-color: rgba(167, 139, 250, 0.35); background: rgba(167, 139, 250, 0.1); }
.tag.mm { color: var(--accent-2); border-color: rgba(91, 140, 255, 0.35); background: rgba(91, 140, 255, 0.1); }

/* ============================================================================
   Download tab
   ========================================================================== */
.search-row { display: flex; gap: 10px; margin-bottom: 14px; }
.search-row input {
  flex: 1; padding: 10px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 13.5px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.search-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hf-results { display: flex; flex-direction: column; gap: 9px; }
.hf-result {
  display: flex; align-items: center; gap: 13px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}
.hf-result:hover { border-color: var(--border-strong); }
.hf-result .info { flex: 1; min-width: 0; }
.hf-result .id { font-weight: 600; font-size: 13.5px; word-break: break-all; }
.hf-result .meta { font-size: 11.5px; color: var(--text-2); display: flex; gap: 12px; margin-top: 2px; }
.download-item {
  display: flex; align-items: center; gap: 13px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px;
}
.download-item .info { flex: 1; min-width: 0; }
.download-item .status { font-size: 12px; font-weight: 600; }
.download-item .status.done { color: var(--green); }
.download-item .status.error { color: var(--red); }
.download-item .status.downloading { color: var(--accent); }
.progress { height: 7px; background: var(--surface-3); border-radius: 4px; margin-top: 7px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.5s; }

/* ============================================================================
   Keys tab + usage export
   ========================================================================== */
.keys-wrap { padding: 18px 22px 28px; height: 100%; overflow-y: auto; }
.keys-toolbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 20px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.keys-toolbar .section-title { font-size: 15px; margin-bottom: 6px; letter-spacing: 0; }
.keys-toolbar code { font-family: var(--mono); font-size: 11px; color: var(--accent); }
.key-create { display: flex; gap: 8px; align-items: center; }
.key-create input {
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 12px; font-size: 12.5px; width: 220px; outline: none;
  transition: border-color 0.15s;
}
.key-create input:focus { border-color: var(--accent); }
.keys-total { font-family: var(--mono); font-size: 11px; color: var(--text-3); margin-bottom: 12px; letter-spacing: 0.4px; }
.keys-table { display: flex; flex-direction: column; gap: 12px; max-width: 1100px; }
.key-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.key-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.key-head .key-name { font-size: 13.5px; }
.key-actions { margin-left: auto; display: flex; gap: 6px; }
.key-value { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-family: var(--mono); font-size: 11.5px; }
.key-value code {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 10px; word-break: break-all; color: var(--accent);
}
.key-value code.masked {
  color: var(--text-3);
  background: repeating-linear-gradient(90deg, var(--bg-2) 0 8px, #161c2b 8px 16px);
  user-select: all;
}
.key-stats { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.key-stats .stat-box { min-width: 96px; }
.key-stats .stat-box .v { font-size: 13px; }
.key-spark { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 220px; }
.key-spark .spark { width: 100%; height: 30px; }
.key-spark .spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.key-spark .spark-lbl { font-size: 9.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.7px; white-space: nowrap; }
.key-meta { display: flex; gap: 18px; font-size: 11px; color: var(--text-3); margin-top: 8px; flex-wrap: wrap; }
.key-meta b { color: var(--text-2); font-weight: 600; }

.usage-export { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.usage-export-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.usage-date { display: flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 12px; }
.usage-date input[type="date"] {
  background: #12182a; color: inherit; border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font: inherit; color-scheme: dark;
}

/* ============================================================================
   Logs tab
   ========================================================================== */
.log-viewer {
  background: #07080c; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 15px; font-family: var(--mono); font-size: 12px; line-height: 1.7;
  height: 480px; overflow-y: auto; white-space: pre-wrap; color: var(--text-2);
}
.log-viewer .ln { white-space: pre-wrap; word-break: break-all; }
.log-viewer .t { color: var(--text-3); margin-right: 8px; }
.log-viewer .lvl-I { color: #9aa7c7; }
.log-viewer .lvl-W { color: var(--amber); }
.log-viewer .lvl-E { color: var(--red); }
.log-viewer .ok-line { color: var(--green); }

/* ============================================================================
   Tokens tab
   ========================================================================== */
.chart-wrap { height: 230px; position: relative; }

/* ============================================================================
   Integrations
   ========================================================================== */
.code-block {
  background: #0a0b0f; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
  word-break: break-all; position: relative; margin-bottom: 16px;
}
.copy-btn { position: absolute; top: 8px; right: 8px; }

/* ============================================================================
   Chat
   ========================================================================== */
.chat-wrap { display: flex; height: 100%; min-height: 0; }
.sessions-col {
  width: 232px; min-width: 232px; border-right: 1px solid var(--border);
  background: var(--bg-2); display: flex; flex-direction: column; overflow: hidden;
}
.sessions-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px; }
.sessions-title { font-size: 10.5px; font-weight: 700; letter-spacing: 1.2px; color: var(--text-3); text-transform: uppercase; }
.sessions-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.session-row {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 2px;
  transition: background 0.12s; position: relative;
}
.session-row:hover { background: var(--surface); }
.session-row.active { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.session-row .stitle { flex: 1; min-width: 0; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.session-row .ssub { font-size: 10px; color: var(--text-3); font-family: var(--mono); }
.session-row .sact { display: none; gap: 2px; }
.session-row:hover .sact { display: inline-flex; }
.sact button {
  background: transparent; border: none; color: var(--text-3); cursor: pointer;
  font-size: 12px; padding: 2px 4px; border-radius: 4px; line-height: 1;
}
.sact button:hover { color: var(--text); background: var(--surface-3); }
.sact button.danger:hover { color: var(--red); }
.session-row .sedit {
  flex: 1; min-width: 0; background: var(--bg); color: var(--text);
  border: 1px solid var(--accent); border-radius: 6px; padding: 4px 7px;
  font: 12.5px var(--font); outline: none;
}

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 20px 26px; }
.msg { display: flex; gap: 12px; margin-bottom: 18px; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.msg.user .avatar { background: linear-gradient(135deg, #33415c, #1f2940); color: #9fb0d8; }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.msg .body { flex: 1; min-width: 0; }
.msg .bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px; padding: 12px 15px; max-width: 820px;
  white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px; line-height: 1.65;
}
.msg.user .bubble { background: var(--surface-2); border-radius: 14px 4px 14px 14px; }
.msg .meta { font-size: 10.5px; color: var(--text-3); margin-top: 5px; font-family: var(--mono); }
.reasoning {
  margin-bottom: 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-2); overflow: hidden;
}
.reasoning summary { cursor: pointer; padding: 7px 11px; font-size: 11px; color: var(--amber); font-weight: 600; user-select: none; }
.reasoning .rbody { padding: 4px 12px 10px; font-size: 12px; color: var(--text-2); white-space: pre-wrap; max-height: 240px; overflow-y: auto; font-style: italic; }
.typing { display: inline-flex; gap: 3px; align-items: center; height: 16px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-2); animation: pulse 1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

.chat-input-bar {
  border-top: 1px solid var(--border); background: var(--bg-2);
  padding: 12px 22px; display: flex; gap: 10px; align-items: flex-end;
}
.chat-input-bar textarea {
  flex: 1; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 11px 14px; font: 13.5px var(--font); resize: none; outline: none;
  max-height: 160px; line-height: 1.5; transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-bar textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chat-side {
  width: 284px; min-width: 284px; border-left: 1px solid var(--border);
  background: var(--bg-2); padding: 14px; overflow-y: auto;
}
.chat-side .section-title { margin: 14px 0 8px; }
.chat-side .section-title:first-child { margin-top: 0; }
.server-select-row { display: flex; gap: 6px; }
.server-select-row select { flex: 1; }
.new-chat-btn { width: 100%; }

/* ============================================================================
   History drawer
   ========================================================================== */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; backdrop-filter: blur(2px);
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 91;
  width: min(460px, 94vw); background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform 0.24s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer-head .title { font-size: 15px; font-weight: 700; }
.drawer-head .spacer { flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px; }

.hist-item {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 13px; margin-bottom: 10px; transition: border 0.12s;
}
.hist-item:hover { border-color: var(--border-strong); }
.hist-item .h-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.hist-item .h-prompt {
  font-size: 12.5px; color: var(--text-2); white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 8px;
}
.hist-item .h-time { font-size: 11px; color: var(--text-3); }
.hist-item .h-status { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.hist-item .h-status.success { color: var(--green); background: rgba(52, 211, 153, 0.12); }
.hist-item .h-status.error { color: var(--red); background: rgba(248, 113, 113, 0.12); }
.hist-metrics { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11.5px; color: var(--text-2); margin-bottom: 8px; }
.hist-metrics b { color: var(--text); font-variant-numeric: tabular-nums; }
.hist-params { font-size: 11px; color: var(--text-3); margin-bottom: 8px; font-family: var(--mono); }
.hist-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.compare-bar { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 12.5px; }
.compare-bar table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.compare-bar th, .compare-bar td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); }
.compare-bar th:first-child, .compare-bar td:first-child { text-align: left; }

/* ============================================================================
   Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 6, 10, 0.7);
  display: grid; place-items: center; z-index: 50; backdrop-filter: blur(3px);
}
.modal {
  width: 560px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 20px;
}
.modal h3 { font-size: 15px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .mono-path { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); word-break: break-all; }

/* ============================================================================
   Toast + spinner
   ========================================================================== */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text);
  padding: 10px 20px; border-radius: 10px; font-size: 12.5px; z-index: 100;
  box-shadow: var(--shadow); opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.err { border-color: rgba(248, 113, 113, 0.5); color: var(--red); }

.toast {
  position: fixed; bottom: 22px; right: 22px; padding: 13px 20px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 13px; z-index: 100; animation: slideUp 0.28s ease; max-width: 420px;
  box-shadow: var(--shadow);
}
.toast.success { background: #0f2e1f; border: 1px solid #166534; color: var(--green); }
.toast.error { background: #2a1212; border: 1px solid #991b1b; color: var(--red); }
.toast.info { background: #101b33; border: 1px solid #1e3a8a; color: var(--accent-2); }
@keyframes slideUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }

.spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid transparent; border-top-color: currentColor; border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1280px) {
  .dash-layout { grid-template-columns: 1fr; }
  :root { --telemetry-w: 100%; }
}
@media (max-width: 760px) {
  #sidebar { width: var(--sidebar-w-collapsed); min-width: var(--sidebar-w-collapsed); }
  .gauge-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .server-card-body { grid-template-columns: 1fr; }
  .chat-side { display: none; }
}
