:root {
  --bg: #020d1a;
  --cyan: #00d4ff;
  --blue: #0066ff;
  --green: #00ff9d;
  --text: #e0f4ff;
  --dim: #4a7a99;
  --panel: rgba(0, 30, 60, 0.6);
  --border: rgba(0, 212, 255, 0.2);
  --border-strong: rgba(0, 212, 255, 0.5);
  --glow: 0 0 12px rgba(0, 212, 255, 0.4);
  --glow-strong: 0 0 20px rgba(0, 212, 255, 0.7);
  --font-hud: 'Orbitron', monospace;
  --font-body: 'Rajdhani', sans-serif;
}

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

/* ── ROOT: lock viewport, no overflow ── */
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

/* ── BACKGROUND CANVAS ── */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.045;
  pointer-events: none;
}

/* ══════════════════════════════════════
   BOOT SCREEN
══════════════════════════════════════ */
.boot-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.8s ease;
}
.boot-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.boot-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

.boot-arc {
  position: relative;
  width: 120px;
  height: 120px;
}

.boot-text {
  font-family: var(--font-hud);
  font-size: 0.75rem;
  letter-spacing: 0.3em;
  color: var(--cyan);
  animation: pulse-text 1.2s ease-in-out infinite;
}

/* ══════════════════════════════════════
   APP SHELL — fills full viewport
══════════════════════════════════════ */
.app {
  /* Fixed overlay, full viewport */
  position: fixed;
  inset: 0;
  z-index: 1;

  /* Vertical flex column: header + body */
  display: flex;
  flex-direction: column;

  /* Opacity transitions for boot reveal */
  opacity: 0;
  transition: opacity 0.6s ease;
}
.app.hidden { pointer-events: none; }
.app.visible { opacity: 1; }

/* ══════════════════════════════════════
   TOP BAR — fixed height, never shrinks
══════════════════════════════════════ */
#top-bar {
  position: relative;
  height: 68px;
  min-height: 68px;        /* ← prevents shrink */
  flex-shrink: 0;          /* ← never shrink */
  background: rgba(0, 10, 30, 0.92);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  overflow: hidden;
  z-index: 10;
}

.scan-line {
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0,212,255,0.06), transparent);
  animation: scan 3s ease-in-out 1s 1 forwards;
}

@keyframes scan {
  0%   { left: -60%; }
  100% { left: 110%; }
}

.top-bar-inner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
}

.top-center { text-align: center; }

.nova-title {
  font-family: var(--font-hud);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.5em;
  color: var(--cyan);
  text-shadow: var(--glow-strong);
  min-height: 2rem;
}

.nova-subtitle {
  font-family: var(--font-hud);
  font-size: 0.5rem;
  letter-spacing: 0.35em;
  color: var(--dim);
  margin-top: 2px;
}

.status-pill {
  font-family: var(--font-hud);
  font-size: 0.55rem;
  letter-spacing: 0.15em;
  padding: 4px 10px;
  border-radius: 2px;
  border: 1px solid var(--border);
  color: var(--dim);
}
.status-pill.online { color: var(--green); border-color: rgba(0,255,157,0.3); }
.status-pill.active { color: var(--cyan); border-color: var(--border-strong); }

/* ══════════════════════════════════════
   MAIN LAYOUT — fills remaining height
══════════════════════════════════════ */
.main-layout {
  /* Takes ALL remaining space after the header */
  flex: 1;
  min-height: 0;           /* ← critical: allows children to shrink below content size */

  display: flex;
  overflow: hidden;
}

/* ══════════════════════════════════════
   SIDEBAR
══════════════════════════════════════ */
.sidebar {
  width: 220px;
  min-width: 220px;
  flex-shrink: 0;
  background: rgba(0, 8, 20, 0.75);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  font-family: var(--font-hud);
  font-size: 0.5rem;
  letter-spacing: 0.25em;
  color: var(--dim);
  margin-bottom: 0.75rem;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

/* Pushes clear button to the bottom */
.sidebar-spacer { flex: 1; }

.status-row {
  display: flex;
  align-items: center;
  padding: 5px 0;
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.status-row.visible {
  opacity: 1;
  transform: translateX(0);
}

.status-label {
  font-family: var(--font-hud);
  font-size: 0.52rem;
  letter-spacing: 0.1em;
  color: var(--dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.status-dots {
  flex: 1;
  border-bottom: 1px dotted rgba(0,212,255,0.2);
  margin: 0 6px;
  position: relative;
  top: -1px;
  min-width: 8px;
}

.status-value {
  font-family: var(--font-hud);
  font-size: 0.52rem;
  letter-spacing: 0.08em;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}
.status-value.active { color: var(--cyan); }
.status-value.accent { color: var(--green); text-shadow: 0 0 8px rgba(0,255,157,0.5); }
.status-value.dim    { color: var(--dim); }

.pulse-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  animation: pulse-dot 2s ease-in-out infinite;
}
.pulse-dot.green {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

/* QUICK BUTTONS */
.quick-btn {
  display: block;
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--dim);
  font-family: var(--font-hud);
  font-size: 0.48rem;
  letter-spacing: 0.1em;
  padding: 7px 10px;
  text-align: left;
  cursor: pointer;
  margin-bottom: 6px;
  border-radius: 2px;
  transition: all 0.2s ease;
}
.quick-btn:hover {
  border-color: var(--border-strong);
  color: var(--cyan);
  box-shadow: var(--glow);
  background: rgba(0,212,255,0.04);
}

.clear-btn {
  display: block;
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,60,60,0.2);
  color: rgba(255,100,100,0.5);
  font-family: var(--font-hud);
  font-size: 0.48rem;
  letter-spacing: 0.1em;
  padding: 7px 10px;
  text-align: left;
  cursor: pointer;
  border-radius: 2px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.clear-btn:hover {
  border-color: rgba(255,60,60,0.5);
  color: rgba(255,100,100,0.9);
  box-shadow: 0 0 10px rgba(255,60,60,0.2);
}

/* ══════════════════════════════════════
   CHAT AREA — vertical flex column
══════════════════════════════════════ */
.chat-area {
  flex: 1;
  min-width: 0;            /* ← prevents overflow past sidebar */
  min-height: 0;           /* ← critical */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ══════════════════════════════════════
   MESSAGES — the scrollable region
══════════════════════════════════════ */
.messages {
  flex: 1;
  min-height: 0;           /* ← critical: enables scroll */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.messages::-webkit-scrollbar       { width: 3px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.sidebar::-webkit-scrollbar       { width: 2px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); }

/* ══════════════════════════════════════
   CHAT FOOTER — wraps flash + input
══════════════════════════════════════ */
.chat-footer {
  flex-shrink: 0;          /* ← never pushed out of view */
  border-top: 1px solid var(--border);
  background: rgba(0, 8, 20, 0.7);
  backdrop-filter: blur(10px);
}

/* ══════════════════════════════════════
   MESSAGES — bubble styles
══════════════════════════════════════ */
.message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  opacity: 0;
  animation: msg-in 0.35s ease forwards;
}

.message.user { align-self: flex-end; align-items: flex-end; }
.message.nova { align-self: flex-start; align-items: flex-start; }

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

.msg-panel {
  padding: 0.9rem 1.2rem;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border-radius: 2px;
  font-size: 1.05rem;
  line-height: 1.65;
  font-weight: 400;
}

.message.user .msg-panel {
  border-left: 2px solid var(--blue);
  border-top: 1px solid rgba(0,102,255,0.3);
  color: var(--text);
}

.message.nova .msg-panel {
  border-left: 2px solid var(--cyan);
  border-top: 1px solid var(--border);
  color: var(--text);
  box-shadow: -2px 0 14px rgba(0,212,255,0.07);
}

.msg-meta {
  font-family: var(--font-hud);
  font-size: 0.48rem;
  letter-spacing: 0.15em;
  color: var(--dim);
  margin-top: 4px;
  padding: 0 4px;
}
.message.user .msg-meta { text-align: right; }
.message.nova .msg-meta { text-align: left; color: rgba(0,212,255,0.4); }

/* ══════════════════════════════════════
   MARKDOWN RENDERING
══════════════════════════════════════ */
.msg-panel p {
  margin-bottom: 0.5rem;
}
.msg-panel p:last-child { margin-bottom: 0; }

.msg-panel strong { color: var(--cyan); font-weight: 600; }
.msg-panel em     { color: rgba(224,244,255,0.75); font-style: italic; }

.msg-panel ul,
.msg-panel ol {
  padding-left: 1.3rem;
  margin: 0.4rem 0 0.6rem;
}
.msg-panel li {
  margin-bottom: 0.3rem;
  color: var(--text);
}
.msg-panel li::marker { color: var(--cyan); }

.msg-panel code {
  font-family: 'Courier New', monospace;
  font-size: 0.88rem;
  background: rgba(0,212,255,0.08);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 2px;
  color: var(--cyan);
}

.msg-panel pre {
  background: rgba(0,5,15,0.85);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  margin: 0.6rem 0;
}
.msg-panel pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
}

.msg-panel h1,
.msg-panel h2,
.msg-panel h3 {
  font-family: var(--font-hud);
  color: var(--cyan);
  letter-spacing: 0.05em;
  margin: 0.75rem 0 0.35rem;
  line-height: 1.3;
}
.msg-panel h1 { font-size: 1rem; }
.msg-panel h2 { font-size: 0.9rem; }
.msg-panel h3 { font-size: 0.8rem; }

.msg-panel hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8rem 0;
}

/* ══════════════════════════════════════
   NETWORK FLASH
══════════════════════════════════════ */
.network-flash {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-hud);
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  color: var(--cyan);
  padding: 6px 2rem;
  animation: flash-pulse 0.8s ease-in-out infinite;
}
.network-flash.hidden { display: none; }

.flash-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  flex-shrink: 0;
  animation: flash-pulse 0.8s ease-in-out infinite;
}

@keyframes flash-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ══════════════════════════════════════
   INPUT ZONE
══════════════════════════════════════ */
.input-zone {
  padding: 0.9rem 1.5rem 1.1rem;
}

.input-wrap {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.user-input {
  flex: 1;
  background: rgba(0, 20, 45, 0.65);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  padding: 0.7rem 1rem;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.user-input::placeholder {
  color: var(--dim);
  font-family: var(--font-hud);
  font-size: 0.62rem;
  letter-spacing: 0.15em;
}

.user-input:focus {
  border-color: var(--border-strong);
  box-shadow: var(--glow);
}

.user-input::-webkit-scrollbar { width: 2px; }
.user-input::-webkit-scrollbar-thumb { background: var(--border); }

.send-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--cyan);
  font-family: var(--font-hud);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  padding: 0.7rem 1.25rem;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
  align-self: stretch;
  transition: all 0.2s ease;
}
.send-btn:hover {
  background: rgba(0,212,255,0.1);
  box-shadow: var(--glow);
}
.send-btn:active { transform: scale(0.97); }
.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ══════════════════════════════════════
   ARC LOADER
══════════════════════════════════════ */
.arc-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  padding: 0.4rem 0;
}
.arc-loader.hidden { display: none; }

/* Shared ring container */
.arc-ring {
  position: relative;
  width: 52px;
  height: 52px;
}

.arc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}
.arc-1 {
  border-top-color: var(--cyan);
  border-right-color: rgba(0,212,255,0.25);
  animation: spin 1.2s linear infinite;
}
.arc-2 {
  inset: 8px;
  border-bottom-color: var(--blue);
  border-left-color: rgba(0,102,255,0.25);
  animation: spin 0.8s linear infinite reverse;
}
.arc-3 {
  inset: 0;
  border-left-color: rgba(0,212,255,0.12);
  animation: spin 2s linear infinite;
}

.arc-center,
.boot-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 16px var(--cyan), 0 0 32px rgba(0,212,255,0.5);
  animation: pulse-center 1.2s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse-center {
  0%, 100% { opacity: 1;   transform: translate(-50%, -50%) scale(1); }
  50%       { opacity: 0.5; transform: translate(-50%, -50%) scale(0.6); }
}

.processing-text {
  font-family: var(--font-hud);
  font-size: 0.55rem;
  letter-spacing: 0.3em;
  color: var(--cyan);
  animation: pulse-text 1.2s ease-in-out infinite;
}

@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ══════════════════════════════════════
   TYPING DOTS
══════════════════════════════════════ */
.typing-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 0.6rem 0.2rem;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cyan);
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 100% { opacity: 0.2; transform: scale(0.7); }
  50%       { opacity: 1;   transform: scale(1); }
}

/* ══════════════════════════════════════
   WELCOME MESSAGE
══════════════════════════════════════ */
.welcome-msg {
  align-self: center;
  text-align: center;
  padding: 2.5rem 2rem;
  margin-top: auto;
  margin-bottom: auto;
  opacity: 0;
  animation: msg-in 0.6s ease 0.5s forwards;
}

.welcome-arc {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 1.5rem;
}

.welcome-title {
  font-family: var(--font-hud);
  font-size: 1.1rem;
  letter-spacing: 0.3em;
  color: var(--cyan);
  text-shadow: var(--glow);
  margin-bottom: 0.5rem;
}

.welcome-sub {
  font-size: 1rem;
  color: var(--dim);
  max-width: 380px;
  line-height: 1.6;
}

/* ══════════════════════════════════════
   BOOT ARC
══════════════════════════════════════ */
.boot-arc {
  position: relative;
  width: 120px;
  height: 120px;
}
.boot-arc .arc-1 { animation: spin 1.2s linear infinite; }
.boot-arc .arc-2 { animation: spin 0.8s linear infinite reverse; }
.boot-arc .arc-3 { animation: spin 2s linear infinite; }

/* ══════════════════════════════════════
   SEARCH SOURCE CITATION
══════════════════════════════════════ */
.search-source {
  font-family: var(--font-hud);
  font-size: 0.48rem;
  letter-spacing: 0.08em;
  color: rgba(0,212,255,0.35);
  margin-top: 0.6rem;
  border-top: 1px solid var(--border);
  padding-top: 0.4rem;
}
.search-source a {
  color: rgba(0,212,255,0.5);
  text-decoration: none;
}
.search-source a:hover { color: var(--cyan); }
