:root {
  --font-sans: "Inter", "HarmonyOS Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, ui-monospace, monospace;

  /* Scheme 1 Default: Precision SaaS Light (方案一：现代精密 B 端 SaaS 风) */
  --bg-canvas: #f3f5f9;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;
  --bg-input: #ffffff;
  --bg-hover: #f1f5fb;
  --bg-active: #eff6ff;

  --ink-strong: #0f172a;
  --ink-base: #1e293b;
  --ink-secondary: #475569;
  --ink-muted: #64748b;

  --border-subtle: #e6ebf2;
  --border-base: #dce3ee;
  --border-strong: #cbd5e1;

  --brand-50: #eff6ff;
  --brand-100: #dbeafe;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --brand-glow: rgba(37, 99, 235, 0.16);
  --accent-gold: #d97706;

  --emerald-bg: #ecfdf5;
  --emerald-ink: #047857;
  --emerald-border: #a7f3d0;

  --amber-bg: #fffbeb;
  --amber-ink: #b45309;
  --amber-border: #fde68a;

  --rose-bg: #fff1f2;
  --rose-ink: #be123c;
  --rose-border: #fecdd3;

  --violet-bg: #f5f3ff;
  --violet-ink: #6d28d9;
  --violet-border: #ddd6fe;

  --sidebar-w: 248px;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e4e9f2;
  --sidebar-ink: #334155;
  --sidebar-muted: #64748b;
  --sidebar-group-ink: #64748b;
  --sidebar-hover-bg: #f4f7fb;
  --sidebar-active-bg: #eff6ff;
  --sidebar-active-ink: #1d4ed8;
  --sidebar-active-bar: #2563eb;

  --topbar-h: 56px;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --radius-card: 12px;
  --radius-ctrl: 8px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.03), 0 4px 14px -4px rgba(15, 23, 42, 0.04);
  --shadow-float: 0 14px 38px -6px rgba(15, 23, 42, 0.16), 0 4px 12px -2px rgba(15, 23, 42, 0.06);
  --cell-pad-y: 10px;
  --cell-pad-x: 12px;
}

html[data-density="compact"] {
  --cell-pad-y: 6px;
  --cell-pad-x: 10px;
  --topbar-h: 50px;
}

/* ==========================================================================
   SCHEME 2: 沉稳政企深色侧栏风 (Executive Deep-Navy)
   ========================================================================== */
html[data-scheme="gov"] {
  --bg-canvas: #edf1f7;
  --bg-card: #ffffff;
  --bg-subtle: #f4f7fb;
  --bg-muted: #e9eff7;
  --border-subtle: #dce4ef;
  --border-base: #cfd9e6;
  --border-strong: #b8c6d9;

  --brand-50: #eef4ff;
  --brand-100: #d9e6ff;
  --brand-500: #2b6cb0;
  --brand-600: #1e4e8c;
  --brand-700: #153e75;
  --brand-glow: rgba(30, 78, 140, 0.2);
  --accent-gold: #e5b85c;

  --sidebar-w: 252px;
  --sidebar-bg: linear-gradient(180deg, #071324 0%, #0c1e38 58%, #08162a 100%);
  --sidebar-border: #162b49;
  --sidebar-ink: #cbd5e1;
  --sidebar-muted: #94a3b8;
  --sidebar-group-ink: #7c93b0;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
  --sidebar-active-bg: linear-gradient(90deg, rgba(37, 99, 235, 0.36) 0%, rgba(37, 99, 235, 0.08) 100%);
  --sidebar-active-ink: #ffffff;
  --sidebar-active-bar: #e5b85c;

  --radius-card: 7px;
  --radius-ctrl: 6px;
  --shadow-card: 0 1px 2px rgba(9, 21, 38, 0.05);
}

/* ==========================================================================
   SCHEME 3: 智能科技 AI 工作台风 (Aurora Glass Studio)
   ========================================================================== */
html[data-scheme="ai"] {
  --bg-canvas: #f3f5fc;
  --bg-card: rgba(255, 255, 255, 0.92);
  --bg-subtle: rgba(246, 248, 255, 0.9);
  --bg-muted: #eef1fb;
  --border-subtle: rgba(99, 102, 241, 0.13);
  --border-base: rgba(99, 102, 241, 0.2);
  --border-strong: rgba(99, 102, 241, 0.34);

  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-glow: rgba(79, 70, 229, 0.2);

  --sidebar-w: 244px;
  --sidebar-bg: rgba(255, 255, 255, 0.86);
  --sidebar-border: rgba(99, 102, 241, 0.16);
  --sidebar-active-bg: linear-gradient(90deg, rgba(79, 70, 229, 0.12), rgba(6, 182, 212, 0.08));
  --sidebar-active-ink: #4338ca;
  --sidebar-active-bar: #4f46e5;

  --radius-card: 16px;
  --radius-ctrl: 9px;
  --shadow-card: 0 2px 6px rgba(30, 27, 75, 0.03), 0 10px 26px -8px rgba(79, 70, 229, 0.08);
}

/* ==========================================================================
   DARK MODE OVERRIDES
   ========================================================================== */
html[data-theme="dark"] {
  --bg-canvas: #090e1a;
  --bg-card: #111827;
  --bg-subtle: #162033;
  --bg-muted: #1e293b;
  --bg-input: #0d1424;
  --bg-hover: #1c283d;
  --bg-active: rgba(59, 130, 246, 0.16);

  --ink-strong: #f8fafc;
  --ink-base: #e2e8f0;
  --ink-secondary: #cbd5e1;
  --ink-muted: #94a3b8;

  --border-subtle: #1e293b;
  --border-base: #283548;
  --border-strong: #384963;

  --brand-50: rgba(59, 130, 246, 0.15);
  --brand-100: rgba(59, 130, 246, 0.26);
  --brand-500: #60a5fa;
  --brand-600: #3b82f6;
  --brand-700: #93c5fd;

  --emerald-bg: rgba(16, 185, 129, 0.14);
  --emerald-ink: #34d399;
  --emerald-border: rgba(52, 211, 153, 0.3);

  --amber-bg: rgba(245, 158, 11, 0.14);
  --amber-ink: #fbbf24;
  --amber-border: rgba(251, 191, 36, 0.3);

  --rose-bg: rgba(244, 63, 94, 0.15);
  --rose-ink: #fb7185;
  --rose-border: rgba(251, 113, 133, 0.3);

  --violet-bg: rgba(139, 92, 246, 0.16);
  --violet-ink: #c4b5fd;
  --violet-border: rgba(196, 181, 253, 0.3);

  --sidebar-bg: #0c1322;
  --sidebar-border: #1e293b;
  --sidebar-ink: #cbd5e1;
  --sidebar-muted: #94a3b8;
  --sidebar-group-ink: #64748b;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.05);
  --sidebar-active-bg: rgba(59, 130, 246, 0.18);
  --sidebar-active-ink: #93c5fd;
  --topbar-bg: rgba(15, 23, 42, 0.88);
  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.32);
}

html[data-theme="dark"][data-scheme="ai"] {
  --bg-canvas: #060913;
  --bg-card: rgba(17, 24, 42, 0.88);
  --bg-subtle: rgba(23, 32, 56, 0.84);
  --sidebar-bg: rgba(14, 20, 36, 0.88);
  --brand-500: #818cf8;
  --brand-600: #6366f1;
  --brand-700: #a5b4fc;
  --sidebar-active-ink: #a5b4fc;
}

/* ==========================================================================
   BASE RESET & QUALITY GATES (>=12px everywhere, zero horizontal overflow)
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-base);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
}

body.admin-shell-body {
  overflow: hidden;
}

html[data-scheme="ai"] body {
  background-image:
    radial-gradient(at 8% 0%, rgba(79, 70, 229, 0.10) 0px, transparent 42%),
    radial-gradient(at 92% 6%, rgba(6, 182, 212, 0.09) 0px, transparent 38%),
    radial-gradient(at 52% 100%, rgba(99, 102, 241, 0.07) 0px, transparent 45%);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: inherit;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.32);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.52);
}

.mono, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.ui-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.hidden {
  display: none !important;
}

/* Custom Precision Checkbox */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-input);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.14s ease;
  margin: 0;
}

input[type="checkbox"]:hover {
  border-color: var(--brand-500);
}

input[type="checkbox"]:checked {
  background: var(--brand-600);
  border-color: var(--brand-600);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.2 6.6 11.3 12.6 4.8'/%3E%3C/svg%3E");
  background-size: 13px 13px;
  background-position: center;
  background-repeat: no-repeat;
}

/* ==========================================================================
   PRECISION LOGIN SCREEN (Clean Architectural SaaS)
   ========================================================================== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(640px 360px at 15% 15%, rgba(37, 99, 235, 0.09), transparent 65%),
    radial-gradient(560px 340px at 85% 85%, rgba(14, 165, 233, 0.08), transparent 65%),
    var(--bg-canvas);
}

.login-shell {
  width: min(920px, 96vw);
  display: grid;
  grid-template-columns: 1.08fr 1fr;
  background: var(--bg-card);
  border: 1px solid var(--border-base);
  border-radius: 16px;
  box-shadow: var(--shadow-float);
  overflow: hidden;
}

.login-showcase {
  padding: 38px 36px;
  background: linear-gradient(155deg, #0b1528 0%, #102445 58%, #173464 100%);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
  position: relative;
}

.login-showcase-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(96, 165, 250, 0.32);
  color: #93c5fd;
  font-size: 12px;
  font-weight: 600;
  width: fit-content;
}

.login-showcase h2 {
  margin: 14px 0 10px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: #ffffff;
}

.login-showcase p {
  margin: 0;
  font-size: 13.5px;
  color: #cbd5e1;
  line-height: 1.65;
}

.login-feature-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-feature-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  font-size: 12.5px;
  color: #e2e8f0;
}

.login-feature-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: rgba(59, 130, 246, 0.24);
  color: #93c5fd;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.login-card {
  padding: 38px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink-strong);
  letter-spacing: -0.015em;
}

.login-brand p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.login-hint {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctrl);
  font-size: 12px;
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 820px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-showcase { display: none; }
}

/* ==========================================================================
   APP SHELL LAYOUT (方案一 100vw x 100vh Precision Frame)
   ========================================================================== */
.app-shell {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: width 0.2s cubic-bezier(0.2, 0, 0, 1), margin 0.2s ease;
  user-select: none;
}

html[data-scheme="ai"] .sidebar {
  margin: 10px 0 10px 10px;
  height: calc(100vh - 20px);
  border: 1px solid var(--sidebar-border);
  border-radius: 18px;
  backdrop-filter: blur(20px);
  box-shadow: 0 10px 30px -10px rgba(30, 27, 75, 0.12);
}

.app-shell.sidebar-collapsed .sidebar {
  width: 68px;
}

.brand-header {
  height: var(--topbar-h);
  padding: 0 12px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}

.brand-symbol {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand-600), var(--brand-500));
  color: #ffffff;
  box-shadow: 0 3px 10px var(--brand-glow), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  flex-shrink: 0;
}

html[data-scheme="gov"] .brand-symbol {
  background: linear-gradient(135deg, #1e4e8c 0%, #2b6cb0 65%, #d4a853 140%);
  border: 1px solid rgba(229, 184, 92, 0.45);
}

html[data-scheme="ai"] .brand-symbol {
  background: linear-gradient(135deg, #4f46e5 0%, #0891b2 100%);
}

.brand-symbol svg {
  width: 21px;
  height: 21px;
}

.brand-wordmark {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.22;
}

.brand-wordmark strong {
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -0.01em;
  color: var(--ink-strong);
  white-space: nowrap;
}

html[data-scheme="gov"] .brand-wordmark strong {
  color: #f8fafc;
}

.brand-wordmark small {
  font-size: 12px;
  color: var(--sidebar-muted);
  white-space: nowrap;
}

.sidebar-collapse-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--sidebar-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.sidebar-collapse-btn:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-ink);
}

.app-shell.sidebar-collapsed .brand-wordmark,
.app-shell.sidebar-collapsed .nav-group-title,
.app-shell.sidebar-collapsed .nav-item-copy,
.app-shell.sidebar-collapsed .nav-item-meta,
.app-shell.sidebar-collapsed .sidebar-footer-copy,
.app-shell.sidebar-collapsed .brand-symbol {
  display: none;
}

.app-shell.sidebar-collapsed .brand-header {
  justify-content: center;
  padding: 0 8px;
}

.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 8px;
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-group-title {
  padding: 2px 10px 4px;
  font-size: 12px;
  font-weight: 650;
  color: var(--sidebar-group-ink);
  letter-spacing: 0.02em;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-ctrl);
  background: transparent;
  color: var(--sidebar-ink);
  text-align: left;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-item:hover {
  background: var(--sidebar-hover-bg);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-ink);
  font-weight: 650;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--sidebar-active-bar);
}

.nav-item-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--sidebar-muted);
  background: transparent;
  transition: all 0.14s ease;
}

.nav-item:hover .nav-item-icon {
  color: var(--sidebar-ink);
}

.nav-item.active .nav-item-icon {
  color: var(--sidebar-active-ink);
  background: rgba(37, 99, 235, 0.1);
}

html[data-scheme="gov"] .nav-item.active .nav-item-icon {
  color: #e5b85c;
  background: rgba(229, 184, 92, 0.14);
}

.nav-item-copy {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.nav-item-copy strong {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}

.nav-item.active .nav-item-copy strong {
  font-weight: 700;
}

.nav-item-copy small {
  font-size: 12px;
  color: var(--sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html[data-scheme="gov"] .nav-item.active .nav-item-copy small {
  color: #cbd5e1;
}

.nav-item-meta {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-badge {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  font-family: var(--font-mono);
  background: var(--bg-muted);
  color: var(--ink-secondary);
}

html[data-scheme="gov"] .nav-badge {
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
}

.nav-dot-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.sidebar-util-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.app-shell.sidebar-collapsed .sidebar-util-row {
  grid-template-columns: 1fr;
}

.sidebar-util-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 31px;
  padding: 0 8px;
  border-radius: var(--radius-ctrl);
  border: 1px solid var(--sidebar-border);
  background: transparent;
  color: var(--sidebar-ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-util-btn:hover {
  background: var(--sidebar-hover-bg);
}

.service-health-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-ctrl);
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.22);
  color: var(--emerald-ink);
  font-size: 12px;
  font-weight: 600;
}

html[data-scheme="gov"] .service-health-bar {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(52, 211, 153, 0.28);
  color: #6ee7b7;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.22);
  flex-shrink: 0;
}

/* ==========================================================================
   MAIN WORKSPACE COLUMN & TOPBAR
   ========================================================================== */
.workspace-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-shrink: 0;
  z-index: 15;
}

html[data-scheme="ai"] .topbar {
  margin: 10px 12px 0 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-module-badge {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand-50);
  color: var(--brand-600);
  display: grid;
  place-items: center;
  border: 1px solid var(--brand-100);
  flex-shrink: 0;
}

.topbar-title-group {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.topbar-title-group strong {
  font-size: 15px;
  font-weight: 750;
  color: var(--ink-strong);
  white-space: nowrap;
}

.topbar-eyebrow {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.gateway-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
  color: var(--brand-700);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.gateway-pill:hover {
  border-color: var(--brand-500);
  box-shadow: 0 2px 8px var(--brand-glow);
}

.cmd-search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px 0 11px;
  min-width: 196px;
  flex-shrink: 0;
  border-radius: var(--radius-ctrl);
  border: 1px solid var(--border-base);
  background: var(--bg-subtle);
  color: var(--ink-muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

@media (max-width: 1480px) {
  .gateway-pill {
    display: none;
  }
  .cmd-search-trigger {
    min-width: 168px;
  }
}

.cmd-search-trigger:hover {
  border-color: var(--brand-500);
  background: var(--bg-input);
  color: var(--ink-base);
}

.cmd-kbd {
  margin-left: auto;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-base);
  background: var(--bg-card);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
}

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

.workspace-scroll {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 22px 48px;
}

.page-stack {
  max-width: 1580px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: viewFade 0.16s ease;
}

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

/* ==========================================================================
   CARDS, BUTTONS, SEGMENTED CLUSTERS & INPUTS
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-hd {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-hd-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.step-pill {
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
  color: var(--brand-600);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 750;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}

html[data-scheme="gov"] .step-pill {
  background: #0c1e38;
  border-color: #1e3a5f;
  color: #e5b85c;
}

.card-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 750;
  color: var(--ink-strong);
}

.card-sub {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.card-bd {
  padding: 16px 18px;
}

/* 4-Tier Precision Buttons */
.btn {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-ctrl);
  border: 1px solid var(--border-base);
  background: var(--bg-card);
  color: var(--ink-base);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: all 0.14s ease;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--ink-strong);
}

.btn-sm {
  height: 29px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-xs {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--brand-500) 0%, var(--brand-600) 100%);
  color: #ffffff;
  border-color: var(--brand-600);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.btn-primary:hover {
  filter: brightness(1.06);
  color: #ffffff;
  border-color: var(--brand-700);
  box-shadow: 0 4px 12px var(--brand-glow);
}

.btn-soft {
  background: var(--brand-50);
  color: var(--brand-700);
  border-color: var(--brand-100);
}

.btn-soft:hover {
  background: var(--brand-100);
  border-color: var(--brand-500);
  color: var(--brand-700);
}

.btn-success {
  background: var(--emerald-bg);
  color: var(--emerald-ink);
  border-color: var(--emerald-border);
}

.btn-success:hover {
  filter: brightness(0.97);
  color: var(--emerald-ink);
}

.btn-danger {
  background: var(--rose-bg);
  color: var(--rose-ink);
  border-color: var(--rose-border);
}

.btn-danger:hover {
  filter: brightness(0.97);
  color: var(--rose-ink);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-secondary);
}

.btn-ghost:hover {
  background: var(--bg-muted);
  border-color: transparent;
  color: var(--ink-strong);
}

/* Segmented Action Cluster */
.action-cluster {
  display: inline-flex;
  align-items: center;
  background: var(--bg-muted);
  padding: 3px;
  border-radius: calc(var(--radius-ctrl) + 2px);
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.action-cluster > button {
  height: 27px;
  padding: 0 10px;
  border: 0;
  border-radius: calc(var(--radius-ctrl) - 1px);
  background: transparent;
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.13s ease;
  white-space: nowrap;
}

.action-cluster > button:hover {
  color: var(--ink-strong);
}

.action-cluster > button.active {
  background: var(--bg-card);
  color: var(--brand-600);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

/* Inputs & Selects */
.form-group {
  margin-bottom: 13px;
  min-width: 0;
}

.form-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-secondary);
  margin-bottom: 5px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.input, .select, .textarea {
  width: 100%;
  border-radius: var(--radius-ctrl);
  border: 1px solid var(--border-base);
  background: var(--bg-input);
  color: var(--ink-strong);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.input, .select {
  height: 35px;
  padding: 0 11px;
}

.select {
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  cursor: pointer;
}

.textarea {
  padding: 9px 11px;
  min-height: 110px;
  line-height: 1.58;
  resize: vertical;
}

.input:hover, .select:hover, .textarea:hover {
  border-color: var(--border-strong);
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 23px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  border: 1px solid var(--border-subtle);
  background: var(--bg-muted);
  color: var(--ink-secondary);
}

.badge-emerald { background: var(--emerald-bg); color: var(--emerald-ink); border-color: var(--emerald-border); }
.badge-amber { background: var(--amber-bg); color: var(--amber-ink); border-color: var(--amber-border); }
.badge-rose { background: var(--rose-bg); color: var(--rose-ink); border-color: var(--rose-border); }
.badge-blue, .badge-brand { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-100); }
.badge-violet { background: var(--violet-bg); color: var(--violet-ink); border-color: var(--violet-border); }

/* ==========================================================================
   KPI TELEMETRY CARDS & SMOOTH SVG TREND CHART
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 15px 18px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  border-color: var(--border-strong);
}

html[data-scheme="gov"] .kpi-card {
  border-left: 3.5px solid var(--brand-600);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 650;
}

.kpi-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink-strong);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.kpi-foot {
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.grid-2col {
  display: grid;
  grid-template-columns: 1.52fr 1fr;
  gap: 16px;
}

/* Precision SVG Spline Chart Container */
.svg-chart-wrap {
  width: 100%;
  padding: 6px 0 2px;
}

.svg-chart-wrap svg {
  width: 100%;
  height: 196px;
  display: block;
  overflow: visible;
}

.chart-legend {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-secondary);
  font-weight: 600;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
}

.usage-rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border-subtle);
}

.usage-rank-row:last-child {
  border-bottom: none;
}

.usage-bar-track {
  flex: 1;
  height: 7px;
  background: var(--bg-muted);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}

/* ==========================================================================
   DATA TABLES & COMPACT ACTION CLUSTERS
   ========================================================================== */
.toolbar {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.action-btns {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table, .data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

th {
  padding: 10px var(--cell-pad-x);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-base);
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}

td {
  padding: var(--cell-pad-y) var(--cell-pad-x);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--ink-base);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: var(--bg-hover);
}

.key-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-base);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-strong);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.14s ease;
}

.key-chip:hover {
  background: var(--brand-50);
  border-color: var(--brand-500);
  color: var(--brand-700);
}

.progress-mini {
  width: 88px;
  height: 5px;
  background: var(--bg-muted);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-mini > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-600));
  border-radius: 999px;
}

.batch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 18px;
  background: var(--brand-50);
  border-bottom: 1px solid var(--brand-100);
  flex-wrap: wrap;
}

/* ==========================================================================
   SKILL STUDIO & SANDBOX WORKBENCH
   ========================================================================== */
.studio-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.skill-item-card {
  padding: 12px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctrl);
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--bg-subtle);
  transition: all 0.14s ease;
}

.skill-item-card:last-child {
  margin-bottom: 0;
}

.skill-item-card:hover {
  background: var(--bg-card);
  border-color: var(--brand-500);
}

.skill-item-card.active {
  border-color: var(--brand-600);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand-600);
}

.dual-editors {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
}

.thin-box {
  border: 1px solid var(--border-base);
  background: var(--bg-subtle);
  padding: 13px;
  border-radius: 10px;
  min-width: 0;
}

.protected-box {
  border: 1px solid var(--amber-border);
  background: var(--amber-bg);
  padding: 13px;
  border-radius: 10px;
  min-width: 0;
}

.cap-builder-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cap-builder-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-base);
  border-radius: 10px;
  padding: 13px 14px;
  transition: border-color 0.14s ease;
}

.cap-builder-card:hover {
  border-color: var(--brand-500);
}

.cap-card-grid {
  display: grid;
  grid-template-columns: 1.2fr 1.25fr 0.85fr 0.6fr 1.35fr auto;
  gap: 10px;
  align-items: end;
}

.sandbox-layout {
  display: grid;
  grid-template-columns: 430px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.code-viewer {
  margin: 0;
  background: #0d1424;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  overflow-x: auto;
  min-height: 410px;
  max-height: 620px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.revision-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctrl);
  margin-bottom: 8px;
  background: var(--bg-subtle);
}

/* ==========================================================================
   MODALS, COMMAND PALETTE & TOASTS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 14, 26, 0.52);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-box {
  width: min(600px, 96vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-base);
  border-radius: 14px;
  box-shadow: var(--shadow-float);
  padding: 20px 22px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15.5px;
  font-weight: 750;
  color: var(--ink-strong);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.cmd-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 340px;
  overflow-y: auto;
}

.cmd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-ctrl);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-base);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: all 0.12s ease;
}

.cmd-item:hover {
  background: var(--brand-50);
  border-color: var(--brand-100);
  color: var(--brand-700);
}

.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-float);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  animation: toastSlide 0.18s ease;
}

.toast.error {
  background: #be123c;
}

@keyframes toastSlide {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   USER PORTAL STYLES (/portal)
   ========================================================================== */
.portal-topbar {
  height: 56px;
  padding: 0 28px;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
}

.portal-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 22px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.portal-workbench-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 24px;
  align-items: center;
}

.skill-portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 14px;
}

.portal-skill-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-base);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: all 0.15s ease;
}

.portal-skill-card:hover {
  background: var(--bg-card);
  border-color: var(--brand-500);
  box-shadow: var(--shadow-card);
}

/* ==========================================================================
   DIFF VIEWER & TOPUP VOUCHER ENHANCEMENTS
   ========================================================================== */
.diff-tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.diff-viewer {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  background: #0d1424;
  color: #cbd5e1;
  border: 1px solid #1e293b;
  border-radius: 10px;
  max-height: 410px;
  overflow: auto;
  padding: 8px 0;
}

.diff-line {
  display: flex;
  gap: 10px;
  padding: 1px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-line-prefix {
  width: 16px;
  flex-shrink: 0;
  user-select: none;
  opacity: 0.78;
  font-weight: 700;
}

.diff-line.add {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
}

.diff-line.remove {
  background: rgba(244, 63, 94, 0.17);
  color: #fda4af;
}

.diff-line.same {
  color: #94a3b8;
}

.top-tool-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 12px;
}

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2col, .studio-layout, .sandbox-layout, .dual-editors, .portal-workbench-banner {
    grid-template-columns: 1fr;
  }
  .cap-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cmd-search-trigger { display: none; }
}
