/* Ledger chat surface (DESIGN_SYSTEM.md §5 chat bubbles/citations/composer).
   Loads after ledger.css; styles the DOM structures chat.js builds. */

.cs-chat {
  flex: 1; display: flex; flex-direction: column;
  max-width: 860px; width: 100%; margin: 0 auto;
  padding: 20px clamp(16px, 4vw, 32px) 28px;
}

/* ── Header row ───────────────────────────────────────────────────────────── */
.cs-chat-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.cs-chat-head h1 {
  margin: 0; font-family: var(--serif); font-size: 20px; font-weight: 600; letter-spacing: -0.015em;
}
.cs-newchat {
  margin-left: auto; font-size: 12.5px; color: var(--accent);
  background: none; border: none; cursor: pointer; font-family: inherit; padding: 6px 0;
}
.cs-newchat:hover { text-decoration: underline; }

.scope-dropdown { position: relative; }
.scope-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink2); background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px; padding: 6px 10px;
  cursor: pointer; font-family: inherit; max-width: 320px;
}
.scope-trigger:hover { border-color: var(--accent); }
.scope-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  min-width: 280px; max-height: 320px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: 4px 0;
}
.scope-option {
  display: flex; gap: 10px; align-items: baseline; width: 100%;
  background: none; border: none; cursor: pointer; font-family: inherit;
  font-size: 13px; color: var(--ink2); padding: 8px 14px; text-align: left;
}
.scope-option:hover { background: var(--hover); }
.scope-option.selected { color: var(--accent); font-weight: 600; }
.scope-opt-date { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 11.5px; color: var(--ink3); flex-shrink: 0; }
.scope-option-all { font-weight: 600; }

.model-switch {
  display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
}
.model-btn {
  font-size: 12px; font-weight: 600; border: none; padding: 6px 14px;
  cursor: pointer; font-family: inherit; background: var(--surface); color: var(--ink3);
}
.model-btn.active { background: var(--accent); color: var(--onaccent); }

/* ── Messages ─────────────────────────────────────────────────────────────── */
.cs-messages { flex: 1; display: flex; flex-direction: column; gap: 20px; padding: 22px 0; }

.cs-welcome {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 18px; padding: 48px 0; text-align: center;
}
.cs-welcome h2 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
.cs-welcome p { margin: 0; font-size: 14.5px; color: var(--ink2); max-width: 480px; line-height: 1.65; }
.cs-welcome-suggestions { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 480px; }
.cs-welcome-note { font-size: 12px !important; color: var(--faint) !important; }

.message { display: flex; flex-direction: column; gap: 8px; }
.message.user { align-items: flex-end; }
.message.user .bubble {
  max-width: 85%; background: var(--accent); color: var(--onaccent);
  border-radius: 10px 10px 2px 10px; padding: 10px 16px;
  font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
/* Assistant message = the "giant bubble" card: answer + copy row + sources. */
.message.assistant {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 2px 10px 10px 10px; padding: 16px 20px; gap: 14px; max-width: 100%;
}
.message.assistant .bubble {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px; line-height: 1.65; color: var(--ink); word-break: break-word;
}
.message.assistant .bubble p { margin: 0 0 10px; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }
.message.assistant .bubble a { color: var(--accent); }
.message.assistant .bubble ul, .message.assistant .bubble ol { margin: 0 0 10px; padding-left: 22px; }
/* Markdown headings inside answers stay body-scale — the answer is prose,
   not a document page. */
.message.assistant .bubble h1, .message.assistant .bubble h2,
.message.assistant .bubble h3, .message.assistant .bubble h4 {
  font-family: var(--sans);
  font-size: 15px; font-weight: 600; margin: 14px 0 6px; line-height: 1.4;
}
.message.assistant .bubble h1:first-child, .message.assistant .bubble h2:first-child,
.message.assistant .bubble h3:first-child { margin-top: 0; }
.message.assistant .bubble.error { color: var(--match); }
/* Markdown tables inside answers — denser than the 14px prose so reference
   tables read as compact data. msg_render.js wraps each table in
   .table-scroll: the wrapper scrolls horizontally while the table lays out
   at max-content, so columns keep natural width (long cells wrap only at
   their max-width cap) instead of compressing to fit a narrow screen. */
.message.assistant .bubble .table-scroll {
  overflow-x: auto; margin: 4px 0 12px;
  /* opt out of mobile font boosting — Chrome/Safari inflate text inside
     wide scrollable blocks, which blew up the long-text column on phones */
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
.message.assistant .bubble table {
  width: max-content; border-collapse: collapse;
  font-size: 11px; line-height: 1.45;
}
.message.assistant .bubble th, .message.assistant .bubble td {
  border: 1px solid var(--line); padding: 5px 9px;
  text-align: left; vertical-align: top;
  white-space: normal; word-break: normal;
  max-width: min(60vw, 520px);  /* no column dominates the page */
}
.message.assistant .bubble th {
  font-weight: 600;
  background: color-mix(in srgb, var(--line) 18%, var(--surface));
}
.search-status { font-size: 13px; color: var(--ink3); font-style: italic; }

.typing-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink3);
  animation: cs-blink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes cs-blink { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

/* Copy row (appended into the bubble by chat.js) */
.copy-row { border-top: 1px solid var(--line2); padding-top: 8px; margin-top: 12px; display: flex; justify-content: flex-end; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500; color: var(--ink3);
  background: none; border: none; padding: 2px 0; cursor: pointer; font-family: inherit;
}
.copy-btn:hover { color: var(--ink2); }

.cs-model-note { font-size: 12px; color: var(--ink3); }

/* ── Inline citations (.source-ref built by renderMarkdown) ───────────────── */
.source-ref {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 15px; height: 15px; border-radius: 999px;
  font-size: 9.5px; font-weight: 700; padding: 0 3px; margin: 0 1px;
  cursor: pointer; vertical-align: text-bottom;
  color: var(--ink3); border: 1px solid var(--line); background: var(--hover);
}
.source-ref.transcript { color: var(--tTi); border-color: color-mix(in srgb, var(--tT) 55%, var(--surface)); background: color-mix(in srgb, var(--tT) 10%, var(--surface)); }
.source-ref.agenda     { color: var(--tAi); border-color: color-mix(in srgb, var(--tA) 55%, var(--surface)); background: color-mix(in srgb, var(--tA) 10%, var(--surface)); }
.source-ref.minutes    { color: var(--tMi); border-color: color-mix(in srgb, var(--tM) 55%, var(--surface)); background: color-mix(in srgb, var(--tM) 10%, var(--surface)); }
.source-ref.policy     { color: var(--tPi); border-color: color-mix(in srgb, var(--tP) 55%, var(--surface)); background: color-mix(in srgb, var(--tP) 10%, var(--surface)); }
.source-ref.handbook   { color: var(--tHi); border-color: color-mix(in srgb, var(--tH) 55%, var(--surface)); background: color-mix(in srgb, var(--tH) 10%, var(--surface)); }
.source-ref.web        { color: var(--tWi); border-color: color-mix(in srgb, var(--tW) 55%, var(--surface)); background: color-mix(in srgb, var(--tW) 10%, var(--surface)); }

/* ── Sources block (rendered by renderSources) ────────────────────────────── */
.sources:not(:empty) { display: flex; flex-direction: column; gap: 8px; }
.sources .cs-micro { margin: 0; }
.cs-source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.cs-source-card { padding: 8px !important; gap: 6px !important; }
.cs-source-card .doc { color: var(--xi, var(--ink2)); }
.cs-source-card .cs-oval { cursor: pointer; }

/* ── Modal (system prompt) ────────────────────────────────────────────────── */
.cs-modal {
  border: 1px solid var(--line); border-radius: 8px; padding: 0;
  max-width: 720px; width: 92vw; background: var(--surface); color: var(--ink);
}
.cs-modal::backdrop { background: rgba(0,0,0,.45); }
.cs-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.cs-modal-head h2 { margin: 0; font-family: var(--serif); font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.cs-modal-head button {
  background: none; border: none; font-size: 22px; color: var(--ink3);
  cursor: pointer; line-height: 1; padding: 4px 8px;
}
.cs-modal-body { max-height: 65vh; overflow-y: auto; padding: 18px 22px; font-size: 13.5px; line-height: 1.65; color: var(--ink2); }
.cs-modal-body h1, .cs-modal-body h2, .cs-modal-body h3 { font-size: 14.5px; color: var(--ink); }
.cs-modal-foot { display: flex; justify-content: flex-end; padding: 12px 22px 16px; border-top: 1px solid var(--line); }
