:root {
  --bg-obsidian: #05070b;
  --bg-graphite: #080c12;
  --bg-surface: #0b1119;
  --bg-surface-hover: #0e1622;
  --bg-elevated: #0e1622;
  --border-faint: rgba(139, 92, 246, 0.08);
  --border-subtle: rgba(139, 92, 246, 0.14);
  --border-default: rgba(139, 92, 246, 0.22);
  --border-bright: rgba(139, 92, 246, 0.40);
  --violet: #8b5cf6;
  --violet-bright: #a78bfa;
  --violet-dim: #6d28d9;
  --cyan: #15d9ff;
  --cyan-dim: #0a7a9a;
  --green: #17e89a;
  --green-dim: #0a6b48;
  --amber: #f5a623;
  --amber-dim: #8a5a10;
  --red: #ff3b4f;
  --red-dim: #8a1f2a;
  --text-primary: #e8edf5;
  --text-secondary: #91a0b5;
  --text-muted: #5a6a7e;
  --text-dim: #3d4a5c;
  --top-bar-h: 150px;
  --sidebar-w: 290px;
  --context-w: 480px;
  --hud-h: 78px;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg-obsidian);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
textarea { font-family: inherit; }

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--context-w);
  grid-template-rows: var(--top-bar-h) 1fr var(--hud-h);
  grid-template-areas:
    "topbar  topbar  topbar"
    "sidebar main    ctx"
    "hud     hud     hud";
  height: 100vh;
  width: 100vw;
}

/* TOP BAR */
.top-bar {
  grid-area: topbar;
  display: flex;
  flex-direction: column;
  background: var(--bg-graphite);
  border-bottom: 1px solid var(--border-default);
  z-index: 100;
}

.top-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 22px;
  border-bottom: 1px solid var(--border-faint);
}

.top-bar-left { display: flex; align-items: center; gap: 14px; }

.menu-toggle {
  display: none;
  width: 32px; height: 32px;
  align-items: center; justify-content: center;
  color: var(--text-secondary);
  border-radius: 6px;
}
.menu-toggle:hover { color: var(--violet-bright); background: var(--bg-surface-hover); }

.top-bar-brand { display: flex; align-items: baseline; gap: 10px; }
.brand-name {
  font-size: 28px; font-weight: 700; letter-spacing: 3px;
  color: var(--violet-bright);
}
.brand-tagline {
  font-size: 13px; color: var(--text-muted); letter-spacing: 0.5px;
}

.top-bar-title {
  font-size: 13px; font-weight: 600; letter-spacing: 2px;
  color: var(--text-muted); text-transform: uppercase;
}

.top-bar-right { display: flex; align-items: center; gap: 16px; }
.brand-status {
  font-size: 11px; font-weight: 600; letter-spacing: 1px;
  color: var(--green);
  padding: 4px 10px;
  border: 1px solid rgba(23, 232, 154, 0.3);
  border-radius: 3px;
  background: rgba(23, 232, 154, 0.05);
}
.top-bar-clock {
  font-family: var(--font-mono); font-size: 15px;
  color: var(--text-secondary);
}

/* STAT MODULES */
.top-bar-stats {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 0 20px;
  gap: 1px;
  background: var(--bg-obsidian);
}

.stat-module {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px 20px;
  gap: 6px;
  border-right: 1px solid var(--border-faint);
  position: relative;
}
.stat-module:last-child { border-right: none; }

.stat-module::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 2px; height: 100%;
  background: var(--violet);
  opacity: 0.3;
}
.stat-module#stat-attention::before { background: var(--amber); }
.stat-module#stat-critical::before { background: var(--red); }
.stat-module#stat-availability::before { background: var(--green); }

.stat-module-top { display: flex; align-items: center; gap: 8px; }
.stat-icon { width: 20px; height: 20px; color: var(--text-muted); }
.stat-label {
  font-size: 11px; font-weight: 600; letter-spacing: 1.5px;
  color: var(--text-muted); text-transform: uppercase;
}

.stat-module-value {
  font-family: var(--font-mono);
  font-size: 32px; font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}
.stat-module#stat-attention .stat-module-value { color: var(--amber); }
.stat-module#stat-critical .stat-module-value { color: var(--red); }
.stat-module#stat-availability .stat-module-value { color: var(--green); }

.stat-module-sub {
  font-size: 13px; color: var(--text-muted);
}

.stat-module-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--bg-surface);
  margin-top: 4px;
  overflow: hidden;
}
.stat-module-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--violet);
  transition: width 0.5s ease;
}
.stat-module#stat-attention .stat-module-bar-fill { background: var(--amber); }
.stat-module#stat-critical .stat-module-bar-fill { background: var(--red); }
.stat-module#stat-availability .stat-module-bar-fill { background: var(--green); }

/* HUD BAR */
.hud-bar {
  grid-area: hud;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-graphite);
  border-top: 1px solid var(--border-default);
  font-family: var(--font-mono);
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 28px; }

.hud-item { display: flex; align-items: center; gap: 8px; }
.hud-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1.5px;
  color: var(--text-dim); text-transform: uppercase;
}
.hud-value {
  font-size: 14px; color: var(--text-secondary);
}
.hud-state { color: var(--green); }
.hud-state.investigating { color: var(--cyan); }
.hud-state.error { color: var(--red); }

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* OVERLAYS */
.sidebar-overlay, .context-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(5, 7, 11, 0.6);
  z-index: 200;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active, .context-overlay.active { display: block; }

/* RESPONSIVE */
@media (max-width: 1024px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main"
      "hud";
  }
  .menu-toggle { display: flex; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 300px;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .context-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 380px;
    z-index: 300;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  .context-panel.open { transform: translateX(0); }
  .context-toggle { display: flex; }
  .top-bar-title { display: none; }
  .stat-module-sub { display: none; }
}

@media (max-width: 640px) {
  .top-bar-stats { overflow-x: auto; }
  .stat-module { min-width: 100px; }
  .brand-tagline { display: none; }
  .hud-left .hud-item:nth-child(3), .hud-right .hud-item:nth-child(2) { display: none; }
}
