/* ============================================================
   INKWELL — Research, written for you.
   Aesthetic: warm editorial dark · ink canvas + parchment gold
   Newsreader (serif answers) · Hanken Grotesk (UI) · JetBrains Mono
   ============================================================ */

:root {
  /* canvas */
  --ink-900: #14130f;
  --ink-850: #191713;
  --ink-800: #1f1c17;
  --ink-750: #26221c;
  --ink-700: #2e2a22;
  --line:    #36312a;
  --line-soft: #2a2620;

  /* text */
  --text:    #ece6da;
  --text-dim: #b4ac9c;
  --text-mute: #8a8170;
  --text-faint: #6a6354;

  /* accent — parchment gold + sage */
  --gold:    #c9a45f;
  --gold-soft: #d9bd86;
  --gold-deep: #a8854a;
  --sage:    #8fa68a;
  --rose:    #c98570;

  --gold-glow: rgba(201, 164, 95, 0.14);
  --gold-line: rgba(201, 164, 95, 0.30);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;

  --sans: 'Hanken Grotesk', system-ui, sans-serif;
  --serif: 'Newsreader', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  --shadow: 0 18px 50px -18px rgba(0,0,0,.6);
  --shadow-soft: 0 8px 24px -12px rgba(0,0,0,.5);

  --sidebar-w: 276px;
  --rail-w: 340px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--ink-900);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

/* subtle paper grain over the whole canvas */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(circle at 18% 12%, rgba(201,164,95,.05), transparent 42%),
    radial-gradient(circle at 88% 88%, rgba(143,166,138,.04), transparent 46%);
}

::selection { background: var(--gold-line); color: #fff; }

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
kbd {
  font-family: var(--mono); font-size: 10px;
  background: var(--ink-700); border: 1px solid var(--line);
  padding: 2px 5px; border-radius: 5px; color: var(--text-mute);
}

/* ---------- layout shell ---------- */
.app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr 0;
  height: 100vh;
  transition: grid-template-columns .32s cubic-bezier(.4,0,.2,1);
}
.app.show-rail { grid-template-columns: var(--sidebar-w) 1fr var(--rail-w); }
.app.collapsed { grid-template-columns: 0 1fr 0; }
.app.collapsed.show-rail { grid-template-columns: 0 1fr var(--rail-w); }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  background: linear-gradient(180deg, var(--ink-850), var(--ink-900));
  border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
}
.sidebar__top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand__mark { color: var(--gold); display: grid; place-items: center; }
.brand__name {
  font-family: var(--serif); font-size: 22px; font-weight: 600;
  letter-spacing: .3px;
}
.sidebar__collapse { color: var(--text-mute); }

.icon-btn {
  background: transparent; border: none; color: var(--text-dim);
  display: grid; place-items: center; padding: 7px; border-radius: 9px;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--ink-750); color: var(--text); }
.icon-btn--mini { padding: 3px; }

.new-chat {
  margin: 4px 14px 14px;
  display: flex; align-items: center; gap: 10px;
  background: var(--ink-800); border: 1px solid var(--line);
  color: var(--text); padding: 11px 14px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  transition: border-color .18s, background .18s, transform .12s;
}
.new-chat:hover { border-color: var(--gold-line); background: var(--ink-750); }
.new-chat:active { transform: scale(.98); }
.new-chat svg { color: var(--gold); }
.new-chat kbd { margin-left: auto; }

.sidebar__scroll { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.sidebar__scroll::-webkit-scrollbar { width: 8px; }
.sidebar__scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid var(--ink-850); }

.section-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 10px 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-faint);
}

.space-list { list-style: none; margin: 0; padding: 0; }
.space-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; color: var(--text-dim);
  transition: background .14s, color .14s;
}
.space-item__select { min-width: 0; flex: 1; display: flex; align-items: center; gap: 9px;
  padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.space-item__name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.space-item:hover { background: var(--ink-800); color: var(--text); }
.space-item.active { background: var(--gold-glow); color: var(--gold-soft); }
.space-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.space-item .count { margin-left: auto; font-size: 11px; color: var(--text-faint); }

.history { margin-top: 4px; }
.hist-group { margin-bottom: 4px; }
.hist-group__label {
  padding: 12px 10px 4px; font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint);
}
.thread-item {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; color: var(--text-dim);
  transition: background .14s, color .14s;
}
.thread-item__open { min-width: 0; flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.thread-item:hover { background: var(--ink-800); color: var(--text); }
.thread-item.active { background: var(--ink-750); color: var(--text); }
.thread-item.active::before {
  content: ""; position: absolute; left: 0; top: 18%; bottom: 18%;
  width: 2.5px; border-radius: 3px; background: var(--gold);
}
.thread-item__title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-item__menu {
  opacity: 0; color: var(--text-mute); padding: 2px; border-radius: 6px;
  background: transparent; border: none; transition: opacity .14s;
}
.thread-item:hover .thread-item__menu { opacity: 1; }
.thread-item__menu:hover { color: var(--text); background: var(--ink-700); }
.thread-item__menu.open, .space-item__menu.open { opacity: 1; color: var(--text); }

.space-item__menu {
  opacity: 0; color: var(--text-mute); padding: 2px; border-radius: 6px;
  background: transparent; border: none; transition: opacity .14s; margin-left: 4px;
}
.space-item:hover .space-item__menu { opacity: 1; }
.space-item__menu:hover { color: var(--text); background: var(--ink-700); }
.space-item .count + .space-item__menu { margin-left: 4px; }

/* ---------- popover menu ---------- */
.popmenu {
  position: fixed; z-index: 80; min-width: 184px;
  background: var(--ink-750); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; animation: popIn .12s ease;
}
@keyframes popIn { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.popmenu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: none; background: transparent; border-radius: 8px;
  color: var(--text-dim); font-size: 13px; text-align: left;
  transition: background .12s, color .12s;
}
.popmenu button:hover { background: var(--ink-700); color: var(--text); }
.popmenu button svg { flex: none; }
.popmenu button.danger { color: var(--rose); }
.popmenu button.danger:hover { background: rgba(201,133,112,.14); color: var(--rose); }
.popmenu .popmenu__sep { height: 1px; background: var(--line-soft); margin: 5px 4px; }
.popmenu .popmenu__label {
  padding: 6px 10px 3px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint);
}
.popmenu .popmenu__check { margin-left: auto; color: var(--gold); }

.sidebar__foot { border-top: 1px solid var(--line-soft); padding: 10px; }
.lib-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px; cursor: pointer; color: var(--text-dim);
  font-size: 13.5px; transition: background .14s, color .14s;
}
.lib-link:hover { background: var(--ink-800); color: var(--text); }
.lib-link svg { color: var(--sage); }
.lib-link em { margin-left: auto; font-style: normal; font-size: 11px;
  background: var(--ink-700); padding: 2px 7px; border-radius: 20px; color: var(--text-mute); }

.user {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; margin-top: 4px; border: none; background: transparent;
  border-radius: 10px; text-align: left; color: var(--text);
  transition: background .14s;
}
.user:hover { background: var(--ink-800); }
.user__meta { flex: 1; min-width: 0; }
.user__caret { color: var(--text-faint); flex: none; }
.user__avatar {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: linear-gradient(135deg, var(--gold-deep), var(--gold-soft));
  color: var(--ink-900);
}
.user__meta strong { display: block; font-size: 13px; }
.user__meta small { color: var(--text-faint); font-size: 11.5px; }

/* ============================================================
   MAIN
   ============================================================ */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; position: relative; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(20,19,15,.72); backdrop-filter: blur(14px);
  z-index: 5;
}
.topbar__menu { display: none; }
.app.collapsed .topbar__menu { display: grid; }
.topbar__title {
  font-family: var(--serif); font-size: 17px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.topbar__actions { display: flex; align-items: center; gap: 6px; }
.ghost-btn {
  display: flex; align-items: center; gap: 7px;
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  padding: 7px 11px; border-radius: 9px; font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.ghost-btn:hover { background: var(--ink-800); color: var(--text); }
.ghost-btn--danger:hover { color: var(--rose); }
.sources-toggle.active { border-color: var(--gold-line); color: var(--gold-soft); background: var(--gold-glow); }

.thread-wrap { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread-wrap::-webkit-scrollbar { width: 10px; }
.thread-wrap::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 3px solid var(--ink-900); }

/* ---------- empty state ---------- */
.empty { min-height: 100%; display: grid; place-items: center; padding: 40px 24px 80px; }
.empty__inner { max-width: 720px; width: 100%; text-align: center;
  animation: rise .6s cubic-bezier(.2,.7,.2,1) both; }
.empty__mark { color: var(--gold); display: inline-grid; margin-bottom: 22px;
  filter: drop-shadow(0 0 24px var(--gold-glow)); }
.empty__mark img { width: 64px; height: 64px; border-radius: 16px; display: block; }
.brand__mark img { border-radius: 8px; display: block; }
.empty__title { font-family: var(--serif); font-size: 38px; font-weight: 500;
  margin: 0 0 12px; letter-spacing: -.5px; line-height: 1.1; }
.empty__sub { color: var(--text-mute); font-size: 15.5px; max-width: 460px;
  margin: 0 auto 36px; line-height: 1.6; }

.prompt-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; text-align: left; }
.prompt-card {
  background: linear-gradient(160deg, var(--ink-800), var(--ink-850));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; cursor: pointer; position: relative; overflow: hidden;
  transition: border-color .2s, transform .2s, background .2s;
  color: inherit; text-align: left;
}
.prompt-card::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at top left, var(--gold-glow), transparent 60%);
  opacity: 0; transition: opacity .25s;
}
.prompt-card:hover { border-color: var(--gold-line); transform: translateY(-3px); }
.prompt-card:hover::after { opacity: 1; }
.prompt-card__icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--ink-700); color: var(--gold); margin-bottom: 12px; }
.prompt-card__kind { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--gold-deep); margin-bottom: 4px; }
.prompt-card__text { font-family: var(--serif); font-size: 16px; color: var(--text); line-height: 1.35; }

/* ---------- messages ---------- */
.messages { max-width: 760px; margin: 0 auto; padding: 34px 24px 60px; }
.msg { margin-bottom: 34px; animation: rise .45s cubic-bezier(.2,.7,.2,1) both; }

.msg--user { display: flex; justify-content: flex-end; }
.msg--user .bubble {
  background: var(--ink-750); border: 1px solid var(--line);
  padding: 13px 17px; border-radius: 16px 16px 4px 16px;
  max-width: 86%; font-size: 15px; line-height: 1.55; color: var(--text);
}

.msg--ai .ai-head { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.ai-head__mark { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--ink-750); color: var(--gold); border: 1px solid var(--gold-line); }
.ai-head__name { font-size: 13px; font-weight: 600; color: var(--text-dim); letter-spacing: .02em; }

/* searching animation */
.searching { display: flex; flex-direction: column; gap: 10px; padding: 4px 0 2px; }
.searching__line { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-mute);
  opacity: 0; animation: fadeStep .4s ease forwards; }
.searching__line .spark {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.6px solid var(--gold-line); border-top-color: var(--gold);
  animation: spin .8s linear infinite; flex: none;
}
.searching__line .done { color: var(--sage); }
.searching__line.q1 { animation-delay: .05s; }
.searching__line.q2 { animation-delay: .55s; }
.searching__line.q3 { animation-delay: 1.05s; }

/* answer prose — the serif star of the show */
.answer {
  font-family: var(--serif); font-size: 18px; line-height: 1.68; color: var(--text);
  font-weight: 400;
}
.answer p { margin: 0 0 16px; }
.answer h3 { font-size: 19px; font-weight: 600; margin: 26px 0 10px; letter-spacing: -.2px; }
.answer h4 { font-size: 16px; font-weight: 600; margin: 20px 0 8px; color: var(--text-dim); font-family: var(--sans); }
.answer ul, .answer ol { margin: 0 0 16px; padding-left: 22px; }
.answer li { margin-bottom: 8px; }
.answer strong { font-weight: 600; color: #fff; }
.answer em { color: var(--gold-soft); }
.answer code {
  font-family: var(--mono); font-size: .82em; background: var(--ink-800);
  border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; color: var(--gold-soft);
}
.answer blockquote {
  margin: 0 0 16px; padding: 4px 0 4px 18px; border-left: 2.5px solid var(--gold-line);
  color: var(--text-dim); font-style: italic;
}
.answer a { color: var(--gold-soft); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--gold-line); }
.answer pre { font-family: var(--mono); font-size: 13px; background: var(--ink-850); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 0 0 16px; line-height: 1.5; color: var(--text-dim); }
.answer pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }
.answer table { width: 100%; border-collapse: collapse; margin: 0 0 18px; font-family: var(--sans); font-size: 14px; }
.answer th { text-align: left; font-weight: 600; color: var(--text-dim); padding: 9px 12px;
  border-bottom: 1.5px solid var(--gold-line); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.answer td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); color: var(--text); vertical-align: top; }
.answer tr:last-child td { border-bottom: none; }

/* inline citation chips */
.cite {
  font-family: var(--sans); font-size: 11px; font-weight: 600; vertical-align: super;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin: 0 1px;
  background: var(--ink-750); border: 1px solid var(--gold-line); border-radius: 6px;
  color: var(--gold-soft); cursor: pointer; line-height: 1;
  transition: background .15s, transform .12s; text-decoration: none;
}
.cite:hover { background: var(--gold-glow); transform: translateY(-1px); }

/* streaming caret */
.caret { display: inline-block; width: 7px; height: 1.05em; vertical-align: -2px;
  background: var(--gold); margin-left: 2px; border-radius: 1px; animation: blink 1s step-end infinite; }

/* answer footer: source chips + follow-ups + actions */
.answer-foot { margin-top: 18px; }
.src-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.src-chip {
  display: flex; align-items: center; gap: 8px; max-width: 280px;
  background: var(--ink-800); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 11px 7px 8px; cursor: pointer; transition: border-color .15s, transform .12s;
  color: inherit; text-align: left;
}
.src-chip:hover { border-color: var(--gold-line); transform: translateY(-1px); }
.src-chip__fav { width: 20px; height: 20px; border-radius: 5px; flex: none; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: var(--ink-900); }
.src-chip__meta { min-width: 0; }
.src-chip__title { font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-chip__domain { font-size: 11px; color: var(--text-faint); }
.src-chip__num { font-size: 10px; font-weight: 700; color: var(--gold-deep); margin-left: auto; padding-left: 4px; }

.followups { display: flex; flex-direction: column; gap: 1px; border-top: 1px solid var(--line-soft); padding-top: 6px; }
.followup {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  text-align: left; background: transparent; border: none; color: var(--text-dim);
  padding: 11px 4px; font-size: 14.5px; font-family: var(--serif);
  border-bottom: 1px solid var(--line-soft); transition: color .15s, padding .15s;
}
.followup:last-child { border-bottom: none; }
.followup:hover { color: var(--gold-soft); padding-left: 8px; }
.followup svg { color: var(--gold); flex: none; opacity: .6; }

.msg-actions { display: flex; gap: 4px; margin-top: 4px; }
.msg-actions button {
  display: flex; align-items: center; gap: 6px; background: transparent; border: none;
  color: var(--text-faint); font-size: 12px; padding: 6px 9px; border-radius: 8px;
  transition: color .15s, background .15s;
}
.msg-actions button:hover { color: var(--text); background: var(--ink-800); }
.msg-actions button.ok { color: var(--sage); }

/* ---------- composer ---------- */
.composer-wrap { padding: 0 24px 22px; background: linear-gradient(0deg, var(--ink-900) 55%, transparent); }
.composer {
  max-width: 760px; margin: 0 auto;
  background: var(--ink-800); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 6px 6px 0;
  box-shadow: var(--shadow-soft);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--gold-line); box-shadow: 0 0 0 4px var(--gold-glow), var(--shadow-soft); }
.composer__context { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 4px; }
.ctx-tag { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-dim);
  background: var(--ink-700); border: 1px solid var(--line); padding: 4px 8px; border-radius: 7px; }
.ctx-tag svg { color: var(--sage); }
.composer__row { display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 14px; }
#input {
  flex: 1; background: transparent; border: none; resize: none; color: var(--text);
  font-size: 16px; line-height: 1.5; padding: 6px 0; max-height: 200px; outline: none;
}
#input::placeholder { color: var(--text-faint); }
.send {
  width: 38px; height: 38px; flex: none; border-radius: 11px; border: none;
  background: var(--ink-700); color: var(--text-mute);
  display: grid; place-items: center; transition: all .18s;
}
.send:not(:disabled) { background: linear-gradient(135deg, var(--gold-deep), var(--gold)); color: var(--ink-900); }
.send:not(:disabled):hover { transform: scale(1.06); box-shadow: 0 6px 18px -6px var(--gold); }
.send:disabled { cursor: not-allowed; }

.composer__hint { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px 12px; }
.chip-pill { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-mute); }
.chip-pill svg { color: var(--sage); }
.chip-pill em { font-style: normal; font-weight: 700; color: var(--gold-soft); }
.composer__tip { font-size: 11.5px; color: var(--text-faint); }

/* ============================================================
   SOURCES RAIL
   ============================================================ */
.rail {
  background: var(--ink-850); border-left: 1px solid var(--line-soft);
  min-width: 0; overflow: hidden; display: flex; flex-direction: column;
}
.rail__head { display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.rail__head h2 { font-family: var(--serif); font-size: 17px; font-weight: 500; margin: 0; }
.rail__body { flex: 1; overflow-y: auto; padding: 14px; }
.rail__body::-webkit-scrollbar { width: 8px; }
.rail__body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid var(--ink-850); }
.rail__empty { color: var(--text-faint); font-size: 14px; text-align: center; padding: 40px 18px; line-height: 1.6; }

.source-card {
  background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; cursor: pointer;
  transition: border-color .18s, transform .14s; animation: rise .4s cubic-bezier(.2,.7,.2,1) both;
  width: 100%; color: inherit; text-align: left;
}
.source-card:hover { border-color: var(--gold-line); }
.source-card__top { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.source-card__fav { width: 24px; height: 24px; border-radius: 6px; flex: none; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: var(--ink-900); }
.source-card__num { font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--gold-deep);
  border: 1px solid var(--gold-line); border-radius: 6px; padding: 1px 6px; }
.source-card__domain { font-size: 11.5px; color: var(--text-faint); margin-left: auto; }
.source-card__title { font-family: var(--serif); font-size: 15px; line-height: 1.35; margin-bottom: 6px; color: var(--text); }
.source-card__snippet { font-size: 13px; line-height: 1.55; color: var(--text-mute);
  max-height: 0; overflow: hidden; transition: max-height .3s ease, margin .3s; }
.source-card.open .source-card__snippet { max-height: 200px; margin-top: 4px; }
.source-card__more { font-size: 11.5px; color: var(--gold-deep); margin-top: 8px; display: flex; align-items: center; gap: 4px; }

/* ============================================================
   MODALS
   ============================================================ */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; }
.modal[hidden] { display: none; }
/* the [hidden] attribute must always win over author display rules
   (e.g. .empty{display:grid}, .composer__context, etc.) */
[hidden] { display: none !important; }
.modal__backdrop { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(8,7,5,.66); backdrop-filter: blur(6px);
  animation: fade .2s ease; }
.modal__panel {
  position: relative; width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto;
  background: var(--ink-850); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 24px; animation: pop .26s cubic-bezier(.2,.8,.2,1) both;
}
.modal__panel--wide { max-width: 720px; }
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal__head h2 { font-family: var(--serif); font-size: 23px; font-weight: 500; margin: 0 0 4px; }
.modal__sub { color: var(--text-mute); font-size: 14px; margin: 0; }

.lib-add { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.lib-add__row { display: flex; gap: 8px; }
.lib-add input { flex: 1; background: var(--ink-800); border: 1px solid var(--line); color: var(--text);
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 14px; outline: none; transition: border-color .15s; }
.lib-add input:focus, .lib-add textarea:focus { border-color: var(--gold-line); }
.lib-add textarea { background: var(--ink-800); border: 1px solid var(--line); color: var(--text);
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 14px; outline: none; resize: vertical;
  font-family: inherit; line-height: 1.5; transition: border-color .15s; }
.lib-add select { background: var(--ink-800); border: 1px solid var(--line); color: var(--text-dim);
  padding: 0 12px; border-radius: var(--radius-sm); font-size: 13px; outline: none; }
.lib-empty { grid-column: 1 / -1; text-align: center; color: var(--text-faint); font-size: 13.5px;
  padding: 36px 20px; line-height: 1.55; }
.hist-empty { color: var(--text-faint); font-size: 12.5px; padding: 10px 14px; line-height: 1.5; }

/* honest error message + retry */
.ai-head__mark--err { color: var(--rose, #c98570); }
.answer--error { color: var(--text-dim); }
.answer--error p { margin: 0 0 12px; }
.retry-btn { display: inline-flex; align-items: center; gap: 7px; background: var(--ink-800);
  border: 1px solid var(--line); color: var(--text); padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: border-color .15s, background .15s; }
.retry-btn:hover { border-color: var(--gold-line); background: var(--ink-700, var(--ink-800)); }
.btn-solid { background: linear-gradient(135deg, var(--gold-deep), var(--gold)); color: var(--ink-900);
  border: none; padding: 0 18px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
  transition: transform .12s, box-shadow .15s; }
.btn-solid:hover { transform: translateY(-1px); box-shadow: 0 8px 20px -8px var(--gold); }
.access-panel h1 { font-family: var(--serif); font-size: 28px; margin: 6px 0 8px; }
.access-panel .modal__sub { margin-bottom: 22px; line-height: 1.55; }
.access-error { color: var(--rose); margin: 2px 0; font-size: 13px; }
.access-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.access-link { min-height: 42px; display: inline-flex; align-items: center; text-decoration: none; }
.lib-link { width: 100%; border: 0; background: transparent; text-align: left; }

.lib-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.doc-card { background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; position: relative; transition: border-color .15s; animation: rise .35s ease both; }
.doc-card:hover { border-color: var(--gold-line); }
.doc-card__icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; margin-bottom: 12px; }
.doc-card__title { font-size: 14px; font-weight: 500; line-height: 1.35; margin-bottom: 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card__meta { font-size: 11.5px; color: var(--text-faint); }
.doc-card__ctx { display: flex; align-items: center; gap: 7px; margin-top: 12px; font-size: 12px; color: var(--text-dim); }
.switch { position: relative; width: 34px; height: 19px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track { position: absolute; inset: 0; background: var(--ink-700); border: 1px solid var(--line);
  border-radius: 20px; transition: background .2s; }
.switch__track::after { content: ""; position: absolute; left: 2px; top: 1.5px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--text-mute); transition: transform .2s, background .2s; }
.switch input:checked + .switch__track { background: var(--gold-glow); border-color: var(--gold-line); }
.switch input:checked + .switch__track::after { transform: translateX(15px); background: var(--gold); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--gold); outline-offset: 3px; }
.doc-card__del { position: absolute; top: 12px; right: 12px; color: var(--text-faint); background: transparent;
  border: none; padding: 4px; border-radius: 6px; opacity: 0; transition: opacity .15s, color .15s; }
.doc-card:hover .doc-card__del { opacity: 1; }
.doc-card__del:hover { color: var(--rose); background: var(--ink-700); }

/* command palette */
.palette { position: relative; width: 100%; max-width: 560px; background: var(--ink-850);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; animation: pop .22s cubic-bezier(.2,.8,.2,1) both; margin-top: -8vh; }
#paletteInput { width: 100%; background: transparent; border: none; border-bottom: 1px solid var(--line-soft);
  color: var(--text); font-size: 16px; padding: 18px 20px; outline: none; }
#paletteInput::placeholder { color: var(--text-faint); }
.palette__list { list-style: none; margin: 0; padding: 8px; max-height: 50vh; overflow-y: auto; }
.palette__item { display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 9px;
  cursor: pointer; color: var(--text-dim); font-size: 14px; }
.palette__item:hover, .palette__item.active { background: var(--ink-750); color: var(--text); }
.palette__item svg { color: var(--gold); flex: none; }
.palette__item .sub { margin-left: auto; font-size: 11px; color: var(--text-faint); }
.palette__item.is-new { color: var(--gold-soft); }

/* toasts */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 80;
  display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink-750); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 11px; font-size: 13.5px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 9px; animation: toastIn .3s cubic-bezier(.2,.8,.2,1) both; }
.toast svg { color: var(--gold); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fadeStep { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spin-slow { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

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

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .app.show-rail { grid-template-columns: var(--sidebar-w) 1fr 0; }
  .rail { position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 86vw); z-index: 40;
    transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1); box-shadow: var(--shadow); }
  .app.show-rail .rail { transform: none; }
}
@media (max-width: 820px) {
  .app, .app.show-rail, .app.collapsed { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: 50;
    transform: translateX(-100%); transition: transform .3s cubic-bezier(.4,0,.2,1); box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 45; }
  .topbar__menu { display: grid; }
  .sidebar__collapse { display: none; }
  .empty__title { font-size: 30px; }
  .prompt-cards { grid-template-columns: 1fr; }
  .lib-grid { grid-template-columns: 1fr; }
  .ghost-btn span { display: none; }
}

/* ============================================================
   NAV PILL (Home) + active state
   ============================================================ */
.nav-pill {
  margin: 0 14px 6px; display: flex; align-items: center; gap: 10px; width: calc(100% - 28px);
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  padding: 9px 14px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.nav-pill:hover { background: var(--ink-800); color: var(--text); }
.nav-pill svg { color: var(--gold); }
.nav-pill.active { background: var(--gold-glow); color: var(--gold-soft); border-color: var(--gold-line); }

/* ============================================================
   CLIENT DASHBOARD / HOME
   ============================================================ */
.dash { min-height: 100%; padding: 0; }
.dash__inner { max-width: 940px; margin: 0 auto; padding: 36px 28px 80px; animation: rise .5s cubic-bezier(.2,.7,.2,1) both; }

.dash__hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.dash__eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--gold-deep); margin-bottom: 8px; }
.dash__title { font-family: var(--serif); font-size: 34px; font-weight: 500; letter-spacing: -.5px; margin: 0 0 8px; line-height: 1.1; }
.dash__lead { color: var(--text-mute); font-size: 15px; margin: 0; max-width: 460px; line-height: 1.55; }
.dash__cta { display: inline-flex; align-items: center; gap: 8px; height: 44px; white-space: nowrap; flex: none; }

.dstats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.dstat {
  background: linear-gradient(160deg, var(--ink-800), var(--ink-850));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  transition: border-color .2s, transform .2s;
}
.dstat:hover { border-color: var(--gold-line); transform: translateY(-2px); }
.dstat__icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--ink-700); margin-bottom: 12px; }
.dstat__val { font-family: var(--serif); font-size: 28px; font-weight: 600; line-height: 1; letter-spacing: -.5px; }
.dstat__label { font-size: 12.5px; color: var(--text-dim); margin-top: 6px; font-weight: 500; }
.dstat__sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

.dash__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dcard { background: var(--ink-850); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.dcard--span { grid-column: 1 / -1; }
.dcard__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dcard__head h2 { font-family: var(--serif); font-size: 18px; font-weight: 500; margin: 0; }
.dlink { background: transparent; border: none; color: var(--gold-soft); font-size: 13px; font-weight: 500; padding: 4px 6px; border-radius: 7px; transition: background .14s; }
.dlink:hover { background: var(--ink-800); }

.drecent-list { display: flex; flex-direction: column; gap: 2px; }
.drecent { display: flex; align-items: center; gap: 11px; text-align: left; width: 100%;
  background: transparent; border: none; padding: 11px 12px; border-radius: 10px; color: var(--text-dim);
  transition: background .14s, color .14s; }
.drecent:hover { background: var(--ink-800); color: var(--text); }
.drecent__dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.drecent__title { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drecent__meta { font-size: 11.5px; color: var(--text-faint); flex: none; }

.dlib__count { font-family: var(--serif); font-size: 34px; font-weight: 600; line-height: 1; display: flex; align-items: baseline; gap: 8px; }
.dlib__count span { font-family: var(--sans); font-size: 13px; color: var(--text-mute); font-weight: 400; }
.dlib__pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 10px; }
.dpill { font-size: 11px; font-weight: 600; letter-spacing: .03em; color: var(--gold-soft);
  background: var(--ink-700); border: 1px solid var(--line); padding: 3px 9px; border-radius: 20px; }
.dlib__ctx { font-size: 12.5px; color: var(--sage); }

.dsugg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dsugg__item { display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 15px; color: var(--text); font-family: var(--serif); font-size: 15px;
  transition: border-color .18s, transform .15s, color .15s; }
.dsugg__item:hover { border-color: var(--gold-line); transform: translateY(-1px); color: var(--gold-soft); }
.dsugg__item svg { color: var(--gold); flex: none; opacity: .7; }

.dempty { color: var(--text-faint); font-size: 13.5px; padding: 18px 4px; line-height: 1.5; }

@media (max-width: 900px) {
  .dstats { grid-template-columns: repeat(2, 1fr); }
  .dash__grid { grid-template-columns: 1fr; }
  .dsugg { grid-template-columns: 1fr; }
  .dash__hero { flex-direction: column; }
}

/* ============================================================
   ONBOARDING
   ============================================================ */
body.onb-open { overflow: hidden; }
.onb { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 24px; }
.onb__backdrop { position: absolute; inset: 0; background: rgba(8,7,5,.82); backdrop-filter: blur(10px);
  animation: fade .3s ease; }
.onb__card { position: relative; width: 100%; max-width: 540px; background: var(--ink-850);
  border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 0; overflow: hidden; animation: pop .35s cubic-bezier(.2,.8,.2,1) both; }
.onb--leaving .onb__card { animation: pop .25s reverse both; }
.onb--leaving .onb__backdrop { opacity: 0; transition: opacity .25s; }
.onb__progress { height: 3px; background: var(--ink-700); }
.onb__progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width .4s cubic-bezier(.4,0,.2,1); }
.onb__skip { position: absolute; top: 16px; right: 18px; background: transparent; border: none;
  color: var(--text-faint); font-size: 12.5px; padding: 6px 10px; border-radius: 8px; transition: color .14s, background .14s; z-index: 2; }
.onb__skip:hover { color: var(--text); background: var(--ink-800); }
.onb__body { padding: 40px 40px 36px; }

.onb__center { text-align: center; animation: rise .4s ease both; }
.onb__mark { color: var(--gold); display: inline-grid; margin-bottom: 18px; filter: drop-shadow(0 0 22px var(--gold-glow)); }
.onb__eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--gold-deep); margin-bottom: 6px; }
.onb__title { font-family: var(--serif); font-size: 40px; font-weight: 600; margin: 0 0 14px; letter-spacing: -.5px; }
.onb__lead { color: var(--text-mute); font-size: 15px; line-height: 1.6; max-width: 400px; margin: 0 auto 26px; }
.onb__feats { list-style: none; margin: 0 0 28px; padding: 0; display: flex; flex-direction: column; gap: 12px; text-align: left; max-width: 380px; margin-left: auto; margin-right: auto; }
.onb__feats li { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-dim); }
.onb__feats li span { width: 26px; height: 26px; flex: none; border-radius: 8px; display: grid; place-items: center;
  background: var(--ink-700); border: 1px solid var(--gold-line); color: var(--gold-soft); font-size: 12px; font-weight: 700; }

.onb__step { animation: rise .35s ease both; }
.onb__h2 { font-family: var(--serif); font-size: 26px; font-weight: 500; margin: 0 0 8px; letter-spacing: -.3px; }
.onb__sub { color: var(--text-mute); font-size: 14px; margin: 0 0 22px; line-height: 1.5; }
.onb__input { width: 100%; background: var(--ink-800); border: 1px solid var(--line); color: var(--text);
  font-size: 16px; padding: 13px 16px; border-radius: var(--radius-sm); outline: none; transition: border-color .15s, box-shadow .15s; }
.onb__input:focus { border-color: var(--gold-line); box-shadow: 0 0 0 3px var(--gold-glow); }
.onb__select { background: var(--ink-800); border: 1px solid var(--line); color: var(--text-dim);
  padding: 0 12px; border-radius: var(--radius-sm); font-size: 14px; outline: none; }

.onb__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.onb__opt { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  color: var(--text); transition: border-color .18s, background .18s, transform .15s; }
.onb__opt:hover { border-color: var(--gold-line); transform: translateY(-2px); }
.onb__opt.sel { border-color: var(--gold); background: var(--gold-glow); }
.onb__opt-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--ink-700); color: var(--gold); margin-bottom: 6px; }
.onb__opt-label { font-size: 14.5px; font-weight: 600; }
.onb__opt-sub { font-size: 12px; color: var(--text-faint); }

.onb__spaces { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.onb__space { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px;
  color: var(--text); transition: border-color .15s, background .15s; }
.onb__space:hover { border-color: var(--gold-line); }
.onb__space.sel { border-color: var(--gold); background: var(--gold-glow); }
.onb__space-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.onb__space-meta { flex: 1; min-width: 0; }
.onb__space-meta strong { display: block; font-size: 14px; font-weight: 600; }
.onb__space-meta small { font-size: 12px; color: var(--text-faint); }
.onb__space-check { width: 22px; height: 22px; border-radius: 6px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--line); color: transparent; transition: all .15s; }
.onb__space.sel .onb__space-check { background: var(--gold); border-color: var(--gold); color: var(--ink-900); }

.onb__doc { margin-bottom: 22px; }
.onb__doc-label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.onb__doc-label em { font-style: normal; color: var(--text-faint); font-weight: 400; }
.onb__doc-row { display: flex; gap: 8px; }
.onb__doc-row .onb__input { flex: 1; }

.onb__nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; }
.onb__back { background: transparent; border: none; color: var(--text-mute); font-size: 14px; padding: 10px 14px; border-radius: 9px; transition: color .14s, background .14s; }
.onb__back:hover { color: var(--text); background: var(--ink-800); }
.onb__next { min-width: 140px; height: 44px; }
.onb__next:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.onb__center .onb__next { width: 100%; }

@media (max-width: 560px) {
  .onb__body { padding: 30px 24px 28px; }
  .onb__title { font-size: 32px; }
  .onb__grid { grid-template-columns: 1fr; }
}
