/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:           #0a0f1a;
  --bg-2:         #0f1624;
  --bg-3:         #151e30;
  --surface:      #1a2540;
  --surface-2:    #1f2d4a;
  --border:       #243354;
  --border-light: #2e3f63;

  --accent:       #38bdf8;
  --accent-dim:   #0ea5e915;
  --accent-glow:  #38bdf830;
  --accent-dark:  #0369a1;

  --text:         #e2eaf5;
  --text-2:       #94a3b8;
  --text-3:       #64748b;

  --user-bubble:  #0c2d4a;
  --ai-bubble:    #111827;

  --radius:       14px;
  --radius-sm:    8px;
  --sidebar-w:    270px;

  --font-display: 'Syne', sans-serif;
  --font-mono:    'DM Mono', monospace;

  --shadow:       0 4px 24px #00000050;
  --shadow-accent:0 0 24px #38bdf820;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 16.5px;
  overflow: hidden;
}

/* ── Background Effects ─────────────────────────────────────────────────────── */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  top: -200px;
  left: 50%;
  transform: translateX(-50%);
  width: 700px;
  height: 500px;
  background: radial-gradient(ellipse, #38bdf812 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
body { display: flex; position: relative; z-index: 1; }

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.32rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logo-icon { font-size: 1.4rem; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.sidebar-close:hover { color: var(--text); background: var(--surface); }

.sidebar-section {
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
}

.topic-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.topic-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.topic-icon { font-size: 0.9rem; }

.topic-input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  width: 100%;
}

.topic-input::placeholder { color: var(--text-3); }

.sidebar-hint {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 7px;
}

.quick-prompts {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.quick-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-family: var(--font-display);
  font-size: 0.85rem;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.quick-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateX(3px);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 18px;
  font-size: 0.72rem;
  color: var(--text-3);
  line-height: 1.7;
  font-family: var(--font-mono);
  border-top: 1px solid var(--border);
}

/* ── Main ────────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  z-index: 10;
  flex-shrink: 0;
}

.menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.menu-btn:hover { background: var(--surface); }

.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-2);
  border-radius: 2px;
}

.topbar-title {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 7px;
}

.clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 1rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.clear-btn:hover {
  border-color: #ef444455;
  color: #ef4444;
  background: #ef444410;
}

/* ── Chat Window ─────────────────────────────────────────────────────────────── */
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.chat-window::-webkit-scrollbar { width: 5px; }
.chat-window::-webkit-scrollbar-track { background: transparent; }
.chat-window::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.chat-window::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Messages ────────────────────────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 12px;
  max-width: 820px;
  width: 100%;
  animation: fadeUp 0.35s ease forwards;
}

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

.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.05em;
  box-shadow: var(--shadow-accent);
}

.message.user .avatar {
  background: linear-gradient(135deg, #1e3a5f, #2563eb);
}

.bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  line-height: 1.75;
  font-size: 1rem;
  max-width: calc(100% - 50px);
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-color: var(--accent-dark);
  color: var(--text);
}

/* ── Markdown Styles inside bubble ──────────────────────────────────────────── */
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
  margin: 16px 0 8px;
  line-height: 1.3;
}

.bubble h1 { font-size: 1.35rem; }
.bubble h2 { font-size: 1.18rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.bubble h3 { font-size: 1.05rem; }
.bubble h4 { font-size: 0.95rem; color: var(--text-2); }

.bubble p { margin: 8px 0; }

.bubble ul, .bubble ol {
  padding-left: 20px;
  margin: 8px 0;
}

.bubble li { margin: 4px 0; }

.bubble strong { color: var(--accent); font-weight: 600; }
.bubble em { color: var(--text-2); font-style: italic; }

.bubble code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: #7dd3fc;
}

.bubble pre {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 12px 0;
}

.bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text);
}

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.92rem;
  overflow-x: auto;
  display: block;
}

.bubble thead tr {
  background: var(--surface-2);
  border-bottom: 2px solid var(--accent);
}

.bubble th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.87rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.bubble td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: top;
}

.bubble tbody tr:hover { background: var(--accent-dim); }

.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 10px 0;
  background: var(--accent-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-2);
  font-style: italic;
}

.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* ── Typing Indicator ────────────────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 10px 14px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* ── Input Area ──────────────────────────────────────────────────────────────── */
.input-area {
  padding: 14px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}

.input-wrap {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.query-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.6;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
}

.query-input::placeholder { color: var(--text-3); }

.send-btn {
  background: var(--accent);
  border: none;
  color: var(--bg);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.send-btn svg { width: 17px; height: 17px; }

.send-btn:hover {
  background: #7dd3fc;
  transform: scale(1.05);
  box-shadow: 0 0 14px var(--accent-glow);
}

.send-btn:disabled {
  background: var(--surface-2);
  color: var(--text-3);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.input-hint {
  font-size: 0.7rem;
  color: var(--text-3);
  margin-top: 7px;
  font-family: var(--font-mono);
}

/* ── Accent ──────────────────────────────────────────────────────────────────── */
.accent { color: var(--accent); }

/* ── Overlay ─────────────────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #00000070;
  z-index: 90;
  backdrop-filter: blur(2px);
}

/* ── Mobile Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  html, body { font-size: 15px; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-close { display: flex; }

  .overlay.show { display: block; }

  .menu-btn { display: flex; }

  .topbar-title { font-size: 0.95rem; }

  .logo { font-size: 1.2rem; }

  .chat-window { padding: 16px 12px; gap: 16px; }

  .bubble { font-size: 0.88rem; padding: 12px 14px; }

  .input-area { padding: 10px 12px 12px; }

  .input-hint { display: none; }

  .query-input { font-size: 0.92rem; }

  .bubble table { font-size: 0.78rem; }

  .bubble th { font-size: 0.75rem; }
  .bubble td { padding: 7px 10px; }

  .bubble h1 { font-size: 1.1rem; }
  .bubble h2 { font-size: 1rem;   }
  .bubble h3 { font-size: 0.92rem;}
}

@media (max-width: 420px) {
  .message { gap: 8px; }
  .avatar { width: 30px; height: 30px; font-size: 0.6rem; border-radius: 8px; }
  .bubble { padding: 10px 12px; font-size: 0.85rem; }
}