:root {
  --bg: #050a12;
  --surface: #0b1322;
  --surface-2: #111d33;
  --border: #1e2f4d;
  --border-glow: rgba(56, 189, 248, 0.35);
  --text: #e6eefb;
  --muted: #889ec2;
  --accent: #34d399;
  --accent-dim: rgba(52, 211, 153, 0.14);
  --sky: #38bdf8;
  --sky-dim: rgba(56, 189, 248, 0.14);
  --warn: #fbbf24;
  --warn-dim: rgba(251, 191, 36, 0.15);
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.16);
  --radius: 13px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.35) transparent;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.34); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.56); }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
  color-scheme: dark;
}
.hidden { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }

/* Utility classes (strict style-src 'self': zero inline style="" attributes!) */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-nowrap { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
.spacer { flex: 1; }
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.stack-6 { display: flex; flex-direction: column; gap: 6px; }
.stack-10 { display: flex; flex-direction: column; gap: 10px; }
.stack-12 { display: flex; flex-direction: column; gap: 12px; }
.title-sm { font-weight: 700; font-size: 14.5px; }
.title-md { font-size: 16px; }
.mono-line { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.kpi-val { font-family: var(--mono); font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.kpi-val-accent { color: var(--accent); }
.kpi-val-sky { color: var(--sky); }
.kpi-val-warn { color: var(--warn); }
.kpi-val-danger { color: var(--danger); }

/* Lock / Vault Screen */
.vault-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top, #0f2440 0%, var(--bg) 62%);
}
.vault-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.brand-row img { width: 42px; height: 42px; border-radius: 12px; }
.brand-title { font-size: 19px; font-weight: 700; margin: 0; }
.brand-sub { font-size: 12.5px; color: var(--muted); margin: 2px 0 0; }
.field { margin-top: 13px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.input, textarea.input, select.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 88px; font-family: var(--mono); font-size: 12.5px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.hint.ok { color: var(--accent); }
.hint.warn { color: var(--warn); }
.hint.err { color: var(--danger); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 13px;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: #3a5480; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #052016; }
.btn-primary:hover { background: #4be3aa; border-color: #4be3aa; }
.btn-sky { background: var(--sky-dim); border-color: rgba(56, 189, 248, 0.45); color: var(--sky); }
.btn-danger { background: var(--danger-dim); border-color: var(--danger); color: #fecaca; }
.btn-danger:hover { background: var(--danger); color: #240606; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-send-arrow {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
}
.send-icon {
  width: 17px;
  height: 17px;
  display: block;
}
.drop-active {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: rgba(52, 211, 153, 0.06);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}
.badge-9 { color: var(--accent); border-color: rgba(52, 211, 153, 0.35); background: var(--accent-dim); }
.badge-10 { color: var(--sky); border-color: rgba(56, 189, 248, 0.35); background: var(--sky-dim); }
.badge-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.4); background: var(--warn-dim); }
.badge-danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); background: var(--danger-dim); }

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  height: 100dvh;
  overflow: hidden;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-head img { width: 28px; height: 28px; border-radius: 8px; }
.node-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.node-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 9px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.node-item:hover { background: var(--surface-2); }
.node-item.active { background: var(--surface-2); border-color: var(--accent); }
.node-top { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; flex-shrink: 0; }
.dot.online { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.node-meta { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.sidebar-foot {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Main Panel + Topbar */
.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  position: relative;
}
.topbar {
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.menu-btn { display: none; }
.node-head-meta { min-width: 0; }
.theme-switcher {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
  gap: 2px;
}
.theme-pill {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.theme-pill.active { background: var(--sky-dim); color: var(--sky); }
.lang-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}
.lang-select:hover, .lang-select:focus { border-color: var(--sky); }

.demo-banner {
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.14), rgba(56, 189, 248, 0.12));
  border-bottom: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--warn);
  padding: 6px 14px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* Compact Telemetry Strip (shown in Simple theme & Mobile) */
.telemetry-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 14px;
  background: #08101d;
  border-bottom: 1px solid var(--border);
}
.tele-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.tele-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.tele-num { font-family: var(--mono); font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Navigation Tabs (Simple Mode) */
.tabs {
  display: flex;
  gap: 4px;
  padding: 7px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(52, 211, 153, 0.35); }

/* Workspace Area (Supports Simple Tabs OR 3D Mission Control HUD + Right Chat Dock!) */
.workspace-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  position: relative;
}
.primary-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tab-view { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.scroll-pane { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 11px; }

/* 3D Mission Control HUD Layouts (Theme 2: Shell3D & Theme 3: Neural3D) */
.hud-stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: radial-gradient(circle at 35% 40%, rgba(16, 40, 72, 0.38), var(--bg) 72%);
}
.hud-ticker {
  display: flex;
  flex-wrap: wrap;
  row-gap: 4px;
  column-gap: 14px;
  align-items: center;
  flex-shrink: 0;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 11.5px;
}
.hud-grid-shell3d {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
  flex: 1;
  min-height: 0;
}
.hud-grid-neural3d {
  display: grid;
  grid-template-columns: minmax(190px, 0.85fr) minmax(240px, 1.25fr) minmax(220px, 0.95fr);
  gap: 10px;
}
.hud-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
}
.hud-panel {
  background: rgba(11, 19, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.hud-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sky);
  border-bottom: 1px solid rgba(30, 47, 77, 0.8);
  padding-bottom: 6px;
}
.core-canvas {
  width: 100%;
  height: 310px;
  display: block;
  border-radius: 10px;
}
.spark-canvas {
  width: 100%;
  height: 68px;
  display: block;
  border-radius: 8px;
}
.hist-canvas {
  width: 100%;
  height: 120px;
  display: block;
  border-radius: 8px;
}
.subsys-row {
  display: grid;
  grid-template-columns: 88px 1fr 48px;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
}
.trace-log {
  font-family: var(--mono);
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 185px;
  overflow-y: auto;
}
.trace-line { display: flex; gap: 7px; align-items: baseline; padding: 3px 6px; border-radius: 6px; background: rgba(5, 10, 18, 0.65); }
.trace-ok { color: var(--accent); }
.trace-warn { color: var(--warn); }
.trace-block { color: var(--danger); }

/* Right Slide-Over Command Chat Dock (Active on 3D themes!) */
.chat-dock {
  width: clamp(290px, 31vw, 370px);
  max-width: 100%;
  min-width: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-dock-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.dock-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.quick-cmd-bar {
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.quick-cmd-bar .input, .chat-bar .input {
  min-width: 0;
  flex: 1;
}

/* Chat Bubbles, Media Preview & Inline Cards */
.msg {
  max-width: 760px;
  padding: 10px 13px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { align-self: flex-end; background: #10263e; border-color: #1e4670; }
.msg.assistant { align-self: flex-start; }
.msg.system { align-self: stretch; max-width: 820px; background: var(--surface-2); }
.msg-meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 7px; align-items: center; }
.chat-media-thumb {
  max-width: 240px;
  max-height: 180px;
  border-radius: 9px;
  border: 1px solid var(--border);
  margin-top: 6px;
  display: block;
}

.inline-card {
  max-width: 820px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--sky);
  border-radius: 13px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.inline-card.approval { border-left-color: var(--warn); background: linear-gradient(180deg, rgba(251, 191, 36, 0.06), var(--surface)); }
.inline-card.done { border-left-color: var(--accent); }
.inline-card.cancelled { border-left-color: var(--danger); }
.card-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.step-list { margin: 0; padding-left: 18px; font-size: 13px; }
.step-list li { margin: 2px 0; }

.composer-wrap {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.plan-drawer {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.plan-drawer .full { grid-column: 1 / -1; }
.chat-bar { display: flex; gap: 6px; align-items: center; }
.chat-bar input { flex: 1; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.finding-item {
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.token-progress {
  width: 100%;
  height: 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  appearance: none;
}
.token-progress::-webkit-progress-bar { background: var(--bg); border-radius: 999px; }
.token-progress::-webkit-progress-value { background: linear-gradient(90deg, var(--accent), var(--sky)); border-radius: 999px; }
.token-progress::-moz-progress-bar { background: linear-gradient(90deg, var(--accent), var(--sky)); border-radius: 999px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 12, 0.8);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 500px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.qr-video {
  width: 100%;
  max-height: 230px;
  border-radius: 12px;
  background: #000;
  object-fit: cover;
  border: 1px solid var(--border);
}

@media (max-width: 1160px) {
  .hud-grid-neural3d { grid-template-columns: 1fr 1fr; }
  .hud-grid-shell3d { grid-template-columns: 1fr; }
  .telemetry-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chat-dock {
    position: absolute;
    inset: 0 0 0 auto;
    width: min(370px, 92%);
    z-index: 42;
    box-shadow: -16px 0 48px rgba(0, 0, 0, 0.72);
  }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 274px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vw rgba(0, 0, 0, 0.6); }
  .menu-btn { display: inline-flex; }
  .hud-grid-neural3d, .hud-bottom-grid { grid-template-columns: 1fr; }
  .telemetry-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-drawer { grid-template-columns: 1fr; }
  .chat-dock {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    height: 84dvh;
    z-index: 45;
    border-left: 0;
    border-top: 1px solid var(--border-glow);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.7);
  }
}
