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

:root {
  --bg-primary: #06060e;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --text-primary: #e8e8f0;
  --text-secondary: #7a7a95;
  --text-muted: #4a4a60;
  --accent-medical: #f0a030;
  --accent-medical-dim: rgba(240, 160, 48, 0.15);
  --accent-spiritual: #7c3aed;
  --accent-spiritual-dim: rgba(124, 58, 237, 0.15);
  --accent-active: var(--accent-medical);
  --accent-active-dim: var(--accent-medical-dim);
  --glass-blur: 24px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Ambient Background ── */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  transition: opacity 1.5s ease, background 2s ease;
}

.bg-glow-1 {
  width: 600px;
  height: 600px;
  top: -200px;
  right: -100px;
  background: radial-gradient(circle, rgba(240, 160, 48, 0.08) 0%, transparent 70%);
}

.bg-glow-2 {
  width: 500px;
  height: 500px;
  bottom: -150px;
  left: -100px;
  background: radial-gradient(circle, rgba(124, 58, 237, 0.06) 0%, transparent 70%);
}

body.spiritual .bg-glow-1 {
  background: radial-gradient(circle, rgba(124, 58, 237, 0.08) 0%, transparent 70%);
}

body.spiritual .bg-glow-2 {
  background: radial-gradient(circle, rgba(240, 160, 48, 0.04) 0%, transparent 70%);
}

/* ── Container ── */
.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 60px 24px 40px;
  position: relative;
  z-index: 1;
}

/* ── Hero ── */
.hero {
  text-align: center;
  margin-bottom: 48px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
}

.logo-icon {
  width: 42px;
  height: 42px;
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 300;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ── Search Card ── */
.search-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  transition: border-color 0.3s ease;
}

.search-card:focus-within {
  border-color: rgba(255, 255, 255, 0.15);
}

/* ── Engine Tabs ── */
.engine-tabs {
  display: flex;
  position: relative;
  margin-bottom: 24px;
  gap: 4px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-md);
  padding: 4px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  z-index: 1;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--text-primary);
}

.tab-icon {
  font-size: 1.1rem;
}

.tab-count {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.7;
}

.tab-indicator {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 6px);
  height: calc(100% - 8px);
  background: var(--accent-active-dim);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), background 0.6s ease;
  z-index: 0;
}

/* 3-tab layout */
.three-tabs .tab-indicator {
  width: calc(33.333% - 5px);
}

.tab-indicator.center {
  transform: translateX(calc(100% + 4px));
}

.tab-indicator.right {
  transform: translateX(calc(200% + 8px));
}

/* ── Search Box ── */
.search-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 6px 4px 18px;
  transition: all 0.3s ease;
}

.search-box:focus-within {
  border-color: var(--accent-active);
  box-shadow: 0 0 0 3px var(--accent-active-dim), 0 8px 32px rgba(0, 0, 0, 0.3);
}

.search-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 14px 0;
  min-width: 0;
}

.search-input::placeholder {
  color: var(--text-muted);
}

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

.search-btn svg {
  width: 18px;
  height: 18px;
}

.search-btn:hover {
  transform: scale(1.05);
  filter: brightness(1.1);
}

.search-btn:active {
  transform: scale(0.97);
}

/* ── Hints ── */
.search-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.hint {
  padding: 6px 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.hint:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.15);
}

/* ── Results Area ── */
.results-area {
  margin-top: 32px;
  transition: opacity 0.4s ease;
}

.results-area.hidden {
  display: none;
}

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-active);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Answer Card ── */
.answer-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
  backdrop-filter: blur(var(--glass-blur));
  animation: fadeUp 0.5s ease;
}

.answer-card.hidden {
  display: none;
}

.answer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--accent-active);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.answer-icon {
  width: 18px;
  height: 18px;
}

.answer-text {
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text-primary);
}

.answer-text p {
  margin-bottom: 12px;
}

.answer-text .citation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent-active);
  background: var(--accent-active-dim);
  border-radius: 50%;
  vertical-align: super;
  margin: 0 2px;
  cursor: help;
}

/* ── Sources ── */
.sources-section {
  animation: fadeUp 0.6s ease;
}

.sources-section.hidden {
  display: none;
}

.sources-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.source-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.source-item:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.12);
}

.source-num {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-active);
  background: var(--accent-active-dim);
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}

.source-content {
  flex: 1;
  min-width: 0;
}

.source-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  word-break: break-word;
}

.source-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Footer ── */
.footer {
  margin-top: 60px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

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

/* ── Spiritual Theme ── */
body.spiritual {
  --accent-active: var(--accent-spiritual);
  --accent-active-dim: var(--accent-spiritual-dim);
}

/* ── Unified Theme ── */
body.unified {
  --accent-active: #c084fc;
  --accent-active-dim: rgba(192, 132, 252, 0.15);
}

/* ── Unified Synthesis Styles ── */
.unified-header {
  color: #c084fc;
}

.synthesis-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  background: linear-gradient(135deg, rgba(240, 160, 48, 0.2), rgba(124, 58, 237, 0.2));
  color: #d4b8ff;
  letter-spacing: 0.06em;
  margin-left: auto;
}

/* Domain-tagged citations */
.medical-citation {
  color: var(--accent-medical) !important;
  background: var(--accent-medical-dim) !important;
}

.spiritual-citation {
  color: var(--accent-spiritual) !important;
  background: var(--accent-spiritual-dim) !important;
}

/* Domain source groups */
.domain-group {
  margin-bottom: 20px;
}

.domain-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  padding-left: 4px;
}

.domain-label.medical-label {
  color: var(--accent-medical);
}

.domain-label.spiritual-label {
  color: var(--accent-spiritual);
}

/* Source domain badges */
.source-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.medical-badge {
  background: var(--accent-medical-dim);
  color: var(--accent-medical);
}

.spiritual-badge {
  background: var(--accent-spiritual-dim);
  color: var(--accent-spiritual);
}

.source-medical {
  border-left: 2px solid var(--accent-medical);
}

.source-spiritual {
  border-left: 2px solid var(--accent-spiritual);
}

/* ── Auth Gate ── */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  max-width: 420px;
  width: 90%;
  animation: fadeUp 0.6s ease;
}

.auth-card .auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
}

.auth-card .auth-logo h1 {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 300;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.auth-divider {
  width: 60px;
  height: 1px;
  background: var(--border);
  margin: 24px auto;
}

.auth-message {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.6;
  margin-bottom: 32px;
}

.passphrase-group {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.passphrase-input {
  flex: 1;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.92rem;
  outline: none;
  transition: all 0.25s ease;
}

.passphrase-input::placeholder {
  color: var(--text-muted);
}

.passphrase-input:focus {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 0 20px rgba(192, 132, 252, 0.08);
}

.passphrase-btn {
  padding: 12px 24px;
  background: linear-gradient(135deg, rgba(192, 132, 252, 0.25), rgba(240, 160, 48, 0.2));
  border: 1px solid rgba(192, 132, 252, 0.3);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
}

.passphrase-btn:hover {
  background: linear-gradient(135deg, rgba(192, 132, 252, 0.35), rgba(240, 160, 48, 0.3));
  border-color: rgba(192, 132, 252, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(192, 132, 252, 0.15);
}

.passphrase-btn:active {
  transform: translateY(0);
}

.auth-error {
  margin-top: 16px;
  color: #e05050;
  font-size: 0.82rem;
}

.auth-error.hidden {
  display: none;
}

/* ── User Bar ── */
.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.user-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-convo-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  background: var(--accent-active-dim);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 100px;
  color: var(--accent-active);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
}

.new-convo-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent-active);
  transform: translateY(-1px);
}

.new-convo-btn.hidden {
  display: none;
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.75rem;
  padding: 5px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.logout-btn:hover {
  color: var(--text-secondary);
  border-color: rgba(255, 255, 255, 0.15);
}

/* ── Conversation Container ── */
.conversation-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conversation-turn {
  animation: fadeUp 0.5s ease;
}

.conversation-turn.latest .answer-card {
  border-color: rgba(255, 255, 255, 0.12);
}

/* ── Turn Query (user question bubble) ── */
.turn-query {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 100px;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 500;
  max-width: 100%;
}

.turn-query-icon {
  color: var(--accent-active);
  flex-shrink: 0;
  display: flex;
}

.turn-query-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Turn Divider ── */
.turn-divider {
  width: 40px;
  height: 1px;
  background: linear-gradient(to right, var(--border), transparent);
  margin: 20px 0 16px 20px;
}

/* ── Collapsible sources for older turns ── */
.collapsed-sources {
  display: none;
}

.sources-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.72rem;
  padding: 4px 12px;
  margin-top: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sources-toggle:hover {
  color: var(--text-secondary);
  border-color: rgba(255, 255, 255, 0.15);
}

/* ── Follow-up Questions ── */
.follow-up-area {
  margin-top: 24px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  animation: fadeUp 0.6s ease;
}

.follow-up-area.hidden {
  display: none;
}

.follow-up-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.follow-up-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.follow-up-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.4;
}

.follow-up-chip svg {
  color: var(--accent-active);
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.follow-up-chip:hover {
  background: var(--accent-active-dim);
  border-color: rgba(255, 255, 255, 0.12);
}

.follow-up-chip:hover svg {
  opacity: 1;
  transform: translateX(3px);
}

.follow-up-chip:active {
  transform: scale(0.99);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .container {
    padding: 32px 16px 24px;
  }

  .logo h1 {
    font-size: 1.8rem;
  }

  .search-card {
    padding: 20px;
  }

  .tab-count {
    display: none;
  }

  .search-hints {
    gap: 6px;
  }

  .hint {
    font-size: 0.72rem;
    padding: 5px 10px;
  }

  .turn-query {
    font-size: 0.82rem;
    padding: 6px 12px;
  }

  .follow-up-chip {
    font-size: 0.8rem;
    padding: 8px 12px;
  }

  .user-actions {
    gap: 4px;
  }

  .new-convo-btn {
    font-size: 0.7rem;
    padding: 4px 10px;
  }
}

