:root {
  /* Default (Light) Theme */
  --bg-gradient: radial-gradient(circle at top left, #eef2ff, #f8fafc, #fff1f2);
  --glass-bg: rgba(255, 255, 255, 0.65);
  --glass-border: rgba(255, 255, 255, 0.4);
  --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);

  --primary: #6366f1;
  /* Indigo 500 */
  --primary-hover: #4f46e5;
  --secondary: #0ea5e9;
  /* Sky 500 */
  --text-main: #1e293b;
  /* Slate 800 */
  --text-muted: #64748b;
  /* Slate 500 */
  --accent-glow: rgba(99, 102, 241, 0.2);

  --sidebar-bg: rgba(255, 255, 255, 0.5);
  --input-bg: rgba(255, 255, 255, 0.8);
  --user-bubble: linear-gradient(135deg, #6366f1, #8b5cf6);
  --ai-bubble: rgba(255, 255, 255, 0.7);

  /* Scrollbar */
  --scroll-thumb: #cbd5e1;
}

[data-theme="dark"] {
  /* Dark Theme - Deep Space / Cyberpunk vibes */
  --bg-gradient: radial-gradient(circle at top, #0f172a, #1e1b4b);
  --glass-bg: rgba(30, 41, 59, 0.6);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

  --primary: #818cf8;
  /* Indigo 400 */
  --primary-hover: #6366f1;
  --secondary: #38bdf8;
  --text-main: #f1f5f9;
  /* Slate 100 */
  --text-muted: #94a3b8;
  /* Slate 400 */
  --accent-glow: rgba(129, 140, 248, 0.15);

  --sidebar-bg: rgba(15, 23, 42, 0.6);
  --input-bg: rgba(30, 41, 59, 0.6);
  --user-bubble: linear-gradient(135deg, #4f46e5, #7c3aed);
  --ai-bubble: rgba(30, 41, 59, 0.7);

  --scroll-thumb: #475569;
}

* {
  box-sizing: border-box;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  /* Keep heavy gradient fixed */
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Glassmorphism Utility */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 280px;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  border-right: 1px solid var(--glass-border);
  background: var(--sidebar-bg);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.brand {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 2rem;
  letter-spacing: -0.5px;
}

.new-chat-btn {
  background: linear-gradient(135deg, var(--primary), #4338ca);
  color: white;
  border: none;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.history-list {
  margin-top: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.history-item {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
}

.history-item:hover {
  background: var(--accent-glow);
  color: var(--primary);
  border-color: var(--glass-border);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Main Content */
.main-content {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.top-bar {
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: flex-end;
  /* Just the theme toggle here */
  align-items: center;
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  pointer-events: none;
  /* Let clicks pass through to chat */
}

.top-bar>* {
  pointer-events: auto;
}

.theme-toggle {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 0.5rem;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}

.theme-toggle:hover {
  background: var(--accent-glow);
}

/* Chat Area */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 15% 10rem 15%;
  /* Bottom padding for input area */
  scroll-behavior: smooth;
}

/* Bubbles */
.message {
  display: flex;
  margin-bottom: 1.5rem;
  opacity: 0;
  animation: slideIn 0.3s forwards;
}

@keyframes slideIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }

  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.user-message {
  justify-content: flex-end;
}

.ai-message {
  justify-content: flex-start;
}

.bubble {
  max-width: 80%;
  padding: 1rem 1.5rem;
  border-radius: 18px;
  line-height: 1.6;
  font-size: 0.95rem;
  position: relative;
}

.user-bubble {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.ai-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(8px);
}

/* Inputs & Forms - Floating at bottom */
.input-area {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  max-width: 900px;
  z-index: 20;
}

.input-card {
  border-radius: 20px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.textarea-wrapper {
  position: relative;
  width: 100%;
}

textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 1rem 3rem 1rem 1rem;
  /* Space for send button */
  color: var(--text-main);
  font-family: inherit;
  resize: none;
  min-height: 60px;
  max-height: 200px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.send-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.send-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.5rem;
}

.file-upload-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.file-upload-label:hover {
  color: var(--primary);
}

#files {
  display: none;
}

/* Hide default file input */

/* Progress Bar */
.progress-container {
  height: 4px;
  background: var(--glass-border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
  display: none;
}

.progress-bar {
  height: 100%;
  background: var(--success, #10b981);
  width: 0%;
  transition: width 0.3s;
}

/* Citations & Analytics Links inside bubbles */
a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

a:hover {
  text-decoration: underline;
}

.confidence-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 8px;
}

.citation-box {
  background: rgba(0, 0, 0, 0.03);
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  margin-top: 8px;
  font-size: 0.85rem;
  border-radius: 0 8px 8px 0;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}