/* ============================================
   RAG ChatBot — Minimal UI
   Monochrome, typography-led, no decorative noise.
   Light + dark via [data-theme] (app.js controls it).
   All class names/IDs unchanged — app.js + tests depend on them.
   ============================================ */

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

/* Keep the hidden attribute authoritative over any display rule */
[hidden] {
  display: none !important;
}

:root,
[data-theme="light"] {
  --bg-app: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-header: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f7f7f8;
  --bg-active: #f0f0f1;
  --bg-input: #ffffff;
  --bg-pill: #ffffff;
  --bg-pill-hover: #f0f0f1;

  --text-primary: #18181b;
  --text-secondary: #71717a;
  --text-tertiary: #a1a1aa;

  /* Single neutral accent — near-black interactive elements */
  --accent: #18181b;
  --accent-hover: #000000;
  --accent-contrast: #ffffff;

  --status-green: #16a34a;
  --status-green-pulse: rgba(22, 163, 74, 0.18);
  --status-error: #dc2626;
  --status-error-bg: #fef2f2;
  --status-error-border: #fecaca;

  --border-subtle: #ececee;
  --border-default: #e4e4e7;
  --border-strong: #d4d4d8;

  --shadow-sm: none;
  --shadow-card: none;
  --shadow-dropdown: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 10px;
}

[data-theme="dark"] {
  --bg-app: #09090b;
  --bg-sidebar: #0c0c0e;
  --bg-header: #0c0c0e;
  --bg-card: #111113;
  --bg-hover: #1c1c1f;
  --bg-active: #26262a;
  --bg-input: #111113;
  --bg-pill: #111113;
  --bg-pill-hover: #1c1c1f;

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #63636b;

  --accent: #fafafa;
  --accent-hover: #ffffff;
  --accent-contrast: #18181b;

  --status-green: #22c55e;
  --status-green-pulse: rgba(34, 197, 94, 0.2);
  --status-error: #f87171;
  --status-error-bg: rgba(239, 68, 68, 0.1);
  --status-error-border: rgba(239, 68, 68, 0.25);

  --border-subtle: #1c1c1f;
  --border-default: #26262a;
  --border-strong: #3f3f46;

  --shadow-sm: none;
  --shadow-card: none;
  --shadow-dropdown: 0 4px 16px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
}

html, body {
  height: 100%;
  width: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  transition: background-color 0.15s ease, color 0.15s ease;
  -webkit-font-smoothing: antialiased;
}

/* Accessibility helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 1.5px solid var(--text-secondary);
  outline-offset: 2px;
}

/* ==================== LAYOUT ==================== */
.app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh; /* account for mobile browser chrome */
  width: 100%;
  overflow: hidden;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  width: 260px;
  min-width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  z-index: 40;
  overflow: hidden; /* collapsed width-0 must clip children, not spill them over main */
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s ease;
}

.sidebar.collapsed {
  width: 0px;
  min-width: 0px;
  transform: translateX(-100%);
  border-right: none;
}

.sidebar-header {
  height: 60px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-sub {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--text-tertiary);
  margin-top: 1px;
}

.sidebar-collapse-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s ease, background 0.12s ease;
}

.sidebar-collapse-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-section {
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
}

.conversation-section {
  flex: 1;
  overflow-y: auto;
  padding-top: 8px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}

.section-title {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.section-icon-btn {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.section-icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Upload zone */
.large-upload-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
  background-color: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  user-select: none;
  text-align: center;
  margin-bottom: 12px;
}

.large-upload-card:hover {
  border-color: var(--text-tertiary);
  background-color: var(--bg-hover);
}

.large-upload-card.drag-over {
  border-color: var(--text-primary);
  background-color: var(--bg-hover);
}

.upload-icon-circle {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.upload-main-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.upload-sub-text {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Empty state */
.empty-docs-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px 10px;
}

.empty-docs-icon-box {
  color: var(--text-tertiary);
  margin-bottom: 8px;
  opacity: 0.7;
}

.empty-docs-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.empty-docs-desc {
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Document rows */
.doc-list-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 220px;
  overflow-y: auto;
}

.doc-row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  background-color: transparent;
  transition: background 0.12s ease;
}

.doc-row-item:hover {
  background-color: var(--bg-hover);
}

.doc-row-item.active {
  background-color: var(--bg-active);
}

.doc-left-group {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}

/* Uniform neutral file-type chips (class names kept for app.js) */
.doc-type-icon {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  background-color: var(--bg-active);
  color: var(--text-secondary);
}

.doc-text-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.doc-filename {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-submeta {
  font-size: 10.5px;
  color: var(--text-tertiary);
}

.doc-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--status-green);
  flex-shrink: 0;
  margin-left: 6px;
}

.doc-status-dot.indexing {
  background-color: var(--text-tertiary);
  animation: pulse 1.4s infinite;
}

.doc-status-dot.failed {
  background-color: var(--status-error);
}

.doc-delete-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.doc-row-item:hover .doc-delete-btn {
  display: flex;
}

.doc-delete-btn:hover {
  color: var(--status-error);
}

/* Upload progress */
.upload-progress-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}

/* Upload progress cards: real % while uploading, indeterminate while indexing */
.upload-file-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 10px;
  font-size: 11.5px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}

.upload-file-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.upload-file-name {
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-file-status {
  color: var(--text-tertiary);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.upload-file-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--bg-active);
  overflow: hidden;
}

.upload-file-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.upload-file-bar-fill.indeterminate {
  width: 40%;
  animation: indeterminate 1.1s ease-in-out infinite;
}

.upload-file-item.failed .upload-file-bar-fill {
  background: var(--status-error);
  width: 100%;
  animation: none;
}

.upload-file-item.failed .upload-file-status {
  color: var(--status-error);
}

@keyframes indeterminate {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(360%); }
}

/* Conversations */
.history-list-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease;
  border: 1px solid transparent;
}

.conversation-item:hover {
  background-color: var(--bg-hover);
}

.conversation-item.active {
  background-color: var(--bg-active);
}

.conv-left-col {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.conversation-icon {
  font-size: 14px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.conversation-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-time {
  font-size: 10.5px;
  color: var(--text-tertiary);
}

.conv-delete-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
}

.conversation-item:hover .conv-delete-btn {
  display: flex;
}

.conv-delete-btn:hover {
  color: var(--status-error);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-status-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius);
}

.status-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.status-indicator-line,
.engine-indicator-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-tertiary);
}

.status-dot.connected {
  background-color: var(--status-green);
}

.status-dot.disconnected {
  background-color: var(--status-error);
}

.status-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.shield-icon {
  color: var(--text-tertiary);
}

.engine-label {
  font-size: 11px;
  color: var(--text-tertiary);
}

.info-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s ease, background 0.12s ease;
}

.info-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  background-color: var(--bg-app);
  overflow: hidden;
}

.main-header {
  height: 60px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-header);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu-btn {
  display: none;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Reopen control: the header ☰ appears while the sidebar is collapsed on desktop */
.app-layout:has(.sidebar.collapsed) .mobile-menu-btn {
  display: flex;
}

.header-titles {
  display: flex;
  flex-direction: column;
}

.header-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-main-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  line-height: 1.2;
}

.badge-grounded {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  background-color: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 10.5px;
  font-weight: 500;
}

.header-subtitle {
  font-size: 11.5px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.theme-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sun-icon { display: block; }
.moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

/* ==================== MESSAGES & CHAT AREA ==================== */
.messages-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  scroll-behavior: smooth;
}

.welcome-container {
  max-width: 680px;
  width: 100%;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero-input-card {
  width: 100%;
  background-color: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 14px 16px 10px;
  display: flex;
  flex-direction: column;
  text-align: left;
  transition: border-color 0.15s ease;
}

.hero-input-card:focus-within {
  border-color: var(--border-strong);
}

.hero-input-card textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
  min-height: 44px;
}

.hero-input-card textarea::placeholder {
  color: var(--text-tertiary);
}

.hero-input-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.hero-input-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dropdown-wrapper {
  position: relative;
}

.filter-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background-color: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.filter-pill-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.chevron-icon {
  color: var(--text-tertiary);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-dropdown);
  display: none;
  flex-direction: column;
  gap: 1px;
  z-index: 50;
  min-width: 150px;
}

.dropdown-menu.open {
  display: flex;
}

.dropdown-item {
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s ease;
}

.dropdown-item:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.dropdown-item.active {
  background-color: var(--bg-active);
  color: var(--text-primary);
  font-weight: 600;
}

.hero-input-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s ease, background 0.12s ease;
}

.tool-icon-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.stop-pill-btn {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--status-error-border);
  background: var(--status-error-bg);
  color: var(--status-error);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}

.send-action-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background-color: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.send-action-btn:not(:disabled):hover {
  background-color: var(--accent-hover);
}

.send-action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ==================== CONVERSATION MESSAGES ==================== */
.messages-container-active {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 16px 0;
}

.message-row {
  display: flex;
  gap: 12px;
  width: 100%;
  animation: fadeIn 0.18s ease-out;
}

.message-avatar-box {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  background-color: var(--bg-active);
  color: var(--text-secondary);
}

.message-row.user .message-avatar-box,
.message-row.assistant .message-avatar-box {
  background-color: var(--bg-active);
  color: var(--text-secondary);
}

.message-body-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-meta-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.message-sender-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.message-timestamp {
  font-size: 11px;
  color: var(--text-tertiary);
}

.message-text {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
}

.message-text p { margin-bottom: 8px; }
.message-text p:last-child { margin-bottom: 0; }

.message-text h1,
.message-text h2,
.message-text h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 12px 0 6px;
  line-height: 1.4;
}

.message-text li {
  margin: 0 0 4px 18px;
}

.message-text blockquote {
  margin: 8px 0;
  padding-left: 12px;
  border-left: 2px solid var(--border-default);
  color: var(--text-secondary);
}

.message-text strong { font-weight: 600; }

.message-text code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background-color: var(--bg-hover);
  padding: 2px 5px;
  border-radius: 4px;
}

.message-text pre {
  margin: 10px 0;
  padding: 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow-x: auto;
}

.message-text pre code {
  background: transparent;
  padding: 0;
  border: none;
}

.stream-status-box {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.stream-spinner {
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--border-strong);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.message-error {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--status-error-bg);
  border: 1px solid var(--status-error-border);
  color: var(--status-error);
  font-size: 12.5px;
  margin-top: 6px;
}

/* Sources */
.sources-container {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sources-header-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.sources-cards-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-citation-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  background-color: transparent;
  border: 1px solid var(--border-default);
  transition: border-color 0.12s ease, background 0.12s ease;
  cursor: pointer;
}

.source-citation-card:hover {
  border-color: var(--border-strong);
  background-color: var(--bg-hover);
}

.source-icon-badge {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  background-color: var(--bg-active);
  color: var(--text-secondary);
}

.source-meta-col {
  display: flex;
  flex-direction: column;
}

.source-filename {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-primary);
}

.source-detail {
  font-size: 10px;
  color: var(--text-tertiary);
}

.source-more-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background-color: transparent;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

/* ==================== FOLLOW-UP BOTTOM BAR ==================== */
.followup-bottom-bar {
  width: 100%;
  padding: 10px 24px 16px;
  background-color: var(--bg-app);
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.followup-card {
  width: 100%;
  max-width: 720px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: border-color 0.15s ease;
}

.followup-card:focus-within {
  border-color: var(--border-strong);
}

.followup-card textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.4;
  height: 22px;
  max-height: 100px;
}

.followup-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.followup-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  user-select: none;
}

/* ==================== TOASTS ==================== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-dropdown);
  animation: slideIn 0.18s ease-out;
}

.toast.error {
  background: var(--status-error-bg);
  border: 1px solid var(--status-error-border);
  color: var(--status-error);
}

.toast.success {
  background: var(--accent);
  color: var(--accent-contrast);
}

.toast.out {
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.2s ease;
}

/* ==================== MISC ==================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 35;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
}

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

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

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

@keyframes slideIn {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ==================== RESPONSIVE ==================== */

/* Tablet (≤1023px): sidebar becomes a slide-in drawer */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(280px, 84vw);
    min-width: 0;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-dropdown);
  }

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

  .sidebar.collapsed {
    width: min(280px, 84vw);
    min-width: 0;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .main-header {
    padding: 0 16px;
  }

  .messages-scroll-area {
    padding: 20px 16px;
  }

  .followup-bottom-bar {
    padding: 8px 14px 12px;
  }
}

/* Phone (≤640px) */
@media (max-width: 640px) {
  .main-header {
    height: 56px;
    padding: 0 12px;
  }

  .header-subtitle {
    display: none;
  }

  .header-main-title {
    font-size: 14.5px;
  }

  /* Larger tap targets */
  .section-icon-btn,
  .sidebar-collapse-btn,
  .info-btn {
    width: 26px;
    height: 26px;
  }

  .messages-scroll-area {
    padding: 14px 12px;
  }

  .messages-container-active {
    gap: 20px;
    padding: 12px 0;
  }

  .message-row {
    gap: 10px;
  }

  .hero-input-card {
    padding: 12px 12px 8px;
  }

  /* 16px prevents iOS Safari auto-zoom on focus */
  .hero-input-card textarea,
  .followup-card textarea {
    font-size: 16px;
  }

  .followup-hint {
    display: none;
  }

  .welcome-examples {
    margin: 10px 0 0;
  }

  .example-chip {
    padding: 8px 14px;
  }

  .toast-container {
    left: 12px;
    right: 12px;
  }

  .toast {
    width: 100%;
  }
}

/* Small phones (≤380px) */
@media (max-width: 380px) {
  .user-chip-name {
    max-width: 88px;
  }

  .badge-grounded {
    display: none;
  }
}

/* Example chips */
.welcome-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 14px 0 0;
}

.example-chip {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-default);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.example-chip:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.accent-text {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ==================== LOGIN (kept for parity; unused in open sandbox) ==================== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-app);
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  padding: 36px 30px;
  box-shadow: var(--shadow-dropdown);
}

.login-brand-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 12px;
  background: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.login-title {
  font-size: 19px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.login-subtitle {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ==================== USER CHIP ==================== */
.sandbox-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 5px 3px 7px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: var(--bg-card);
}

.sandbox-badge-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-active);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar-img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.user-avatar-fallback {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-active);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.user-chip-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.logout-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.12s ease;
}

.logout-btn:hover {
  color: var(--status-error);
}
