/* ============================================================
   OCTANE v10 — Design System
   Sovereign Intelligence Platform
   ============================================================ */

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

:root {
  /* Background scale */
  --bg-void: #05070f;
  --bg-base: #090c14;
  --bg-surface: #0f1320;
  --bg-elevated: #161b2e;
  --bg-overlay: #1d2340;
  --bg-hover: #222846;

  /* Borders */
  --border-faint: rgba(79, 140, 255, 0.08);
  --border-subtle: rgba(79, 140, 255, 0.15);
  --border-muted: #2a3050;
  --border-strong: #3a4470;

  /* Typography */
  --text-primary: #e8eaf2;
  --text-secondary: #8b92b2;
  --text-muted: #4d5470;
  --text-disabled: #2d3250;

  /* Accent / Brand */
  --accent: #4f8cff;
  --accent-bright: #6ea4ff;
  --accent-dim: #2a5ccc;
  --accent-glow: rgba(79, 140, 255, 0.18);
  --accent-pulse: rgba(79, 140, 255, 0.06);

  /* Semantic */
  --success: #00e878;
  --success-dim: rgba(0, 232, 120, 0.12);
  --warning: #ffaa00;
  --warning-dim: rgba(255, 170, 0, 0.12);
  --danger: #ff4455;
  --danger-dim: rgba(255, 68, 85, 0.12);
  --purple: #9b6dff;
  --purple-dim: rgba(155, 109, 255, 0.12);
  --cyan: #00d4ff;
  --cyan-dim: rgba(0, 212, 255, 0.12);
  --amber: #ff8c42;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Radius */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.7);
  --shadow-glow: 0 0 24px rgba(79, 140, 255, 0.25);

  /* Transitions */
  --t-fast: 100ms ease;
  --t-base: 180ms ease;
  --t-slow: 320ms ease;

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --content-max: 1440px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family:
    "Inter",
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ──────────────────────────────────────────── */
h1 {
  font-size: 1.714rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
h2 {
  font-size: 1.357rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
h3 {
  font-size: 1.143rem;
  font-weight: 600;
  line-height: 1.4;
}
h4 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}
h5 {
  font-size: 0.857rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
h6 {
  font-size: 0.786rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

p {
  color: var(--text-secondary);
  line-height: 1.7;
}

.mono {
  font-family:
    "JetBrains Mono", "Fira Code", "Cascadia Code", "Courier New", monospace;
  font-size: 0.857rem;
}

/* ── Layout Shell ────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar content";
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.mobile-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-muted);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-base);
}

.mobile-nav-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 0.857rem;
  color: var(--text-muted);
}

.topbar-breadcrumb .crumb {
  color: var(--text-secondary);
}
.topbar-breadcrumb .crumb.active {
  color: var(--text-primary);
  font-weight: 500;
}
.topbar-breadcrumb .sep {
  opacity: 0.4;
}

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

.topbar-status {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 0.786rem;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-full);
  padding: 4px var(--sp-3);
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-md);
  padding: 6px var(--sp-3);
  color: var(--text-muted);
  font-size: 0.857rem;
  cursor: pointer;
  transition: border-color var(--t-base);
  min-width: 200px;
}
.topbar-search:hover {
  border-color: var(--accent);
}
.topbar-search kbd {
  background: var(--bg-overlay);
  border: 1px solid var(--border-muted);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.714rem;
  margin-left: auto;
  font-family: inherit;
}

.topbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  background: transparent;
  border: 1px solid var(--border-muted);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-base);
  text-decoration: none;
}
.topbar-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--accent-dim), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.786rem;
  font-weight: 700;
  color: white;
  cursor: pointer;
  border: 2px solid var(--border-subtle);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--bg-void);
  border-right: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-muted) transparent;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 18, 0.68);
  backdrop-filter: blur(2px);
  z-index: 59;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border-subtle);
  text-decoration: none;
  flex-shrink: 0;
}

.logo-mark {
  width: 28px;
  height: 28px;
  position: relative;
  flex-shrink: 0;
}

.logo-mark svg {
  width: 28px;
  height: 28px;
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.logo-name {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text-primary);
  line-height: 1.1;
  text-transform: uppercase;
}

.logo-version {
  font-size: 0.643rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-transform: uppercase;
  line-height: 1;
}

.sidebar-section {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  flex-shrink: 0;
}

.sidebar-section-label {
  font-size: 0.643rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.857rem;
  font-weight: 450;
  transition: all var(--t-base);
  position: relative;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

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

.nav-item.active {
  color: var(--accent-bright);
  background: var(--accent-glow);
  font-weight: 500;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
  opacity: 1;
}

.nav-badge {
  margin-left: auto;
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(255, 68, 85, 0.25);
  border-radius: var(--r-full);
  padding: 1px 6px;
  font-size: 0.643rem;
  font-weight: 700;
  line-height: 1.4;
}

.nav-badge.success {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(0, 232, 120, 0.25);
}

.nav-badge.warning {
  background: var(--warning-dim);
  color: var(--warning);
  border-color: rgba(255, 170, 0, 0.25);
}

.nav-badge.neutral {
  background: var(--bg-overlay);
  color: var(--text-muted);
  border-color: var(--border-muted);
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--sp-4) var(--sp-3);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.system-health {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--sp-3);
}

.system-health-title {
  font-size: 0.643rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}

.health-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-2);
}

.health-label {
  font-size: 0.786rem;
  color: var(--text-secondary);
}

.health-bar {
  flex: 1;
  height: 3px;
  background: var(--bg-overlay);
  border-radius: var(--r-full);
  margin: 0 var(--sp-2);
  overflow: hidden;
}

.health-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--success);
  transition: width 1s ease;
}

.health-fill.warning {
  background: var(--warning);
}
.health-fill.danger {
  background: var(--danger);
}

.health-pct {
  font-size: 0.714rem;
  font-family: "JetBrains Mono", monospace;
  color: var(--text-secondary);
  min-width: 32px;
  text-align: right;
}

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  grid-area: content;
  padding: var(--sp-8);
  overflow-y: auto;
  max-height: calc(100vh - var(--topbar-height));
  overflow-x: hidden;
  padding-bottom: calc(var(--sp-8) + var(--safe-bottom));
}

.main-content > * {
  width: 100%;
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
}

/* ── Runtime Surface Embed Host ────────────────────────── */
.runtime-surface-host {
  padding: 0;
  margin-left: 2%;
  margin-right: 2%;
  width: calc(100% - 4%);
  max-width: none;
  box-sizing: border-box;
}

.page-surveillance .runtime-surface-host {
  margin-left: 0;
  margin-right: 0;
  width: 100%;
}

.page-surveillance .main-content > * {
  width: calc(100% - 10%);
  max-width: none;
  margin-left: 5%;
  margin-right: 5%;
}

@media (max-width: 768px) {
  .page-surveillance .main-content > * {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }
}

.runtime-surface-host iframe {
  width: 100%;
  display: block;
  height: clamp(840px, 90vh, 1800px);
  min-height: 840px;
  border: 0;
  background: var(--bg-void);
}

@media (max-width: 768px) {
  .runtime-surface-host {
    padding: 0;
  }
}

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

.app-shell.sidebar-collapsed .sidebar {
  width: 0;
  min-width: 0;
  border-right: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.app-shell.sidebar-collapsed .topbar,
.app-shell.sidebar-collapsed .main-content {
  margin-left: 0;
}

.page-header {
  margin-bottom: var(--sp-8);
}

.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.page-eyebrow {
  font-size: 0.714rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--sp-2);
}

.page-desc {
  color: var(--text-secondary);
  font-size: 0.929rem;
  max-width: 560px;
  margin-top: var(--sp-2);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px var(--sp-4);
  border-radius: var(--r-md);
  font-size: 0.857rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-base);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
  box-shadow: 0 0 16px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-muted);
}
.btn-secondary:hover {
  background: var(--bg-overlay);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(255, 68, 85, 0.3);
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(0, 232, 120, 0.3);
}
.btn-success:hover {
  background: var(--success);
  color: #000;
}

.btn-sm {
  padding: 5px var(--sp-3);
  font-size: 0.786rem;
}
.btn-lg {
  padding: 11px var(--sp-6);
  font-size: 0.929rem;
}
.btn-icon {
  padding: 7px;
}
.btn-icon.btn-sm {
  padding: 5px;
}

.btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.btn-sm svg {
  width: 12px;
  height: 12px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  transition: border-color var(--t-base);
}
.card:hover {
  border-color: var(--border-strong);
}

.card-flush {
  padding: 0;
}
.card-sm {
  padding: var(--sp-4);
  border-radius: var(--r-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-5);
  gap: var(--sp-3);
}

.card-title {
  font-size: 0.929rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.786rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.card-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--sp-5) calc(-1 * var(--sp-6));
}

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-6);
  position: relative;
  overflow: hidden;
  transition: all var(--t-base);
}
.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--stat-color, var(--accent));
}

.stat-label {
  font-size: 0.714rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}

.stat-value {
  font-size: 1.857rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-bottom: var(--sp-2);
}

.stat-unit {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.stat-trend {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: 0.786rem;
  font-weight: 500;
}
.stat-trend.up {
  color: var(--success);
}
.stat-trend.down {
  color: var(--danger);
}
.stat-trend.neutral {
  color: var(--text-muted);
}

.stat-icon {
  position: absolute;
  top: var(--sp-5);
  right: var(--sp-5);
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--stat-bg, var(--accent-glow));
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon svg {
  width: 18px;
  height: 18px;
  color: var(--stat-color, var(--accent));
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  margin: 0 calc(-1 * var(--sp-6));
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.857rem;
}

thead tr {
  border-bottom: 1px solid var(--border-subtle);
}

thead th {
  padding: var(--sp-3) var(--sp-6);
  text-align: left;
  font-size: 0.714rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border-faint);
  transition: background var(--t-fast);
}
tbody tr:hover {
  background: var(--bg-elevated);
}
tbody tr:last-child {
  border-bottom: none;
}

tbody td {
  padding: var(--sp-4) var(--sp-6);
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody td.td-primary {
  color: var(--text-primary);
  font-weight: 500;
}

tbody td.td-mono {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.786rem;
  color: var(--accent-bright);
}

/* ── Badges / Pills ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 0.714rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-success {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(0, 232, 120, 0.2);
}
.badge-success .badge-dot {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.badge-warning {
  background: var(--warning-dim);
  color: var(--warning);
  border: 1px solid rgba(255, 170, 0, 0.2);
}
.badge-warning .badge-dot {
  background: var(--warning);
}

.badge-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(255, 68, 85, 0.2);
}
.badge-danger .badge-dot {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
}

.badge-accent {
  background: var(--accent-glow);
  color: var(--accent-bright);
  border: 1px solid rgba(79, 140, 255, 0.2);
}
.badge-accent .badge-dot {
  background: var(--accent);
}

.badge-purple {
  background: var(--purple-dim);
  color: var(--purple);
  border: 1px solid rgba(155, 109, 255, 0.2);
}

.badge-neutral {
  background: var(--bg-overlay);
  color: var(--text-secondary);
  border: 1px solid var(--border-muted);
}

.badge-cyan {
  background: var(--cyan-dim);
  color: var(--cyan);
  border: 1px solid rgba(0, 212, 255, 0.2);
}

/* ── Grids ───────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-4);
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
}
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--sp-4);
}
.col-span-2 {
  grid-column: span 2;
}
.col-span-3 {
  grid-column: span 3;
}

/* ── Progress / Gauges ───────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--bg-overlay);
  border-radius: var(--r-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.progress-fill.success {
  background: var(--success);
}
.progress-fill.warning {
  background: var(--warning);
}
.progress-fill.danger {
  background: var(--danger);
}
.progress-fill.purple {
  background: var(--purple);
}

.progress-fill::after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 20px;
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.3));
  border-radius: var(--r-full);
}

/* ── Timeline ────────────────────────────────────────────── */
.timeline {
  position: relative;
  padding-left: var(--sp-8);
}

.timeline::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 6px;
  bottom: 0;
  width: 1px;
  background: var(--border-subtle);
}

.timeline-item {
  position: relative;
  padding-bottom: var(--sp-6);
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--sp-8) + 7px);
  top: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
  z-index: 1;
}

.timeline-item.success::before {
  background: var(--success);
}
.timeline-item.warning::before {
  background: var(--warning);
}
.timeline-item.danger::before {
  background: var(--danger);
}
.timeline-item.muted::before {
  background: var(--text-muted);
}

.timeline-time {
  font-size: 0.714rem;
  color: var(--text-muted);
  font-family: "JetBrains Mono", monospace;
  margin-bottom: 2px;
}

.timeline-title {
  font-size: 0.857rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.timeline-desc {
  font-size: 0.786rem;
  color: var(--text-muted);
}

/* ── Toggle Switch ───────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--border-faint);
}
.toggle-row:last-child {
  border-bottom: none;
}

.toggle-info .toggle-label {
  font-size: 0.857rem;
  font-weight: 500;
  color: var(--text-primary);
}
.toggle-info .toggle-desc {
  font-size: 0.786rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-overlay);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-full);
  transition: all var(--t-base);
}
.toggle input:checked ~ .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-track::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform var(--t-base);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle input:checked ~ .toggle-track::after {
  transform: translateX(18px);
}

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--sp-6);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  font-size: 0.857rem;
  font-weight: 450;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--t-base);
  white-space: nowrap;
  text-decoration: none;
}
.tab:hover {
  color: var(--text-primary);
}
.tab.active {
  color: var(--accent-bright);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

/* ── Alerts / Banners ────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-md);
  font-size: 0.857rem;
  border: 1px solid;
  margin-bottom: var(--sp-4);
}

.alert-success {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(0, 232, 120, 0.2);
}
.alert-warning {
  background: var(--warning-dim);
  color: var(--warning);
  border-color: rgba(255, 170, 0, 0.2);
}
.alert-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(255, 68, 85, 0.2);
}
.alert-info {
  background: var(--accent-glow);
  color: var(--accent-bright);
  border-color: rgba(79, 140, 255, 0.2);
}

.alert svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── Code / Terminal ─────────────────────────────────────── */
.code-block {
  background: var(--bg-void);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.786rem;
  color: var(--accent-bright);
  line-height: 1.6;
  overflow-x: auto;
}

.code-block .comment {
  color: var(--text-muted);
}
.code-block .keyword {
  color: var(--purple);
}
.code-block .string {
  color: var(--success);
}
.code-block .number {
  color: var(--warning);
}

/* ── Node / Pipeline Components ─────────────────────────── */
.pipeline {
  display: flex;
  align-items: center;
  gap: 0;
  overflow-x: auto;
  padding-bottom: var(--sp-2);
}

.pipeline-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  position: relative;
}

.pipeline-node + .pipeline-node::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--sp-4));
  top: 22px;
  width: var(--sp-8);
  height: 1px;
  background: var(--border-muted);
}

.pipeline-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  font-size: 0.786rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--t-base);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.pipeline-box:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.pipeline-box.active {
  border-color: var(--success);
  background: var(--success-dim);
  color: var(--success);
}
.pipeline-box.error {
  border-color: var(--danger);
  background: var(--danger-dim);
  color: var(--danger);
}
.pipeline-box.idle {
  border-color: var(--border-muted);
  color: var(--text-muted);
}

.pipeline-label {
  font-size: 0.643rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

.pipeline-connector {
  width: var(--sp-8);
  height: 1px;
  background: var(--border-muted);
  flex-shrink: 0;
  position: relative;
}
.pipeline-connector::after {
  content: "";
  position: absolute;
  right: -4px;
  top: -3px;
  width: 0;
  height: 0;
  border-left: 6px solid var(--border-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}
.pipeline-connector.active {
  background: var(--accent);
}
.pipeline-connector.active::after {
  border-left-color: var(--accent);
}

/* ── Search / Filter Bar ─────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.input-field {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-md);
  padding: 7px var(--sp-3);
  color: var(--text-primary);
  font-size: 0.857rem;
  transition: border-color var(--t-base);
}
.input-field:focus-within {
  border-color: var(--accent);
}
.input-field svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.input-field input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.857rem;
  font-family: inherit;
  min-width: 180px;
}
.input-field input::placeholder {
  color: var(--text-muted);
}

.select-field {
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-md);
  padding: 7px var(--sp-3);
  color: var(--text-primary);
  font-size: 0.857rem;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234d5470' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  transition: border-color var(--t-base);
}
.select-field:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Pulse / Live indicators ─────────────────────────────── */
.pulse {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  position: relative;
  flex-shrink: 0;
}
.pulse-dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0.3;
  animation: pulse-ring 2s ease infinite;
}
@keyframes pulse-ring {
  0% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.6);
    opacity: 0;
  }
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
}
.pulse-dot.warning {
  background: var(--warning);
}
.pulse-dot.warning::after {
  background: var(--warning);
}
.pulse-dot.danger {
  background: var(--danger);
}
.pulse-dot.danger::after {
  background: var(--danger);
}
.pulse-dot.muted {
  background: var(--text-muted);
}
.pulse-dot.muted::after {
  display: none;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-muted);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ── Utility ─────────────────────────────────────────────── */
.flex {
  display: flex;
}
.flex-col {
  display: flex;
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.items-start {
  align-items: flex-start;
}
.justify-between {
  justify-content: space-between;
}
.justify-center {
  justify-content: center;
}
.gap-1 {
  gap: var(--sp-1);
}
.gap-2 {
  gap: var(--sp-2);
}
.gap-3 {
  gap: var(--sp-3);
}
.gap-4 {
  gap: var(--sp-4);
}
.gap-6 {
  gap: var(--sp-6);
}
.gap-8 {
  gap: var(--sp-8);
}
.mt-1 {
  margin-top: var(--sp-1);
}
.mt-2 {
  margin-top: var(--sp-2);
}
.mt-3 {
  margin-top: var(--sp-3);
}
.mt-4 {
  margin-top: var(--sp-4);
}
.mt-6 {
  margin-top: var(--sp-6);
}
.mt-8 {
  margin-top: var(--sp-8);
}
.mb-2 {
  margin-bottom: var(--sp-2);
}
.mb-4 {
  margin-bottom: var(--sp-4);
}
.mb-6 {
  margin-bottom: var(--sp-6);
}
.mb-8 {
  margin-bottom: var(--sp-8);
}
.mr-auto {
  margin-right: auto;
}
.ml-auto {
  margin-left: auto;
}
.w-full {
  width: 100%;
}
.min-w-0 {
  min-width: 0;
}
.text-primary {
  color: var(--text-primary);
}
.text-secondary {
  color: var(--text-secondary);
}
.text-muted {
  color: var(--text-muted);
}
.text-accent {
  color: var(--accent-bright);
}
.text-success {
  color: var(--success);
}
.text-warning {
  color: var(--warning);
}
.text-danger {
  color: var(--danger);
}
.text-purple {
  color: var(--purple);
}
.text-cyan {
  color: var(--cyan);
}
.text-sm {
  font-size: 0.857rem;
}
.text-xs {
  font-size: 0.786rem;
}
.text-xxs {
  font-size: 0.714rem;
}
.font-mono {
  font-family: "JetBrains Mono", monospace;
}
.font-medium {
  font-weight: 500;
}
.font-semibold {
  font-weight: 600;
}
.font-bold {
  font-weight: 700;
}
.opacity-50 {
  opacity: 0.5;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shrink-0 {
  flex-shrink: 0;
}
.hidden {
  display: none;
}
.relative {
  position: relative;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "topbar" "content";
  }

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

  .sidebar {
    display: flex;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 320px);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--t-slow);
    height: 100dvh;
    box-shadow: var(--shadow-lg);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app-shell.sidebar-open .sidebar-overlay {
    display: block;
  }

  .mobile-nav-btn {
    display: inline-flex;
  }

  .topbar {
    padding-left: calc(var(--sp-4) + var(--safe-left));
    padding-right: calc(var(--sp-4) + var(--safe-right));
    gap: var(--sp-2);
  }

  .topbar-breadcrumb {
    font-size: 0.786rem;
    min-width: 0;
  }

  .topbar-breadcrumb .crumb,
  .topbar-breadcrumb .sep {
    white-space: nowrap;
  }

  .topbar-left {
    min-width: 0;
    flex: 1;
  }

  .topbar-right {
    gap: var(--sp-2);
    flex-shrink: 0;
  }

  .topbar-search {
    min-width: 160px;
    max-width: 220px;
    padding: 6px var(--sp-2);
  }

  .topbar-search span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-status {
    padding: 4px var(--sp-2);
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1920px) {
  :root {
    --content-max: 1760px;
  }

  html {
    font-size: 15px;
  }

  .topbar {
    padding-left: clamp(var(--sp-6), 2vw, var(--sp-10));
    padding-right: clamp(var(--sp-6), 2vw, var(--sp-10));
  }

  .main-content {
    padding: var(--sp-10);
  }
}

@media (min-width: 2560px) {
  :root {
    --content-max: 1920px;
  }

  html {
    font-size: 16px;
  }
}

@media (max-width: 768px) {
  .topbar {
    height: auto;
    min-height: var(--topbar-height);
    padding-top: calc(var(--sp-2) + var(--safe-top));
    padding-bottom: var(--sp-2);
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .topbar-left,
  .topbar-right {
    width: 100%;
  }

  .topbar-right {
    justify-content: space-between;
  }

  .topbar-search {
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  .topbar-search kbd,
  .avatar,
  .topbar-btn[title="Notifications"] {
    display: none;
  }

  .topbar-status {
    margin-left: auto;
  }

  .main-content {
    max-height: none;
    padding: var(--sp-4);
    padding-bottom: calc(var(--sp-6) + var(--safe-bottom));
  }

  .page-header {
    margin-bottom: var(--sp-5);
  }

  .page-title-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }

  .page-title-row h1 {
    font-size: 1.429rem;
  }

  .page-desc {
    max-width: none;
    font-size: 0.857rem;
  }

  .page-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: var(--sp-2);
  }

  .page-actions .btn,
  .page-actions .badge {
    flex-shrink: 0;
  }

  .card {
    padding: var(--sp-4);
    border-radius: var(--r-md);
  }

  .card-divider {
    margin-left: calc(-1 * var(--sp-4));
    margin-right: calc(-1 * var(--sp-4));
  }

  .card-header {
    flex-wrap: wrap;
    align-items: flex-start;
    margin-bottom: var(--sp-4);
  }

  .card-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .table-wrapper {
    margin: 0 calc(-1 * var(--sp-4));
  }

  thead th,
  tbody td {
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }

  .tabs {
    margin-bottom: var(--sp-4);
    gap: var(--sp-1);
  }

  .tab {
    padding: var(--sp-2) var(--sp-3);
  }

  .filter-bar {
    gap: var(--sp-2);
  }

  .filter-bar .input-field,
  .filter-bar .select-field {
    width: 100%;
  }

  .pipeline {
    padding-bottom: var(--sp-3);
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .col-span-2,
  .col-span-3 {
    grid-column: span 1;
  }
}

@media (max-width: 560px) {
  .topbar-breadcrumb .crumb:first-child,
  .topbar-breadcrumb .sep:first-of-type {
    display: none;
  }

  .topbar-status {
    font-size: 0.714rem;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .page-actions .btn {
    width: auto;
  }

  .page-actions .btn-primary,
  .page-actions .btn-secondary {
    flex: 1 1 calc(50% - var(--sp-1));
    justify-content: center;
  }

  .page-actions .btn-ghost {
    flex: 1 1 100%;
  }

  .card-actions .btn,
  .filter-bar .btn {
    width: 100%;
  }

  .settings-row {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-input {
    width: 100%;
    min-width: 0;
  }
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.animate-in {
  animation: fade-in 0.3s ease forwards;
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elevated) 25%,
    var(--bg-overlay) 50%,
    var(--bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm);
}

/* ── Divider ─────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--sp-6) 0;
}

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-16) var(--sp-8);
  text-align: center;
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-4);
}
.empty-state-icon svg {
  width: 22px;
  height: 22px;
  color: var(--text-muted);
}
.empty-state h4 {
  font-size: 0.929rem;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}
.empty-state p {
  font-size: 0.857rem;
  color: var(--text-muted);
  max-width: 280px;
}

/* ── Chart Placeholder ───────────────────────────────────── */
.chart-area {
  width: 100%;
  height: 180px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  padding: var(--sp-2) 0;
}

.chart-bar {
  flex: 1;
  background: var(--accent-glow);
  border-radius: 2px 2px 0 0;
  border: 1px solid rgba(79, 140, 255, 0.2);
  border-bottom: none;
  transition: all var(--t-base);
  position: relative;
  cursor: pointer;
}
.chart-bar:hover {
  background: rgba(79, 140, 255, 0.3);
}
.chart-bar.success {
  background: var(--success-dim);
  border-color: rgba(0, 232, 120, 0.2);
}
.chart-bar.warning {
  background: var(--warning-dim);
  border-color: rgba(255, 170, 0, 0.2);
}

/* ── Sparkline ───────────────────────────────────────────── */
.sparkline {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 28px;
}
.spark-bar {
  width: 4px;
  background: var(--accent-dim);
  border-radius: 1px;
  transition: background var(--t-base);
}
.spark-bar:hover {
  background: var(--accent);
}
