/* ── Design Tokens ── */
:root {
  --bg: #0a0f1e;
  --surface: rgba(255,255,255,0.05);
  --surface-solid: #111827;
  --surface-soft: rgba(255,255,255,0.03);
  --glass: rgba(255,255,255,0.07);
  --glass-border: rgba(255,255,255,0.12);
  --text: #e2e8f0;
  --text-strong: #f8fafc;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-glow: rgba(99,102,241,0.35);
  --primary-dark: #4f46e5;
  --accent: #06b6d4;
  --accent-glow: rgba(6,182,212,0.25);
  --success: #10b981;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 25px 60px rgba(0,0,0,0.5);
  --shadow-sm: 0 4px 20px rgba(0,0,0,0.3);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --sidebar-w: 260px;
}

/* Light mode overrides */
html[data-theme="light"] {
  --bg: #f0f4ff;
  --surface: rgba(255,255,255,0.8);
  --surface-solid: #ffffff;
  --surface-soft: rgba(99,102,241,0.04);
  --glass: rgba(255,255,255,0.7);
  --glass-border: rgba(99,102,241,0.15);
  --text: #1e293b;
  --text-strong: #0f172a;
  --muted: #64748b;
  --border: rgba(99,102,241,0.12);
  --shadow: 0 25px 60px rgba(99,102,241,0.12);
  --shadow-sm: 0 4px 20px rgba(99,102,241,0.08);
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(99,102,241,0.18) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(6,182,212,0.12) 0%, transparent 60%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

/* ── Layout ── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: rgba(10,15,30,0.95);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

html[data-theme="light"] .sidebar {
  background: rgba(255,255,255,0.9);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.brand-mark {
  width: 42px; height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid; place-items: center;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 8px 24px var(--primary-glow);
  flex-shrink: 0;
}

.brand h1 { font-size: 1rem; font-weight: 700; color: var(--text-strong); }
.brand p { font-size: 0.75rem; color: var(--muted); }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.sidebar-nav a, .theme-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  border: 1px solid transparent;
  transition: all 200ms ease;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  width: 100%;
}

.sidebar-nav a:hover, .theme-toggle:hover {
  background: var(--glass);
  border-color: var(--glass-border);
  color: var(--text-strong);
  transform: translateX(3px);
}

.sidebar-nav a.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(6,182,212,0.1));
  border-color: rgba(99,102,241,0.3);
  color: var(--primary);
}

.sidebar-nav a i, .theme-toggle i { width: 18px; text-align: center; font-size: 0.95rem; }

.theme-toggle { margin-top: auto; }

.demo-banner {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(251,191,36,0.1);
  border: 1px solid rgba(251,191,36,0.25);
  color: #fbbf24;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* ── Main ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px 32px;
  max-width: 100%;
}

.auth-layout { margin-left: 0; display: grid; place-items: center; min-height: 100vh; padding: 24px; }

/* ── Glassmorphism Panel ── */
.panel, .page-header, .stat-card {
  background: var(--glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

html[data-theme="light"] .panel,
html[data-theme="light"] .page-header,
html[data-theme="light"] .stat-card {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ── Page Header ── */
.page-header {
  padding: 22px 26px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.split-header { align-items: flex-start; }

.eyebrow {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 6px;
}

.page-header h2 { font-size: 1.5rem; font-weight: 700; color: var(--text-strong); }
.page-header p { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 200ms ease;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 16px var(--primary-glow);
}
.btn-primary:hover { box-shadow: 0 8px 28px var(--primary-glow); }

.btn-secondary {
  background: var(--glass);
  color: var(--text);
  border-color: var(--glass-border);
  backdrop-filter: blur(8px);
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); }

.btn-danger {
  background: linear-gradient(135deg, var(--danger), var(--danger-dark));
  color: #fff;
  box-shadow: 0 4px 16px rgba(239,68,68,0.25);
}
.btn-danger:hover { box-shadow: 0 8px 28px rgba(239,68,68,0.4); }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  transition: transform 200ms ease;
}
.stat-card:hover { transform: translateY(-3px); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.stat-card span { font-size: 0.8rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-card strong { display: block; font-size: 2.2rem; font-weight: 800; color: var(--text-strong); margin-top: 8px; line-height: 1; }

/* ── Dashboard Grid ── */
.dashboard-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }

.panel { padding: 22px; }

.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.panel-head h3 { font-size: 1rem; font-weight: 700; color: var(--text-strong); }

/* ── List Items ── */
.list-stack { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  transition: all 200ms ease;
}
.list-item:hover {
  border-color: rgba(99,102,241,0.35);
  background: rgba(99,102,241,0.06);
  transform: translateX(4px);
}
.list-item strong { font-size: 0.9rem; color: var(--text-strong); }
.list-item p { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.list-item i { color: var(--muted); font-size: 0.85rem; }

.empty-state { color: var(--muted); font-size: 0.88rem; padding: 16px 0; }

/* ── Upload ── */
.upload-panel { min-height: 400px; }

.dropzone {
  border: 2px dashed rgba(99,102,241,0.35);
  border-radius: var(--radius);
  padding: 56px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 220ms ease;
  background: radial-gradient(ellipse at center, rgba(99,102,241,0.05), transparent 70%);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: radial-gradient(ellipse at center, rgba(99,102,241,0.12), transparent 70%);
  transform: scale(1.01);
}
.dropzone i { font-size: 2.8rem; color: var(--primary); margin-bottom: 12px; display: block; }
.dropzone h3 { font-size: 1.1rem; color: var(--text-strong); margin-bottom: 6px; }
.dropzone p { color: var(--muted); font-size: 0.88rem; }

.upload-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 18px 0; flex-wrap: wrap; }
.helper-text { color: var(--muted); font-size: 0.82rem; margin: 0; }

.file-list { display: flex; flex-direction: column; gap: 8px; }
.file-item {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2);
  font-size: 0.88rem;
}
.file-item strong { color: var(--text-strong); }
.file-item p { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

/* ── Summary Grid ── */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}
.summary-grid.full { grid-template-columns: 1fr; }
.summary-grid.full .summary-side { display: none; }

.summary-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.summary-controls label { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }

input, select {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  backdrop-filter: blur(8px);
  transition: border-color 200ms;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

html[data-theme="light"] input,
html[data-theme="light"] select { background: #fff; }

.summary-text {
  line-height: 1.85;
  font-size: 0.97rem;
  min-height: 200px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.summary-text p { margin: 0; }

/* ── Tags ── */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(99,102,241,0.12);
  color: var(--primary);
  border: 1px solid rgba(99,102,241,0.25);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 180ms;
}
.tag:hover { background: rgba(99,102,241,0.22); transform: scale(1.05); }

/* ── Flashcards ── */
.flashcard-list { display: flex; flex-direction: column; gap: 10px; max-height: 55vh; overflow-y: auto; padding-right: 4px; }

.flashcard {
  position: relative;
  width: 100%;
  min-height: 90px;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--glass);
  text-align: left;
  cursor: pointer;
  transition: all 200ms ease;
  font-size: 0.88rem;
  overflow: hidden;
}
.flashcard:hover { border-color: rgba(99,102,241,0.4); background: rgba(99,102,241,0.08); transform: translateY(-2px); }
.flashcard.flipped { background: rgba(6,182,212,0.08); border-color: rgba(6,182,212,0.35); }

.flashcard-front { display: block; color: var(--text); }
.flashcard-back { display: none; color: var(--accent); font-weight: 500; }
.flashcard.flipped .flashcard-front { display: none; }
.flashcard.flipped .flashcard-back { display: block; }

/* ── Export ── */
.export-group { margin-top: 20px; }
.export-group h3 { font-size: 0.88rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Chat ── */
.chat-panel { display: flex; flex-direction: column; gap: 16px; height: calc(100vh - 220px); }

.chat-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 2px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.3); border-radius: 99px; }

.chat-bubble {
  max-width: 78%;
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.65;
  animation: bubble-in 200ms ease;
}
.chat-bubble.user {
  margin-left: auto;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 4px 16px var(--primary-glow);
}
.chat-bubble.bot {
  margin-right: auto;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 16px 16px 16px 4px;
  backdrop-filter: blur(8px);
}

.chat-answer { white-space: pre-wrap; word-break: break-word; }

.chat-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}
.confidence-bar {
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  width: 60px;
  overflow: hidden;
}
.confidence-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--success), var(--accent));
  transition: width 600ms ease;
}

.chat-form {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.chat-form input { flex: 1; }
.chat-form .btn { flex-shrink: 0; }

/* typing indicator */
.typing-dots span {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot-bounce 1.2s infinite ease-in-out;
  margin: 0 2px;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── Auth ── */
.auth-card {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  border-radius: 28px;
  overflow: hidden;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

html[data-theme="light"] .auth-card { background: rgba(255,255,255,0.9); }

.auth-copy {
  padding: 52px 44px;
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(6,182,212,0.1));
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-copy h2 { font-size: 1.9rem; font-weight: 800; color: var(--text-strong); margin: 8px 0 12px; }
.auth-copy p { color: var(--muted); line-height: 1.7; }

.auth-form { padding: 52px 44px; display: flex; flex-direction: column; gap: 16px; }
.auth-form label { display: flex; flex-direction: column; gap: 7px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.auth-switch { font-size: 0.85rem; color: var(--muted); margin: 0; }
.auth-switch a { color: var(--primary); font-weight: 600; }

/* ── Toasts ── */
.toast-container { position: fixed; top: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 999; }

.toast {
  min-width: 300px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  backdrop-filter: blur(16px);
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
  animation: toast-slide 280ms cubic-bezier(0.34,1.56,0.64,1);
}
.toast.success { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.35); color: #6ee7b7; }
.toast.error   { background: rgba(239,68,68,0.15);  border-color: rgba(239,68,68,0.35);  color: #fca5a5; }
.toast.info    { background: rgba(99,102,241,0.15); border-color: rgba(99,102,241,0.35); color: #a5b4fc; }
.toast.warning { background: rgba(251,191,36,0.15); border-color: rgba(251,191,36,0.35); color: #fde68a; }

/* ── Scrollbar (global) ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 99px; }

/* ── Keyframes ── */
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-slide {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: none; }
}
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-side { display: none; }
}

@media (max-width: 820px) {
  .sidebar { position: static; width: 100%; border-right: none; border-bottom: 1px solid var(--border); padding: 16px; flex-direction: row; flex-wrap: wrap; }
  .sidebar-nav { flex-direction: row; flex: none; flex-wrap: wrap; }
  .sidebar-nav a { padding: 8px 12px; }
  .brand { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
  .app-shell { flex-direction: column; }
  .main-content { margin-left: 0; padding: 16px; }
  .dashboard-grid, .auth-card { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .chat-bubble { max-width: 92%; }
  .auth-copy { padding: 28px; }
  .auth-form { padding: 28px; }
}
