/* ── Chat panel ─────────────────────────────────────────────
   Top-right navbar toggle button. Slide-out panel pushes
   content (real panel reflow, not hover overlay) by adding
   body padding-right when open.

   When closed: page is full width — the only chat artifact is
   the small toggle button sitting in the navbar's right side.
   When open: panel slides in from the right and content
   reflows to make room.

   --chat-panel-width is set inline by chat-panel.js when the
   user drags the resize handle, persisted via localStorage.
   ────────────────────────────────────────────────────────── */

body {
  --chat-panel-width: 380px;
  --chat-panel-min-width: 280px;
  --chat-panel-max-width: 720px;
}

body.chat-rail-mounted {
  /* No padding when closed — page goes full width. */
  transition: padding-right 0.18s ease;
}

body.chat-rail-mounted.chat-open {
  padding-right: var(--chat-panel-width);
}

body.chat-resizing {
  transition: none;
  user-select: none;
  cursor: col-resize;
}

/* ── Toggle button (top-right of navbar) ─────────────────── */
.chat-toggle-btn {
  position: fixed;
  top: 0.55rem;
  right: 1rem;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.chat-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

body.chat-open .chat-toggle-btn {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* Slide the toggle along with the panel so it sits flush
   against the panel's left edge and acts like a "tab handle". */
body.chat-open .chat-toggle-btn {
  right: calc(var(--chat-panel-width) + 0.5rem);
  transition: right 0.18s ease;
}

body.chat-rail-mounted:not(.chat-resizing) .chat-toggle-btn {
  transition: right 0.18s ease, background 0.12s, color 0.12s;
}

/* ── Editor ↔ Wizard toggle (sibling of .chat-toggle-btn) ─────
   Sits one button-width + 0.5rem gap to the left of the chat toggle.
   Slides left in lockstep when the chat panel is open, just like
   .chat-toggle-btn does. Independent positioning (not nested inside
   the chat partial) so this stays visible when chat is feature-gated. */
.editor-wizard-toggle-btn {
  position: fixed;
  top: 0.55rem;
  right: calc(1rem + 2.75rem);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, right 0.18s ease;
}

.editor-wizard-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

body.chat-open .editor-wizard-toggle-btn {
  right: calc(var(--chat-panel-width) + 0.5rem + 2.75rem);
}

body.chat-resizing .editor-wizard-toggle-btn {
  transition: background 0.12s, color 0.12s;
}

/* ── Commits topbar button (sibling of .editor-wizard-toggle-btn) ─────
   Sits one button-width + 0.5rem gap further left than the editor↔wizard
   toggle. Slides left in lockstep when the chat panel is open, just like
   its siblings. Same visual treatment so the three buttons read as a
   single cluster in the top-right. */
.commits-topbar-btn {
  position: fixed;
  top: 0.55rem;
  right: calc(1rem + 5.5rem);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, right 0.18s ease;
}

.commits-topbar-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

body.chat-open .commits-topbar-btn {
  right: calc(var(--chat-panel-width) + 0.5rem + 5.5rem);
}

body.chat-resizing .commits-topbar-btn {
  transition: background 0.12s, color 0.12s;
}

/* ── Project Resources topbar button ───────────────────────
   Project-wide resources sit immediately to the left of Commits, so they are
   reachable from both Wizard and Editor without living in either surface rail. */
.resources-topbar-btn {
  position: fixed;
  top: 0.55rem;
  right: calc(1rem + 8.25rem);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, right 0.18s ease;
}

.resources-topbar-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

body.chat-open .resources-topbar-btn {
  right: calc(var(--chat-panel-width) + 0.5rem + 8.25rem);
}

body.chat-resizing .resources-topbar-btn {
  transition: background 0.12s, color 0.12s;
}

/* ── Copy Wizard artifacts topbar button ─────────────────────
   Wizard-only action that sits to the left of the desktop MATLAB button,
   Resources, Commits, editor↔wizard, and chat buttons. Shares the same fixed
   topbar placement and slides left with the chat panel so the full control
   cluster stays together. */
.copy-wizard-artifacts-topbar-form {
  margin: 0;
}

.copy-wizard-artifacts-topbar-btn {
  position: fixed;
  top: 0.55rem;
  right: calc(1rem + 13.75rem);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.65rem;
  border: none;
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, right 0.18s ease;
}

.copy-wizard-artifacts-topbar-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.copy-wizard-artifacts-topbar-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

body.chat-open .copy-wizard-artifacts-topbar-btn {
  right: calc(var(--chat-panel-width) + 0.5rem + 13.75rem);
}

body.chat-resizing .copy-wizard-artifacts-topbar-btn {
  transition: background 0.12s, color 0.12s;
}

/* Back-to-top: keep clear of the panel when open. */
body.chat-rail-mounted.chat-open #back-to-top {
  right: calc(var(--chat-panel-width) + 1.5rem);
}

/* ── Panel (slides in from right) ────────────────────────── */
.chat-panel {
  position: fixed;
  top: 3.5rem;
  right: 0;
  bottom: 0;
  width: var(--chat-panel-width);
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  z-index: 39;
  box-shadow: -4px 0 12px rgba(15, 23, 42, 0.06);

  /* Closed: slide off-screen and stop intercepting clicks. */
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.18s ease, visibility 0s linear 0.18s;
}

body.chat-open .chat-panel {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.18s ease, visibility 0s linear 0s;
}

body.chat-resizing .chat-panel {
  transition: none;
}

/* ── Resize handle (drag inner edge) ─────────────────────── */
.chat-resize-handle {
  position: absolute;
  top: 0;
  left: -3px;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 1;
}

.chat-resize-handle:hover,
body.chat-resizing .chat-resize-handle {
  background: rgba(30, 64, 175, 0.18);
}

/* ── Rail header (sits in the navbar band, above the panel) ─
   Floats over the dark navbar at top: 0 with a white background,
   so it reads as a continuation of the panel below. Tracks
   --chat-panel-width and slides in/out in lockstep with the panel. */
.chat-rail-header {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--chat-panel-width);
  height: 3.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.625rem;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  border-left: 1px solid #e2e8f0;
  box-shadow: -4px 0 12px rgba(15, 23, 42, 0.06);
  z-index: 40;

  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.18s ease, visibility 0s linear 0.18s;
}

body.chat-open .chat-rail-header {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.18s ease, visibility 0s linear 0s;
}

body.chat-resizing .chat-rail-header {
  transition: none;
}

.chat-panel-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 0.25rem;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  flex: 0 0 auto;
}

.chat-panel-icon-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.chat-panel-title {
  flex: 1 1 auto;
  margin-left: 0.25rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #475569;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 0.25rem;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
}

.chat-panel-close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* ── Messages ────────────────────────────────────────────── */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-empty-state {
  margin: auto;
  text-align: center;
  color: #64748b;
  padding: 1rem;
}

.chat-empty-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
  margin-bottom: 0.25rem;
}

.chat-empty-hint {
  font-size: 0.8rem;
  color: #94a3b8;
}

.chat-msg {
  display: flex;
  max-width: 100%;
}

.chat-msg-user {
  justify-content: flex-end;
}

.chat-msg-assistant {
  justify-content: flex-start;
}

.chat-msg-bubble {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* User bubbles preserve raw input whitespace; assistant bubbles render
   as Markdown so block-level HTML handles its own spacing. */
.chat-msg-user .chat-msg-bubble {
  background: #1e40af;
  color: #fff;
  border-top-right-radius: 0.125rem;
  white-space: pre-wrap;
}

.chat-msg-assistant .chat-msg-bubble {
  background: #f1f5f9;
  color: #0f172a;
  border-top-left-radius: 0.125rem;
}

/* ── Markdown prose inside assistant bubbles ─────────────── */
/* Markdown is rendered into a `.chat-msg-text` wrapper child so cards
   and tool-call lists can sit as siblings without trampling the
   render. Margin-collapsing rules descend through the wrapper. */
.chat-msg-assistant .chat-msg-bubble .chat-msg-text > *:first-child { margin-top: 0; }
.chat-msg-assistant .chat-msg-bubble .chat-msg-text > *:last-child  { margin-bottom: 0; }

.chat-msg-assistant .chat-msg-bubble p {
  margin: 0.5em 0;
}

.chat-msg-assistant .chat-msg-bubble h1,
.chat-msg-assistant .chat-msg-bubble h2,
.chat-msg-assistant .chat-msg-bubble h3,
.chat-msg-assistant .chat-msg-bubble h4,
.chat-msg-assistant .chat-msg-bubble h5,
.chat-msg-assistant .chat-msg-bubble h6 {
  margin: 0.75em 0 0.4em;
  font-weight: 600;
  line-height: 1.25;
}
.chat-msg-assistant .chat-msg-bubble h1 { font-size: 1.125rem; }
.chat-msg-assistant .chat-msg-bubble h2 { font-size: 1rem; }
.chat-msg-assistant .chat-msg-bubble h3 { font-size: 0.95rem; }
.chat-msg-assistant .chat-msg-bubble h4,
.chat-msg-assistant .chat-msg-bubble h5,
.chat-msg-assistant .chat-msg-bubble h6 { font-size: 0.875rem; }

.chat-msg-assistant .chat-msg-bubble ul,
.chat-msg-assistant .chat-msg-bubble ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}

.chat-msg-assistant .chat-msg-bubble li {
  margin: 0.15em 0;
}

.chat-msg-assistant .chat-msg-bubble li > p {
  margin: 0.15em 0;
}

.chat-msg-assistant .chat-msg-bubble blockquote {
  margin: 0.5em 0;
  padding: 0.1em 0.75em;
  border-left: 3px solid #cbd5e1;
  color: #475569;
}

.chat-msg-assistant .chat-msg-bubble a {
  color: #1d4ed8;
  text-decoration: underline;
}

.chat-msg-assistant .chat-msg-bubble strong { font-weight: 600; }
.chat-msg-assistant .chat-msg-bubble em     { font-style: italic; }
.chat-msg-assistant .chat-msg-bubble hr {
  border: 0;
  border-top: 1px solid #cbd5e1;
  margin: 0.75em 0;
}

.chat-msg-assistant .chat-msg-bubble code {
  font-family: ui-monospace, 'SFMono-Regular', 'Menlo', monospace;
  font-size: 0.82rem;
  background: rgba(15, 23, 42, 0.07);
  padding: 0.05em 0.3em;
  border-radius: 0.25rem;
}

.chat-msg-assistant .chat-msg-bubble pre {
  margin: 0.5em 0;
  padding: 0.55rem 0.7rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 0.375rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.45;
}

.chat-msg-assistant .chat-msg-bubble pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

.chat-msg-assistant .chat-msg-bubble table {
  border-collapse: collapse;
  margin: 0.5em 0;
  font-size: 0.82rem;
}
.chat-msg-assistant .chat-msg-bubble th,
.chat-msg-assistant .chat-msg-bubble td {
  border: 1px solid #cbd5e1;
  padding: 0.2em 0.5em;
  text-align: left;
}
.chat-msg-assistant .chat-msg-bubble th {
  background: #e2e8f0;
  font-weight: 600;
}

/* ── Input ───────────────────────────────────────────────── */
.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 0.375rem;
  padding: 0.625rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex: 0 0 auto;
}

.chat-input {
  flex: 1 1 auto;
  resize: none;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  padding: 0.5rem 0.625rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.375rem;
  background: #fff;
  color: #0f172a;
  outline: none;
  min-height: 2.25rem;
  max-height: 8rem;
}

.chat-input:focus {
  border-color: #1e40af;
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.chat-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 0.375rem;
  background: #1e40af;
  color: #fff;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.12s;
  position: relative;
}

.chat-send-btn:hover {
  background: #1e3a8a;
}

.chat-send-btn:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

/* Send/stop icon swap: while a request is in flight the button shows the
   stop square; otherwise the send arrow. The .chat-inflight class is
   toggled by chat-panel.js. */
.chat-send-icon,
.chat-stop-icon {
  width: 1rem;
  height: 1rem;
}

.chat-stop-icon {
  display: none;
}

.chat-panel.chat-inflight .chat-send-icon {
  display: none;
}

.chat-panel.chat-inflight .chat-stop-icon {
  display: block;
}

.chat-panel.chat-inflight .chat-send-btn {
  background: #b91c1c;
}

.chat-panel.chat-inflight .chat-send-btn:hover {
  background: #991b1b;
}

/* ── Typing dots (assistant placeholder) ─────────────────── */
.chat-typing-dots {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  height: 1em;
}

.chat-typing-dots > span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: #64748b;
  opacity: 0.4;
  animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing-dots > span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing-dots > span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* ── Streaming / queued / cancelled / errored bubble states ─ */
.chat-msg-assistant.is-streaming .chat-msg-bubble {
  /* A subtle pulse on the bubble border while text is streaming in. */
  box-shadow: 0 0 0 1px rgba(30, 64, 175, 0.18);
}

.chat-msg-user.is-queued .chat-msg-bubble {
  opacity: 0.55;
  border: 1px dashed rgba(255, 255, 255, 0.45);
}

.chat-msg-assistant.is-cancelled .chat-msg-bubble {
  background: #fef3c7;
  color: #78350f;
}

.chat-msg-assistant.is-errored .chat-msg-bubble {
  background: #fee2e2;
  color: #991b1b;
}

.chat-msg-tag {
  font-size: 0.7rem;
  color: #92400e;
  font-style: italic;
  margin-left: 0.25rem;
}

/* ── Panel body wrapper ──────────────────────────────────── */
.chat-panel-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ── Conversation list ───────────────────────────────────── */
.chat-conv-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chat-conv-list-new {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.625rem;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  background: #1e40af;
  color: #fff;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.12s;
}

.chat-conv-list-new:hover {
  background: #1e3a8a;
}

.chat-conv-list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.chat-conv-list-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.625rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.chat-conv-list-item:hover {
  background: #f1f5f9;
  border-color: #e2e8f0;
}

.chat-conv-list-title {
  font-size: 0.875rem;
  color: #0f172a;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.chat-conv-list-meta {
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 0.125rem;
}

/* ── Tool-call log (P2.6) ────────────────────────────────── */
/* Renders inside the assistant bubble, above any text content.
   Muted, monospace, one line per dispatch — Claude-Code style. */
.chat-tool-calls {
  list-style: none;
  margin: 0 0 0.5rem 0;
  padding: 0;
  font-size: 0.78rem;
  color: #64748b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.chat-tool-call {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.1rem 0;
  line-height: 1.3;
}

.chat-tool-call-icon {
  flex: 0 0 auto;
  width: 1rem;
  text-align: center;
}

.chat-tool-call-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-tool-call.is-running {
  color: #64748b;
}

.chat-tool-call.is-done {
  color: #15803d;
}

.chat-tool-call.is-errored {
  color: #b91c1c;
}

/* Used by the shared `_generating.html` partial — the chat panel
   embeds the list inside an assistant bubble (already constrained),
   but the Generate card is wider, so cap the log column width and
   left-align it inside the centered card body. */
.generating-tool-calls {
  max-width: 32rem;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* ── Chat-edit proposal cards (P3.1) ──────────────────────── */
/* Three lifecycle states share one card structure:
   - is-pending: full card — header, fields, Accept/Reject buttons.
   - is-accepted / is-rejected: collapsed to a single one-line marker
     (header + fields + actions hidden via CSS), so the conversation
     keeps a visible audit trail after reload without dominating the
     bubble. The same DOM is produced on the live propose path and the
     reload-rehydrate path. */
.chat-edit-card {
  margin: 0.5rem 0;
  padding: 0.55rem 0.7rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  background: #ffffff;
  font-size: 0.82rem;
  color: #0f172a;
}

.chat-edit-card.is-pending {
  border-color: #93c5fd;
  background: #eff6ff;
  box-shadow: 0 1px 2px rgba(30, 64, 175, 0.06);
}

.chat-edit-card-header {
  font-weight: 600;
  color: #1e3a8a;
  margin-bottom: 0.35rem;
  line-height: 1.3;
}

.chat-edit-card-fields {
  margin: 0 0 0.5rem 0;
  padding: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.15rem 0.5rem;
}

.chat-edit-card-fields dt {
  font-weight: 600;
  color: #475569;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-top: 0.1rem;
}

.chat-edit-card-fields dd {
  margin: 0;
  color: #0f172a;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-edit-card-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.chat-edit-accept,
.chat-edit-reject {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 5rem;
  padding: 0.35rem 0.85rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.2;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}

.chat-edit-accept {
  background: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

.chat-edit-accept:hover:not(:disabled) {
  background: #1e3a8a;
  border-color: #1e3a8a;
}

.chat-edit-accept:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.3);
}

.chat-edit-reject {
  background: #fff;
  color: #475569;
  border-color: #cbd5e1;
}

.chat-edit-reject:hover:not(:disabled) {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #94a3b8;
}

.chat-edit-reject:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.4);
}

.chat-edit-accept:disabled,
.chat-edit-reject:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-edit-card-status {
  margin-top: 0.35rem;
  font-size: 0.76rem;
  color: #475569;
  line-height: 1.35;
  min-height: 1em;
}

/* Resolved markers: collapse the card body, surface just the status
   line as a thin one-line history record. Same DOM as the pending
   card — CSS hides the noise. */
.chat-edit-card.is-accepted,
.chat-edit-card.is-rejected {
  padding: 0.3rem 0.6rem;
  background: transparent;
  border: none;
  border-left: 2px solid #cbd5e1;
  border-radius: 0;
  margin: 0.25rem 0;
  font-size: 0.76rem;
}

.chat-edit-card.is-accepted .chat-edit-card-header,
.chat-edit-card.is-rejected .chat-edit-card-header,
.chat-edit-card.is-accepted .chat-edit-card-fields,
.chat-edit-card.is-rejected .chat-edit-card-fields,
.chat-edit-card.is-accepted .chat-edit-card-actions,
.chat-edit-card.is-rejected .chat-edit-card-actions {
  display: none;
}

.chat-edit-card.is-accepted {
  border-left-color: #16a34a;
}

.chat-edit-card.is-accepted .chat-edit-card-status {
  color: #15803d;
  margin: 0;
}

.chat-edit-card.is-accepted .chat-edit-card-status::before {
  content: '✓ ';
  font-weight: 600;
}

.chat-edit-card.is-rejected {
  border-left-color: #b91c1c;
}

.chat-edit-card.is-rejected .chat-edit-card-status {
  color: #b91c1c;
  margin: 0;
}

.chat-edit-card.is-rejected .chat-edit-card-status::before {
  content: '✗ ';
  font-weight: 600;
}

.chat-edit-card.is-busy {
  opacity: 0.7;
}

/* Tighten spacing between the streaming text node and any sibling
   tool list / edit card so the bubble doesn't look gappy. */
.chat-msg-text:empty {
  display: none;
}

/* ── Pending-batch badge (chat-rail header) ───────────────────────
   Renders "N pending" when there are batches awaiting review. The
   modal opens for the most recent unsubmitted batch on click.
   Hidden by default; chat-edit-batch-modal.js toggles visibility. */
.chat-edit-batch-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
  margin-right: 0.5rem;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  border: 1px solid #fbbf24;
  background: #fef3c7;
  color: #92400e;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.chat-edit-batch-badge[hidden] {
  display: none;
}

.chat-edit-batch-badge:hover {
  background: #fde68a;
  border-color: #f59e0b;
}

.chat-edit-batch-badge:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.35);
}

/* ── Inline batch-applied summary (auto-apply path) ────────────────
   Renders inside the assistant bubble when the server auto-applied a
   batch of additive proposals. One thin line with the artifact list +
   a "Review batch" link that re-opens the modal in read-only mode. */
.chat-edit-batch-summary {
  margin: 0.5rem 0;
  padding: 0.4rem 0.65rem;
  border: 1px solid #bbf7d0;
  border-left: 3px solid #16a34a;
  border-radius: 0.4rem;
  background: #f0fdf4;
  font-size: 0.78rem;
  color: #14532d;
  line-height: 1.4;
}

.chat-edit-batch-summary-title {
  font-weight: 600;
  margin-right: 0.25rem;
}

.chat-edit-batch-summary-review {
  margin-left: 0.5rem;
  font-size: 0.74rem;
  color: #15803d;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.chat-edit-batch-summary-review:hover {
  color: #14532d;
}

/* ── Batch-review modal ────────────────────────────────────────────
   Full-screen overlay over the current page. The dialog renders one
   row per proposal with the diff + per-row accept toggle + footer
   submit. The same component renders read-only for retroactive review
   of auto-applied batches — the toggles + submit are hidden in that
   mode. */
.chat-edit-batch-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.chat-edit-batch-modal.is-open {
  display: block;
}

.chat-edit-batch-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.chat-edit-batch-modal-dialog {
  position: relative;
  margin: 4rem auto 0;
  max-width: 640px;
  max-height: calc(100vh - 8rem);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
  overflow: hidden;
}

.chat-edit-batch-modal-header {
  display: flex;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.chat-edit-batch-modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
  margin: 0;
  flex: 1 1 auto;
}

.chat-edit-batch-modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: #475569;
  cursor: pointer;
  padding: 0 0.25rem;
}

.chat-edit-batch-modal-close:hover {
  color: #0f172a;
}

.chat-edit-batch-modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.chat-edit-batch-row {
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  padding: 0.55rem 0.7rem;
  background: #ffffff;
  font-size: 0.82rem;
}

.chat-edit-batch-row.is-pending {
  border-color: #93c5fd;
  background: #eff6ff;
}

.chat-edit-batch-row.is-accepted {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.chat-edit-batch-row.is-rejected {
  border-color: #fecaca;
  background: #fef2f2;
}

.chat-edit-batch-row.is-marked-reject {
  background: #fff7ed;
  border-color: #fed7aa;
}

.chat-edit-batch-row-header {
  font-weight: 600;
  color: #1e3a8a;
  margin-bottom: 0.35rem;
  line-height: 1.3;
}

.chat-edit-batch-row-meta {
  margin-top: 0.4rem;
  display: flex;
  justify-content: flex-end;
  font-size: 0.78rem;
}

.chat-edit-batch-row-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
}

.chat-edit-batch-row-status {
  display: inline-flex;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.chat-edit-batch-row-status.is-accepted {
  background: #dcfce7;
  color: #166534;
}

.chat-edit-batch-row-status.is-rejected {
  background: #fee2e2;
  color: #991b1b;
}

.chat-edit-batch-row-status.is-pending {
  background: #e0e7ff;
  color: #3730a3;
}

.chat-edit-batch-modal-footer {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  gap: 0.75rem;
}

.chat-edit-batch-modal-status {
  flex: 1 1 auto;
  font-size: 0.78rem;
  color: #475569;
}

.chat-edit-batch-modal-actions {
  display: flex;
  gap: 0.5rem;
}

.chat-edit-batch-modal-cancel,
.chat-edit-batch-modal-submit {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 1rem;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  cursor: pointer;
}

.chat-edit-batch-modal-cancel {
  background: #ffffff;
  color: #475569;
  border-color: #cbd5e1;
}

.chat-edit-batch-modal-cancel:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.chat-edit-batch-modal-submit {
  background: #1e40af;
  color: #ffffff;
  border-color: #1e40af;
}

.chat-edit-batch-modal-submit:hover:not(:disabled) {
  background: #1e3a8a;
  border-color: #1e3a8a;
}

.chat-edit-batch-modal-submit:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-edit-batch-modal-submit[hidden] {
  display: none;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  body {
    --chat-panel-width: min(360px, 100vw);
  }
  .chat-edit-batch-modal-dialog {
    margin: 1rem;
    max-height: calc(100vh - 2rem);
  }
}

/* ── Library chat markdown prose (RFC #288 IDE chat) ──────── */
/* The platform Library IDE chat (library-chat.js / library_shell.html) is
   DaisyUI/Tailwind, not the fixed-theme project chat. Its assistant prose
   streams as Markdown into a `.lib-chat-text` child of a `.chat-bubble`.
   Two things differ from the project-chat rules above and must be handled
   here: (1) the bubble carries Tailwind `whitespace-pre-wrap`, which is
   inherited and would double the line breaks in rendered block HTML — so we
   reset it to `normal`; (2) the Tailwind CDN preflight strips `list-style`,
   so bullets/numbers are set explicitly (same as the docs-prose page). */
.lib-chat-text {
  white-space: normal;
}
.lib-chat-text > *:first-child { margin-top: 0; }
.lib-chat-text > *:last-child  { margin-bottom: 0; }

.lib-chat-text p { margin: 0.5em 0; }

.lib-chat-text h1,
.lib-chat-text h2,
.lib-chat-text h3,
.lib-chat-text h4,
.lib-chat-text h5,
.lib-chat-text h6 {
  margin: 0.75em 0 0.4em;
  font-weight: 600;
  line-height: 1.25;
}
.lib-chat-text h1 { font-size: 1.125rem; }
.lib-chat-text h2 { font-size: 1rem; }
.lib-chat-text h3 { font-size: 0.95rem; }
.lib-chat-text h4,
.lib-chat-text h5,
.lib-chat-text h6 { font-size: 0.875rem; }

.lib-chat-text ul,
.lib-chat-text ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}
.lib-chat-text ul { list-style: disc; }
.lib-chat-text ol { list-style: decimal; }
.lib-chat-text li { margin: 0.15em 0; }
.lib-chat-text li > p { margin: 0.15em 0; }

.lib-chat-text blockquote {
  margin: 0.5em 0;
  padding: 0.1em 0.75em;
  border-left: 3px solid rgba(0, 0, 0, 0.18);
  opacity: 0.85;
}

.lib-chat-text a {
  color: oklch(var(--p));
  text-decoration: underline;
}

.lib-chat-text strong { font-weight: 600; }
.lib-chat-text em { font-style: italic; }
.lib-chat-text hr {
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.15);
  margin: 0.75em 0;
}

.lib-chat-text code {
  font-family: ui-monospace, 'SFMono-Regular', 'Menlo', monospace;
  font-size: 0.82rem;
  background: rgba(0, 0, 0, 0.07);
  padding: 0.05em 0.3em;
  border-radius: 0.25rem;
}
.lib-chat-text pre {
  margin: 0.5em 0;
  padding: 0.55rem 0.7rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 0.375rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.45;
}
.lib-chat-text pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  color: inherit;
}
