@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,500&family=Source+Sans+3:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --paper: #E7E2D3;
  --paper-deep: #DCD4BF;
  --paper-card: #F1EDE0;
  --ink: #1E2A24;
  --ink-soft: #4C5850;
  --ink-faint: #7C8A80;
  --brass: #A97C50;
  --brass-deep: #82602E;
  --brass-bright: #C69A6D;
  --sage: #6E8A76;
  --brick: #A24435;
  --line: #C9C0A9;
  --radius: 3px;
  --shadow: 0 1px 2px rgba(30, 42, 36, 0.08), 0 6px 20px rgba(30, 42, 36, 0.06);
  --focus: 2px solid var(--brass-deep);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(30,42,36,0.05) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: 'Source Sans 3', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2, h3, .display {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
}

.mono {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  letter-spacing: 0.01em;
}

a { color: var(--brass-deep); }

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

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

/* ── Shell ────────────────────────────────────────────────────── */

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand .mark {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 20px;
}

.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-deep);
}

.nav-link {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  text-decoration: none;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: var(--radius);
  transition: border-color 0.15s ease, color 0.15s ease;
}
.nav-link:hover { border-color: var(--brass-deep); color: var(--ink); }

/* ── Hero ─────────────────────────────────────────────────────── */

.hero {
  padding: 64px 0 40px;
  border-bottom: 1px solid var(--line);
}

.hero h1 {
  font-size: clamp(32px, 5vw, 52px);
  line-height: 1.05;
  max-width: 16ch;
}

.hero p {
  margin-top: 16px;
  max-width: 52ch;
  color: var(--ink-soft);
  font-size: 17px;
}

/* ── Drop zone ────────────────────────────────────────────────── */

.intake {
  padding: 48px 0;
}

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--paper-card);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  position: relative;
}
.dropzone.drag-over {
  border-color: var(--brass-deep);
  background: #ECE3CE;
}
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.dropzone .slot {
  width: 56px; height: 40px;
  margin: 0 auto 18px;
  border: 2px solid var(--brass-deep);
  border-radius: 2px;
  position: relative;
}
.dropzone .slot::before {
  content: "";
  position: absolute;
  top: -8px; left: 50%; transform: translateX(-50%);
  width: 30px; height: 10px;
  border: 2px solid var(--brass-deep);
  border-bottom: none;
  border-radius: 2px 2px 0 0;
}

.dropzone .title { font-family: 'Fraunces', serif; font-size: 19px; margin-bottom: 6px; }
.dropzone .hint { color: var(--ink-faint); font-size: 14px; font-family: 'IBM Plex Mono', monospace; }

/* ── Index cards (document list) ─────────────────────────────── */

.cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 28px;
}

.card {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 16px;
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass-deep);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}

.card .name { font-weight: 600; font-size: 15px; }
.card .meta { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--ink-faint); }

.badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.indexing { background: #E9DDBE; color: var(--brass-deep); }
.badge.ready { background: #DCE6DE; color: #3E5D48; }
.badge.failed { background: #EBD3CD; color: var(--brick); }

.icon-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 32px; height: 32px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--ink-faint);
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover { border-color: var(--brick); color: var(--brick); }

.empty-note {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--ink-faint);
  padding: 20px 0;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--brass-deep);
  background: var(--brass-deep);
  color: var(--paper-card);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--brass-deep); }

.btn-row { margin-top: 32px; display: flex; justify-content: flex-end; }

/* ── Chat screen ──────────────────────────────────────────────── */

.reading-room {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 73px);
}

.rail {
  border-right: 1px solid var(--line);
  padding: 24px 18px;
}

.rail h2 { font-size: 14px; font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 14px; }

.rail-doc {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 8px;
  border-radius: var(--radius);
  font-size: 13.5px;
  cursor: pointer;
}
.rail-doc:hover { background: var(--paper-card); }
.rail-doc input { margin-top: 3px; accent-color: var(--brass-deep); }
.rail-doc .fn { font-weight: 600; }
.rail-doc .cn { display: block; color: var(--ink-faint); font-family: 'IBM Plex Mono', monospace; font-size: 11px; margin-top: 2px; }

.conversation {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 73px);
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 32px 32px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.msg { max-width: 72ch; }
.msg.user { align-self: flex-end; }
.msg.user .bubble {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.msg.assistant .bubble {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.msg.assistant.not-found .bubble {
  background: repeating-linear-gradient(135deg, var(--paper-card), var(--paper-card) 10px, #EEE6D2 10px, #EEE6D2 20px);
  border-style: dashed;
  border-color: var(--brick);
}
.stamp {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--brick);
  border: 1px solid var(--brick);
  padding: 2px 8px;
  border-radius: 2px;
  transform: rotate(-2deg);
  margin-bottom: 8px;
}

.cite-tag {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--brass-deep);
  background: #EEE1CC;
  border-radius: 3px;
  padding: 0 5px;
  margin: 0 1px;
}

/* Citation ledger — the signature element: receipt-style ticket per source */
.ledger {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ticket {
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass);
  background: var(--paper);
  border-radius: 2px;
  padding: 10px 12px;
  font-size: 13px;
}
.ticket summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--ink-soft);
}
.ticket summary::-webkit-details-marker { display: none; }
.ticket summary::before { content: "▸"; color: var(--brass-deep); }
.ticket[open] summary::before { content: "▾"; }
.ticket .excerpt {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  color: var(--ink-soft);
  font-style: italic;
  white-space: pre-wrap;
}
.ticket .score { color: var(--ink-faint); }

.composer {
  border-top: 1px solid var(--line);
  padding: 16px 32px 24px;
  display: flex;
  gap: 10px;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 15px;
  background: var(--paper-card);
  color: var(--ink);
  min-height: 48px;
  max-height: 160px;
}
.composer textarea:focus { border-color: var(--brass-deep); }

.thinking { display: flex; gap: 6px; align-items: center; color: var(--ink-faint); font-family: 'IBM Plex Mono', monospace; font-size: 13px; }
.thinking .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--brass-deep); animation: pulse 1.2s infinite ease-in-out; }
.thinking .dot:nth-child(2) { animation-delay: 0.15s; }
.thinking .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .thinking .dot { animation: none; }
  html { scroll-behavior: auto; }
}

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

@media (max-width: 860px) {
  .reading-room { grid-template-columns: 1fr; }
  .rail { border-right: none; border-bottom: 1px solid var(--line); }
  .card { grid-template-columns: 1fr; row-gap: 8px; }
  .thread { padding: 20px 16px; }
  .composer { padding: 12px 16px 18px; }
}

.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 40;
}
