/* ==========================================================================
   GASCO Admin Control Plane — Utility Command Design System (v2.0)
   Design Audit Fix: type scale 6→13, spacing 8px grid, amber identity
   ========================================================================== */

/* ─── TOKEN LAYER ─────────────────────────────────────────────────────────── */
:root {
  /* Surface Colors — 3 levels only */
  --surface-0: #080d16;        /* Canvas / page background */
  --surface-1: #0f1623;        /* Sidebar, topbar, modals */
  --surface-2: #161e2e;        /* Cards, table backgrounds */
  --surface-3: rgba(255,255,255,0.05); /* Hover states, subtle fills */

  /* Border — single consistent value */
  --border: rgba(255,255,255,0.09);
  --border-focus: rgba(14,165,233,0.5);

  /* Brand Colors — 2 only */
  --brand: #0ea5e9;            /* Electric Cyan — action, links, CTA */
  --utility: #f59e0b;          /* Amber — GASCO identity, energy/utility stripe */

  /* Semantic Status — 3 only */
  --ok: #10b981;               /* Active / success */
  --warn: #f59e0b;             /* Draft / warning (reuses --utility) */
  --err: #ef4444;              /* Error / danger / high-risk */

  /* Text — 3 levels only */
  --text-hi: #f1f5f9;          /* Primary text, high contrast */
  --text-md: #94a3b8;          /* Secondary labels, descriptions */
  --text-lo: #475569;          /* Placeholders, disabled, very muted */

  /* Type Scale — 6 sizes, ratio 1.2 from 11px base */
  --text-xs:   11px;   /* Badge labels, legal, timestamps */
  --text-sm:   13px;   /* Table cells, secondary text, sidebar items */
  --text-base: 14px;   /* Body default, form inputs */
  --text-md-s: 16px;   /* Section titles, card headers */
  --text-lg:   20px;   /* Page-level subheadings */
  --text-xl:   28px;   /* Dashboard stat values */

  /* Font Weights — 3 only */
  --weight-regular: 400;
  --weight-medium:  600;
  --weight-bold:    700;

  /* Fonts */
  --font-ui:   'Inter', system-ui, -apple-system, sans-serif;
  --font-code: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing — 8px grid */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  24px;
  --sp-6:  32px;
  --sp-7:  48px;
  --sp-8:  64px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  /* Effects */
  --shadow: 0 4px 24px -8px rgba(0,0,0,0.6);
  --shadow-lg: 0 16px 48px -12px rgba(0,0,0,0.8);
  --glow-brand: 0 0 20px rgba(14,165,233,0.2);
  --glow-utility: 0 0 20px rgba(245,158,11,0.2);
  --transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
}

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

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── RESET ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  background-color: var(--surface-0);
  color: var(--text-hi);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ─── SIGNATURE ELEMENT: AMBIENT ORBS (Subtle, not aggressive) ─────────── */
/* Amber orb = GASCO utility identity; blue orb = tech/digital */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(140px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.18;
  animation: floatOrb 18s infinite alternate ease-in-out;
}
.orb-1 { width: 480px; height: 480px; background: var(--brand);   top: -100px; left: -80px; }
.orb-2 { width: 420px; height: 420px; background: var(--utility); bottom: -100px; right: -80px; animation-delay: -9s; }

@keyframes floatOrb {
  0%   { transform: translate(0,0) scale(1); }
  100% { transform: translate(30px,40px) scale(1.05); }
}

/* ─── APP SHELL ──────────────────────────────────────────────────────────── */
#app { position: relative; z-index: 1; width: 100%; height: 100vh; overflow: hidden; display: flex; }

/* ─── GLASS CARD (shared surface pattern) ───────────────────────────────── */
.glass-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
}

/* ─── AUTH LAYOUT ────────────────────────────────────────────────────────── */
.auth-wrapper {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: var(--sp-6);
  animation: cardFadeIn 0.4s ease-out;
}

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-header {
  text-align: center;
  margin-bottom: var(--sp-6);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.auth-logo-img {
  max-height: 42px;
  max-width: 140px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 12px rgba(14, 165, 233, 0.35));
  transition: var(--transition);
}

.sidebar-logo-img {
  max-height: 34px;
  max-width: 110px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(14, 165, 233, 0.25));
  transition: var(--transition);
}

/* Signature: brand icon with utility amber accent ring */
.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--brand) 0%, #38bdf8 100%);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #fff;
  box-shadow: var(--glow-brand);
  position: relative;
}

.brand-title {
  font-size: var(--text-md-s);
  font-weight: var(--weight-bold);
  color: var(--text-hi);
  letter-spacing: -0.02em;
}

.auth-subtitle {
  font-size: var(--text-sm);
  color: var(--text-md);
  line-height: 1.5;
}

/* ─── ALERTS ─────────────────────────────────────────────────────────────── */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
  line-height: 1.5;
}
.alert-danger  { background: rgba(239,68,68,0.12);  border: 1px solid rgba(239,68,68,0.3);  color: #fca5a5; }
.alert-success { background: rgba(16,185,129,0.12); border: 1px solid rgba(16,185,129,0.3); color: #6ee7b7; }
.alert-info    { background: rgba(14,165,233,0.12); border: 1px solid rgba(14,165,233,0.3); color: #7dd3fc; }

/* ─── FORM CONTROLS ──────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.form-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input {
  width: 100%;
  padding: 10px var(--sp-4);
  padding-left: 40px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-hi);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  outline: none;
  transition: var(--transition);
}

.form-input:not(.input-wrapper > .form-input) {
  padding-left: var(--sp-4);
}

select.form-input {
  padding-left: var(--sp-4);
  cursor: pointer;
}

.form-input::placeholder { color: var(--text-lo); }

.form-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}

.input-icon {
  position: absolute;
  left: var(--sp-3);
  color: var(--text-lo);
  font-size: 13px;
  pointer-events: none;
}

.toggle-pwd {
  position: absolute;
  right: var(--sp-3);
  background: none;
  border: none;
  color: var(--text-lo);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
  padding: var(--sp-1);
}
.toggle-pwd:hover { color: var(--text-hi); }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  font-size: var(--text-sm);
}

.remember-me {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-md);
  cursor: pointer;
}
.remember-me input { accent-color: var(--brand); }

.auth-link {
  color: var(--brand);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: var(--transition);
  cursor: pointer;
}
.auth-link:hover { color: #38bdf8; text-decoration: underline; }

/* ─── BUTTONS ────────────────────────────────────────────────────────────── */
.btn-primary {
  padding: 10px var(--sp-5);
  background: linear-gradient(135deg, var(--brand) 0%, #38bdf8 100%);
  border: none;
  border-radius: var(--r-sm);
  color: #fff;
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  box-shadow: var(--glow-brand);
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary:hover   { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active  { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary.full-width { width: 100%; }

.btn-secondary {
  padding: 8px var(--sp-4);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-ui);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  transition: var(--transition);
  white-space: nowrap;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); color: var(--text-hi); }

.btn-danger {
  padding: 8px var(--sp-4);
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--r-sm);
  color: #fca5a5;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-ui);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  transition: var(--transition);
}
.btn-danger:hover { background: rgba(239,68,68,0.2); color: #ef4444; }

/* ─── SPINNER ────────────────────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── DASHBOARD LAYOUT ───────────────────────────────────────────────────── */
.dashboard-layout {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ─── SIDEBAR ────────────────────────────────────────────────────────────── */
/* SIGNATURE: Amber utility stripe at top of sidebar header */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 248px;
  height: 100vh;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

/* Amber stripe — the signature that makes GASCO unique */
.sidebar::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--utility) 0%, transparent 100%);
  border-radius: 0 0 3px 0;
}

.sidebar-header {
  padding: var(--sp-4) var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.sidebar-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex: 1;
  padding: var(--sp-4) var(--sp-3);
  overflow-y: auto;
}

/* ─── NAV ITEMS ──────────────────────────────────────────────────────────── */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: var(--surface-3);
  color: var(--text-hi);
}

/* Active state: inset shadow instead of border-left (no layout shift) */
.nav-item.active {
  background: rgba(14,165,233,0.1);
  color: var(--brand);
  font-weight: var(--weight-medium);
  box-shadow: inset 3px 0 0 var(--brand);
}

.nav-icon {
  font-size: 14px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

/* ─── SIDEBAR FOOTER ─────────────────────────────────────────────────────── */
.sidebar-footer {
  padding: var(--sp-3) var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
}

.user-profile-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  gap: var(--sp-2);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  flex: 1;
}

.user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-hi);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: var(--text-xs);
  color: var(--text-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-md);
  cursor: pointer;
  font-size: 14px;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-logout:hover { background: rgba(239,68,68,0.15); color: var(--err); }

/* ─── MAIN CONTENT ───────────────────────────────────────────────────────── */
.main-content {
  margin-left: 248px;
  width: calc(100% - 248px);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
}

/* ─── TOPBAR ─────────────────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15,22,35,0.8);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.topbar-title {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-hi);
}

.btn-mobile-nav {
  display: none;
  background: none;
  border: none;
  color: var(--text-hi);
  font-size: var(--text-base);
  cursor: pointer;
  padding: var(--sp-1);
}

/* ─── SESSION BADGE — Signature pulse element ───────────────────────────── */
.session-badge {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: rgba(16,185,129,0.08);
  padding: var(--sp-1) var(--sp-3);
  border-radius: 20px;
  border: 1px solid rgba(16,185,129,0.2);
}

.pulse-dot {
  width: 7px; height: 7px;
  background: var(--ok);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--ok);
  animation: pulse 2.4s infinite ease-in-out;
}

@keyframes pulse {
  0%   { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16,185,129,0.6); }
  70%  { transform: scale(1.1); box-shadow: 0 0 0 5px rgba(16,185,129,0); }
  100% { transform: scale(0.9); }
}

.session-text {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: #6ee7b7;
}

/* ─── CONTENT BODY ───────────────────────────────────────────────────────── */
.content-body {
  padding: var(--sp-4);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ─── STATS GRID ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.stat-card {
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  transition: var(--transition);
}

/* First stat card gets amber accent — GASCO identity signal */
.stat-card:first-child {
  border-left: 3px solid var(--utility);
}

.stat-card:hover {
  background: rgba(255,255,255,0.03);
  transform: translateY(-1px);
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text-hi);
  letter-spacing: -0.02em;
  /* Numbers use Inter with tabular numerals — NOT monospace */
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Text stat values (non-numeric) are smaller and no tabular */
.stat-value.is-text {
  font-size: var(--text-md-s);
  font-weight: var(--weight-medium);
  letter-spacing: -0.01em;
}

.stat-sub {
  font-size: var(--text-xs);
  color: var(--text-md);
  line-height: 1.4;
}

/* ─── BADGES ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  font-family: var(--font-code);
  letter-spacing: 0.03em;
}

/* Risk badges */
.badge-risk-normal {
  background: rgba(100,116,139,0.15);
  color: #94a3b8;
  border: 1px solid rgba(100,116,139,0.25);
}

.badge-risk-high {
  background: rgba(239,68,68,0.12);
  color: #fca5a5;
  border: 1px solid rgba(239,68,68,0.25);
}

/* Status badges */
.badge-status-active {
  background: rgba(16,185,129,0.12);
  color: #6ee7b7;
  border: 1px solid rgba(16,185,129,0.25);
}

.badge-status-draft {
  background: rgba(245,158,11,0.12);
  color: #fcd34d;
  border: 1px solid rgba(245,158,11,0.25);
}

.badge-status-archived {
  background: rgba(100,116,139,0.12);
  color: #64748b;
  border: 1px solid rgba(100,116,139,0.2);
}

/* Permission group badges (in dashboard) */
.perm-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: var(--text-xs);
  font-family: var(--font-code);
  font-weight: var(--weight-regular);
  line-height: 1.6;
  white-space: nowrap;
}
.perm-admin    { background: rgba(99,102,241,0.12); color: #a5b4fc; border: 1px solid rgba(99,102,241,0.25); }
.perm-ai       { background: rgba(14,165,233,0.12); color: #7dd3fc; border: 1px solid rgba(14,165,233,0.25); }
.perm-knowledge{ background: rgba(16,185,129,0.12); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.25); }
.perm-service  { background: rgba(245,158,11,0.12); color: #fcd34d; border: 1px solid rgba(245,158,11,0.25); }
.perm-analytics{ background: rgba(236,72,153,0.12); color: #f9a8d4; border: 1px solid rgba(236,72,153,0.25); }
.perm-other    { background: rgba(100,116,139,0.12); color: #94a3b8; border: 1px solid rgba(100,116,139,0.2); }

/* ─── PROFILE INFO SECTION (Dashboard) ──────────────────────────────────── */
.profile-section {
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
}

.section-title {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  color: var(--text-hi);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}

.section-title .title-icon {
  color: var(--brand);
  font-size: 14px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: var(--sp-5);
}

.profile-info {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.profile-field-label {
  font-size: var(--text-xs);
  color: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: var(--weight-medium);
  margin-bottom: var(--sp-1);
}

.profile-field-value {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-hi);
}

.profile-field-value.email  { color: var(--brand); font-family: var(--font-code); font-size: var(--text-sm); }
.profile-field-value.status { color: var(--ok); }

.permissions-section-label {
  font-size: var(--text-xs);
  color: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: var(--weight-medium);
  margin-bottom: var(--sp-3);
}

.permissions-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  max-height: 160px;
  overflow-y: auto;
  padding-right: var(--sp-2);
}

/* ─── SERVICES TOOLBAR ───────────────────────────────────────────────────── */
.svc-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  flex-wrap: wrap;
}

.svc-toolbar .input-wrapper {
  flex: 1;
  min-width: 200px;
  max-width: 300px;
}

.svc-toolbar select.form-input {
  width: 140px;
  flex-shrink: 0;
  padding: 10px var(--sp-3);
}

.toolbar-spacer { flex: 1; }

/* ─── PAGE & TABLE VIEW FLEX CONSTRAINTS ─────────────────────────────────── */
#page-services-view:not(.hidden),
#page-chat-sessions-view:not(.hidden),
#page-audit-logs-view:not(.hidden),
#page-knowledge-view:not(.hidden),
#page-admin-users-view:not(.hidden),
#kb-services-view:not(.hidden),
#kb-documents-view:not(.hidden) {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

#page-services-view > .glass-card:first-child,
#page-chat-sessions-view > .glass-card:first-child,
#page-audit-logs-view > .glass-card:first-child,
#page-admin-users-view > .glass-card:first-child,
#kb-services-view > .glass-card:first-child,
#kb-documents-view > .glass-card:first-child {
  flex-shrink: 0 !important;
  margin-bottom: 16px !important;
}

#page-services-view > .glass-card:last-child,
#page-chat-sessions-view > .glass-card:last-child,
#page-audit-logs-view > .glass-card:last-child,
#page-admin-users-view > .glass-card:last-child,
#kb-services-view > .glass-card:last-child {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 !important;
  min-height: 0 !important;
  overflow: hidden !important;
  margin-bottom: 0 !important;
}

#page-dashboard-view,
#page-ai-config-view,
#page-widgets-view,
#page-system-settings-view {
  flex: 1 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  padding-right: var(--sp-1);
}

/* ─── ADMIN TABLE ────────────────────────────────────────────────────────── */
.table-container {
  flex: 1 !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow-y: auto !important;
  overflow-x: auto !important;
  position: relative !important;
}

.admin-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

.admin-table th {
  position: sticky !important;
  top: 0 !important;
  z-index: 20 !important;
  background: #0f1623 !important;
  box-shadow: 0 1px 0 var(--border) !important;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.admin-table td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
  color: var(--text-hi);
}

.admin-table tbody tr:hover {
  background: var(--surface-3);
}

.admin-table td code,
.admin-table td .code-text {
  font-family: var(--font-code);
  font-size: var(--text-xs);
  color: var(--brand);
}

.table-muted { color: var(--text-md) !important; font-size: var(--text-xs) !important; }

/* ─── TABLE ACTION BUTTONS ───────────────────────────────────────────────── */
.action-group {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  justify-content: flex-end;
}

.btn-action {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-md);
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
}
.btn-action:hover { background: rgba(14,165,233,0.12); color: var(--brand); border-color: rgba(14,165,233,0.3); }
.btn-action.danger:hover { background: rgba(239,68,68,0.12); color: var(--err); border-color: rgba(239,68,68,0.3); }

/* ─── PAGINATION ─────────────────────────────────────────────────────────── */
.pagination-bar {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 10px 70px 10px 16px !important;
  background: #0d1527 !important;
  border-top: 1px solid var(--border) !important;
  font-size: var(--text-xs);
  color: var(--text-md);
  flex-shrink: 0 !important;
  z-index: 30 !important;
  gap: 12px;
}

.pagination-left {
  font-size: var(--text-xs);
  color: var(--text-md);
  white-space: nowrap;
}

.pagination-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-center .btn-secondary {
  padding: 6px 12px;
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pagination-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-box {
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.page-box:hover {
  border-color: var(--brand);
  color: var(--text-hi);
  background: rgba(14, 165, 233, 0.15);
}

.page-box.active {
  background: var(--brand);
  color: #0d1527;
  border-color: var(--brand);
  font-weight: var(--weight-bold);
  box-shadow: 0 0 10px rgba(14, 165, 233, 0.4);
}

.page-box {
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-md);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  user-select: none;
}

.page-box:hover:not(.active):not(.disabled) {
  background: rgba(14, 165, 233, 0.15);
  border-color: rgba(14, 165, 233, 0.4);
  color: var(--brand);
}

.page-box.active {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 0 8px rgba(14, 165, 233, 0.4);
}

.page-box.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── MODAL ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,8,15,0.75);
  backdrop-filter: blur(6px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 540px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: modalSlide 0.25s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}

@keyframes modalSlide {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: var(--text-md-s);
  font-weight: var(--weight-bold);
  color: var(--text-hi);
}

.modal-subtitle {
  font-size: var(--text-xs);
  color: var(--text-md);
  margin-top: var(--sp-1);
  font-family: var(--font-code);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-md);
  font-size: 16px;
  cursor: pointer;
  padding: var(--sp-1);
  border-radius: var(--r-sm);
  transition: var(--transition);
  flex-shrink: 0;
  margin-left: var(--sp-3);
}
.modal-close:hover { color: var(--text-hi); background: var(--surface-3); }

.modal-body { padding: var(--sp-4) var(--sp-5) var(--sp-5); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

/* ─── DETAIL MODAL (wide) ────────────────────────────────────────────────── */
.modal-card.modal-wide { max-width: 720px; }

/* ─── TABS ───────────────────────────────────────────────────────────────── */
.detail-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-5);
  gap: var(--sp-1);
}

.tab-btn {
  padding: var(--sp-3) var(--sp-4);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-ui);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text-hi); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.15s ease; }

.tab-body { padding: var(--sp-4) var(--sp-5) var(--sp-5); }

/* Route/Alias add form */
.add-form {
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border);
}

.add-form-row {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-end;
}

.add-form-row .form-group { margin-bottom: 0; flex: 1; }
.add-form-row select.form-input { padding-left: var(--sp-3); }

/* ─── TOAST ──────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: var(--sp-5);
  right: var(--sp-5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.toast {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-hi);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--text-sm);
  animation: toastIn 0.25s ease forwards;
  min-width: 280px;
  max-width: 380px;
}

.toast-icon { font-size: 14px; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--ok); }
.toast.warning .toast-icon { color: var(--warn); }
.toast.danger  .toast-icon { color: var(--err); }
.toast.info    .toast-icon { color: var(--brand); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(32px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── UTILITY ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

code, .font-mono {
  font-family: var(--font-code);
  font-size: var(--text-xs);
}

.text-brand   { color: var(--brand); }
.text-utility { color: var(--utility); }
.text-ok      { color: var(--ok); }
.text-err     { color: var(--err); }
.text-muted   { color: var(--text-md); }

/* Legacy compat aliases (for app.js dynamic content) */
.stat-badge, .badge-role, .badge-active {
  display: inline-flex;
  padding: 2px var(--sp-2);
  border-radius: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: rgba(14,165,233,0.12);
  color: #7dd3fc;
  border: 1px solid rgba(14,165,233,0.2);
}

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .btn-mobile-nav { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0,0,0,0.6);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 90;
  }

  .topbar { padding: 0 var(--sp-4); }
  .content-body { padding: var(--sp-4); }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .svc-toolbar { gap: var(--sp-2); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .svc-toolbar .input-wrapper { max-width: none; }
}
