/* ═══════════════════════════════════════════
   HQ Chat View Styles
   Two-pane: agent directory left, conversation right.
   Depends on tokens.css.
   ═══════════════════════════════════════════ */

/* ── Chat view wrapper ─────────────────────── */
.chat-view {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Agent directory (left pane) ───────────── */
.chat-directory {
  width: 280px;
  background: var(--color-panel);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.chat-directory__search {
  padding: 12px 12px 8px;
  position: sticky;
  top: 0;
  background: var(--color-panel);
  z-index: 2;
  border-bottom: 1px solid var(--color-border);
}

.chat-directory__search-input {
  width: 100%;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  color: var(--color-text);
  font-size: var(--text-base);
  outline: none;
  font-family: var(--font-body);
  transition: border-color var(--transition-base);
  min-height: 38px;
}

.chat-directory__search-input:focus {
  border-color: var(--color-amber-glow);
}

/* ── Agent list section ────────────────────── */
.agent-section {
  margin-bottom: 4px;
}

.agent-section__header {
  padding: 10px 14px 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--color-amber);
  display: flex;
  align-items: center;
  gap: 6px;
}

.agent-section__count {
  color: var(--color-muted);
  font-family: var(--font-mono);
}

/* ── Agent list item ───────────────────────── */
.agent-item {
  padding: 7px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 2px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  min-height: 44px;
}

.agent-item:hover {
  background: var(--color-panel2);
}

.agent-item.active {
  background: var(--color-panel2);
  border-left-color: var(--color-amber);
}

.agent-item__info {
  flex: 1;
  overflow: hidden;
}

.agent-item__name {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-item__role {
  font-size: var(--text-sm);
  color: var(--color-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Conversation pane (right) ─────────────── */
.chat-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Conversation header ───────────────────── */
.chat-conv-header {
  padding: 14px var(--space-5);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-panel);
  flex-shrink: 0;
}

.chat-conv-header__info {
  flex: 1;
  min-width: 0;
}

.chat-conv-header__name {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
}

.chat-conv-header__meta {
  font-size: 11px;
  color: var(--color-dim);
}

.chat-conv-header__online {
  color: var(--color-green);
  margin-left: var(--space-2);
}

/*
 * Rule 18 header pill — session-level tagger + aggregated count badges.
 * Counts = sessionLevel + Σ(perMessage). Clicking the pill tags the session
 * itself (messageId=null). Colors mirror .message-tag-badge--r12/--r16 so the
 * header and per-message badges read as the same visual vocabulary.
 */
.chat-conv-header__tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: var(--space-2);
  padding: 2px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.chat-conv-header__tag-pill:hover,
.chat-conv-header__tag-pill:focus-visible {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  outline: none;
}

/*
 * Zero-state — pill shown on fresh conversations with no tags yet
 * (Q-FL-2c-1 resolution, 2026-04-20). The goal is "tap to add" not
 * "zero violations": the label must be discoverable but must not
 * compete visually with the conversation name or with pills that have
 * actual R12/R16 counts. Dim text + dashed border hint communicates
 * "affordance, not state." Hover/focus-visible raise it to full
 * prominence so the click target is obvious on mouse-in.
 */
.chat-conv-header__tag-pill--empty {
  opacity: 0.6;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  padding: 1px 8px;
}

.chat-conv-header__tag-pill--empty .chat-conv-header__tag-pill-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-dim, rgba(255, 255, 255, 0.55));
  line-height: 1.4;
}

.chat-conv-header__tag-pill--empty:hover,
.chat-conv-header__tag-pill--empty:focus-visible {
  opacity: 1;
  border-color: rgba(212, 165, 116, 0.45);
}

.chat-conv-header__tag-pill--empty:hover .chat-conv-header__tag-pill-label,
.chat-conv-header__tag-pill--empty:focus-visible .chat-conv-header__tag-pill-label {
  color: var(--color-amber);
}

.chat-conv-header__tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.chat-conv-header__tag--r12 {
  background: rgba(212, 165, 116, 0.12);
  border-color: rgba(212, 165, 116, 0.45);
  color: var(--color-amber);
}

.chat-conv-header__tag--r16 {
  background: rgba(125, 200, 210, 0.12);
  border-color: rgba(125, 200, 210, 0.45);
  color: var(--color-teal, #7dc8d2);
}

.chat-conv-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ── Scope selector dropdown ───────────────── */
.scope-select {
  position: relative;
}

.scope-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-dim);
  padding: 5px 10px;
  border-radius: var(--radius-md);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all var(--transition-fast);
  white-space: nowrap;
  min-height: 32px;
}

.scope-btn:hover {
  border-color: var(--color-muted);
  color: var(--color-text);
}

.scope-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--color-panel2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  min-width: 180px;
  z-index: 50;
  overflow: hidden;
  display: none;
}

.scope-dropdown.open {
  display: block;
  animation: fade-in 0.15s ease;
}

.scope-dropdown__item {
  padding: 9px 14px;
  font-size: var(--text-base);
  color: var(--color-dim);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 8px;
}

.scope-dropdown__item:hover {
  background: var(--color-panel);
  color: var(--color-text);
}

.scope-dropdown__item.active {
  color: var(--color-amber);
}

.scope-dropdown__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* "virtual" pill next to project name in the scope dropdown. Distinguishes
   path-less projects that will run in global scope on send. */
.scope-dropdown__badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--color-border);
  color: var(--color-muted);
  margin-left: auto;
}

.scope-dropdown__note {
  padding: 8px 14px;
  font-size: 10px;
  line-height: 1.4;
  color: var(--color-dim);
  font-style: italic;
  border-top: 1px solid var(--color-border);
  background: var(--color-panel);
}

/* ── Message area ──────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Individual message ────────────────────── */
.message-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fade-in 0.2s ease;
}

.message-row--user {
  flex-direction: row-reverse;
}

.message-row--system {
  justify-content: center;
}

.message-content {
  max-width: 70%;
  display: flex;
  flex-direction: column;
}

.message-content--user {
  align-items: flex-end;
}

.message-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 3px;
}

.message-meta--user {
  justify-content: flex-end;
}

.message-meta__name {
  font-size: 11px;
  font-weight: 700;
}

.message-meta__time {
  font-size: var(--text-sm);
  color: var(--color-dim);
  font-family: var(--font-mono);
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-xl);
  font-size: var(--text-md);
  line-height: 1.55;
}

.message-bubble--agent {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.message-bubble--user {
  background: var(--color-amber-dim);
  border: 1px solid var(--color-amber-glow);
  color: var(--color-text);
}

.message-bubble--system {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-dim);
  font-style: italic;
  font-size: 11px;
  text-align: center;
  padding: 8px 12px;
  border-radius: var(--radius-md);
}

/* ── Markdown rendering inside bubbles ─────── */
.message-bubble p  { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol {
  margin: 6px 0 8px 20px;
}
.message-bubble li { margin-bottom: 4px; }
.message-bubble code {
  background: var(--color-bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.message-bubble pre {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.message-bubble pre code {
  background: none;
  padding: 0;
}
.message-bubble strong { color: var(--color-amber); }
.message-bubble a {
  color: var(--color-blue);
  text-decoration: underline;
}

/* ── Input area ────────────────────────────── */
.chat-input-area {
  padding: 14px var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-panel);
  flex-shrink: 0;
  /* Prevent the input row from overflowing horizontally on narrow viewports
     (iPad portrait/landscape) when the textarea + mic + tts + send buttons
     would otherwise blow past the conversation pane width. Caught 2026-05-03
     when Brian reported mic missing + send button off-screen on iPad. */
  box-sizing: border-box;
  max-width: 100%;
  overflow-x: hidden;
}

.chat-input-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  /* min-width: 0 lets this row shrink below its content's intrinsic width
     when its parent is constrained — without it, the textarea's default
     `min-width: auto` (content-driven) keeps the row wider than the parent
     and pushes mic/send off-screen. */
  min-width: 0;
}

.chat-textarea {
  flex: 1;
  /* min-width: 0 overrides the flex default `min-width: auto`, which for a
     <textarea> is the rendered content width. Without this, the textarea
     refuses to shrink, the row overflows right, and the mic + send buttons
     get pushed off-screen on iPad portrait (768px) and landscape (1024px). */
  min-width: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 10px 12px;
  font-size: var(--text-md);
  outline: none;
  font-family: var(--font-body);
  resize: none;
  min-height: 44px;
  max-height: 200px;
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-base);
  overflow-y: auto;
  line-height: 1.5;
}

.chat-textarea:focus {
  border-color: var(--color-amber-glow);
}

.chat-send-btn {
  background: var(--color-amber);
  color: var(--color-bg);
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-lg);
  font-weight: 700;
  font-size: var(--text-base);
  cursor: pointer;
  font-family: var(--font-body);
  transition: opacity var(--transition-fast);
  white-space: nowrap;
  min-height: 44px;
  flex-shrink: 0;
}

.chat-send-btn:hover  { opacity: 0.9; }
.chat-send-btn:active { opacity: 0.8; }
.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Mic button (shared base — see public/js/util/mic-button.js) ──
   Used directly in chat-input-row and reused via micButtonHtml() across
   dashboard chief-input, task-modal title, and tag-modal note. The .pulse
   ring fades in only while .is-listening is set by wireMicButton(). */
.chat-mic-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-body);
  transition: border-color var(--transition-base), opacity var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
}
.chat-mic-btn:hover:not(:disabled)  { border-color: var(--color-amber-glow); }
.chat-mic-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
/* Dimmed-but-clickable: voice mode is OFF but the user can click to enable.
   Different from :disabled (used for STT-unsupported, where no click would
   help). Visual cue: slight dim, but cursor:pointer signals interactivity.
   See mic-button.js refresh() click-to-enable comment, 2026-05-04. */
.chat-mic-btn.chat-mic-btn--off:not(:disabled) {
  opacity: 0.6;
  cursor: pointer;
}
.chat-mic-btn.chat-mic-btn--off:not(:disabled):hover {
  opacity: 0.85;
  border-color: var(--color-amber-glow);
}
.chat-mic-btn__icon {
  font-size: 18px;
  line-height: 1;
}
.chat-mic-btn__pulse {
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--color-amber);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.chat-mic-btn.is-listening {
  border-color: var(--color-amber);
}
.chat-mic-btn.is-listening .chat-mic-btn__pulse {
  opacity: 1;
  animation: chat-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes chat-mic-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(1.05); }
}

/* TTS pause/resume button — same square footprint as .chat-mic-btn so the
   composer reads as a row of equal-width controls. The 2026-05-03 iPad
   audit caught this had no explicit size rule, leaving it at default
   <button> width (variable based on emoji glyph width); on narrow viewports
   that variable width contributed to row overflow.  Pinning it to 44×44
   matches the mic and the textarea's min-height for a uniform row. */
.chat-tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  transition: border-color var(--transition-base), opacity var(--transition-fast);
}
.chat-tts-btn:hover { border-color: var(--color-amber-glow); }
.chat-tts-btn:active { opacity: 0.8; }

/* Stop button — shown only while a reply is in flight (streaming OR
   pre-stream processing window). Tap dispatches a WS cancel; the
   in-flight CLI subprocess gets SIGINT and emits a final result. Sized
   to match the mic/tts neighbors so the row stays uniform when it
   toggles in. The amber-on-bg colour matches the Send button's filled
   posture so the user reads it as the active action while it's
   visible. The label is hidden on narrow viewports — the ⏹ glyph
   alone is sufficient at mobile width. */
.chat-stop-btn {
  display: none; /* toggled to inline-flex by JS while in-flight */
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  background: var(--color-bg);
  color: var(--color-amber);
  border: 1px solid var(--color-amber);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--text-base);
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity var(--transition-fast), border-color var(--transition-base);
}
.chat-stop-btn:hover  { opacity: 0.9; border-color: var(--color-amber-glow); }
.chat-stop-btn:active { opacity: 0.8; }
.chat-stop-btn__label { font-size: var(--text-sm); }

/* Narrow viewports: drop the "Stop" word, keep the glyph. Send button
   remains the wider control; Stop becomes a square 44×44 button while
   in-flight so the row fits on 375px. Send button also tightens its
   horizontal padding so the textarea keeps a usable width when mic +
   voice + stop are all visible (worst-case crowding at 375px observed
   by Playwright probe 2026-05-11: textarea collapsed to 97-105px before
   this fix). */
@media (max-width: 480px) {
  .chat-stop-btn { padding: 0; width: 44px; }
  .chat-stop-btn__label { display: none; }
  /* Tighter row gap to reclaim pixels for the textarea on iPhone SE. */
  .chat-input-row { gap: 4px; }
  /* Send button: keep the word "Send" but pull padding inward; the amber
     fill keeps it readable as the primary action. */
  .chat-send-btn { padding: 10px 10px; min-width: 44px; }
}

/* Tag-modal mic anchors to bottom-right of the textarea via a relative
   wrapper, so it doesn't disrupt the textarea's full-width layout. */
.tag-modal__textarea-wrap {
  position: relative;
}
.tag-modal__mic-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 36px;
  min-height: 36px;
}
.tag-modal__mic-btn .chat-mic-btn__icon { font-size: 16px; }

/* Dashboard chief-input mic — uses the shared chat-mic-btn 44×44 footprint
   to honor the iOS 44px touch-target floor. The chief-input field itself
   is 38px-min-height for visual density; the mic button stays 44×44 (which
   makes it taller than the field by 6px — acceptable trade for tappability
   on mobile). Caught 2026-05-11 by Playwright probe: 38×44 mic was
   undersized at every viewport. Smaller icon font keeps the visual weight
   appropriate to the chief composer scale. */
.chief-mic-btn .chat-mic-btn__icon { font-size: 16px; }

.chat-input-hint {
  font-size: var(--text-sm);
  color: var(--color-dim);
  margin-top: 6px;
  display: flex;
  gap: 12px;
}

/* ── Mobile: directory becomes drawer ──────── */
@media (max-width: 768px) {
  .chat-directory {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    /* Respect iOS dynamic viewport (address-bar collapse). Falls back
       to 100vh if dvh isn't supported. */
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
    z-index: 101;
    width: 300px;
    max-width: 85vw;
    padding-left: env(safe-area-inset-left);
    /* Reserve iOS notch / status bar inset so the drawer's first
       child (search input) isn't hidden under the status bar when
       the drawer is open. Caught 2026-05-04 (hq-v50) — same root
       cause as .top-bar. */
    padding-top: env(safe-area-inset-top);
  }

  .chat-directory.open {
    transform: translateX(0);
  }

  .chat-conv-header {
    padding: 12px var(--space-4);
  }

  .chat-messages {
    padding: var(--space-4);
  }

  .message-content {
    max-width: 85%;
  }

  .chat-input-hint {
    display: none;
  }

  /* iOS zooms the page when a textarea with font-size < 16px gets focus.
     Pin the chat textarea to 16px on phone to suppress that zoom. */
  .chat-textarea {
    font-size: 16px;
  }

  /* Safe-area-aware padding so the chat input bar sits above the
     iOS home indicator instead of under it. */
  .chat-input-area {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    padding-left: max(var(--space-5), env(safe-area-inset-left));
    padding-right: max(var(--space-5), env(safe-area-inset-right));
  }

  /* Tighten input row gap on phone/iPad-portrait so 4-5 controls
     (hamburger + textarea + mic + tts + send) fit without overflow. */
  .chat-input-row {
    gap: 6px;
  }
}

/* ── Tablet (iPad landscape): narrow directory + tighter input row ──
   Range 769-1024px catches iPad landscape (1024×768) and similar tablets
   that fall between the phone (≤768px) and full-desktop ranges. The
   directory at 280px + input row with mic/tts/send buttons was overflowing
   the conversation pane on iPad landscape; narrowing the directory and
   reducing input padding gives the composer enough room.  Caught 2026-05-03
   from Brian's iPad report (mic missing, send button off-screen). */
@media (min-width: 769px) and (max-width: 1024px) {
  .chat-directory {
    width: 240px;
  }

  .chat-input-area {
    padding: 12px var(--space-4);
  }

  /* Allow the input row to wrap to a second line on tablet landscape if
     the conversation pane is unusually narrow (e.g. devtools open).
     Wrapping is a graceful fallback; the primary fix is the min-width: 0
     on textarea + chat-input-row above. */
  .chat-input-row {
    flex-wrap: wrap;
  }

  /* When wrap kicks in, the textarea takes its own row at full width and
     the buttons cluster on a second row. Ensure the textarea claims the
     full row when it wraps, rather than sharing with a partial button. */
  .chat-input-row .chat-textarea {
    flex-basis: 100%;
  }

  /* NOTE: We deliberately do NOT force the mic button visible here. The
     JS-controlled visibility (chat.js refreshMicButton) is the source of
     truth — when voiceMode is "off" (default), the mic is hidden by design.
     Brian's "not seeing mic" report is solved by (a) the overflow fix
     (mic was being pushed off-screen when voice was enabled) and/or
     (b) enabling voice in settings. Mic-visible-by-default is a UX
     direction call, not a layout fix; tracked in notes.md as scope
     expansion requiring product direction. */
}

@media (max-width: 480px) {
  .chat-input-area {
    /* Override the 768px rule — tighter top padding but keep the
       safe-area-aware bottom padding. */
    padding: 10px var(--space-3);
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(var(--space-3), env(safe-area-inset-left));
    padding-right: max(var(--space-3), env(safe-area-inset-right));
  }

  .chat-messages {
    padding: var(--space-3);
  }

  /* Full-width drawer on very small screens — leaves just enough
     edge peek to signal "swipe/tap to close". */
  .chat-directory {
    width: 100%;
    max-width: 92vw;
  }

  /* Shrink the agent-item avatars slightly on phone for better density. */
  .agent-item {
    padding: 8px 12px;
  }

  /* Tighter conversation header to save vertical space. */
  .chat-conv-header {
    padding: 10px var(--space-3);
    gap: 8px;
  }

  .chat-conv-header__actions {
    gap: 4px;
  }

  /* Scope dropdown: align to right edge so it doesn't clip off-screen. */
  .scope-dropdown {
    min-width: 160px;
    right: 0;
    left: auto;
  }
}

/* ── Rule 18.A §1 — Message tag affordances ───────────────────────
   Per-message ⋯ button, R12/R16 badges, dropdown menu, modal. */

.message-tag-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-dim);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  line-height: 1;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast),
              background var(--transition-fast),
              border-color var(--transition-fast),
              color var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.message-row:hover .message-tag-btn,
.message-tag-btn:focus,
.message-tag-btn[aria-expanded="true"] {
  opacity: 1;
}

.message-tag-btn:hover,
.message-tag-btn[aria-expanded="true"] {
  background: var(--color-panel2);
  border-color: var(--color-border);
  color: var(--color-text);
}

/* Touch devices: no hover — show the button by default, dimmed. */
@media (hover: none) {
  .message-tag-btn { opacity: 0.55; }
}

.message-tag-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  letter-spacing: 0.3px;
  border: 1px solid transparent;
  line-height: 1.4;
}

/* R12 = unexamined-default (warm amber pill). */
.message-tag-badge--r12 {
  background: rgba(212, 165, 116, 0.12);
  border-color: rgba(212, 165, 116, 0.45);
  color: var(--color-amber);
}

/* R16 = challenge-raised (cool teal/blue pill). */
.message-tag-badge--r16 {
  background: rgba(125, 200, 210, 0.12);
  border-color: rgba(125, 200, 210, 0.45);
  color: var(--color-teal, #7dc8d2);
}

/* ── Tag dropdown menu (opened by ⋯ click) ──────────────────────── */
.tag-menu {
  position: fixed;
  background: var(--color-panel2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  min-width: 180px;
  z-index: 200;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: fade-in 0.12s ease;
}

.tag-menu__item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: var(--radius-md, 6px);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  color: var(--color-text);
  transition: background var(--transition-fast);
}

.tag-menu__item:hover,
.tag-menu__item:focus-visible {
  background: var(--color-panel);
  outline: none;
}

.tag-menu__label {
  font-size: var(--text-base);
  font-weight: 600;
}

.tag-menu__hint {
  font-size: var(--text-sm);
  color: var(--color-dim);
}

/* ── Tag modal ──────────────────────────────────────────────────── */
.tag-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  /* Reserve iOS notch / status bar / Dynamic Island. Tall modal
     content on small phones (e.g. tag rationale textarea + actions)
     can collide with the status bar; max() falls back to 16px on
     non-iOS so non-iOS is unaffected. Pattern from hq@e37c073. */
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  animation: fade-in 0.15s ease;
}

.tag-modal {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tag-modal__title {
  font-family: var(--font-heading, "Playfair Display", serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
}

.tag-modal__subtitle {
  font-size: var(--text-sm);
  color: var(--color-dim);
  margin-bottom: 4px;
}

.tag-modal__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-dim);
  display: block;
}

.tag-modal__optional {
  font-weight: 400;
  color: var(--color-muted, var(--color-dim));
}

.tag-modal__textarea {
  width: 100%;
  background: var(--color-panel2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--text-base);
  padding: 10px;
  resize: vertical;
  min-height: 80px;
}

.tag-modal__textarea:focus {
  outline: none;
  border-color: var(--color-amber);
}

.tag-modal__counter {
  font-size: 11px;
  color: var(--color-dim);
  font-family: var(--font-mono);
  text-align: right;
}

.tag-modal__error {
  font-size: var(--text-sm);
  color: var(--color-red, #c86464);
  background: rgba(200, 100, 100, 0.08);
  border: 1px solid rgba(200, 100, 100, 0.3);
  border-radius: var(--radius-md, 6px);
  padding: 8px 10px;
}

.tag-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.tag-modal__cancel,
.tag-modal__submit {
  font-family: inherit;
  font-size: var(--text-base);
  padding: 8px 16px;
  border-radius: var(--radius-md, 6px);
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: background var(--transition-fast),
              border-color var(--transition-fast),
              color var(--transition-fast);
  min-height: 36px;
}

.tag-modal__cancel {
  background: transparent;
  color: var(--color-dim);
}

.tag-modal__cancel:hover {
  background: var(--color-panel2);
  color: var(--color-text);
}

.tag-modal__submit {
  background: var(--color-amber);
  color: #1a1a1a;
  border-color: var(--color-amber);
  font-weight: 700;
}

.tag-modal__submit:hover:not(:disabled) {
  filter: brightness(1.08);
}

.tag-modal__submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Mobile: pad the modal so it never touches the edge. */
@media (max-width: 600px) {
  .tag-modal { padding: 16px; }
  .tag-modal__title { font-size: 18px; }
  .message-tag-btn { opacity: 0.6; }
}

/* ── Path-collision modal (chat-scope-model Model B §3.6) ───────── */

.path-collision-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  /* iOS notch / status bar safety — see .tag-modal-overlay note. */
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  animation: fade-in 0.15s ease;
}

.path-collision-modal {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.path-collision-modal__title {
  font-family: var(--font-heading, "Playfair Display", serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
}

.path-collision-modal__body {
  font-size: var(--text-sm);
  color: var(--color-dim);
  line-height: 1.5;
}

.path-collision-modal__body code {
  background: var(--color-panel2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-text);
  word-break: break-all;
}

.path-collision-modal__choices {
  margin: 8px 0 0 0;
  padding-left: 20px;
}

.path-collision-modal__choices li {
  margin-bottom: 4px;
}

.path-collision-modal__error {
  font-size: var(--text-sm);
  color: var(--color-red, #c86464);
  background: rgba(200, 100, 100, 0.08);
  border: 1px solid rgba(200, 100, 100, 0.3);
  border-radius: var(--radius-md, 6px);
  padding: 8px 10px;
}

.path-collision-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.path-collision-modal__cancel,
.path-collision-modal__submit {
  font-family: inherit;
  font-size: var(--text-base);
  padding: 8px 16px;
  border-radius: var(--radius-md, 6px);
  cursor: pointer;
  border: 1px solid var(--color-border);
  min-height: 36px;
}

.path-collision-modal__cancel {
  background: transparent;
  color: var(--color-dim);
}

.path-collision-modal__cancel:hover {
  background: var(--color-panel2);
  color: var(--color-text);
}

.path-collision-modal__submit {
  background: var(--color-amber);
  color: #1a1a1a;
  border-color: var(--color-amber);
  font-weight: 700;
}

.path-collision-modal__submit:hover:not(:disabled) {
  filter: brightness(1.08);
}

.path-collision-modal__submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Muted "general" catchall row in the scope dropdown — signals that it's the
   catchall without making it a visual separator. */
.scope-dropdown__item--general {
  opacity: 0.78;
  font-style: italic;
}

.scope-dropdown__item--general:hover {
  opacity: 1;
}

@media (max-width: 600px) {
  .path-collision-modal { padding: 16px; }
  .path-collision-modal__title { font-size: 18px; }
}

/* ── Scope dropdown: Dormant section (V27+) ──
   Per D5 — active projects + General at the top, collapsible "Dormant"
   section below. Archived projects are absent from the picker entirely;
   un-archive via Settings to surface them here. */
.scope-dropdown__dormant {
  border-top: 1px solid var(--color-border);
  background: var(--color-panel);
}

.scope-dropdown__dormant-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 14px;
  background: transparent;
  border: none;
  color: var(--color-dim);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: var(--font-body);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
  text-align: left;
}

.scope-dropdown__dormant-header:hover {
  color: var(--color-text);
  background: var(--color-panel2);
}

.scope-dropdown__dormant-caret {
  display: inline-block;
  font-size: 10px;
  color: var(--color-muted);
  transition: transform var(--transition-fast);
  width: 10px;
  flex-shrink: 0;
}

.scope-dropdown__dormant-header[aria-expanded="true"] .scope-dropdown__dormant-caret {
  transform: rotate(90deg);
}

.scope-dropdown__dormant-count {
  color: var(--color-muted);
  margin-left: auto;
  font-weight: 400;
}

.scope-dropdown__dormant-list {
  background: var(--color-panel2);
}

.scope-dropdown__item--dormant {
  color: var(--color-muted);
  font-size: var(--text-sm);
  padding-left: 22px;
}

.scope-dropdown__item--dormant:hover {
  color: var(--color-dim);
  background: var(--color-panel);
}

/* ── Layer 2 dispatch UI ────────────────────────────────────────── */
/* Review pill rendered inline in a Chief message bubble when one or more
   [DISPATCH-PREVIEW] blocks were intercepted by dispatch-modal.js. */
.dispatch-pill {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 14px;
  background: linear-gradient(135deg, var(--color-amber) 0%, #c89461 100%);
  color: #1a1a1a;
  border: 1px solid var(--color-amber);
  border-radius: 999px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--transition-fast), transform var(--transition-fast);
}
.dispatch-pill:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.dispatch-pill:active {
  transform: translateY(0);
}

/* Dispatch usage indicator in the chat header (Chief only). */
.dispatch-usage {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-dim);
  background: var(--color-panel2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  padding: 4px 8px;
  white-space: nowrap;
}

/* Dispatch modal — same look-and-feel as .tag-modal. */
.dispatch-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 320;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  /* iOS notch / status bar safety — see .tag-modal-overlay note. */
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  animation: fade-in 0.15s ease;
}
.dispatch-modal {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dispatch-modal__title {
  font-family: var(--font-heading, "Playfair Display", serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
}
.dispatch-modal__subtitle {
  font-size: var(--text-sm);
  color: var(--color-dim);
}
.dispatch-modal__rows {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dispatch-row {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  padding: 12px;
  background: var(--color-panel2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dispatch-row__head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  cursor: pointer;
  user-select: none;
}
.dispatch-row__check {
  width: 18px;
  height: 18px;
  accent-color: var(--color-amber);
  cursor: pointer;
}
.dispatch-row__lead {
  font-weight: 700;
  color: var(--color-text);
  font-size: var(--text-base);
}
.dispatch-row__project {
  color: var(--color-dim);
  font-size: var(--text-sm);
}
.dispatch-row__tool {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-panel);
  color: var(--color-dim);
}
.dispatch-row__tool--dispatch {
  border-color: var(--color-amber);
  color: var(--color-amber);
}
.dispatch-row__tool--task {
  border-color: var(--color-border);
  color: var(--color-dim);
}
.dispatch-row__directive {
  width: 100%;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--text-sm);
  padding: 10px;
  resize: vertical;
  min-height: 100px;
}
.dispatch-row__directive:focus {
  outline: none;
  border-color: var(--color-amber);
}
.dispatch-row__token {
  font-size: 11px;
  color: var(--color-muted, var(--color-dim));
  opacity: 0.7;
}
.dispatch-modal__error {
  font-size: var(--text-sm);
  color: var(--color-red, #c86464);
  background: rgba(200, 100, 100, 0.08);
  border: 1px solid rgba(200, 100, 100, 0.3);
  border-radius: var(--radius-md, 6px);
  padding: 8px 10px;
}
.dispatch-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.dispatch-modal__close,
.dispatch-modal__cancel,
.dispatch-modal__send {
  font-family: inherit;
  font-size: var(--text-base);
  padding: 8px 16px;
  border-radius: var(--radius-md, 6px);
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: background var(--transition-fast),
              border-color var(--transition-fast),
              color var(--transition-fast),
              filter var(--transition-fast);
  min-height: 36px;
}
.dispatch-modal__close {
  background: transparent;
  color: var(--color-dim);
}
.dispatch-modal__close:hover {
  background: var(--color-panel2);
  color: var(--color-text);
}
.dispatch-modal__cancel {
  background: transparent;
  color: var(--color-red, #c86464);
  border-color: var(--color-red, #c86464);
}
.dispatch-modal__cancel:hover {
  background: rgba(200, 100, 100, 0.1);
}
.dispatch-modal__send {
  background: var(--color-amber);
  color: #1a1a1a;
  border-color: var(--color-amber);
  font-weight: 700;
}
.dispatch-modal__send:hover {
  filter: brightness(1.08);
}
@media (max-width: 600px) {
  .dispatch-modal { padding: 16px; }
  .dispatch-modal__title { font-size: 18px; }
  .dispatch-row__head { gap: 6px; }
  .dispatch-row__tool { margin-left: 0; }
}

/* Edit-on-send deferred notice — shown above the modal actions to make it
   clear that textarea edits are review-only until the backend endpoint
   ships. See dispatch-modal.js and docs/work-products/layer-2-finishing-
   frontend/notes.md (Q2 backend dependency). */
.dispatch-modal__notice {
  font-size: var(--text-sm);
  color: var(--color-dim);
  background: rgba(212, 165, 116, 0.06);
  border: 1px solid rgba(212, 165, 116, 0.25);
  border-radius: var(--radius-md, 6px);
  padding: 8px 10px;
  line-height: 1.45;
}
.dispatch-modal__notice strong {
  color: var(--color-text);
}

/* Cancel-confirm sub-dialog (Q1) — overlays the dispatch modal so the row
   list remains visible behind it. CSP-safe: no inline scripts. */
.dispatch-confirm {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 330; /* above .dispatch-modal-overlay (320) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  /* iOS notch / status bar safety — see .tag-modal-overlay note. */
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  animation: fade-in 0.12s ease;
}
.dispatch-confirm__panel {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dispatch-confirm__title {
  font-family: var(--font-heading, "Playfair Display", serif);
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}
.dispatch-confirm__body {
  font-size: var(--text-sm);
  color: var(--color-dim);
  line-height: 1.5;
}
.dispatch-confirm__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Conversations drawer (V130, Task 6b) ── */
.conv-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
}

.conv-drawer {
  width: min(400px, 94vw);
  height: 100%;
  background: var(--color-panel);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.4);
}

.conv-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  padding-top: max(var(--space-4), env(safe-area-inset-top));
  border-bottom: 1px solid var(--color-border);
}

.conv-drawer__title {
  font-weight: 700;
  font-family: var(--font-display);
  font-size: var(--text-xl);
}

.conv-drawer__new {
  margin: var(--space-3) var(--space-4);
  min-height: 44px;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-amber);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
}

.conv-drawer__new:hover {
  border-color: var(--color-amber);
}

.conv-drawer__list {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-3) var(--space-4);
}

.conv-drawer__empty {
  color: var(--color-dim);
  padding: var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
}

.conv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: 52px;
}

.conv-row:hover {
  background: var(--color-panel2);
}

.conv-row.is-active {
  background: var(--color-amber-dim);
}

.conv-row__body {
  flex: 1;
  min-width: 0;
}

.conv-row__title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-row__meta {
  font-size: 11px;
  color: var(--color-dim);
  font-family: var(--font-mono);
}

.conv-row__actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.conv-row__act {
  min-width: 36px;
  min-height: 36px;
  padding: 4px;
}

.conv-drawer__archived {
  margin-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-2);
}

.conv-drawer__archived summary {
  color: var(--color-dim);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: 6px 10px;
  min-height: 36px;
}

/* ── Conversation-boundary divider (V129 synopsis) ── */
.message-row--session-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  justify-content: center;
}

.session-divider__line {
  flex: 1;
  height: 1px;
  background: var(--color-border);
  max-width: 120px;
}

.session-divider__label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--color-dim);
  text-align: center;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
