/**
 * Stock AI Lab v2.0 - Chat 2: Sovereign UI & Bento Grid
 * Canonical #090A0F Obsidian Dark Design System & Typography Tokens
 * Namespace: src/ui/theme_tokens.css
 * 
 * Strict Invariants:
 * - Pure Obsidian Dark palette: #090A0F baseline
 * - Ultra-dense institutional typography
 * - Zero-blur high-contrast borders
 * - Hardware-accelerated CSS Grid layout
 */

:root {
  /* ==========================================================================
     COLOR TOKENS (Obsidian Dark Spectrum)
     ========================================================================== */
  --bg-obsidian: #090A0F;
  --bg-card: #0D111A;
  --bg-card-hover: #121724;
  --bg-elevated: #161D2B;
  --bg-glass: rgba(13, 17, 26, 0.75);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.20);
  --border-accent: rgba(6, 182, 212, 0.30);

  /* Semantic Quantitative Accents */
  --cyan: #06B6D4;
  --cyan-glow: rgba(6, 182, 212, 0.15);
  --emerald: #10B981;
  --emerald-glow: rgba(16, 185, 129, 0.15);
  --amber: #F59E0B;
  --amber-glow: rgba(245, 158, 11, 0.15);
  --rose: #F43F5E;
  --rose-glow: rgba(244, 63, 94, 0.15);
  --purple: #A855F7;
  --purple-glow: rgba(168, 85, 247, 0.15);
  --blue: #3B82F6;
  --blue-glow: rgba(59, 130, 246, 0.15);

  /* Text & Foreground */
  --text-primary: #FFFFFF;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --text-faint: #475569;

  /* ==========================================================================
     TYPOGRAPHY TOKENS
     ========================================================================== */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, 'Courier New', monospace;

  /* Font Sizes */
  --text-2xs: 9px;
  --text-xs: 10px;
  --text-sm: 11px;
  --text-base: 12px;
  --text-md: 13px;
  --text-lg: 14px;
  --text-xl: 16px;
  --text-2xl: 20px;
  --text-3xl: 26px;

  /* ==========================================================================
     SPACING & RADIUS TOKENS
     ========================================================================== */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows & Glows */
  --shadow-bento: 0 4px 20px rgba(0, 0, 0, 0.6);
  --shadow-glow-cyan: 0 0 15px rgba(6, 182, 212, 0.25);
  --shadow-glow-emerald: 0 0 15px rgba(16, 185, 129, 0.25);
}

/* Base Body Application */
body.obsidian-theme {
  background-color: var(--bg-obsidian);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.45;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

/* Universal Monospace Class */
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* Subtle Text */
.muted-txt {
  color: var(--text-muted);
}

/* Quantitative Status Colors */
.up { color: var(--emerald); }
.down { color: var(--rose); }
.warn { color: var(--amber); }
.info { color: var(--cyan); }

/* ==========================================================================
   APEX-SOVEREIGN v5.0 — MOBILE HEADER & NATIVE BOTTOM SHEET ARCHITECTURE
   Chief Quantitative Architect Directive: Google Gemini 4 Argon
   ========================================================================== */

/* Telemetry Capsule (Shared Desktop & Mobile Trigger) */
.sys-telemetry-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: #e2e8f0;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.02em;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.sys-telemetry-pill:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.sys-telemetry-pill:active {
  transform: scale(0.96);
  background: rgba(30, 41, 59, 0.9);
}

.sys-telemetry-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  flex-shrink: 0;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.sys-telemetry-dot.warn { background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }
.sys-telemetry-dot.crit { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.sys-telemetry-dot.boot { background: #64748b; box-shadow: none; }

/* Backdrop for Mobile Bottom Sheet */
.sys-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.sys-sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Telemetry Diagnostic Container (Desktop Popover -> Mobile Bottom Sheet) */
.sys-telemetry-sheet {
  position: fixed;
  z-index: 9999;
  background: rgba(9, 13, 24, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75);
  color: #f8fafc;
  font-family: 'Inter', -apple-system, sans-serif;
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

/* Desktop Popover Positioning (>= 769px) */
@media (min-width: 769px) {
  .sys-telemetry-sheet {
    top: 54px;
    right: 16px;
    width: 320px;
    border-radius: 12px;
    padding: 14px;
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
    pointer-events: none;
  }
  .sys-telemetry-sheet.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
  .sys-sheet-handle-wrap {
    display: none;
  }
}

/* Mobile Bottom Sheet & Header Architecture (<= 768px) */
@media (max-width: 768px) {
  .mobile-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 48px;
    padding: 0 12px !important;
    box-sizing: border-box;
    background: rgba(6, 10, 19, 0.94) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(148, 163, 184, 0.12) !important;
    position: sticky;
    top: 0;
    z-index: 1000;
    overflow: hidden;
  }

  .m-brand-cluster {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    flex-shrink: 1;
  }

  .m-brand-title {
    font-size: 13.5px;
    font-weight: 700;
    color: #f8fafc;
    letter-spacing: -0.02em;
    white-space: nowrap;
  }

  .m-regime-badge {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(16, 185, 129, 0.14);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
    white-space: nowrap;
  }

  .m-action-cluster {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .m-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.14);
    color: #cbd5e1;
    padding: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .m-icon-btn:active {
    background: rgba(51, 65, 85, 0.85);
    transform: scale(0.94);
  }

  .sys-telemetry-pill {
    height: 28px;
    padding: 0 9px;
    font-size: 11px;
    gap: 6px;
    background: #0C0D12;
    border: 1px solid rgba(255, 255, 255, 0.14);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
  }

  .sys-telemetry-dot {
    transform: translateY(-0.5px);
  }

  /* Native Slide-Up Drawer on Mobile */
  .sys-telemetry-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    padding: 10px 16px calc(20px + env(safe-area-inset-bottom, 0px)) 16px;
    transform: translateY(105%);
  }

  .sys-telemetry-sheet.open {
    transform: translateY(0);
  }

  .sys-sheet-handle-wrap {
    display: flex;
    justify-content: center;
    padding: 4px 0 12px 0;
    cursor: pointer;
  }

  .sys-sheet-handle {
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.35);
  }
}

/* Internal Diagnostic Grid inside Sheet */
.sys-diag-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.sys-diag-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
}

.sys-diag-clock {
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 11px;
  color: #38bdf8;
}

.sys-diag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sys-diag-card {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 8px;
  padding: 8px 10px;
}

.sys-diag-label {
  font-size: 10px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}

.sys-diag-val {
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
}

.sys-ram-bar-bg {
  width: 100%;
  height: 4px;
  background: rgba(51, 65, 85, 0.6);
  border-radius: 99px;
  margin-top: 5px;
  overflow: hidden;
}

.sys-ram-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #38bdf8);
  border-radius: 99px;
  transition: width 0.3s ease;
}

.sys-sheet-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Global Zero-Horizontal-Overflow Guard */
html, body {
  overflow-x: hidden !important;
  overflow-y: auto;
  max-width: 100vw;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

.sys-sheet-action-btn {
  font-size: 11px;
  font-weight: 600;
  color: #cbd5e1;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

/* ==========================================================================
   APEX-SOVEREIGN v5.0 — CREDIT GOVERNOR 4-GRID & EXECUTION DOCK STYLES
   ========================================================================== */
.cg-chip-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
}

.cg-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  background: #07080C;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.cg-chip.warn {
  border-color: rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.05);
}

.cg-key {
  font-size: 9.5px;
  color: #64748B;
  font-weight: 700;
  text-transform: uppercase;
}

.cg-val {
  font-size: 11px;
  color: #E2E8F0;
  font-weight: 600;
  margin-top: 1px;
}

.cg-chip.warn .cg-val {
  color: #FBBF24;
}

/* Docked Sovereign Execution Guard (Replaces fixed floating overlap) */
.execution-dock-card {
  position: relative !important;
  bottom: auto !important;
  left: auto !important;
  right: auto !important;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #140D12 0%, #090A0F 100%);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 14px;
  margin-bottom: 14px;
  box-sizing: border-box;
}

.exec-dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #94A3B8;
  text-transform: uppercase;
}

.exec-arm-status {
  color: #F87171;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 10px;
}

.exec-controls-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.btn-kill-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 3px 10px 3px 3px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 999px;
  color: #FCA5A5;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.kill-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #EF4444;
  color: #050507;
  font-size: 13px;
  font-weight: 900;
  flex-shrink: 0;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
  transition: transform 0.2s ease;
}

.kill-label {
  white-space: nowrap;
  font-size: 10px;
}

.btn-rebalance-dock {
  height: 38px;
  padding: 0 14px;
  background: rgba(0, 200, 5, 0.12);
  border: 1px solid rgba(0, 200, 5, 0.35);
  border-radius: 10px;
  color: #34D399;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
