/* Sourcebase brand tokens */
:root {
  --ink: #020617;
  --ink-light: #0f172a;
  --slate: #64748b;
  --slate-light: #94a3b8;
  --sky-deep: #3b82f6;
  --sky: #60a5fa;
  --violet: #8b5cf6;
  --cream: #f8fafc;
  --white: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────── */

.header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.gradient-text {
  background: linear-gradient(135deg, var(--sky-deep), var(--violet));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-select {
  font-size: inherit;
  font-weight: 700;
  font-family: inherit;
  color: var(--violet);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--violet);
  cursor: pointer;
  outline: none;
  padding: 0 4px 1px 2px;
  vertical-align: baseline;
}

.title-select:focus {
  border-bottom-color: var(--sky-deep);
  color: var(--sky-deep);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.controls label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--slate);
  white-space: nowrap;
}

/* Breathing room before labels */
.controls label:first-child {
  margin-left: 16px;
}

.controls select + label {
  margin-left: 20px;
}

.controls input, .controls select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--cream);
  outline: none;
  transition: border-color 0.2s;
}

.controls input:focus, .controls select:focus {
  border-color: var(--sky-deep);
}

.controls select#collection {
  min-width: 200px;
}

.initial-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.initial-form .btn {
  height: 44px;
}

.submitted-question {
  display: none;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.submitted-question strong {
  flex: 1;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.initial-form textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--white);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s;
  overflow: hidden;
}

.initial-form textarea:focus {
  border-color: var(--sky-deep);
}

/* ── Buttons ─────────────────────────────────── */

.btn {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--ink);
  color: var(--white);
}

.btn-primary:hover:not(:disabled) {
  background: var(--ink-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(2, 6, 23, 0.2);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--cream);
  color: var(--ink);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--white);
  border-color: var(--sky-deep);
}

.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Panels ─────────────────────────────────── */

.panels {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--white);
}

.panel:first-child {
  border-right: 1px solid var(--border);
}

.panel-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: var(--cream);
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.panel-logo {
  height: 24px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.panel-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  background: linear-gradient(135deg, rgba(59,130,246,0.1), rgba(139,92,246,0.1));
  color: var(--sky-deep);
}

.panel-badge.thinking-on {
  background: linear-gradient(135deg, rgba(139,92,246,0.12), rgba(59,130,246,0.12));
  color: var(--violet);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

/* ── Message bubbles ─────────────────────────── */

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.user {
  align-items: flex-end;
}

.message.assistant {
  align-items: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  max-width: 85%;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--ink);
  color: var(--white);
  border-bottom-right-radius: 4px;
  font-size: 1rem;
}

.message.assistant .message-bubble {
  background: var(--cream);
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  font-size: 1rem;
}

.message.assistant .message-bubble.streaming {
  border-color: var(--sky-deep);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.15);
}

/* Markdown inside assistant bubbles */
.message-bubble p { margin-bottom: 0.6em; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { padding-left: 1.4em; margin-bottom: 0.6em; }
.message-bubble li { margin-bottom: 0.2em; }
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0.8em 0 0.4em;
}
.message-bubble h1:first-child, .message-bubble h2:first-child, .message-bubble h3:first-child {
  margin-top: 0;
}
.message-bubble code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.88em;
  background: rgba(15, 23, 42, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
}
.message-bubble pre {
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0.6em 0;
}
.message-bubble pre code {
  background: none;
  padding: 0;
}
.message-bubble blockquote {
  border-left: 3px solid var(--sky-deep);
  padding-left: 10px;
  color: var(--slate);
  margin: 0.6em 0;
}
.message-bubble strong { font-weight: 700; }
.message-bubble a { color: var(--sky-deep); text-decoration: underline; }

/* ── Loading indicator (spinner + status) ────── */

.loading-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.loading-indicator.hidden {
  display: none;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(59, 130, 246, 0.15);
  border-top-color: var(--sky-deep);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

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

.status-label {
  font-size: 0.92rem;
  color: var(--slate-light);
  font-style: italic;
  transition: opacity 0.2s;
}

/* Streaming cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--sky-deep);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

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

/* Error message */
.message-error {
  padding: 10px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: #dc2626;
  font-size: 0.95rem;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--slate-light);
  text-align: center;
  gap: 8px;
  pointer-events: none;
  user-select: none;
}

.empty-state svg {
  opacity: 0.35;
}

.empty-state p {
  font-size: 0.95rem;
}

/* ── Follow-up input ─────────────────────────── */

.followup {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--white);
  flex-shrink: 0;
}

.followup .btn {
  height: 40px;
}

.followup textarea {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--cream);
  resize: none;
  min-height: 40px;
  max-height: 100px;
  outline: none;
  transition: border-color 0.2s;
  overflow: hidden;
}

.followup textarea:focus {
  border-color: var(--sky-deep);
  background: var(--white);
}

/* ── Citation chips ─────────────────────────── */

.citation-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--sky-deep);
  font-size: 0.78em;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid rgba(59, 130, 246, 0.25);
  vertical-align: middle;
  margin: 0 1px;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  font-family: "SF Mono", "Fira Code", monospace;
}

.citation-chip:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
}

/* ── Citation modal ──────────────────────────── */

.citation-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.citation-modal.hidden {
  display: none;
}

.citation-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  cursor: pointer;
}

.citation-modal-content {
  position: relative;
  background: var(--white);
  border-radius: var(--radius);
  width: 82vw;
  max-width: 1100px;
  height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(2, 6, 23, 0.3);
}

.citation-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  background: var(--cream);
}

.citation-modal-title {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.citation-modal-title > span:first-child {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-filename {
  font-size: 0.82rem;
  color: var(--slate);
}

.citation-modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--slate);
  transition: background 0.15s;
}

.citation-modal-close:hover {
  background: var(--border-strong);
  color: var(--ink);
}

.citation-modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background: var(--white);
}

.citation-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--slate);
  font-size: 0.95rem;
}

.citation-iframe {
  width: 100%;
  flex: 1;
  border: none;
  min-height: 0;
}

/* ── Summary / PDF tab bar ────────────────────── */

.citation-tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
}

.citation-tab {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--slate);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

.citation-tab:hover { color: var(--ink); }

.citation-tab.active {
  color: var(--sky-deep);
  border-bottom-color: var(--sky-deep);
  font-weight: 600;
}

.citation-tab-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.citation-tab-pane.hidden { display: none; }

/* ── Summary pane ─────────────────────────────── */

.sb-summary-pane {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.sb-summary-box {
  background: var(--white);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.sb-summary-header {
  padding: 12px 16px;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  font-size: 0.9rem;
  font-weight: 700;
  color: #1e40af;
}

.sb-summary-body {
  padding: 14px 16px;
  font-size: 0.92rem;
  color: var(--slate);
  line-height: 1.6;
  white-space: pre-wrap;
}

.sb-excerpt {
  border-left: 3px solid var(--sky-deep);
  padding-left: 12px;
  margin: 0;
  color: var(--ink);
  font-style: normal;
}

.sb-tags { display: flex; flex-wrap: wrap; gap: 8px; }

.sb-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid #bfdbfe;
}

.sb-no-summary {
  color: var(--slate-light);
  font-size: 0.92rem;
  padding: 24px 0;
}

/* ── PDF viewer ───────────────────────────────── */

.citation-pdf-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.citation-pdf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

/* Paginator */
.pdf-paginator {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pdf-page-btns {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pdf-page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #64748b;
  background: var(--white);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}

.pdf-page-btn:hover { background: #f1f5f9; }

.pdf-page-btn.active {
  color: var(--sky-deep);
  background: #f0f9ff;
  border-color: #e0f2fe;
  font-weight: 600;
}

.pdf-ellipsis {
  padding: 0 4px;
  color: var(--slate-light);
  font-size: 0.85rem;
}

/* Shared control button (chevrons + zoom) */
.pdf-ctrl-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #4b5563;
  transition: background 0.12s;
}

.pdf-ctrl-btn:hover:not(:disabled) { background: #f1f5f9; }
.pdf-ctrl-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Zoom group */
.pdf-zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pdf-zoom-pct {
  min-width: 52px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
}

.citation-pdf-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  background: #e5e7eb;
}

#pdfPageWrap {
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}

.citation-media {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.citation-media video,
.citation-media audio {
  width: 100%;
  max-width: 700px;
  border-radius: var(--radius-sm);
}


.citation-error {
  padding: 32px;
  color: #dc2626;
  font-size: 0.95rem;
  text-align: center;
}

/* ── Responsive ─────────────────────────────── */

@media (max-width: 700px) {
  .panels {
    flex-direction: column;
  }
  .panel:first-child {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
