/* =========================================================================
   The Producer — Styles
   Tokens ported from the Platypus Economics Design System (sibling to the
   Substacker app) so the two tools feel like one family. Inlined per that
   system's guidance: never invent colors outside the palette; one accent
   per composition; committed negative space.
   ========================================================================= */

/* ---- Fonts (files live in /public/fonts/, served as static) -------------- */

@font-face {
  font-family: "Sublime";
  src: url("fonts/Sublime.ttf") format("truetype");
  font-weight: 400 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Helvetica Neue LT";
  src: url("fonts/HelveticaNeueLTStd-Roman.otf") format("opentype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Helvetica Neue LT";
  src: url("fonts/HelveticaNeueLTStd-It.otf") format("opentype");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Helvetica Neue LT";
  src: url("fonts/HelveticaNeueLTStd-Md.otf") format("opentype");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Helvetica Neue LT";
  src: url("fonts/HelveticaNeueLTStd-Bd.otf") format("opentype");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Helvetica Neue LT";
  src: url("fonts/HelveticaNeueLTStd-Blk.otf") format("opentype");
  font-weight: 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Helvetica Neue LT Cond";
  src: url("fonts/HelveticaNeueLTStd-BdCn.otf") format("opentype");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Helvetica Neue LT Cond";
  src: url("fonts/HelveticaNeueLTStd-BlkCn.otf") format("opentype");
  font-weight: 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-Variable.ttf") format("truetype-variations");
  font-weight: 100 900; font-style: normal; font-display: swap;
}

:root {
  /* Platypus Economics palette ------------------------------------------- */
  --ink:        #0b0b0a;
  --shell:      #ffffff;
  --abyss:      #0e4a53;
  --abyss-dark: #083940;
  --surf:       #2f9e97;
  --algae:      #006b2e;
  --sun:        #d9a315;
  --coral:      #d93a43;
  --orchid:     #8e4aa0;
  --abyss-neon: #16a7b4;
  --abyss-tint: #a8ecef;
  --surf-neon:  #00fff0;
  --surf-tint:  #ccfffb;
  --sun-tint:   #ffd966;
  --coral-tint: #ff9aa0;

  /* Semantic aliases (kept matching Producer's prior names so existing
     selectors keep working without a sweeping refactor). */
  --bg:           #f5f7f7;
  --surface:      var(--shell);
  --surface-alt:  #ecf3f3;
  --border:       #e2e6e6;
  --border-dark:  #13575f;
  --divider:      rgba(14, 74, 83, 0.12);
  --text:         var(--ink);
  --text-secondary: #5a6467;
  --text-muted:   #3a4347;
  --accent:       var(--surf);
  --accent-hover: var(--abyss);
  --danger:       var(--coral);
  --danger-hover: #b8262f;
  --producer-bg:  #f1f8f8;
  --producer-border: #cfe5e5;
  --user-bg:      #f0fdf4;
  --user-border:  #cfe9d6;
  --recording:    var(--coral);
  --radius:       10px;
  --radius-sm:    6px;
  --radius-pill:  999px;
  --shadow-sm:    0 1px 2px rgba(11, 11, 10, 0.06);
  --shadow-md:    0 4px 14px rgba(11, 11, 10, 0.08);
  --shadow-crisp: 0 0 0 1px rgba(14, 74, 83, 0.14);
  --ease-out:     cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast:     120ms;
  --dur-med:      220ms;

  /* Type stack — UI text is Inter (matches Substacker), brand marks use
     Sublime / Helvetica Cond, scripts and reading prose stay on Lora. */
  --font-display: "Sublime", "Helvetica Neue LT Cond", Impact, "Arial Black", sans-serif;
  --font-impact:  "Helvetica Neue LT Cond", "Helvetica Neue LT", Impact, Helvetica, sans-serif;
  --font-sans:    "Helvetica Neue LT", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-ui:      "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-script:  'Lora', Georgia, serif;
  /* Type scale. Mobile-first: base 16px so iOS Safari doesn't zoom inputs
     on focus. Desktop tightens via a min-width breakpoint further down. */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 20px;
  --fs-input: 16px;
  /* Safe-area insets; fall back to 0 where unsupported. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  height: 100%;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  color: var(--text);
  background: var(--bg);
}

/* Prefer the dynamic viewport on browsers that support it so the virtual
   keyboard on iOS/Android doesn't push the input area off-screen. */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Desktop density: drop base type back to 15px to match the pre-responsive
   look. Mobile/tablet stay at 16px for readability and input-zoom safety. */
@media (min-width: 900px) {
  html, body { font-size: 15px; }
}

/* =========================================================================
   Top Bar — Abyss surface, white marks (sibling to Substacker)
   ========================================================================= */

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) max(20px, var(--safe-right)) 10px max(20px, var(--safe-left));
  background: var(--abyss);
  color: #ffffff;
  border-bottom: 1px solid var(--border-dark);
  flex-shrink: 0;
  z-index: 10;
  gap: 12px;
  min-height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  padding: 4px 8px;
  margin-left: -8px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--ease-out);
}
.brand:hover { background: rgba(255, 255, 255, 0.08); }
.brand:focus-visible { outline: 3px solid var(--surf-neon); outline-offset: 2px; }

.brand-icon {
  height: 40px;
  width: auto;
  display: block;
}

.brand-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 0.9;
  color: #ffffff;
}

.brand-tag {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--surf-tint);
  padding: 3px 8px;
  border: 1px solid rgba(204, 255, 251, 0.3);
  border-radius: var(--radius-pill);
  margin-left: 4px;
}

.brand-glyphs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--surf-tint);
  opacity: 0.85;
}
.brand-glyph {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  display: block;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Topbar buttons (Substacker .icon-btn) — transparent on the abyss surface,
   hover lifts a faint white scrim. */
.icon-btn {
  background: transparent;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.icon-btn.icon-only {
  padding: 7px 9px;
  min-width: 36px;
  justify-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.55); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn:focus-visible { outline: 2px solid var(--surf-neon); outline-offset: 2px; }
.icon-btn.icon-danger { border-color: rgba(217, 58, 67, 0.5); }
.icon-btn.icon-danger:hover { background: rgba(217, 58, 67, 0.18); border-color: var(--coral-tint); }
/* Active toggle state for an .icon-btn (e.g., Outline mode on). */
.icon-btn.active { background: var(--surf); border-color: var(--surf-neon); color: #ffffff; }
.icon-btn.active:hover { background: var(--surf-neon); color: var(--abyss); border-color: var(--surf-neon); }

.topbar-select {
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  max-width: 280px;
  cursor: pointer;
}
.topbar-select:hover { border-color: rgba(255, 255, 255, 0.55); background: rgba(255, 255, 255, 0.12); }
.topbar-select option { color: var(--ink); background: var(--shell); }

.chat-mode-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--surf-tint);
  padding: 3px 8px;
  border: 1px solid rgba(204, 255, 251, 0.3);
  border-radius: var(--radius-pill);
}
.chat-mode-badge:empty { display: none; }

.build-info {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  margin-left: 4px;
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  touch-action: manipulation;
}

.btn:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:hover {
  background: var(--surface-alt);
  border-color: #ccc;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
}

.btn-icon {
  padding: 6px;
  border: 1px solid var(--border);
}

.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.btn-danger:hover {
  background: #fef2f2;
}

/* =========================================================================
   Phase Stepper
   ========================================================================= */

.phase-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 10px 20px 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.script-word-count {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 500;
  color: var(--phase-color, var(--text-secondary));
  background: var(--phase-bg, transparent);
  padding: 1px 8px;
  border-radius: 10px;
  white-space: nowrap;
  pointer-events: none;
  transition: left 0.2s ease;
}

/* Each phase step is a <button> so it's keyboard-focusable and announces
   as a control to assistive tech. Browser button defaults are reset here. */
.phase-step {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid transparent;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}

.phase-step:hover {
  background: var(--phase-bg, var(--surface-alt));
  border-color: color-mix(in srgb, var(--phase-color, var(--accent)) 25%, transparent);
}
.phase-step:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Future (un-reached) phases sit muted. */
.phase-step.future .phase-label,
.phase-step:not(.completed):not(.active) .phase-label { opacity: 0.7; }

.phase-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.phase-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.2s ease;
  white-space: nowrap;
}

.phase-connector {
  width: 24px;
  height: 2px;
  background: var(--border);
  transition: background 0.2s ease;
  flex-shrink: 0;
}

/* Per-phase color palette — one hue per workflow phase.
   Cool → warm progression as the user advances through the workflow. */
[data-phase="0"] { --phase-color: #64748b; --phase-bg: #f1f5f9; --phase-border: #cbd5e1; } /* Research — slate */
[data-phase="1"] { --phase-color: #0d9488; --phase-bg: #ecfeff; --phase-border: #99f6e4; } /* Discovery — teal */
[data-phase="2"] { --phase-color: #7c3aed; --phase-bg: #f5f3ff; --phase-border: #ddd6fe; } /* Structure — violet */
[data-phase="3"] { --phase-color: #2563eb; --phase-bg: #eff6ff; --phase-border: #bfdbfe; } /* Script — blue */
[data-phase="4"] { --phase-color: #d97706; --phase-bg: #fffbeb; --phase-border: #fde68a; } /* Voice Rewrite — amber */
[data-phase="5"] { --phase-color: #e11d48; --phase-bg: #fff1f2; --phase-border: #fecdd3; } /* Punch It Up — rose */
[data-phase="6"] { --phase-color: #059669; --phase-bg: #ecfdf5; --phase-border: #a7f3d0; } /* Fact Check — emerald */

/* Completed phase */
.phase-step.completed .phase-dot {
  background: var(--phase-color);
  border-color: var(--phase-color);
}

.phase-step.completed .phase-label {
  color: var(--phase-color);
}

.phase-connector.completed {
  background: var(--phase-color);
}

/* Active phase */
.phase-step.active {
  background: var(--phase-bg);
}

.phase-step.active .phase-dot {
  border-color: var(--phase-color);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--phase-color) 25%, transparent);
}

.phase-step.active .phase-label {
  color: var(--phase-color);
  font-weight: 600;
}

/* Advance button */
.btn-advance {
  margin-left: 16px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-advance:hover:not(:disabled) {
  background: var(--accent);
  color: white;
}

.btn-advance:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  border-color: var(--border);
  color: var(--text-secondary);
}

/* Previous-phase navigation button — sits before the first phase dot.
   Purely a scroll/jump control; does not change the actual phase. */
.btn-back {
  padding: 5px 14px;
  margin-right: 16px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-back:hover:not(:disabled) {
  background: var(--accent);
  color: white;
}

.btn-back:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  border-color: var(--border);
  color: var(--text-secondary);
}

/* Brief highlight on the message you land on after a phase jump. */
@keyframes phase-jump-flash {
  0%   { box-shadow: 0 0 0 3px var(--accent), var(--shadow-sm); }
  100% { box-shadow: 0 0 0 0 transparent, var(--shadow-sm); }
}
.phase-jump-flash {
  animation: phase-jump-flash 1.4s ease-out;
}

/* =========================================================================
   Chat Area
   ========================================================================= */

main {
  flex: 1;
  overflow-y: auto;
  padding: clamp(12px, 3vw, 20px) max(clamp(12px, 3vw, 20px), var(--safe-left)) clamp(12px, 3vw, 20px) max(clamp(12px, 3vw, 20px), var(--safe-right));
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#messages {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Messages */

.message {
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.producer-message {
  background: var(--producer-bg);
  border: 1px solid var(--producer-border);
  margin-right: clamp(8px, 5vw, 40px);
}

/* When a producer message has a phase marker, tint it with that phase's
   color so the user can tell at a glance which phase a message belongs to. */
.producer-message[data-phase] {
  background: var(--phase-bg);
  border-color: var(--phase-border);
  border-left: 3px solid var(--phase-color);
}

.user-message {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  margin-left: clamp(8px, 5vw, 40px);
}

.message-role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.message-content {
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message-content pre,
.message-content code {
  overflow-x: auto;
  max-width: 100%;
}

/* Markdown rendering inside messages */

.message-content h1, .message-content h2, .message-content h3 {
  font-family: var(--font-ui);
  margin-top: 18px;
  margin-bottom: 8px;
}

.message-content h1 { font-size: 20px; }
.message-content h2 { font-size: 17px; }
.message-content h3 { font-size: 15px; }

.message-content p {
  margin-bottom: 10px;
}

.message-content strong {
  font-weight: 700;
  color: var(--text);
}

.message-content em {
  color: #7c3aed;
  font-style: italic;
}

.message-content ul, .message-content ol {
  margin: 8px 0 8px 20px;
}

.message-content li {
  margin-bottom: 4px;
}

.message-content li ul {
  margin-top: 4px;
}

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 10px 0;
  color: var(--text-secondary);
}

/* Footnotes in script messages */
.message-content .footnotes {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

.message-content sup {
  color: var(--accent);
  font-weight: 600;
  cursor: help;
}

/* Message actions (copy, teleprompter) */

.message-actions {
  position: absolute;
  top: 8px;
  right: 10px;
  display: flex;
  gap: 4px;
  opacity: 0.55;
  transition: opacity 0.15s;
}

@media (hover: hover) and (pointer: fine) {
  .message-actions { opacity: 0; }
  .message:hover .message-actions { opacity: 1; }
}

.message-actions button {
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-secondary);
}

.message-actions button:hover {
  background: var(--surface);
  color: var(--text);
}

/* Typing / searching indicator */

.typing-dots::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* =========================================================================
   Input Area
   ========================================================================= */

footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px max(20px, var(--safe-right)) calc(12px + var(--safe-bottom)) max(20px, var(--safe-left));
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
}

/* Textarea takes the whole top row on narrow screens; attach/mic/send sit
   on a second row. This keeps the textarea at a usable width on 344px phones
   instead of being squeezed to ~50px. */
#messageInput {
  flex: 1 0 100%;
  order: -1;
}

@media (min-width: 640px) {
  .input-row { flex-wrap: nowrap; }
  #messageInput { flex: 1; order: 0; }
}

#messageInput {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: var(--fs-input);
  line-height: 1.5;
  resize: none;
  max-height: 360px;
  outline: none;
  transition: border-color 0.15s;
}

#messageInput:focus {
  border-color: var(--accent);
}

.btn-mic {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-mic.recording {
  background: var(--recording);
  border-color: var(--recording);
  color: white;
  animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.btn-attach, .btn-bluesky {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.btn-attach:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.btn-attach-bg {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.btn-attach-bg:hover {
  color: #7c3aed;
  border-color: #7c3aed;
}

.btn-bluesky:hover {
  color: #0085ff;
  border-color: #0085ff;
}

.attachment-preview {
  max-width: 800px;
  margin: 0 auto 6px;
  padding: 6px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Bucket grouping: "In the conversation" vs "Reference shelf". Each bucket
   gets a small label so the writer can see at a glance where each item will
   be used (inline every turn vs. searched on demand). */
.attachment-preview .att-bucket {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.attachment-preview .att-bucket-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  opacity: 0.7;
  margin-right: 4px;
  flex: 0 0 auto;
}

.attachment-preview .att-bucket-items {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.attachment-preview .att-move {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.7;
}

.attachment-preview .att-move:hover {
  opacity: 1;
  color: var(--accent, var(--text-primary));
}

.attachment-preview .att-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview .att-uploading {
  animation: pulse-fade 1.5s ease-in-out infinite;
  color: var(--warning, #f59e0b);
}

@keyframes pulse-fade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.attachment-preview .att-ready {
  color: var(--success, #22c55e);
}

.attachment-preview .att-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

.attachment-preview .att-remove:hover {
  color: var(--danger);
}

/* Image previews in attachment bar */
.image-previews {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.image-preview-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.image-preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview-thumb .att-remove {
  position: absolute;
  top: 1px;
  right: 1px;
  background: rgba(0,0,0,0.6);
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  padding: 0;
}

.image-preview-thumb .att-remove:hover {
  background: var(--danger);
  color: white;
}

.btn-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  flex-shrink: 0;
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 800px;
  margin: 8px auto 0;
}

.action-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------------------------------------------------------------------------
   Outline mode — collapse Producer replies to a one-line preview so the user
   can scan their own messages and zero in on a particular point.
   --------------------------------------------------------------------------- */
body.outline-mode .producer-message {
  cursor: pointer;
  padding: 6px 14px;
  margin-bottom: -4px;
  transition: background-color 0.15s;
}
body.outline-mode .producer-message:hover {
  filter: brightness(0.97);
}
body.outline-mode .producer-message:not(.expanded) .message-role,
body.outline-mode .producer-message:not(.expanded) .message-actions,
body.outline-mode .producer-message:not(.expanded) .message-files,
body.outline-mode .producer-message:not(.expanded) .message-images {
  display: none;
}
body.outline-mode .producer-message:not(.expanded) .message-content > * {
  display: none;
}
body.outline-mode .producer-message:not(.expanded) .message-content > *:first-child {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  color: var(--text-secondary);
  font-style: italic;
}
body.outline-mode .producer-message:not(.expanded) .message-content > *:first-child::before {
  content: '\25B8\00a0';
  color: var(--text-secondary);
  font-style: normal;
}
body.outline-mode .producer-message.expanded .message-role::after {
  content: ' \00b7 click to collapse';
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-style: italic;
  opacity: 0.6;
}
body.outline-mode .user-message {
  border-width: 2px;
}

/* =========================================================================
   Modal
   ========================================================================= */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 90%;
  max-width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-sm {
  max-width: 450px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0 4px;
}

.settings-tabs {
  display: flex;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  gap: 0;
}

.settings-tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.settings-tab:hover {
  color: var(--text);
}

.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.settings-tab-panel {
  display: none;
}

.settings-tab-panel.active {
  display: block;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.settings-description {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0 0 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: var(--fs-input);
  outline: none;
  transition: border-color 0.15s;
}

@media (min-width: 900px) {
  .form-input { font-size: 14px; }
}

.form-input:focus {
  border-color: var(--accent);
}

.prompt-textarea {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  line-height: 1.5;
  min-height: 300px;
  resize: vertical;
}

/* Script picker items */

.script-picker-item {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
  max-height: 80px;
  overflow: hidden;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.script-picker-item:hover {
  border-color: var(--accent);
  background: var(--surface-alt);
  color: var(--text);
}

/* =========================================================================
   Message Images
   ========================================================================= */

.message-files {
  margin-bottom: 8px;
}

.file-badge {
  display: inline-block;
  background: var(--bg-secondary, #f0f0f0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 0.8em;
  color: var(--text-muted, #666);
}

.message-images {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.message-image {
  max-width: 300px;
  max-height: 250px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.15s;
  object-fit: contain;
}

.message-image:hover {
  opacity: 0.85;
}

/* =========================================================================
   Bluesky Picker
   ========================================================================= */

.modal-lg {
  max-width: 600px;
}

.bsky-thread-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.bsky-thread-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.bsky-body-scroll {
  max-height: 60vh;
  overflow-y: auto;
}

.bsky-loading, .bsky-error, .bsky-empty {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

.bsky-error {
  color: var(--danger);
}

.bsky-error small {
  color: var(--text-secondary);
}

.bsky-post-card {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.bsky-post-card:hover {
  border-color: #0085ff;
  background: #f0f7ff;
}

.bsky-post-card.bsky-selected {
  border-color: #0085ff;
  background: #dbeafe;
  box-shadow: inset 3px 0 0 #0085ff;
}

.bsky-post-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.bsky-post-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 6px;
  white-space: pre-wrap;
  max-height: 120px;
  overflow: hidden;
}

.bsky-post-images {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.bsky-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.bsky-post-stats {
  font-size: 11px;
  color: var(--text-secondary);
}

/* =========================================================================
   Utility
   ========================================================================= */

main.drag-over {
  background: #e8f0fe;
  outline: 3px dashed var(--accent);
  outline-offset: -6px;
}

.hidden {
  display: none !important;
}

/* Scrollbar */

main::-webkit-scrollbar {
  width: 6px;
}

main::-webkit-scrollbar-track {
  background: transparent;
}

main::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

main::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* Toast notifications */

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--abyss);
  color: #ffffff;
  padding: 10px 18px;
  border: 1px solid var(--abyss-neon);
  border-radius: var(--radius-pill);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2s forwards;
}

.toast--action {
  animation: toast-in 0.3s ease;
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 10px;
}

.toast--action.toast--leaving {
  animation: toast-out 0.3s ease forwards;
}

.toast-action {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.toast-action:hover {
  background: rgba(255, 255, 255, 0.15);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* =========================================================================
   Responsive — mobile-first

   Breakpoints:
     base:       0+    (Pixel Fold cover 344px, iPhone SE 375px, iPhone 14 390-430px)
     sm:  480px min    (larger phones, small tablets portrait)
     md:  640px min    (Pixel Fold open 673px, big-phone landscape)
     lg:  900px min    (iPad portrait, small laptops)
     xl: 1200px min    (desktop)

   Base rules below target the narrowest viewports. Larger screens progressively
   restore density via min-width blocks.
   ========================================================================= */

/* -- Narrow-viewport defaults (≤ sm: 479px) --------------------------------- */

/* Stack header (brand on top row, controls wrap onto a second row). */
header.topbar {
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
  padding: 8px max(12px, var(--safe-right)) 8px max(12px, var(--safe-left));
}

.brand {
  flex: 0 0 auto;
  gap: 8px;
  margin-left: 0;
}
.brand-icon { height: 32px; }
.brand-name { font-size: 24px; }
.brand-tag { display: none; }
.brand-glyphs { display: none; }

.topbar-actions {
  flex: 1 1 100%;
  order: 3;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 6px;
}

.topbar-select {
  flex: 1 1 160px;
  min-width: 0;
  max-width: none;
  font-size: var(--fs-input);
}

.icon-btn { font-size: 12px; padding: 6px 10px; }
.icon-btn.icon-only { padding: 6px 8px; min-width: 32px; }

#chatModeBadge { display: none; }
.build-info { display: none; }

/* Phase stepper: horizontal scroll with snap so all 8 phases stay reachable
   on a 344px-wide screen. Active phase is auto-centred by JS. */
.phase-stepper {
  justify-content: flex-start;
  gap: 6px;
  padding: 8px 12px 22px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.phase-stepper::-webkit-scrollbar { display: none; }

.phase-step {
  scroll-snap-align: center;
  flex-shrink: 0;
}

.phase-label { font-size: 11px; }
.phase-connector { width: 10px; flex-shrink: 0; }

.btn-back,
.btn-advance {
  flex-shrink: 0;
  font-size: 11px;
  padding: 5px 10px;
  margin-left: 4px;
  margin-right: 4px;
}

/* Input buttons: bump to 44px (Apple HIG / Material touch minimum). */
.btn-mic,
.btn-attach,
.btn-attach-bg,
.btn-bluesky,
.btn-send {
  width: 44px;
  height: 44px;
}

.btn-sm { min-height: 36px; }

/* Action row wraps cleanly on narrow screens. */
.action-row {
  flex-wrap: wrap;
  gap: 8px;
}

/* Modal: full-screen on narrow viewports. Padding respects safe-area insets
   so the sticky header/footer don't collide with the iOS home indicator. */
.modal-content {
  width: 100%;
  max-width: none;
  max-height: none;
  height: 100%;
  border-radius: 0;
}

.modal-header {
  padding: calc(12px + var(--safe-top)) max(16px, var(--safe-right)) 12px max(16px, var(--safe-left));
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.modal-body {
  padding: 16px max(16px, var(--safe-right)) 16px max(16px, var(--safe-left));
}

.modal-footer {
  padding: 12px max(16px, var(--safe-right)) calc(12px + var(--safe-bottom)) max(16px, var(--safe-left));
  flex-wrap: wrap;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

.settings-tabs {
  padding: 0 max(12px, var(--safe-left));
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.settings-tabs::-webkit-scrollbar { display: none; }
.settings-tab {
  flex-shrink: 0;
  padding: 10px 12px;
}

.prompt-textarea {
  min-height: 180px;
  max-height: 60dvh;
}

/* -- sm: 480px+ ------------------------------------------------------------ */

@media (min-width: 480px) {
  .brand-name { font-size: 28px; }
  .brand-icon { height: 36px; }
  .brand-tag { display: inline-block; }
  .brand-glyphs { display: inline-flex; }

  .phase-label { font-size: 12px; }
  .phase-connector { width: 16px; }

  .btn-back,
  .btn-advance {
    font-size: 12px;
    padding: 5px 12px;
  }

}

/* -- md: 640px+ (Pixel Fold open, big-phone landscape, small tablets) ------ */

@media (min-width: 640px) {
  header.topbar {
    flex-wrap: nowrap;
    padding: calc(10px + var(--safe-top)) max(20px, var(--safe-right)) 10px max(20px, var(--safe-left));
  }

  .topbar-actions {
    order: 0;
    flex: 0 1 auto;
    width: auto;
    flex-wrap: nowrap;
  }

  .topbar-select {
    flex: 0 1 240px;
    max-width: 240px;
  }

  #chatModeBadge { display: inline-flex; }
  .build-info { display: inline; }

  /* Modals leave edges and no longer go full-screen. */
  .modal-content {
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    height: auto;
    border-radius: var(--radius);
  }
  .modal-sm { max-width: 450px; }
  .modal-lg { max-width: 900px; }

  .modal-header,
  .modal-body,
  .modal-footer {
    position: static;
    padding-left: 20px;
    padding-right: 20px;
  }
  .modal-header { padding-top: 16px; padding-bottom: 16px; }
  .modal-footer { padding-top: 14px; padding-bottom: 14px; }
}

/* -- lg: 900px+ (iPad portrait, small laptops) ----------------------------- */

@media (min-width: 900px) {
  .phase-connector { width: 20px; }
  .phase-stepper { padding: 10px 20px 26px; }

  .btn-mic,
  .btn-attach,
  .btn-attach-bg,
  .btn-bluesky,
  .btn-send {
    width: 42px;
    height: 42px;
  }
}

/* -- xl: 1200px+ (laptop, desktop) — restore the centred, non-scrolling
      phase stepper the pre-responsive design expected. Below this, the 8
      phases + buttons exceed the viewport and the stepper scrolls. --------- */

@media (min-width: 1200px) {
  .phase-stepper {
    justify-content: center;
    overflow-x: visible;
  }
  .phase-connector { width: 24px; }
}

/* -- Landscape phones (short viewports) — compress chrome to reclaim
      vertical space for the chat. Keyed on both orientation and height so
      this doesn't fire on tablets. ----------------------------------------- */

@media (orientation: landscape) and (max-height: 500px) {
  header { padding-top: calc(4px + var(--safe-top)); padding-bottom: 4px; }
  .phase-stepper { padding-top: 4px; padding-bottom: 16px; }
  footer { padding-top: 6px; padding-bottom: calc(6px + var(--safe-bottom)); }
  .action-row { margin-top: 4px; }
}

/* =========================================================================
   Upload Mode Modal
   ========================================================================= */

.upload-mode-filename {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  word-break: break-all;
}

.upload-mode-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-mode-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-family: var(--font-ui);
  color: var(--text);
}

.upload-mode-card:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.upload-mode-icon {
  font-size: 22px;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 1px;
}

.upload-mode-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
}

.upload-mode-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.upload-mode-warn {
  font-size: 11px;
  color: #b45309;
  font-weight: 500;
  margin-top: 5px;
}

/* Build info */
.build-info {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.chat-mode-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}
.chat-mode-badge.chained {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}
.chat-mode-badge.stateless {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
}

/* Feedback controls (Implement / Ignore / Other) */

.fb-controls {
  display: flex;
  gap: 5px;
  margin-top: 6px;
  margin-bottom: 4px;
}

.fb-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.fb-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.fb-btn.fb-implement.fb-selected {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.fb-btn.fb-ignore.fb-selected {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #6b7280;
  text-decoration: line-through;
}

.fb-btn.fb-other.fb-selected {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
}

.fb-other-input {
  margin-top: 4px;
  margin-bottom: 4px;
}

.fb-textarea {
  width: 100%;
  max-width: 400px;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  font-family: inherit;
}

.fb-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.fb-submit-bar {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.fb-submit-bar .btn-fb-submit {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.fb-submit-bar .btn-fb-submit:hover {
  background: var(--accent-hover);
}

.fb-submit-bar .btn-fb-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.fb-submit-bar .fb-summary {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Multiple-choice option buttons inside an MC question */
.fb-controls[data-mode="mc"] {
  flex-wrap: wrap;
  gap: 6px;
}

.fb-btn.fb-mc-option {
  font-size: 13px;
  padding: 4px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.fb-btn.fb-mc-option:hover {
  border-color: var(--accent);
  background: #f0f9ff;
}

.fb-btn.fb-mc-option.fb-selected {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e3a8a;
  font-weight: 600;
}

/* Hide the original markdown bullet list once MC buttons replace it */
.message-content .fb-mc-hidden-list {
  display: none;
}

/* Open-ended question text input (replaces Implement/Ignore/Other) */
.fb-controls[data-mode="open"] {
  display: block;
  margin-top: 6px;
}
.fb-open-answer {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  resize: vertical;
  outline: none;
  background: var(--surface);
}
.fb-open-answer:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* =========================================================================
   Choice Widgets (PICK / CHOOSE / ASK markers)
   ========================================================================= */
.choice-widget { margin: 8px 0 12px; }
.cw-label {
  font-family: var(--font-ui); font-size: 12px;
  color: var(--text-secondary); font-weight: 600;
  margin-bottom: 4px; letter-spacing: 0.01em;
}
.cw-options { display: flex; flex-wrap: wrap; gap: 6px; }
.cw-btn {
  font-family: var(--font-ui); font-size: 13px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: all 0.15s; text-align: left; line-height: 1.35;
}
.cw-btn:hover { border-color: var(--accent); background: #f0f9ff; }
.cw-btn.cw-selected {
  background: #dbeafe; border-color: #60a5fa;
  color: #1e3a8a; font-weight: 600;
}
.cw-other-btn { font-style: italic; color: var(--text-secondary); }
/* Radio-style buttons (PICK / single-select) — circle indicator */
.cw-btn.cw-radio::before {
  content: '';
  display: inline-block; width: 12px; height: 12px; margin-right: 6px;
  border: 2px solid var(--border); border-radius: 50%;
  vertical-align: middle; flex-shrink: 0;
  transition: all 0.15s;
}
.cw-btn.cw-radio.cw-selected::before {
  border-color: #60a5fa;
  background: #2563eb;
  box-shadow: inset 0 0 0 2px #fff;
}
.cw-other-textarea, .cw-answer-textarea {
  display: block; width: 100%; min-height: 44px; margin-top: 6px;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: var(--font-ui);
  font-size: 13px; resize: vertical; outline: none; background: var(--surface);
}
.cw-other-textarea:focus, .cw-answer-textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}
.cw-submit-bar {
  display: flex; align-items: center; gap: 12px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.cw-submit-btn {
  padding: 7px 20px; background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-sm); font-family: var(--font-ui);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.cw-submit-btn:hover { background: var(--accent-hover); }
.cw-submit-btn:disabled { opacity: 0.5; cursor: default; }
.cw-summary { font-size: 13px; color: var(--text-secondary); }
.choice-widget.cw-locked { opacity: 0.7; }

/* Paragraph-level thumbs (lean in / lean away) — works on chunks (headings, content, list items) */
.message-content .has-pf {
  position: relative;
  border-radius: 4px;
  transition: background 0.15s;
}

/* List items with thumbs need a bit of extra right padding for the buttons */
li.has-pf {
  padding-right: 4px;
}

/* Subtle highlight so the user can see the full feedback chunk */
.message-content .pf-chunk-hover {
  background: rgba(0, 0, 0, 0.02);
}

.pf-thumbs {
  display: inline-flex;
  gap: 2px;
  margin-left: 8px;
  vertical-align: middle;
  opacity: 0.55;
  transition: opacity 0.15s;
}

/* Show thumbs when hovering any element in the chunk, or when selected */
.message-content .pf-chunk-hover .pf-thumbs,
.message-content .has-pf-selected .pf-thumbs {
  opacity: 1;
}

/* On hover-capable pointers, hide by default so the UI isn't cluttered. */
@media (hover: hover) and (pointer: fine) {
  .pf-thumbs { opacity: 0; }
}

.pf-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  filter: grayscale(60%);
  transition: all 0.15s;
  letter-spacing: -2px;
}

.pf-btn:hover {
  filter: grayscale(0);
  background: rgba(0,0,0,0.04);
}

.pf-btn.pf-selected {
  filter: grayscale(0);
  background: #fef3c7;
  border-color: #fbbf24;
}

.pf-btn.pf-down.pf-selected {
  background: #fee2e2;
  border-color: #f87171;
}

/* Intensity 2 and 3 get slightly more padding for repeated emojis */
.pf-btn[data-intensity="2"],
.pf-btn[data-intensity="3"] {
  padding: 1px 6px;
}

/* Per-message X delete button */
.message-actions button.msg-delete {
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 7px;
  color: #b91c1c;
}

.message-actions button.msg-delete:hover {
  background: #fee2e2;
  border-color: #f87171;
  color: #7f1d1d;
}

/* Rewrite controls (accept/reject) */

.rewrite-controls {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.rewrite-controls .btn-rewrite-accept {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  transition: background 0.15s;
}

.rewrite-controls .btn-rewrite-accept:hover {
  background: var(--accent-hover);
}

.rewrite-controls .btn-rewrite-reject {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: background 0.15s;
}

.rewrite-controls .btn-rewrite-reject:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.rewrite-next-hint {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

/* =========================================================================
   Voice Rewrite — inline editing, track changes, action bar
   ========================================================================= */

/* Subtle hover affordance on editable rewrite blocks */
.rw-editable {
  cursor: text;
  border-radius: 4px;
  transition: background 0.12s, box-shadow 0.12s;
}
.rw-editable:hover {
  background: rgba(120, 140, 200, 0.06);
  box-shadow: inset 0 0 0 1px rgba(120, 140, 200, 0.18);
}

/* Active edit state — clearly distinct from hover */
.rw-editing {
  background: rgba(120, 200, 140, 0.10);
  box-shadow: inset 0 0 0 2px rgba(80, 170, 110, 0.55);
  outline: none;
  cursor: text;
  border-radius: 4px;
  padding: 6px 8px;
}

/* Block already has an accepted edit (track-changes view) */
.rw-has-edit {
  background: rgba(255, 220, 130, 0.08);
  border-left: 3px solid rgba(220, 170, 50, 0.55);
  padding-left: 10px;
}

/* Track-changes inline marks */
.tc-ins {
  text-decoration: none;
  color: #1f7a3a;
  background: rgba(110, 200, 130, 0.18);
  border-radius: 2px;
  padding: 0 2px;
}
.tc-del {
  text-decoration: line-through;
  color: #a93030;
  background: rgba(220, 110, 110, 0.12);
  border-radius: 2px;
  padding: 0 2px;
  opacity: 0.85;
}

/* Bottom-of-message action bar */
.rw-action-bar {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.rw-action-hint {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}
.rw-action-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.rw-action-buttons .btn {
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
}
.rw-action-buttons .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.rw-revise-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.rw-revise-btn:not(:disabled):hover {
  background: var(--surface-alt);
}
.rw-advance-btn {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
}
.rw-advance-btn:not(:disabled):hover {
  background: var(--accent-hover);
}

/* Superseded (original) message when rewrite is accepted */

.message.superseded {
  opacity: 0.4;
  position: relative;
}

.message.superseded::after {
  content: 'Replaced by rewrite';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface);
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* On a superseded earlier rewrite: keep the content (with any track-changes
   and comment highlights) visible as history, but strip the interactive
   affordances — thumbs, hover edit cue, and action bar are all past tense. */
.message.superseded .pf-thumbs,
.message.superseded .rw-action-bar,
.message.superseded .rewrite-next-hint {
  display: none;
}
.message.superseded .rw-editable:hover {
  background: transparent;
  box-shadow: none;
  cursor: default;
}

/* =========================================================================
   Punch It Up — moments-of-joy panel
   ========================================================================= */

.punchup-panel {
  margin: 16px 0 24px;
  padding: 20px 22px;
  background: linear-gradient(135deg, #fff8ee 0%, #fff4f6 100%);
  border: 1px solid #f4d8b8;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(180, 120, 40, 0.06);
}

.punchup-header {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f4d8b8;
}

.punchup-title {
  font-size: 18px;
  font-weight: 700;
  color: #b45309;
  letter-spacing: -0.01em;
}

.punchup-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: #92651d;
}

.punchup-loading,
.punchup-empty {
  padding: 24px 0;
  text-align: center;
  color: #92651d;
  font-style: italic;
}

.punchup-error {
  padding: 16px;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  color: #991b1b;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.punchup-start {
  display: flex;
  justify-content: center;
  padding: 14px 0 4px;
}

.punchup-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: #6b4f24;
}

.punchup-status strong {
  color: #b45309;
}

.punchup-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.punchup-card {
  padding: 14px 16px;
  background: #ffffff;
  border: 1px solid #f0d4a8;
  border-radius: 10px;
  transition: all 0.2s ease;
}

.punchup-card-accepted {
  background: #f0fdf4;
  border-color: #86efac;
}

.punchup-card-skipped {
  opacity: 0.55;
}

.punchup-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.punchup-badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 12px;
  background: #fef3c7;
  color: #92400e;
}

.punchup-badge-structural { background: #e0e7ff; color: #3730a3; }
.punchup-badge-callback { background: #c7d2fe; color: #312e81; }
.punchup-badge-aside { background: #dbeafe; color: #1e40af; }
.punchup-badge-analogy { background: #d1fae5; color: #065f46; }
.punchup-badge-personal { background: #ffe4e6; color: #9f1239; }
.punchup-badge-funny_exaggeration { background: #fce7f3; color: #9d174d; }
.punchup-badge-self_deprecating { background: #fef3c7; color: #92400e; }
.punchup-badge-absurd_australianism { background: #fef9c3; color: #854d0e; }
.punchup-badge-mock_incredulity { background: #ede9fe; color: #5b21b6; }
.punchup-badge-tighten { background: #f3f4f6; color: #374151; }
/* Legacy types from older saved sessions */
.punchup-badge-joke { background: #fce7f3; color: #9d174d; }
.punchup-badge-pun { background: #ede9fe; color: #5b21b6; }
.punchup-badge-self-deprecating { background: #fef3c7; color: #92400e; }
.punchup-badge-accidental_reveal { background: #fee2e2; color: #991b1b; }
.punchup-badge-intuition_flip { background: #cffafe; color: #155e75; }
.punchup-badge-intellectual_concession { background: #ecfccb; color: #3f6212; }

.punchup-placement {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.punchup-status-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
  margin-left: auto;
}

.punchup-tag-accepted {
  background: #d1fae5;
  color: #065f46;
}

.punchup-tag-skipped {
  background: #f3f4f6;
  color: #6b7280;
}

.punchup-tag-toppick {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.punchup-chapter {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  padding: 6px 10px 8px;
  margin-bottom: 10px;
  border-bottom: 1px dashed #f0d4a8;
}

.punchup-chapter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #92400e;
}

.punchup-chapter-title {
  font-size: 13px;
  font-weight: 600;
  color: #1f2937;
}

.punchup-chapter-summary {
  flex-basis: 100%;
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
  margin-top: 2px;
}

.punchup-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.punchup-context {
  padding: 8px 12px;
  background: #fafafa;
  border-left: 2px solid #e5e7eb;
  border-radius: 4px;
  font-size: 13px;
  color: #9ca3af;
  font-family: 'Lora', Georgia, serif;
  line-height: 1.5;
  white-space: pre-wrap;
}

.punchup-anchor {
  padding: 12px 14px;
  background: #f9fafb;
  border-left: 3px solid #6b7280;
  border-radius: 4px;
  font-size: 15px;
  color: #1f2937;
  font-family: 'Lora', Georgia, serif;
  line-height: 1.55;
  white-space: pre-wrap;
}

.punchup-anchor-text {
  white-space: pre-wrap;
}

.punchup-inline-insertion {
  background: #fef08a;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 500;
  box-shadow: 0 0 0 1px #facc15 inset;
}

.punchup-inline-insertion-replace {
  background: #fbcfe8;
  box-shadow: 0 0 0 1px #ec4899 inset;
}

.punchup-inline-strike {
  text-decoration: line-through;
  color: #9ca3af;
}

.punchup-insertion {
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 15px;
  color: #1f2937;
  font-family: 'Lora', Georgia, serif;
}

.punchup-insertion-after,
.punchup-insertion-before {
  background: #fef9c3;
  border-left: 3px solid #facc15;
}

.punchup-insertion-replace {
  background: #fce7f3;
  border-left: 3px solid #ec4899;
}

.punchup-insertion-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  margin-bottom: 4px;
  font-family: 'Inter', sans-serif;
  font-style: normal;
}

.punchup-insertion-text {
  white-space: pre-wrap;
}

.punchup-rationale {
  margin-bottom: 10px;
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}

.punchup-card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.punchup-accept {
  background: #10b981;
  color: white;
  border: 1px solid #10b981;
}

.punchup-accept:hover {
  background: #059669;
}

.punchup-skip {
  color: var(--text-secondary);
}

.punchup-footer {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #f4d8b8;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.punchup-footer-saved {
  justify-content: space-between;
  align-items: center;
}

.punchup-footer-saved .punchup-saved-msg {
  color: #2e7d32;
  font-weight: 500;
  font-size: 13px;
}

/* Punchup header with copy/X actions */
.punchup-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.punchup-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.punchup-header-btn {
  background: none;
  border: 1px solid #d4a574;
  color: #92651d;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.punchup-header-btn:hover {
  background: #f4d8b8;
}

.punchup-header-delete {
  font-size: 16px;
  line-height: 1;
  padding: 2px 8px;
}

/* Provider tags */
.punchup-provider-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-left: auto;
}

.punchup-provider-anthropic {
  background: #f5e6d3;
  color: #b45309;
}

.punchup-provider-openai {
  background: #e0f2e9;
  color: #0d7a3e;
}

.punchup-status-providers {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

/* Editable insertion text — the entire anchor paragraph is contentEditable
   while the suggestion is pending, so the dashed underline marks the
   suggested insertion within an editable surround. */
.punchup-anchor[contenteditable="true"] {
  cursor: text;
  outline: none;
}

.punchup-anchor[contenteditable="true"] .punchup-inline-insertion {
  border-bottom: 1px dashed #d97706;
}

.punchup-anchor[contenteditable="true"]:focus {
  border-left-color: #b45309;
  background: #fffaf0;
}

.punchup-insertion-text[contenteditable="true"] {
  cursor: text;
  border-bottom: 1px dashed #d97706;
  outline: none;
  min-width: 20px;
}

.punchup-insertion-text[contenteditable="true"]:focus {
  border-bottom: 2px solid #b45309;
  background: #fef9c3;
}

/* Stats table in settings */
.punchup-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.punchup-stats-table th,
.punchup-stats-table td {
  padding: 4px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.punchup-stats-table th {
  font-weight: 600;
  color: var(--text-secondary);
}

/* =========================================================================
   Fact Check — structured verification panel (mirrors Punch It Up)
   ========================================================================= */

.factcheck-panel {
  margin: 16px 0 24px;
  padding: 20px 22px;
  background: linear-gradient(135deg, #f0f9ff 0%, #f5f3ff 100%);
  border: 1px solid #bae6fd;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(14, 116, 144, 0.06);
}

.factcheck-header {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #bae6fd;
}

.factcheck-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.factcheck-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.factcheck-header-btn {
  background: none;
  border: 1px solid #7dd3fc;
  color: #0c4a6e;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.factcheck-header-btn:hover {
  background: #bae6fd;
}

.factcheck-header-delete {
  font-size: 16px;
  line-height: 1;
  padding: 2px 8px;
}

.factcheck-title {
  font-size: 18px;
  font-weight: 700;
  color: #0c4a6e;
  letter-spacing: -0.01em;
}

.factcheck-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: #0369a1;
}

.factcheck-loading,
.factcheck-empty {
  padding: 24px 0;
  text-align: center;
  color: #0369a1;
  font-style: italic;
}

.factcheck-error {
  padding: 16px;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  color: #991b1b;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.factcheck-start {
  display: flex;
  justify-content: center;
  padding: 14px 0 4px;
}

.factcheck-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: #155e75;
  flex-wrap: wrap;
}

.factcheck-status strong {
  color: #0c4a6e;
}

.factcheck-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.factcheck-card {
  padding: 14px 16px;
  background: #ffffff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  transition: all 0.2s ease;
}

.factcheck-card-confirmed {
  background: #f0fdf4;
  border-color: #86efac;
}

.factcheck-card-flagged {
  background: #fef3c7;
  border-color: #fcd34d;
}

.factcheck-card-edited {
  background: #faf5ff;
  border-color: #d8b4fe;
}

.factcheck-card-dismissed {
  opacity: 0.55;
}

.factcheck-risk-high {
  border-left: 3px solid #dc2626;
}

.factcheck-risk-medium {
  border-left: 3px solid #f59e0b;
}

.factcheck-risk-low {
  border-left: 3px solid #94a3b8;
}

.factcheck-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.factcheck-badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 12px;
  background: #e0f2fe;
  color: #075985;
}

.factcheck-badge-statistic { background: #dbeafe; color: #1e40af; }
.factcheck-badge-quote { background: #fae8ff; color: #86198f; }
.factcheck-badge-historical { background: #fef3c7; color: #92400e; }
.factcheck-badge-causal { background: #ede9fe; color: #5b21b6; }
.factcheck-badge-attribution { background: #ffe4e6; color: #9f1239; }
.factcheck-badge-definition { background: #d1fae5; color: #065f46; }
.factcheck-badge-other { background: #f3f4f6; color: #374151; }

.factcheck-risk {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
  letter-spacing: 0.04em;
}

.factcheck-risk-tag-high { background: #fee2e2; color: #991b1b; }
.factcheck-risk-tag-medium { background: #fef3c7; color: #92400e; }
.factcheck-risk-tag-low { background: #f1f5f9; color: #475569; }

.factcheck-verdict {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.factcheck-verdict-confirmed { background: #d1fae5; color: #065f46; }
.factcheck-verdict-disputed { background: #fee2e2; color: #991b1b; }
.factcheck-verdict-uncertain { background: #fef3c7; color: #92400e; }

.factcheck-status-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
  margin-left: auto;
}

.factcheck-tag-confirmed { background: #d1fae5; color: #065f46; }
.factcheck-tag-flagged { background: #fef3c7; color: #92400e; }
.factcheck-tag-edited { background: #ede9fe; color: #5b21b6; }
.factcheck-tag-dismissed { background: #f3f4f6; color: #6b7280; }

.factcheck-chapter {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  padding: 6px 10px 8px;
  margin-bottom: 10px;
  border-bottom: 1px dashed #bae6fd;
}

.factcheck-chapter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #075985;
}

.factcheck-chapter-title {
  font-size: 13px;
  font-weight: 600;
  color: #1f2937;
}

.factcheck-chapter-summary {
  flex-basis: 100%;
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
  margin-top: 2px;
}

.factcheck-claim {
  margin-bottom: 10px;
  font-size: 14px;
  color: #1f2937;
  line-height: 1.5;
}

.factcheck-claim-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #075985;
  margin-right: 4px;
}

.factcheck-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.factcheck-context {
  padding: 8px 12px;
  background: #fafafa;
  border-left: 2px solid #e5e7eb;
  border-radius: 4px;
  font-size: 13px;
  color: #9ca3af;
  font-family: 'Lora', Georgia, serif;
  line-height: 1.5;
  white-space: pre-wrap;
}

.factcheck-anchor {
  padding: 12px 14px;
  background: #f9fafb;
  border-left: 3px solid #6b7280;
  border-radius: 4px;
  font-size: 15px;
  color: #1f2937;
  font-family: 'Lora', Georgia, serif;
  line-height: 1.55;
  white-space: pre-wrap;
}

.factcheck-anchor-span {
  background: #dbeafe;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 500;
  box-shadow: 0 0 0 1px #60a5fa inset;
}

.factcheck-anchor-span-confirmed {
  background: #d1fae5;
  box-shadow: 0 0 0 1px #10b981 inset;
}

.factcheck-anchor-span-disputed {
  background: #fee2e2;
  box-shadow: 0 0 0 1px #ef4444 inset;
}

.factcheck-anchor-span-uncertain {
  background: #fef3c7;
  box-shadow: 0 0 0 1px #f59e0b inset;
}

.factcheck-concern {
  margin-bottom: 10px;
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}

.factcheck-research {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  color: #1f2937;
  line-height: 1.5;
}

.factcheck-research-explanation {
  margin-bottom: 6px;
}

.factcheck-sources {
  font-size: 12px;
  color: #6b7280;
}

.factcheck-sources-label {
  font-weight: 600;
  color: #475569;
}

.factcheck-sources a {
  color: #0369a1;
  text-decoration: none;
}

.factcheck-sources a:hover {
  text-decoration: underline;
}

.factcheck-research-notes {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 6px;
  font-size: 13px;
  color: #1f2937;
  line-height: 1.5;
}

.factcheck-research-notes-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #92400e;
  margin-bottom: 4px;
}

.factcheck-research-notes-body {
  margin-bottom: 6px;
}

.factcheck-user-edit {
  margin-bottom: 10px;
  padding: 8px 12px;
  background: #faf5ff;
  border-left: 3px solid #a855f7;
  border-radius: 4px;
  font-size: 14px;
  color: #1f2937;
  line-height: 1.5;
}

.factcheck-user-edit-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b21a8;
  margin-right: 4px;
}

.factcheck-card-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.factcheck-confirm {
  background: #10b981;
  color: white;
  border: 1px solid #10b981;
}

.factcheck-confirm:hover {
  background: #059669;
}

.factcheck-confirm:disabled {
  background: #a7f3d0;
  border-color: #a7f3d0;
  cursor: default;
}

.factcheck-flag {
  background: #f59e0b;
  color: white;
  border: 1px solid #f59e0b;
}

.factcheck-flag:hover {
  background: #d97706;
}

.factcheck-flag:disabled {
  background: #fde68a;
  border-color: #fde68a;
  cursor: default;
}

.factcheck-footer {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #bae6fd;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.factcheck-anchor-span[contenteditable="true"] {
  cursor: text;
  outline: none;
}

.factcheck-anchor-span-editing {
  background: #fef9c3 !important;
  box-shadow: 0 0 0 2px #f59e0b inset !important;
}

.factcheck-research-input-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.factcheck-research-input {
  flex: 1;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  background: #fff;
  color: #1f2937;
  outline: none;
}

.factcheck-research-input:focus {
  border-color: #0369a1;
  box-shadow: 0 0 0 2px rgba(3, 105, 161, 0.15);
}

.factcheck-bulk {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.factcheck-bulk-confirm {
  background: #10b981;
  color: white;
  border: 1px solid #10b981;
}

.factcheck-bulk-confirm:hover {
  background: #059669;
}

.factcheck-bulk-flag {
  background: #f59e0b;
  color: white;
  border: 1px solid #f59e0b;
}

.factcheck-bulk-flag:hover {
  background: #d97706;
}

.factcheck-verified-toggle {
  display: block;
  margin: 14px auto;
  background: transparent;
  color: #4b5563;
  border: 1px solid #d1d5db;
}

.factcheck-verified-toggle:hover {
  background: #f3f4f6;
  color: #111827;
}

.factcheck-list-verified {
  margin-top: 12px;
  opacity: 0.85;
}

/* =========================================================================
   Inline Comments (Google Docs-style)
   ========================================================================= */

/* The message needs to make room for the comment gutter on the right */
.message.has-comments {
  position: relative;
}

/* Highlighted text that has a comment attached */
.comment-highlight {
  background: #fef9c3;
  border-bottom: 2px solid #facc15;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 2px;
}
.comment-highlight:hover {
  background: #fde68a;
}
.comment-highlight.comment-active {
  background: #fde68a;
  border-bottom-color: #f59e0b;
}

/* Floating "Add comment" button that appears on text selection */
.comment-selection-btn {
  position: absolute;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 12px;
  font-family: var(--font-ui);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s;
  pointer-events: auto;
}
.comment-selection-btn:hover {
  background: #f0f4ff;
  border-color: var(--accent);
  color: var(--accent);
}
.comment-selection-btn svg {
  flex-shrink: 0;
}

/* Comment input popover */
.comment-popover {
  position: absolute;
  z-index: 101;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 12px;
  font-family: var(--font-ui);
}
.comment-popover-quote {
  font-size: 12px;
  color: var(--text-secondary);
  border-left: 3px solid #facc15;
  padding: 4px 8px;
  margin-bottom: 8px;
  max-height: 60px;
  overflow: hidden;
  line-height: 1.4;
  font-style: italic;
}
.comment-popover textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  resize: vertical;
  outline: none;
}
.comment-popover textarea:focus {
  border-color: var(--accent);
}
.comment-popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}
.comment-popover-actions button {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-ui);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.comment-popover-actions button.comment-save-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.comment-popover-actions button.comment-save-btn:hover {
  background: var(--accent-hover);
}
.comment-popover-actions .comment-delete-inline-btn {
  color: #dc2626;
  border-color: #fca5a5;
}
.comment-popover-actions .comment-delete-inline-btn:hover {
  background: #fee2e2;
  border-color: #dc2626;
}
.comment-edit-popover .comment-popover-quote {
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Comment cards (shown below message content, styled like Google Docs margin notes) */
.comment-cards {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.comment-card {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
  position: relative;
}
.comment-card:hover {
  background: #fef3c7;
  border-color: #facc15;
}
.comment-card.comment-card-active {
  background: #fef3c7;
  border-color: #f59e0b;
  box-shadow: 0 0 0 1px #f59e0b;
}
.comment-card-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f59e0b;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.comment-card-body {
  flex: 1;
  min-width: 0;
}
.comment-card-quote {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comment-card-text {
  color: var(--text);
}
.comment-card-actions {
  display: flex;
  gap: 4px;
  align-items: flex-start;
  opacity: 0.35;
  transition: opacity 0.15s;
}
.comment-card:hover .comment-card-actions {
  opacity: 1;
}
.comment-card-actions button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 12px;
  color: var(--text-secondary);
  border-radius: 3px;
}
.comment-card-actions button:hover {
  background: rgba(0,0,0,0.06);
  color: var(--text);
}
.comment-card-actions button.comment-resolve-btn {
  color: #059669;
}
.comment-card-actions button.comment-resolve-btn:hover {
  background: #d1fae5;
}
.comment-card-actions button.comment-delete-btn {
  color: #dc2626;
}
.comment-card-actions button.comment-delete-btn:hover {
  background: #fee2e2;
}

/* Resolved comment styling */
.comment-card.comment-resolved {
  opacity: 0.5;
  background: var(--surface-alt);
  border-color: var(--border);
}
.comment-card.comment-resolved .comment-card-icon {
  background: #9ca3af;
}
.comment-card.comment-resolved .comment-card-text {
  text-decoration: line-through;
}

/* Comment count badge on message */
.comment-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  padding: 1px 7px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 10px;
  font-size: 11px;
  color: #92400e;
  font-weight: 600;
  vertical-align: middle;
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   Final Edit panel
   --------------------------------------------------------------------------- */
.final-edit-panel {
  margin: 16px 0 24px;
  padding: 20px 22px;
  background: linear-gradient(135deg, #eef6ff 0%, #f0f0ff 100%);
  border: 1px solid #b8d4f4;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(40, 80, 180, 0.06);
}

.final-edit-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #b8d4f4;
}

.final-edit-title {
  font-size: 18px;
  font-weight: 700;
  color: #1e40af;
  letter-spacing: -0.01em;
}

.final-edit-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: #3b5998;
}

.google-docs-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0 4px;
}

.google-doc-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #1a73e8;
  font-weight: 500;
  font-size: 0.92rem;
  text-decoration: none;
}
.google-doc-link:hover {
  text-decoration: underline;
}

.final-edit-start {
  display: flex;
  justify-content: center;
  padding: 14px 0 4px;
}

/* ---------------------------------------------------------------------------
   On-screen graphs — toggle on image upload thumbs, badge on chat-bubble
   images, inline figure in the Final Edit draft pane.
   --------------------------------------------------------------------------- */
.image-preview-thumb .att-onscreen {
  position: absolute;
  left: 1px;
  top: 1px;
  background: rgba(255, 255, 255, 0.85);
  color: #475569;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  padding: 0;
  font-size: 11px;
  line-height: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview-thumb .att-onscreen:hover {
  background: rgba(37, 99, 235, 0.15);
}
.image-preview-thumb.is-on-screen {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}
.image-preview-thumb.is-on-screen .att-onscreen {
  background: #2563eb;
  color: #fff;
}

.welcome-bucket-item .att-onscreen-mini {
  margin-left: auto;
  margin-right: 4px;
  background: transparent;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  padding: 0 6px;
  font-size: 11px;
  color: #475569;
  cursor: pointer;
  height: 20px;
  line-height: 18px;
}
.welcome-bucket-item.is-on-screen .att-onscreen-mini {
  background: #2563eb;
  border-color: #1d4ed8;
  color: #fff;
}

.message-image-wrap {
  position: relative;
  display: inline-block;
}
.message-image-wrap.is-on-screen {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 6px;
}
.message-image-onscreen-badge {
  position: absolute;
  left: 4px;
  top: 4px;
  background: rgba(37, 99, 235, 0.92);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.final-edit-onscreen-graph {
  margin: 18px 0;
  padding: 10px 12px 12px;
  background: #f1f5ff;
  border: 1px solid #c7d7f7;
  border-left: 3px solid #2563eb;
  border-radius: 8px;
}
.final-edit-onscreen-graph img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid #d8e1f0;
  background: #fff;
}
.final-edit-onscreen-graph figcaption {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  font-size: 12px;
  color: #1e3a8a;
}
.final-edit-onscreen-graph .onscreen-graph-name {
  font-weight: 600;
}
.final-edit-onscreen-graph .onscreen-anchor-select {
  margin-left: auto;
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid #c7d7f7;
  border-radius: 4px;
  background: #fff;
  max-width: 60%;
}

/* ---------------------------------------------------------------------------
   Edit Corpus (Settings tab)
   --------------------------------------------------------------------------- */
.corpus-entry {
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  background: var(--surface, #fff);
}

.corpus-entry-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.corpus-entry-date {
  font-weight: 600;
  color: var(--text-primary, #1a1a1a);
  font-size: 13px;
}

.corpus-entry-meta {
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
}

.corpus-entry-delete {
  margin-left: auto;
  color: #dc2626;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

.corpus-entry-delete:hover {
  background: #fee2e2;
  border-radius: 4px;
}

.corpus-entry-previews {
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 8px;
}

.corpus-preview-before,
.corpus-preview-after {
  padding: 4px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.corpus-preview-before {
  color: #991b1b;
}

.corpus-preview-after {
  color: #166534;
}

.corpus-entry-expand {
  font-size: 11px;
}

/* Diff view */
.diff-view {
  font-family: 'Courier New', Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 6px;
  margin: 8px 0;
}

.diff-line {
  padding: 1px 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-same {
  color: var(--text-secondary, #6b7280);
}

.diff-add {
  background: #dcfce7;
  color: #166534;
}

.diff-del {
  background: #fee2e2;
  color: #991b1b;
}

/* =========================================================================
   Jump-to-live chip — appears when the user has scrolled away from the
   conversation tail while a reply is streaming. Click returns to the live
   edge. Sibling to Substacker's identical pattern.
   ========================================================================= */

#chatArea { position: relative; }

.jump-to-live-chip {
  position: sticky;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--abyss);
  color: #ffffff;
  border: 1px solid var(--surf-tint);
  box-shadow: var(--shadow-md);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  z-index: 5;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  opacity: 1;
  margin: 0 auto;
  width: max-content;
}

.jump-to-live-chip:hover { background: var(--surf); border-color: var(--surf-neon); }
.jump-to-live-chip:focus-visible { outline: 2px solid var(--surf-neon); outline-offset: 2px; }
.jump-to-live-chip.hidden { display: none; }

/* =========================================================================
   YouTube title suggestions card — final phase
   ========================================================================= */

.title-suggestions-card {
  margin: 16px auto;
  max-width: 720px;
  padding: 18px 20px;
  background: var(--shell);
  border: 1px solid var(--border);
  border-left: 4px solid var(--surf);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.title-suggestions-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.title-suggestions-header h3 {
  font-family: var(--font-impact);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--abyss);
  margin: 0;
}
.title-suggestions-sub {
  font-size: 12px;
  color: var(--text-secondary);
}
.title-suggestions-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.title-suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  width: 100%;
}
.title-suggestion:hover {
  background: var(--surf-tint);
  border-color: var(--surf);
}
.title-suggestion-text { flex: 1; line-height: 1.4; }
.title-suggestion-meta {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.title-suggestion.copied {
  background: var(--surf);
  border-color: var(--abyss);
  color: #ffffff;
}
.title-suggestion.copied .title-suggestion-meta {
  color: rgba(255, 255, 255, 0.85);
}

.title-suggestions-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.title-suggestions-regen {
  background: transparent;
  color: var(--surf);
  border: 1px solid var(--surf);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.title-suggestions-regen:hover { background: var(--surf); color: #ffffff; }
.title-suggestions-regen:disabled { opacity: 0.5; cursor: not-allowed; }
.title-suggestions-status {
  font-size: 12px;
  color: var(--text-secondary);
}

/* =========================================================================
   Stepper polish — past phases get a faint surf check, future fade out
   ========================================================================= */

.phase-step.completed .phase-dot::after {
  content: "";
}
.phase-step.completed.advanced .phase-label::before {
  content: "✓ ";
  color: var(--algae);
  font-weight: 700;
  margin-right: 2px;
}

/* =========================================================================
   Welcome card — shown for fresh sessions, with a mode-picker grid that
   mirrors Substacker's pattern. Each mode is a friendly entry point to the
   same idea→script flow.
   ========================================================================= */

.welcome-card {
  max-width: 880px;
  margin: clamp(8px, 4vw, 32px) auto;
  padding: clamp(20px, 4vw, 36px);
  background: var(--shell);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.welcome-card-dismissed {
  display: none;
}

.welcome-card-header {
  margin-bottom: 20px;
}

.welcome-card-title {
  font-family: var(--font-display);
  font-size: clamp(36px, 7vw, 56px);
  font-weight: 900;
  letter-spacing: 0.01em;
  color: var(--abyss);
  line-height: 1;
  margin: 0 0 12px;
}

.welcome-card-blurb {
  font-family: var(--font-ui);
  font-size: clamp(14px, 2.4vw, 17px);
  line-height: 1.55;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0;
}

.welcome-modes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin: 8px 0 16px;
}

.welcome-mode-btn {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 4px;
  padding: 16px 14px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--ink);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.welcome-mode-btn:hover {
  background: var(--surf-tint);
  border-color: var(--surf);
  transform: translateY(-1px);
}
.welcome-mode-btn:focus-visible {
  outline: 2px solid var(--surf);
  outline-offset: 2px;
}

.welcome-mode-icon {
  display: block;
  color: var(--abyss);
  height: 28px;
  margin-bottom: 4px;
}
.welcome-mode-icon svg { display: block; }

.welcome-mode-title {
  font-family: var(--font-impact);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--abyss);
}

.welcome-mode-tagline {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--surf);
}

.welcome-mode-desc {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-muted);
  margin-top: 4px;
}

.welcome-card-footer {
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--divider);
  padding-top: 12px;
  margin-top: 4px;
}

/* =========================================================================
   Welcome card v2 — bucket-first layout. Hero textarea on top, compact
   picker row below it, two labeled bucket panels showing live previews of
   pending attachments, and a Start button in the footer.
   ========================================================================= */

/* While the welcome card is on screen, the hero textarea is the only input
   surface — hide the bottom input bar so the same kernel text isn't echoed
   in two spots. The bar reappears once the writer hits Start. */
body.welcome-active #inputArea { display: none; }

.welcome-card-v2 .welcome-card-header {
  margin-bottom: 14px;
}

.welcome-hero-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--surf);
  margin: 14px 0 6px;
}

.welcome-hero-wrap {
  position: relative;
}

.welcome-hero-input {
  width: 100%;
  min-height: 96px;
  /* Right-padding leaves room for the mic button overlay. */
  padding: 12px 50px 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  resize: vertical;
  box-sizing: border-box;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.welcome-hero-mic {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  color: var(--abyss);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.welcome-hero-mic:hover {
  background: var(--surf-tint);
  border-color: var(--surf);
}

.welcome-hero-mic.recording {
  background: var(--danger, #ef4444);
  border-color: var(--danger, #ef4444);
  color: #ffffff;
}

.welcome-hero-mic:focus-visible {
  outline: 2px solid var(--surf);
  outline-offset: 2px;
}

.welcome-hero-input:focus {
  outline: none;
  border-color: var(--surf);
  box-shadow: 0 0 0 3px var(--surf-tint);
}

.welcome-pickers {
  margin: 16px 0 8px;
}

.welcome-pickers-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.welcome-pickers-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.welcome-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.welcome-picker-btn:hover {
  background: var(--surf-tint);
  border-color: var(--surf);
  transform: translateY(-1px);
}

.welcome-picker-btn:focus-visible {
  outline: 2px solid var(--surf);
  outline-offset: 2px;
}

.welcome-picker-icon { color: var(--abyss); display: inline-flex; }
.welcome-picker-icon svg { display: block; }

.welcome-buckets {
  display: grid;
  /* minmax(0, 1fr) — not just 1fr — so a long filename in one bucket can't
     blow out its track and push the other bucket off screen. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin: 16px 0 8px;
}

@media (max-width: 640px) {
  .welcome-buckets { grid-template-columns: minmax(0, 1fr); }
}

.welcome-bucket {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-width: 0;  /* let flex children inside ellipsize */
}

.welcome-bucket-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--divider);
  padding-bottom: 6px;
}

.welcome-bucket-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--abyss);
}

.welcome-bucket-hint {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
}

.welcome-bucket-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 28px;
}

.welcome-bucket-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--ink);
}

.welcome-bucket-glyph {
  flex: 0 0 auto;
}

.welcome-bucket-name {
  flex: 1 1 auto;
  /* min-width: 0 is required for text-overflow: ellipsis to take effect on
     a flex child — without it, the item refuses to shrink below its
     intrinsic content size and the long filename blows out the column. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.welcome-bucket-empty {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 0;
}

/* Loading placeholder: file is shown immediately on upload start so the
   writer can see where it landed and move it if the routing is wrong.
   Greyed out with a small "reading…" hint until the upload finishes. */
.welcome-bucket-item.att-loading,
.attachment-preview .att-name.att-loading {
  opacity: 0.6;
}

.att-loading-hint {
  font-style: italic;
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: 4px;
}

.welcome-bucket-item.att-loading .welcome-bucket-glyph,
.welcome-bucket-item.att-loading .welcome-bucket-name {
  animation: bucket-loading-pulse 1.6s ease-in-out infinite;
}

@keyframes bucket-loading-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.welcome-bucket .att-move,
.welcome-bucket .att-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0 4px;
  line-height: 1;
  font-size: 14px;
  opacity: 0.7;
}

.welcome-bucket .att-move:hover { opacity: 1; color: var(--surf); }
.welcome-bucket .att-remove { font-size: 16px; }
.welcome-bucket .att-remove:hover { color: var(--danger); opacity: 1; }

.welcome-card-v2 .welcome-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
}

.welcome-card-hint {
  flex: 1 1 auto;
}

.welcome-start-btn {
  flex: 0 0 auto;
  background: var(--abyss);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.welcome-start-btn:hover {
  background: var(--surf);
  transform: translateY(-1px);
}

.welcome-start-btn:focus-visible {
  outline: 2px solid var(--surf);
  outline-offset: 2px;
}

/* =========================================================================
   Ideas notepad — small modal accessible from the topbar (sibling to
   Substacker's Ideas modal). Persisted on the server.
   ========================================================================= */

.ideas-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: none;
  background: rgba(11, 11, 10, 0.45);
  align-items: center;
  justify-content: center;
}
.ideas-modal.open { display: flex; }

.ideas-panel {
  width: min(560px, calc(100% - 32px));
  max-height: min(70vh, 720px);
  background: var(--shell);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
}

.ideas-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--abyss);
  color: #ffffff;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}
.ideas-title {
  font-family: var(--font-impact);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: 1;
  margin: 0;
}
.ideas-status {
  font-size: 11px;
  color: var(--surf-tint);
  font-weight: 500;
}
.ideas-close {
  background: transparent;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 4px 9px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.ideas-close:hover { background: rgba(255, 255, 255, 0.12); }

.ideas-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ideas-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

.ideas-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--divider);
}
.ideas-footer-spacer { flex: 1; }

/* Tabs strip beneath the header. Three tabs: Ideas, Rainy day, Done. */
.ideas-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.ideas-tab {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-secondary);
  padding: 7px 12px 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-top-left-radius: var(--radius-sm);
  border-top-right-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: -1px;
}
.ideas-tab:hover { color: var(--ink); }
.ideas-tab[aria-selected="true"] {
  background: var(--shell);
  border-color: var(--border);
  color: var(--ink);
}
.ideas-tab-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(14, 74, 83, 0.08);
  border-radius: var(--radius-pill);
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}
.ideas-tab[aria-selected="true"] .ideas-tab-count {
  background: var(--surf);
  color: #ffffff;
}

/* Checklist rows. Each row: checkbox + text + hover controls. */
.ideas-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.ideas-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 8px 8px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  position: relative;
}
.ideas-item:hover {
  background: var(--surface-alt);
  border-color: var(--border);
}
.ideas-item-check {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--text-secondary);
  border-radius: 4px;
  background: var(--shell);
  cursor: pointer;
  flex: 0 0 auto;
  margin-top: 1px;
  position: relative;
}
.ideas-item-check:hover { border-color: var(--surf); }
.ideas-item-check:checked {
  background: var(--surf);
  border-color: var(--surf);
}
.ideas-item-check:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 0px;
  width: 6px;
  height: 11px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.ideas-item-text {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
  padding: 1px 2px;
  border-radius: 3px;
}
.ideas-item-text:focus {
  background: var(--shell);
  box-shadow: 0 0 0 2px var(--surf);
}
.ideas-item.done .ideas-item-text {
  color: var(--text-secondary);
  text-decoration: line-through;
  text-decoration-color: rgba(90, 100, 103, 0.6);
}
.ideas-item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s ease;
  flex: 0 0 auto;
}
.ideas-item:hover .ideas-item-actions,
.ideas-item:focus-within .ideas-item-actions { opacity: 1; }
.ideas-item-action {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}
.ideas-item-action:hover {
  background: var(--shell);
  border-color: var(--border);
  color: var(--ink);
}
.ideas-item-action.danger:hover {
  color: #b03a2e;
  border-color: #e6c2bd;
}

.ideas-empty {
  padding: 24px 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}

.ideas-add {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--divider);
}
.ideas-add-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: var(--shell);
}
.ideas-add-input:focus {
  outline: 2px solid var(--surf);
  outline-offset: -2px;
  border-color: var(--surf);
}
.ideas-add-btn {
  appearance: none;
  background: var(--surf);
  color: #ffffff;
  border: 1px solid var(--surf);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.ideas-add-btn:hover { background: var(--abyss); border-color: var(--abyss); }
.ideas-add-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* =========================================================================
   Open-Sessions modal — two-pane session chooser (sibling to Substacker)
   ========================================================================= */

.open-sessions-panel {
  width: min(900px, calc(100% - 32px));
  max-height: min(80vh, 720px);
  background: var(--shell);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
}

.open-sessions-body {
  display: grid;
  grid-template-columns: 1fr;
  flex: 1;
  min-height: 0;
}
@media (min-width: 700px) {
  .open-sessions-body { grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr); }
}

.open-sessions-list-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.open-sessions-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 14px 8px;
  align-items: center;
  border-bottom: 1px solid var(--divider);
}

.open-sessions-search {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--bg);
  color: var(--ink);
}
.open-sessions-search:focus { outline: 2px solid var(--surf); outline-offset: -2px; border-color: var(--surf); }

.open-sessions-trash-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.open-sessions-trash-toggle:hover { background: var(--bg); border-color: var(--surf); color: var(--surf); }
.open-sessions-trash-toggle.active { background: var(--coral); border-color: var(--coral); color: #ffffff; }

.open-sessions-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.open-sessions-list-item {
  padding: 10px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
}
.open-sessions-list-item:hover {
  background: var(--surf-tint);
  border-left-color: var(--surf);
}
.open-sessions-list-item.current {
  background: var(--abyss-tint);
  border-left-color: var(--abyss);
}
.open-sessions-list-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.open-sessions-list-item-meta {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.open-sessions-list-item-phase {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--phase-color, var(--text-muted));
  background: var(--phase-bg, transparent);
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.open-sessions-preview {
  padding: 16px 18px;
  overflow-y: auto;
  background: var(--bg);
}
.open-sessions-preview-empty {
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}
.open-sessions-preview-title {
  font-family: var(--font-impact);
  font-size: 18px;
  font-weight: 700;
  color: var(--abyss);
  margin: 0 0 6px;
}
.open-sessions-preview-stats {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  margin-bottom: 12px;
}
.open-sessions-preview-stats span { margin-right: 12px; }
.open-sessions-preview-snippet {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--shell);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.open-sessions-preview-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.open-sessions-preview-actions button {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--shell);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}
.open-sessions-preview-actions button:hover { background: var(--surf-tint); border-color: var(--surf); color: var(--abyss); }
.open-sessions-preview-actions .preview-action-primary { background: var(--abyss); color: #ffffff; border-color: var(--abyss); }
.open-sessions-preview-actions .preview-action-primary:hover { background: var(--surf); border-color: var(--surf); color: #ffffff; }
.open-sessions-preview-actions .preview-action-danger { background: transparent; color: var(--coral); border-color: var(--coral); }
.open-sessions-preview-actions .preview-action-danger:hover { background: var(--coral); color: #ffffff; }

/* =========================================================================
   Two-pane workspace — conversation on the left, drafts pane on the right,
   6px draggable gutter between them. Sibling to Substacker's layout, with
   the same persisted-per-localStorage --right-pane-width.
   ========================================================================= */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 6px var(--right-pane-width, 400px);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* The 6px gutter between the panes. Hovering or dragging surfaces a
   surf-coloured stripe so it's discoverable without being heavy. */
.pane-resizer {
  cursor: col-resize;
  background: transparent;
  position: relative;
  user-select: none;
  touch-action: none;
}
.pane-resizer::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
  transition: background var(--dur-fast) var(--ease-out);
}
.pane-resizer:hover::before,
.pane-resizer.dragging::before,
.pane-resizer:focus-visible::before {
  background: var(--surf);
}
.pane-resizer:focus-visible { outline: none; }

.pane-right {
  background: var(--bg);
  border-left: 1px solid var(--border);
}

.drafts-header {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.draft-tabs {
  display: flex;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.draft-tabs::-webkit-scrollbar { display: none; }

.draft-tab {
  padding: 10px 14px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
  position: relative;
}
.draft-tab:hover {
  color: var(--abyss);
  background: var(--surface-alt);
}
.draft-tab.active {
  color: var(--abyss);
  border-bottom-color: var(--surf);
}
.draft-tab.has-content::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--surf);
}

.pane-right-close {
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 1;
  padding: 0 14px;
  cursor: pointer;
  display: none; /* shown only in slide-over mode */
}
.pane-right-close:hover { color: var(--abyss); background: var(--surface-alt); }

.draft-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  font-family: var(--font-script);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
}

.draft-empty {
  color: var(--text-secondary);
  font-style: italic;
  font-family: var(--font-ui);
  font-size: 13px;
}

.draft-history {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
}
.draft-history-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.draft-history-select {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: inherit;
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
}
.draft-history-select:focus { outline: 2px solid var(--surf); outline-offset: -2px; border-color: var(--surf); }

.draft-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--surf);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.draft-meta .draft-meta-date {
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.draft-meta .draft-meta-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.draft-meta .draft-meta-action {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.draft-meta .draft-meta-action:hover { background: var(--surf); border-color: var(--surf); color: #ffffff; }

.draft-content { white-space: normal; word-break: break-word; }
.draft-content p { margin: 0 0 12px; }
.draft-content h1, .draft-content h2, .draft-content h3 {
  font-family: var(--font-impact);
  color: var(--abyss);
  margin: 18px 0 8px;
}
.draft-content h1 { font-size: 22px; }
.draft-content h2 { font-size: 18px; }
.draft-content h3 { font-size: 15px; }
.draft-content em { color: var(--orchid); font-style: italic; }
.draft-content strong { color: var(--ink); }
.draft-content blockquote {
  border-left: 3px solid var(--surf);
  padding-left: 12px;
  margin: 10px 0;
  color: var(--text-muted);
}
.draft-content ul, .draft-content ol { margin: 8px 0 12px 22px; }
.draft-content li { margin-bottom: 4px; }
.draft-content sup { color: var(--surf); font-weight: 600; }

/* Research tab — list view (file cards + attachments) */
.research-list { display: flex; flex-direction: column; gap: 10px; font-family: var(--font-ui); }
.research-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--shell);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.research-item-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surf-tint);
  color: var(--abyss);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
}
.research-item-name {
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.research-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
}
.research-item-action {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}
.research-item-action:hover { background: var(--surf); border-color: var(--surf); color: #ffffff; }
.research-section-title {
  font-family: var(--font-impact);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 12px 0 6px;
}

/* Structured research-summary cards (Substacker-style synthesis) ----- */
.research-summaries {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 8px;
}
.research-summary-card {
  padding: 14px 16px;
  background: var(--shell);
  border: 1px solid var(--border);
  border-left: 3px solid var(--surf);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
}
.research-summary-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}
.research-summary-title {
  font-family: var(--font-impact);
  font-size: 15px;
  font-weight: 700;
  color: var(--abyss);
  margin: 0;
  line-height: 1.3;
}
.research-summary-delete {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.research-summary-delete:hover { background: var(--coral-tint); color: var(--coral); }
.research-summary-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: capitalize;
}
.research-summary-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
  margin: 0 0 10px;
}
.research-summary-facts {
  margin: 6px 0 10px 18px;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-muted);
}
.research-summary-facts li { margin-bottom: 3px; }
.research-summary-angles {
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 6px;
  border-top: 1px dashed var(--divider);
}
.research-summary-angles b {
  color: var(--surf);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  font-weight: 700;
  display: block;
  margin-bottom: 4px;
}
.research-summary-angle {
  display: inline-block;
  background: var(--surf-tint);
  color: var(--abyss);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin: 2px 4px 2px 0;
  font-size: 11px;
  font-weight: 600;
}

/* Backdrop for slide-over modes (mobile right pane). */
.pane-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 10, 0.45);
  z-index: 50;
  display: none;
}
.pane-backdrop.visible { display: block; }

/* Drafts toggle button (mobile only — hidden by default; revealed at narrow
   widths in the responsive section below). */
.icon-btn.drafts-toggle { display: none; }

/* =========================================================================
   JSON Widgets — Substacker-style fenced ```widget blocks. Sibling styling
   to Substacker's .widget-* classes; reuses Producer's existing submit-bar
   pattern (.cw-submit-bar) for uniform UX with the legacy markers.
   ========================================================================= */

.json-widget.widget {
  display: block;
  margin: 12px 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--surf);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
}
.json-widget .widget-prompt {
  font-weight: 600;
  font-size: 13px;
  color: var(--abyss);
  margin-bottom: 8px;
}
.json-widget .widget-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.json-widget .widget-opt {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.json-widget .widget-opt:hover {
  background: var(--surf-tint);
  border-color: var(--surf);
}
.json-widget .widget-opt.selected {
  background: var(--surf-tint);
  border-color: var(--surf);
  color: var(--abyss);
  box-shadow: inset 3px 0 0 var(--surf);
}
.json-widget .widget-opt b {
  font-weight: 600;
  display: block;
}
.json-widget .widget-opt-desc {
  display: block;
  grid-column: 1 / 2;
  font-weight: normal;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.json-widget .widget-opt-intensity {
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  color: var(--surf);
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
  align-self: center;
}
.json-widget .widget-intensity-hint {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 4px;
}
.json-widget .widget-opt-other b {
  font-style: italic;
  color: var(--text-secondary);
}
.json-widget .widget-opt-other.selected b {
  color: var(--abyss);
}
.json-widget .widget-other-input {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 2px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  resize: vertical;
  outline: none;
  background: var(--surface);
  box-sizing: border-box;
}
.json-widget .widget-other-input:focus {
  border-color: var(--surf);
  box-shadow: 0 0 0 2px rgba(0, 109, 119, 0.15);
}

.json-widget .widget-confirm-btn {
  background: var(--abyss);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
  transition: background var(--dur-fast) var(--ease-out);
}
.json-widget .widget-confirm-btn:hover { background: var(--surf); }
.json-widget .widget-confirm-btn:disabled {
  background: var(--algae);
  color: #ffffff;
  cursor: default;
  opacity: 0.85;
}

.json-widget .widget-slider {
  width: 100%;
  margin: 4px 0;
  accent-color: var(--surf);
}
.json-widget .widget-readout {
  font-family: var(--font-mono, monospace);
  font-size: 13px;
  color: var(--abyss);
  font-weight: 700;
  text-align: center;
}
.json-widget .widget-scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.json-widget .widget-field {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--bg);
  color: var(--ink);
}
.json-widget .widget-field:focus {
  outline: 2px solid var(--surf);
  outline-offset: -2px;
  border-color: var(--surf);
}

.json-widget.cw-locked {
  opacity: 0.65;
  pointer-events: none;
  border-left-color: var(--algae);
}
.json-widget.cw-locked::after {
  content: "✓ submitted";
  display: block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--algae);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.widget-error {
  background: var(--coral-tint);
  border: 1px solid var(--coral);
  color: var(--abyss-dark);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  margin: 8px 0;
}

/* On narrow viewports the right pane collapses behind a slide-over.
   The grid drops to a single column for the conversation; pane-right is
   removed from the layout flow and absolutely-positioned over the
   conversation when the user opens it. */
@media (max-width: 899px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .pane-resizer { display: none; }
  .pane-right {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 92vw);
    z-index: 60;
    box-shadow: -8px 0 24px rgba(11,11,10,0.18);
    transform: translateX(100%);
    transition: transform var(--dur-med) var(--ease-out);
  }
  .pane-right.open { transform: translateX(0); }
  .pane-right-close { display: inline-flex; align-items: center; }
  .icon-btn.drafts-toggle { display: inline-flex; }
}
