/* ── ContextAware — Black Transparent Animated UI ────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --primary: #00e5ff;
  --primary-dim: rgba(0, 229, 255, 0.15);
  --secondary: #b388ff;
  --secondary-dim: rgba(179, 136, 255, 0.15);
  --tertiary: #76ff03;
  --success: #00e676;
  --danger: #ff5252;

  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --glass-hover: rgba(255, 255, 255, 0.06);

  --text-main: #e8eaed;
  --text-muted: #8a8f98;

  --surface: #000000;
  --surface-1: #0a0a0a;
  --surface-2: #111111;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #000000;
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  position: relative;
}

/* ── Particle Canvas Background ──────────────────────── */
#particleCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ── Animated Mesh Glow Background ──────────────────── */
.bg-mesh {
  position: fixed;
  inset: -30%;
  z-index: 0;
  background-image:
    radial-gradient(at 20% 30%, rgba(0, 229, 255, 0.06) 0px, transparent 50%),
    radial-gradient(at 80% 20%, rgba(179, 136, 255, 0.05) 0px, transparent 50%),
    radial-gradient(at 50% 80%, rgba(0, 230, 118, 0.04) 0px, transparent 50%),
    radial-gradient(at 10% 80%, rgba(0, 229, 255, 0.03) 0px, transparent 40%),
    radial-gradient(at 90% 70%, rgba(179, 136, 255, 0.03) 0px, transparent 40%);
  filter: blur(80px);
  opacity: 1;
  animation: meshDrift 25s ease-in-out infinite alternate;
}

@keyframes meshDrift {
  0%   { transform: scale(1) rotate(0deg) translate(0, 0); }
  33%  { transform: scale(1.1) rotate(5deg) translate(2%, -1%); }
  66%  { transform: scale(1.05) rotate(-3deg) translate(-1%, 2%); }
  100% { transform: scale(1.15) rotate(8deg) translate(1%, -2%); }
}

/* ── Scrollbar ────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 229, 255, 0.15);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 229, 255, 0.3);
}

/* ── Layout ───────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  padding: 0.75rem;
  gap: 0.75rem;
  position: relative;
  z-index: 1;
}
@media (max-width: 768px) { .app-layout { padding: 0.4rem; gap: 0.4rem; } }

/* ── Glass Containers ──────────────────────────────── */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(120%);
  -webkit-backdrop-filter: blur(20px) saturate(120%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 20px;
  transition: background 0.4s ease, border-color 0.4s ease;
}
.glass-panel:hover {
  border-color: rgba(255, 255, 255, 0.08);
}

/* ── Sidebar ──────────────────────────────── */
.sidebar {
  width: 300px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 40;
  border-right: 1px solid rgba(0, 229, 255, 0.05);
}
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0.4rem;
    top: 0.4rem;
    bottom: 0.4rem;
    width: calc(100% - 0.8rem);
  }
  .sidebar.collapsed {
    transform: translateX(-110%) scale(0.96);
    opacity: 0;
    pointer-events: none;
  }
}

/* ── Main Chat Area ───────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Chat Messages ────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  scroll-behavior: smooth;
  margin-bottom: 90px;
}
@media (max-width: 768px) { .chat-messages { padding: 1rem; margin-bottom: 80px; } }

.message {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  animation: msgSlideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.message.user .message-avatar {
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid rgba(0, 229, 255, 0.2);
  color: var(--primary);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.1);
}
.message.assistant .message-avatar {
  background: rgba(179, 136, 255, 0.08);
  border: 1px solid rgba(179, 136, 255, 0.15);
  font-size: 1.2rem;
  box-shadow: 0 0 15px rgba(179, 136, 255, 0.08);
}

.message-content {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 1.1rem 1.4rem;
  border-radius: 4px 16px 16px 16px;
  transition: border-color 0.3s ease;
}
.message-content:hover {
  border-color: rgba(255, 255, 255, 0.08);
}
.message.user .message-content {
  border-radius: 16px 4px 16px 16px;
  background: rgba(0, 229, 255, 0.04);
  border-color: rgba(0, 229, 255, 0.08);
}

.message-text {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text-main);
  font-weight: 400;
  text-align: left;
  white-space: normal;
}
.message-text p { margin-bottom: 0.8rem; }
.message-text p:last-child { margin-bottom: 0; }

.message.assistant .message-content,
.message.assistant .message-text,
.message.assistant .message-text p,
.message.assistant .message-text ul,
.message.assistant .message-text ol,
.message.assistant .message-text li {
  text-align: left;
}

.message-text code {
  background: rgba(0, 229, 255, 0.08);
  color: var(--primary);
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.83rem;
  font-weight: 500;
  border: 1px solid rgba(0, 229, 255, 0.1);
}

.message-text pre {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 1.2rem;
  overflow-x: auto;
  margin: 1rem 0;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}
.message-text pre code {
  background: none;
  border: none;
  padding: 0;
  color: #c8ccd0;
  font-size: 0.83rem;
}
.message-text ul, .message-text ol { padding-left: 1.5rem; margin-bottom: 0.8rem; }
.message-text li { margin-bottom: 0.4rem; }

/* ── Floating Chat Input ───────────────────────────── */
.chat-input-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem 2rem;
  pointer-events: none;
}
@media (max-width: 768px) { .chat-input-area { padding: 0.5rem; } }

.chat-input-wrapper {
  pointer-events: auto;
  max-width: 850px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.8rem;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(0, 229, 255, 0.03);
  border-radius: 20px;
  padding: 0.5rem 0.5rem 0.5rem 1.1rem;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.chat-input-wrapper:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.6), 0 0 40px rgba(0, 229, 255, 0.08);
  border-color: rgba(0, 229, 255, 0.2);
}

.chat-input-wrapper textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  max-height: 150px;
  line-height: 1.5;
  padding: 0.5rem 0;
  font-weight: 400;
}
.chat-input-wrapper textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.2), rgba(179, 136, 255, 0.2));
  border: 1px solid rgba(0, 229, 255, 0.2);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  flex-shrink: 0;
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.1);
}
.send-btn:hover {
  transform: scale(1.08) translateY(-1px);
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.25);
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.3), rgba(179, 136, 255, 0.3));
  border-color: rgba(0, 229, 255, 0.4);
}
.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Interactive Elements ───────────────────────── */
.doc-card, .chat-card, .welcome-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

.doc-card:hover, .chat-card:hover, .welcome-card:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3), 0 0 20px rgba(0, 229, 255, 0.04);
  border-color: rgba(0, 229, 255, 0.12);
}

.upload-zone {
  border: 1px dashed rgba(0, 229, 255, 0.2);
  border-radius: 14px;
  padding: 1.5rem;
  text-align: center;
  background: rgba(0, 229, 255, 0.02);
  transition: all 0.3s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(0, 229, 255, 0.05);
  box-shadow: 0 0 25px rgba(0, 229, 255, 0.08);
}
.upload-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 2; }

/* ── Typography & Welcome ────────────────────────── */
.gradient-text {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

.welcome-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: 600px;
  margin-top: 2rem;
}

/* ── Buttons & Toggles ────────────────────────────── */
.btn-glass {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  color: var(--text-main);
  padding: 0.5rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  transition: all 0.3s;
  cursor: pointer;
}
.btn-glass:hover {
  background: rgba(0, 229, 255, 0.06);
  border-color: rgba(0, 229, 255, 0.15);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.06);
}

/* Theme Toggle */
.theme-toggle {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

/* ── Animations ────────────────────────────────── */
@keyframes msgSlideIn {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes float {
  0%   { transform: translateY(0px); }
  50%  { transform: translateY(-8px); }
  100% { transform: translateY(0px); }
}
.floating { animation: float 5s ease-in-out infinite; }

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 10px rgba(0, 229, 255, 0.1); }
  50% { box-shadow: 0 0 25px rgba(0, 229, 255, 0.2); }
}

@keyframes border-glow {
  0%, 100% { border-color: rgba(0, 229, 255, 0.08); }
  50% { border-color: rgba(0, 229, 255, 0.2); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Sources Toggle Panel */
.sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.8rem;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  background: rgba(0, 229, 255, 0.06);
  border: 1px solid rgba(0, 229, 255, 0.12);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}
.sources-toggle:hover {
  background: rgba(0, 229, 255, 0.1);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.08);
}

.sources-panel {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  margin-top: 0.5rem;
}
.sources-panel.open { max-height: 800px; }
.source-chip {
  background: rgba(255, 255, 255, 0.02);
  border-left: 3px solid var(--primary);
  border-radius: 0 10px 10px 0;
  padding: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.source-meta {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.73rem;
  margin-bottom: 0.3rem;
}

.latency-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.6rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  background: rgba(0, 230, 118, 0.06);
  border: 1px solid rgba(0, 230, 118, 0.12);
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--success);
}

.typing-indicator { display: flex; gap: 0.4rem; padding: 0.5rem 0; }
.typing-indicator span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingBounce 1.4s infinite ease-in-out both;
  opacity: 0.6;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce { 0%, 80%, 100% { transform: scale(0); opacity: 0.3; } 40% { transform: scale(1); opacity: 1; } }

/* ── Document Selection Gateway ──────────────────── */
.gateway-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.2rem;
  margin: 0 auto;
}
@media(min-width: 768px) {
  .gateway-options { grid-template-columns: 1fr 1fr; }
}

.gateway-card {
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  border-radius: 18px;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  min-height: 230px;
}
.gateway-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4), 0 0 30px rgba(0, 229, 255, 0.06);
  border-color: rgba(0, 229, 255, 0.15);
}

.gateway-doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.gateway-doc-item:hover {
  background: rgba(0, 229, 255, 0.05);
  border-color: rgba(0, 229, 255, 0.15);
  transform: translateX(3px);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.05);
}

.gateway-upload-zone {
  border: 1px dashed rgba(179, 136, 255, 0.25);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  background: rgba(179, 136, 255, 0.02);
  transition: all 0.3s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.gateway-upload-zone:hover, .gateway-upload-zone.dragover {
  border-color: var(--secondary);
  background: rgba(179, 136, 255, 0.05);
  box-shadow: 0 0 25px rgba(179, 136, 255, 0.08);
}
.gateway-upload-zone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 2;
}

/* ── Active Document Highlight ───────────────────── */
.doc-card.doc-active {
  background: rgba(0, 229, 255, 0.06) !important;
  border-color: rgba(0, 229, 255, 0.2) !important;
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.08);
}

/* ── Modal Styles ────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}
.modal-overlay.hidden {
  display: none;
}
.modal-content {
  transform: scale(0.96) translateY(15px);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay:not(.hidden) .modal-content {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* ── Glow Line Accents ──────────────────────── */
.glow-line {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 229, 255, 0.15), transparent);
  margin: 1.5rem 0;
}

/* ── Page Container (roadmap/change pages) ───── */
.page-container {
  max-width: 1200px;
  margin: 2rem auto;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  border-radius: 24px;
  padding: 3rem;
  position: relative;
}
@media (max-width: 768px) {
  .page-container { margin: 1rem; padding: 1.5rem; border-radius: 18px; }
}

/* ── Auth Custom Styles ──────────────────────── */
.animate-fade-in {
  animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#authOverlay {
  background: rgba(5, 7, 10, 0.85) !important;
  backdrop-filter: blur(25px) saturate(180%);
}
