/* ────────────────────────────────────────────────────────────
   PM Writing Agent — paper-like, iA Writer / Notion inspired
   ──────────────────────────────────────────────────────────── */

:root {
  /* Paper warmth (overridden by Tweaks) */
  --paper:        #faf7f0;
  --paper-deep:   #f3eee2;
  --paper-rim:    #ece5d3;
  --ink:          #1f1b16;
  --ink-body:     #38322b;
  --ink-muted:    #7b7264;
  --ink-faint:    #b6ad9c;
  --rule:         #e7e0cf;
  --rule-strong:  #d6cdb7;
  --elevated:     #ffffff;

  /* Accent (overridden by Tweaks) */
  --accent:       #b85c38;
  --accent-soft:  rgba(184, 92, 56, 0.10);
  --accent-rim:   rgba(184, 92, 56, 0.28);

  /* Diff */
  --add-bg: #e7efdb;
  --add-rim: #b9c895;
  --add-ink: #455c20;
  --del-bg: #f4e1d7;
  --del-rim: #d6b09b;
  --del-ink: #8a3a1c;

  /* Type */
  --ui-font:    "Instrument Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --doc-font:   "Newsreader", "Source Serif Pro", Georgia, serif;
  --mono-font:  "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Density (overridden by Tweaks) */
  --doc-pad-y: 64px;
  --doc-pad-x: 80px;
  --doc-size:  18px;
  --doc-leading: 1.7;
  --doc-measure: 68ch;

  /* Misc */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-soft: 0 1px 0 rgba(255,255,255,.6) inset, 0 6px 22px -8px rgba(60,40,15,.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; }

/* ─── App shell ────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--chat-w, 360px) minmax(0, 1fr);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ─── Chat sidebar ─────────────────────────────────────────── */
.chat {
  background: var(--paper-deep);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.chat-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--rule);
}

.chat-hd .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  letter-spacing: -0.005em;
  font-size: 14px;
  color: var(--ink);
}

.chat-hd .brand .mark {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  color: var(--ink);
}
.chat-hd .brand .mark svg {
  width: 18px; height: 18px;
}

.chat-hd-actions {
  display: flex; gap: 4px;
}

.icon-btn {
  appearance: none;
  background: transparent;
  border: 0;
  width: 28px; height: 28px;
  border-radius: 7px;
  display: grid; place-items: center;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.12) transparent;
}
.chat-thread::-webkit-scrollbar { width: 8px; }
.chat-thread::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

.msg.user .bubble {
  align-self: flex-end;
  background: var(--elevated);
  border: 1px solid var(--rule);
  border-radius: 14px 14px 4px 14px;
  padding: 9px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  max-width: 86%;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset;
}

.msg.user .quote-attached {
  align-self: flex-end;
  max-width: 86%;
  margin-bottom: 4px;
  padding: 7px 10px;
  background: var(--paper);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  font-size: 12px;
  color: var(--ink-muted);
  font-family: var(--doc-font);
  font-style: italic;
  max-height: 60px;
  overflow: hidden;
  position: relative;
}
.msg.user .quote-attached::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 18px;
  background: linear-gradient(transparent, var(--paper));
  pointer-events: none;
}

.msg.assistant {
  color: var(--ink-body);
  font-size: 13.5px;
  line-height: 1.55;
}
.msg.assistant .who {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  font-weight: 600;
  margin-bottom: 4px;
}

.msg.assistant .body {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.assistant .doc-action {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  font-size: 12px;
  color: var(--ink-muted);
  font-family: var(--ui-font);
}
.msg.assistant .doc-action .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.msg.assistant .doc-action a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 2px;
  cursor: pointer;
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13.5px;
  color: var(--ink-muted);
}
.thinking span {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--ink-muted);
  animation: thinking-pulse 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes thinking-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ─── Composer ─────────────────────────────────────────────── */
.composer-wrap {
  padding: 8px 14px 16px;
  background: linear-gradient(to bottom, transparent, var(--paper-deep) 30%);
}

.composer {
  background: var(--elevated);
  border: 1px solid var(--rule-strong);
  border-radius: 14px;
  padding: 4px;
  transition: border-color .15s, box-shadow .15s;
  box-shadow: 0 1px 0 rgba(255,255,255,.6) inset;
}
.composer:focus-within {
  border-color: var(--accent-rim);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 1px 0 rgba(255,255,255,.6) inset;
}

.composer .quote-chip {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: 6px 8px 4px;
  padding: 7px 10px 7px 10px;
  background: var(--paper);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  font-family: var(--doc-font);
  font-size: 12px;
  color: var(--ink-muted);
  font-style: italic;
  position: relative;
  max-height: 64px;
  overflow: hidden;
}
.composer .quote-chip .qx {
  position: absolute;
  top: 4px; right: 4px;
  width: 18px; height: 18px;
  border-radius: 5px;
  background: var(--paper-deep);
  border: 0;
  color: var(--ink-muted);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 11px;
  font-family: var(--ui-font);
  font-style: normal;
}
.composer .quote-chip .qx:hover { background: var(--paper-rim); color: var(--ink); }
.composer .quote-chip .qtext {
  flex: 1;
  max-height: 50px;
  overflow: hidden;
  padding-right: 22px;
}

/* File attachment chips */
.composer .files-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 8px 2px;
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 6px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  font-size: 12px;
  color: var(--ink);
  max-width: 100%;
  min-width: 0;
}
.file-chip .ficon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 5px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  display: grid;
  place-items: center;
  color: var(--ink-muted);
}
.file-chip .ficon svg { width: 12px; height: 12px; }
.file-chip .finfo {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  line-height: 1.25;
}
.file-chip .fname {
  font-weight: 500;
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.file-chip .fmeta {
  font-size: 10.5px;
  color: var(--ink-faint);
  white-space: nowrap;
}
.file-chip .fx {
  width: 18px;
  height: 18px;
  border: 0;
  background: transparent;
  border-radius: 4px;
  color: var(--ink-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-family: var(--ui-font);
  font-size: 13px;
  margin-left: 2px;
  flex-shrink: 0;
}
.file-chip .fx:hover { background: var(--paper-deep); color: var(--ink); }
.file-chip.error { border-color: var(--del-rim); background: var(--del-bg); }
.file-chip.loading .ficon {
  background: var(--accent-soft);
  border-color: var(--accent-rim);
  color: var(--accent);
}
.file-chip.loading .ficon::after {
  content: "";
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  animation: spin .8s linear infinite;
}
.file-chip.loading .ficon { position: relative; }
.file-chip.loading .ficon svg { display: none; }
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* File chips inside a user message */
.msg.user .files-attached {
  align-self: flex-end;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 86%;
  margin-bottom: 6px;
  align-items: flex-end;
}
.msg.user .files-attached .file-chip {
  background: var(--elevated);
}

/* Attach button in composer */
.attach-btn {
  appearance: none;
  background: transparent;
  border: 0;
  width: 28px; height: 28px;
  border-radius: 7px;
  display: grid; place-items: center;
  color: var(--ink-muted);
  cursor: pointer;
}
.attach-btn:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.attach-btn svg { width: 15px; height: 15px; }

/* Drag-over highlight */
.chat.dragging::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 2px dashed var(--accent);
  background: var(--accent-soft);
  pointer-events: none;
  z-index: 30;
}
.chat.dragging .drag-hint {
  position: absolute;
  inset: 0;
  z-index: 31;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-family: var(--ui-font);
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}

.composer textarea {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 12px 6px;
  resize: none;
  min-height: 24px;
  max-height: 200px;
}
.composer textarea::placeholder { color: var(--ink-faint); }

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 4px;
}
.composer-row .left {
  display: flex; gap: 2px; align-items: center;
  color: var(--ink-faint);
  font-size: 11px;
}

.send-btn {
  appearance: none;
  background: var(--ink);
  color: white;
  border: 0;
  border-radius: 9px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .12s, transform .08s;
}
.send-btn:hover { background: #000; }
.send-btn:active { transform: scale(0.96); }
.send-btn:disabled {
  background: var(--rule-strong);
  cursor: not-allowed;
}
.send-btn svg { width: 14px; height: 14px; }

.composer-hint {
  text-align: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-faint);
}

/* ─── Document pane ────────────────────────────────────────── */
.doc-pane {
  background: var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  gap: 12px;
  z-index: 3;
  flex-wrap: wrap;
  min-width: 0;
}

.toolbar-group {
  flex-shrink: 0;
}

.doc-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 0;
}

.doc-title {
  min-width: 40px;
}

.doc-icon {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  display: grid; place-items: center;
  color: var(--ink-muted);
  flex-shrink: 0;
}
.doc-icon svg { width: 14px; height: 14px; }

.doc-title {
  background: transparent;
  border: 0;
  outline: 0;
  font-family: var(--ui-font);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--ink);
  letter-spacing: -0.005em;
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 6px;
  text-overflow: ellipsis;
}
.doc-title:hover { background: rgba(0,0,0,.03); }
.doc-title:focus { background: rgba(0,0,0,.05); }

.doc-meta {
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--rule);
  margin: 0 6px;
}

/* Mode segmented control */
.mode-seg {
  display: flex;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.mode-seg button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--ink-muted);
  font-family: var(--ui-font);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, color .12s;
}
.mode-seg button svg { width: 12px; height: 12px; }
.mode-seg button:hover { color: var(--ink); }
.mode-seg button.active {
  background: var(--elevated);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(60,40,15,.08), 0 0 0 0.5px var(--rule-strong);
}

.btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  padding: 6px 11px;
  font-family: var(--ui-font);
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--paper-deep); }
.btn svg { width: 13px; height: 13px; }
.btn.primary {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.btn.primary:hover { background: #000; }

/* ─── Document scroll container ────────────────────────────── */
.doc-scroll {
  flex: 1;
  overflow-y: auto;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.12) transparent;
}
.doc-scroll::-webkit-scrollbar { width: 10px; }
.doc-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }

.doc-split {
  display: grid;
  height: 100%;
}
.doc-split.split { grid-template-columns: 1fr 1fr; }
.doc-split.single { grid-template-columns: 1fr; }

.doc-pane-half {
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.12) transparent;
  position: relative;
}
.doc-pane-half::-webkit-scrollbar { width: 10px; }
.doc-pane-half::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
.doc-pane-half + .doc-pane-half {
  border-left: 1px solid var(--rule);
}

.pane-label {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--paper-deep);
  border-bottom: 1px solid var(--rule);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--ink-muted);
}
.pane-label svg { width: 11px; height: 11px; }

/* ─── Rendered preview ─────────────────────────────────────── */
.preview {
  font-family: var(--doc-font);
  color: var(--ink-body);
  font-size: var(--doc-size);
  line-height: var(--doc-leading);
  padding: var(--doc-pad-y) var(--doc-pad-x);
  max-width: calc(var(--doc-measure) + var(--doc-pad-x) * 2);
  margin: 0 auto;
  font-feature-settings: "kern", "liga", "onum";
}
.preview > *:first-child { margin-top: 0; }
.preview > *:last-child { margin-bottom: 0; }

.preview h1 {
  font-family: var(--doc-font);
  font-size: 2.1em;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.018em;
  margin: 0 0 0.4em;
  color: var(--ink);
}
.preview h2 {
  font-family: var(--doc-font);
  font-size: 1.4em;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.012em;
  margin: 1.6em 0 0.5em;
  color: var(--ink);
}
.preview h3 {
  font-family: var(--doc-font);
  font-size: 1.12em;
  font-weight: 600;
  margin: 1.4em 0 0.4em;
  color: var(--ink);
}
.preview p { margin: 0 0 0.9em; text-wrap: pretty; }
.preview ul, .preview ol { margin: 0 0 1em; padding-left: 1.4em; }
.preview li { margin-bottom: 0.3em; }
.preview li::marker { color: var(--ink-faint); }
.preview blockquote {
  margin: 1em 0;
  padding: 0.1em 0 0.1em 1.1em;
  border-left: 3px solid var(--accent);
  color: var(--ink-muted);
  font-style: italic;
}
.preview hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2em 0;
}
.preview code {
  font-family: var(--mono-font);
  font-size: 0.85em;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  padding: 1px 5px;
  border-radius: 4px;
}
.preview pre {
  font-family: var(--mono-font);
  font-size: 0.82em;
  line-height: 1.55;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 1em 0;
}
.preview pre code { background: transparent; border: 0; padding: 0; }
.preview a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-rim);
  text-underline-offset: 2px;
}
.preview strong { font-weight: 600; color: var(--ink); }
.preview em { font-style: italic; }

.preview table {
  border-collapse: collapse;
  margin: 1em 0;
  font-family: var(--ui-font);
  font-size: 0.85em;
  width: 100%;
}
.preview th, .preview td {
  border: 1px solid var(--rule);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.preview th { background: var(--paper-deep); font-weight: 600; }

.preview input[type="checkbox"] {
  margin-right: 6px;
  accent-color: var(--accent);
}

/* ─── Source editor ─────────────────────────────────────────── */
.source-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.source-editor {
  flex: 1;
  width: 100%;
  border: 0;
  outline: 0;
  background: var(--paper);
  color: var(--ink-body);
  font-family: var(--mono-font);
  font-size: 13.5px;
  line-height: 1.65;
  padding: 32px 48px 80px;
  resize: none;
  font-feature-settings: "calt";
  caret-color: var(--accent);
  tab-size: 2;
}
.source-editor:focus {
  background: var(--paper);
}

/* ─── Empty state ─────────────────────────────────────────── */
.doc-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding: 40px;
}
.doc-empty .inner {
  max-width: 380px;
  text-align: center;
  color: var(--ink-muted);
  font-family: var(--ui-font);
}
.doc-empty .inner .glyph {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  margin: 0 auto 18px;
  display: grid; place-items: center;
  color: var(--ink-faint);
}
.doc-empty .inner .glyph svg { width: 22px; height: 22px; }
.doc-empty h2 {
  font-family: var(--doc-font);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.doc-empty p { margin: 0; font-size: 13.5px; line-height: 1.5; }

/* ─── Floating selection toolbar ──────────────────────────── */
.float-tool {
  position: fixed;
  z-index: 50;
  display: flex;
  background: var(--ink);
  color: white;
  border-radius: 9px;
  padding: 3px;
  gap: 1px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.2);
  font-size: 12px;
  transform: translate(-50%, calc(-100% - 8px));
  animation: float-in .14s ease-out;
}
@keyframes float-in {
  from { opacity: 0; transform: translate(-50%, calc(-100% - 4px)); }
  to   { opacity: 1; transform: translate(-50%, calc(-100% - 8px)); }
}
.float-tool button {
  appearance: none;
  background: transparent;
  border: 0;
  color: white;
  font-family: var(--ui-font);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}
.float-tool button:hover { background: rgba(255,255,255,.12); }
.float-tool button svg { width: 12px; height: 12px; }
.float-tool .sep {
  width: 1px;
  background: rgba(255,255,255,.15);
  margin: 4px 1px;
}

/* ─── Streaming cursor ────────────────────────────────────── */
.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
  border-radius: 1px;
}
@keyframes blink {
  50% { opacity: 0; }
}

.streaming-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--ink);
  color: white;
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--ui-font);
  box-shadow: 0 6px 20px -6px rgba(0,0,0,.4);
}
.streaming-banner .pulse {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse-dot 1s infinite;
}
@keyframes pulse-dot {
  0%, 100% { transform: scale(0.9); opacity: .6; }
  50% { transform: scale(1.2); opacity: 1; }
}

/* ─── Versions panel ──────────────────────────────────────── */
.versions-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 27, 22, 0.32);
  z-index: 100;
  animation: fade-in .15s;
}
@keyframes fade-in {
  from { opacity: 0; }
}

.versions-modal {
  position: fixed;
  inset: 40px;
  z-index: 101;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.4), 0 0 0 0.5px var(--rule-strong);
  display: grid;
  grid-template-columns: 240px 1fr;
  overflow: hidden;
  animation: modal-in .2s cubic-bezier(.2,.7,.2,1);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.98); }
}

.versions-list {
  background: var(--paper-deep);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.versions-list-hd {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.versions-list-hd h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.versions-list-items {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  scrollbar-width: thin;
}
.version-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .1s, border-color .1s;
  position: relative;
}
.version-item:hover { background: var(--paper-rim); }
.version-item.selected-a {
  background: var(--paper-rim);
  border-color: var(--accent-rim);
  box-shadow: inset 3px 0 0 var(--accent);
}
.version-item.selected-b {
  background: var(--paper-rim);
  border-color: var(--rule-strong);
  box-shadow: inset 3px 0 0 var(--ink);
}
.version-item .vlabel {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
}
.version-item .vmeta {
  font-size: 11px;
  color: var(--ink-faint);
  display: flex;
  gap: 6px;
}
.version-item .vbadge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 600;
  color: white;
  background: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  letter-spacing: 0.04em;
}
.version-item.selected-b .vbadge { background: var(--ink); }

.versions-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.versions-main-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--rule);
}
.versions-main-hd .pair {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-muted);
}
.versions-main-hd .pair b { color: var(--ink); font-weight: 600; }

.diff-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  min-height: 0;
}
.diff-col {
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.12) transparent;
}
.diff-col + .diff-col {
  border-left: 1px solid var(--rule);
}
.diff-col-hd {
  position: sticky;
  top: 0;
  background: var(--paper-deep);
  border-bottom: 1px solid var(--rule);
  padding: 6px 16px;
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  z-index: 1;
}
.diff-lines {
  font-family: var(--mono-font);
  font-size: 12.5px;
  line-height: 1.6;
  padding: 12px 0;
}
.diff-line {
  display: grid;
  grid-template-columns: 32px 1fr;
  padding: 1px 16px 1px 0;
  min-height: 1.6em;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-line.add { background: var(--add-bg); color: var(--add-ink); }
.diff-line.del { background: var(--del-bg); color: var(--del-ink); }
.diff-line.placeholder { background: rgba(0,0,0,0.025); }
.diff-line .gutter {
  color: var(--ink-faint);
  text-align: right;
  padding-right: 10px;
  user-select: none;
  font-size: 11px;
  padding-top: 2px;
  border-right: 1px solid transparent;
}
.diff-line.add .gutter { color: var(--add-ink); }
.diff-line.del .gutter { color: var(--del-ink); }

/* ─── Top streaming progress bar ─────────────────────────── */
.stream-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--paper-deep);
  overflow: hidden;
  z-index: 5;
}
.stream-progress .bar {
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform-origin: left;
  animation: progress-slide 1.4s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { transform: translateX(-100%) scaleX(0.4); }
  50% { transform: translateX(20%) scaleX(0.6); }
  100% { transform: translateX(120%) scaleX(0.4); }
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 28px -8px rgba(0,0,0,.4);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
}

/* ─── Suggestion chips (empty state) ─────────────────────── */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
  padding: 0 4px;
}
.chip {
  appearance: none;
  background: var(--elevated);
  border: 1px solid var(--rule);
  color: var(--ink-body);
  font-family: var(--ui-font);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
  transition: background .12s, border-color .12s;
}
.chip:hover {
  background: var(--paper);
  border-color: var(--rule-strong);
}
