/* ============================================================
   DocTalk — design tokens
   A "reading room" palette: warm ink background, paper-toned
   AI replies, and highlighter-yellow citation tabs that mimic
   marking up a real PDF.
   ============================================================ */

:root {
  --ink: #15121f;
  --ink-soft: #1e1a2e;
  --ink-softer: #282341;
  --hairline: #372f52;

  --paper: #2B2E3B;
  --paper-ink: #F5F5F5;
  --paper-line: #e1dcf2;
  

  --text: #ece8f7;
  --text-muted: #9b91b8;
  --text-faint: #6f6690;

  --purple: #8b5cf6;
  --purple-deep: #6d3ff0;
  --purple-soft: #382a63;
  --sky: #38bdf8;
  --sky-deep: #0ea5e9;
  --sky-ink: #072a38;
  --sky-soft: #1c3a4d;
  --danger: #f2545b;

  --logo-grad: linear-gradient(135deg, var(--sky) 0%, var(--purple) 100%);

  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --sidebar-w: 288px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

/* ---------- Top bar (mobile only) ---------- */

.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--ink-soft);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  flex: 1;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  color: var(--text);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover { border-color: var(--text-muted); }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 4px 8px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
}

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

.status-chip.busy .status-dot {
  background: var(--purple);
  animation: pulse 1s ease-in-out infinite;
}

.status-chip.ready .status-dot { background: var(--sky); }

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

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--ink-soft);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 22px 18px 16px;
  border-bottom: 1px solid var(--hairline);
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--logo-grad);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
  transform: rotate(-3deg);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.brand-tag {
  margin: 1px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.dropzone {
  margin: 16px 18px;
  padding: 16px 14px;
  border: 1.5px dashed var(--hairline);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.dropzone svg { flex-shrink: 0; color: var(--text-faint); transition: color 0.15s ease; }

.dropzone strong { color: var(--text); font-weight: 500; }

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--purple);
  background: rgba(139, 92, 246, 0.08);
  color: var(--text);
}

.dropzone:hover svg,
.dropzone.drag-over svg { color: var(--purple); }

.dropzone span { font-size: 0.8rem; line-height: 1.4; }

.doc-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 4px 18px 12px;
  min-height: 0;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 10px 0 8px;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.doc-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  width: 24px;
  height: 24px;
  border-radius: 5px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.12s ease, background 0.12s ease;
}

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

.doc-delete-btn:hover {
  color: var(--danger);
  background: rgba(226, 87, 76, 0.12);
}

.doc-item:hover { background: var(--ink-softer); }

.doc-item.active {
  background: var(--ink-softer);
  border-color: var(--hairline);
}

.doc-item.active .doc-page-badge {
  background: var(--purple);
  color: #ffffff;
}

.doc-icon {
  min-width: 26px;
  height: 26px;
  padding: 0 4px;
  border-radius: 5px;
  background: var(--paper);
  color: var(--paper-ink);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  flex-shrink: 0;
}

.doc-meta { min-width: 0; flex: 1; }

.doc-name {
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-status {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

.doc-status.indexing { color: var(--purple); }
.doc-status.ready { color: var(--sky); }
.doc-status.error { color: var(--danger); }

.empty-hint {
  font-size: 0.78rem;
  color: var(--text-faint);
  padding: 4px 2px;
  display: none;
}

.empty-hint.visible { display: block; }

.sidebar-foot {
  border-top: 1px solid var(--hairline);
  padding: 12px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.foot-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-faint);
}

.foot-val {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.sidebar-scrim {
  display: none;
}

/* ---------- Chat column ---------- */

.chat-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--hairline);
}

.active-doc {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.15rem;
  margin: 0;
}

.active-doc-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-faint);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-muted);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.ghost-btn:hover { border-color: var(--text-muted); color: var(--text); }

/* ---------- Thread ---------- */

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  margin: auto;
  max-width: 360px;
  text-align: center;
  color: var(--text-muted);
}

.empty-mark {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 1.5px solid var(--hairline);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--text-faint);
}

.empty-state h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--text);
  margin: 0 0 8px;
}

.empty-state p {
  font-size: 0.82rem;
  line-height: 1.6;
  margin: 0;
}

.msg-row {
  display: flex;
  max-width: 78%;
  animation: rise 0.22s ease both;
}

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

.msg-row.user { align-self: flex-end; }
.msg-row.ai { align-self: flex-start; flex-direction: column; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.55;
}

.msg-row.user .bubble {
  background: var(--purple-soft);
  color: var(--text);
  border-bottom-right-radius: 3px;
}

.msg-row.ai .bubble {
  background: var(--paper);
  color: var(--paper-ink);
  /* border: 1px solid var(--paper-line); */
  border-bottom-left-radius: 3px;
  width: 100%;
}

.msg-row.ai .bubble.pending {
  color: var(--text-faint);
  background: var(--ink-soft);
  border-color: var(--hairline);
}

.typing-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: bounce 1.1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* ---------- Citation tabs (signature element) ---------- */

.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-left: 2px;
}

.citation-tab {
  --tilt: -1.5deg;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--sky);
  color: var(--sky-ink);
  border: none;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 4px 9px 4px 8px;
  border-radius: 3px 8px 3px 8px;
  cursor: pointer;
  transform: rotate(var(--tilt));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}

.citation-tab:nth-child(even) { --tilt: 1.2deg; }
.citation-tab:nth-child(3n) { --tilt: -0.6deg; }

.citation-tab:hover {
  transform: rotate(0deg) translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.18);
}

.citation-source {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.04);
  border-left: 2px solid var(--purple-deep);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--paper-ink);
  opacity: 0.85;
  display: none;
}

.citation-source.open { display: block; }

/* ---------- Composer ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 28px 20px;
  border-top: 1px solid var(--hairline);
}

.composer-input {
  flex: 1;
  resize: none;
  background: var(--ink-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 11px 14px;
  font-size: 0.88rem;
  line-height: 1.4;
  max-height: 140px;
  transition: border-color 0.15s ease;
}

.composer-input:focus { border-color: var(--purple); }

.composer-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-input::placeholder { color: var(--text-faint); }

.send-btn {
  background: var(--logo-grad);
  color: #ffffff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.send-btn:hover:not(:disabled) { transform: translateX(1px); }

.send-btn:disabled {
  background: var(--ink-softer);
  color: var(--text-faint);
  cursor: not-allowed;
}

/* ---------- Scrollbars ---------- */

.doc-list-wrap::-webkit-scrollbar,
.thread::-webkit-scrollbar { width: 8px; }
.doc-list-wrap::-webkit-scrollbar-thumb,
.thread::-webkit-scrollbar-thumb {
  background: var(--hairline);
  border-radius: 8px;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .topbar { display: flex; }

  .app {
    grid-template-columns: 1fr;
    height: calc(100vh - 53px);
  }

  .sidebar {
    position: fixed;
    top: 53px;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

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

  .sidebar-head { display: none; }

  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 53px 0 0 0;
    background: rgba(0,0,0,0.45);
    z-index: 25;
  }

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

  .chat-header { padding: 14px 16px; }
  .thread { padding: 18px 16px; }
  .composer { padding: 12px 16px 16px; }
  .msg-row { max-width: 92%; }
}