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

:root {
  --navy:        #0f1724;
  --navy-2:      #161f30;
  --navy-3:      #1c2840;
  --navy-4:      #243050;
  --gold:        #c8a84b;
  --gold-dim:    #9a7d34;
  --gold-glow:   rgba(200,168,75,0.15);
  --text-1:      #e8e2d4;
  --text-2:      #9ba8bc;
  --text-3:      #576070;
  --border:      rgba(255,255,255,0.07);
  --border-gold: rgba(200,168,75,0.3);
  --red-soft:    #e05252;
  --green-soft:  #4caf82;
  --sidebar-w:   272px;
  --topbar-h:    56px;
  --input-h:     96px;
  --radius:      12px;
  --transition:  0.2s ease;
}

html { height: 100%; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--navy);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  background: var(--gold-glow);
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--gold);
  flex-shrink: 0;
}

.brand-name {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
  display: block;
  line-height: 1.1;
}

.brand-sub {
  font-size: 10px;
  color: var(--text-3);
  display: block;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.new-chat-btn {
  margin: 14px 14px 10px;
  padding: 10px 14px;
  background: var(--gold-glow);
  border: 1px solid var(--border-gold);
  border-radius: 9px;
  color: var(--gold);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition), border-color var(--transition);
  width: calc(100% - 28px);
}

.new-chat-btn:hover {
  background: rgba(200,168,75,0.22);
  border-color: var(--gold);
}

.new-chat-icon { font-size: 16px; font-weight: 300; }

.sidebar-section-label {
  padding: 10px 18px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 1px;
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.sessions-list::-webkit-scrollbar { width: 3px; }
.sessions-list::-webkit-scrollbar-thumb { background: var(--navy-4); border-radius: 2px; }

.sessions-empty {
  padding: 12px 10px;
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
  position: relative;
}

.session-item:hover { background: var(--navy-3); }

.session-item.active {
  background: var(--navy-4);
  border: 1px solid var(--border-gold);
}

.session-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold-dim);
  flex-shrink: 0;
}

.session-item.active .session-dot { background: var(--gold); }

.session-label {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.session-item.active .session-label { color: var(--text-1); }

.session-count {
  font-size: 10px;
  color: var(--text-3);
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-disclaimer {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.4;
}

.disclaimer-icon { color: var(--gold-dim); flex-shrink: 0; }

.footer-meta {
  font-size: 10px;
  color: var(--text-3);
  line-height: 1.5;
}

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

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  background: var(--navy);
}

.topbar-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 500px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-2);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-soft);
  transition: background var(--transition);
}

.status-pill.loading .status-dot {
  background: var(--gold);
  animation: pulse 1s infinite;
}

.status-pill.error .status-dot { background: var(--red-soft); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Screens ── */
.screen {
  display: none;
  flex: 1;
  overflow: hidden;
}

.screen.active { display: flex; }

/* ── Welcome screen ── */
.screen-welcome {
  align-items: center;
  justify-content: center;
  padding: 40px 24px 120px;
  flex-direction: column;
}

.welcome-inner {
  max-width: 640px;
  width: 100%;
  text-align: center;
  animation: fadeUp 0.5s ease;
}

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

.welcome-emblem {
  font-size: 48px;
  margin-bottom: 20px;
  opacity: 0.7;
}

.welcome-heading {
  font-family: 'Cormorant Garamond', serif;
  font-size: 52px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 14px;
  line-height: 1.1;
}

.welcome-body {
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.7;
  margin-bottom: 40px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.suggestion-pill {
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 16px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  text-align: left;
  line-height: 1.5;
  transition: all var(--transition);
}

.suggestion-pill:hover {
  background: var(--navy-3);
  border-color: var(--border-gold);
  color: var(--text-1);
  transform: translateY(-1px);
}

/* ── Chat screen ── */
.screen-chat { flex-direction: column; }

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0 16px;
}

.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--navy-4); border-radius: 2px; }

.messages-list {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Message bubbles ── */
.msg { display: flex; flex-direction: column; gap: 8px; animation: fadeUp 0.3s ease; }

.msg-user { align-items: flex-end; }
.msg-ai   { align-items: flex-start; }

.bubble-user {
  background: var(--navy-4);
  border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  padding: 12px 16px;
  max-width: 72%;
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.6;
}

.bubble-ai {
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 4px 16px 16px 16px;
  padding: 18px 20px;
  max-width: 88%;
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.75;
  position: relative;
}

.bubble-ai p { margin-bottom: 12px; }
.bubble-ai p:last-child { margin-bottom: 0; }

/* AI bubble meta row */
.bubble-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.verify-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}

.verify-badge.verified {
  background: rgba(76,175,130,0.12);
  color: var(--green-soft);
  border: 1px solid rgba(76,175,130,0.3);
}

.verify-badge.unverified {
  background: rgba(224,82,82,0.1);
  color: #e8a060;
  border: 1px solid rgba(224,82,82,0.3);
}

.sources-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--gold);
  background: var(--gold-glow);
  border: 1px solid var(--border-gold);
  border-radius: 20px;
  padding: 3px 12px;
  cursor: pointer;
  transition: background var(--transition);
}

.sources-btn:hover { background: rgba(200,168,75,0.22); }

.latency-label {
  font-size: 11px;
  color: var(--text-3);
  margin-left: auto;
}

.truncated-note {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 8px;
  font-style: italic;
}

/* Loading bubble */
.bubble-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-3);
  font-size: 13px;
  padding: 14px 18px;
}

.dots { display: flex; gap: 4px; }
.dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  animation: dotBounce 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Error bubble */
.bubble-error {
  background: rgba(224,82,82,0.08);
  border: 1px solid rgba(224,82,82,0.25);
  border-left: 3px solid var(--red-soft);
  border-radius: 4px 16px 16px 16px;
  padding: 14px 18px;
  color: #e8a0a0;
  font-size: 13px;
  max-width: 80%;
}

/* ── Sources side panel ── */
.sources-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
}

.sources-panel {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background: var(--navy-2);
  border-left: 1px solid var(--border);
  z-index: 101;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.sources-panel.open,
.sources-overlay.open {
  display: flex;
}

.sources-panel.open { transform: translateX(0); }

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

.sources-panel-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-1);
}

.sources-panel-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color var(--transition);
}

.sources-panel-close:hover { color: var(--text-1); }

.sources-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sources-panel-body::-webkit-scrollbar { width: 3px; }
.sources-panel-body::-webkit-scrollbar-thumb { background: var(--navy-4); }

.source-card {
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  transition: border-color var(--transition);
}

.source-card:hover { border-color: var(--border-gold); }

.source-id {
  font-family: 'Cormorant Garamond', serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 4px;
}

.source-year {
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 10px;
}

.source-excerpt {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
  border-left: 2px solid var(--border-gold);
  padding-left: 10px;
}

.source-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: var(--navy-4);
  border-radius: 50%;
  font-size: 10px;
  color: var(--text-3);
  margin-bottom: 6px;
}

/* ── Input zone ── */
.input-zone {
  padding: 12px 24px 14px;
  background: linear-gradient(transparent, var(--navy) 30%);
  flex-shrink: 0;
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 10px 10px 16px;
  transition: border-color var(--transition);
}

.input-box:focus-within { border-color: var(--border-gold); }

.query-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--text-1);
  resize: none;
  max-height: 140px;
  line-height: 1.6;
  padding: 2px 0;
}

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

.send-btn {
  width: 38px;
  height: 38px;
  background: var(--gold);
  border: none;
  border-radius: 9px;
  color: var(--navy);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform 0.1s;
}

.send-btn:hover { background: #dbb95c; transform: scale(1.04); }
.send-btn:disabled { background: var(--navy-4); color: var(--text-3); cursor: not-allowed; transform: none; }

.input-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 8px;
}

/* ── Answer formatting ── */
.bubble-ai ol, .bubble-ai ul {
  margin: 10px 0 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble-ai ol { list-style: decimal; }
.bubble-ai ul { list-style: disc; }

.bubble-ai li {
  color: var(--text-1);
  line-height: 1.6;
  padding-left: 4px;
}

.bubble-ai h1, .bubble-ai h2, .bubble-ai h3 {
  font-family: 'Cormorant Garamond', serif;
  color: var(--gold);
  margin: 16px 0 8px;
}

.bubble-ai h1 { font-size: 20px; }
.bubble-ai h2 { font-size: 17px; }
.bubble-ai h3 { font-size: 15px; }

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

.bubble-ai code {
  background: var(--navy-4);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  color: var(--gold);
}

.answer-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.answer-table td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  color: var(--text-2);
  line-height: 1.5;
}

.answer-table tr:first-child td {
  background: var(--navy-3);
  color: var(--text-1);
  font-weight: 600;
}

.answer-table tr:hover td { background: var(--navy-3); }

.bubble-ai p {
  margin-bottom: 10px;
}

.bubble-ai p:last-child { margin-bottom: 0; }

/* ── Analytics ────────────────────────────────────────────── */
.analytics-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.analytics-btn:hover {
  background: var(--navy-3);
  color: var(--text-1);
}

.screen-analytics {
  padding: 32px;
  overflow-y: auto;
  height: 100%;
}
.analytics-inner {
  max-width: 800px;
  margin: 0 auto;
}
.analytics-header h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 28px;
  margin: 0 0 4px;
}
.analytics-header p {
  color: var(--text-2);
  font-size: 14px;
  margin: 0 0 32px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
}
.stat-value {
  font-size: 28px;
  font-weight: 600;
}

/* ── Responsive Improvements ── */
html {
  scroll-behavior: smooth;
}

@media (max-width: 768px) {
  :root {
    --sidebar-w: 208px;
    --topbar-h: 48px;
  }

  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100% !important;
    height: auto;
    max-height: 40vh;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .main-wrapper {
    flex: 1;
    overflow-y: auto;
  }

  .topbar-title {
    font-size: 14px;
    max-width: 60%;
  }

  .screen {
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  .screen-welcome {
    padding: 20px 16px 60px !important;
  }

  .welcome-inner {
    max-width: 100% !important;
  }

  .chat-bubble {
    max-width: 95% !important;
  }

  .msg-text {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .sessions-list {
    max-height: 200px;
  }

  .topbar {
    padding: 0 12px;
  }

  .topbar-title {
    font-size: 12px;
  }

  .status-pill {
    font-size: 11px;
    padding: 4px 8px;
  }

  .screen-welcome {
    padding: 16px 12px 40px !important;
  }

  .welcome-inner h1 {
    font-size: 20px !important;
    line-height: 1.3;
  }

  .chat-container {
    max-height: 300px;
  }
}
  color: var(--text-1);
  font-family: 'Cormorant Garamond', serif;
}
.stat-label {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.analytics-charts {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.chart-card {
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.chart-card h3 {
  font-size: 14px;
  font-weight: 500;
  margin: 0 0 16px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.chart-container {
  min-height: 60px;
}
.no-data {
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
  padding: 16px 0;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.bar-label {
  width: 100px;
  color: var(--text-3);
  text-align: right;
  flex-shrink: 0;
}
.bar-track {
  flex: 1;
  height: 8px;
  background: var(--navy-3);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.bar-value {
  width: 30px;
  color: var(--text-1);
  font-weight: 500;
  text-align: right;
}

.sparkline {
  width: 100%;
  height: 60px;
}
.sparkline-range {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

.analytics-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
}
.refresh-btn {
  padding: 8px 16px;
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}
.refresh-btn:hover {
  background: var(--navy-4);
}
.analytics-note {
  font-size: 12px;
  color: var(--text-3);
}