/* ============================================================================
   Sponsor Proposals — module stylesheet (v2 design system)
   ----------------------------------------------------------------------------
   Composer-driven archetype. Composes from canonical tokens in
   tokens/design-tokens.css (linked app-wide in the application layout):
   --color-*, --fg/-muted/-faint, --paper, --border/-strong, --surface-2,
   --font-sans/-mono, --r-input/-pill/-card/-modal, status semantic colors.

   Reskinned to the cool-slate / flat-white / square / dense aesthetic, with
   the saved show page mapped to archetypes/composer-driven/reference.html and
   the create + lockout flow to reference-create.html.

   PRESERVED VERBATIM (behavior-critical; the Stimulus controllers depend on
   these and they must not be renamed):
     - the `.sef-layout` grid driven by the --sp-chat-width custom property
     - the `.sef-layout--chat-collapsed` / `.sef-layout--resizing` states
     - the `.sef-resizer` drag affordance + `.sef-resizer--dragging`
     - the `.sef-tab` / `.sef-panel` tab-switch contract (`.active` + [hidden])
     - the `--sef-composer-height` anchor for the new-messages pill
     - the `.sef-account-picker:has(...)` selected-state toggle
   ============================================================================ */

/* --------- Page + 1280 shell --------- */
.sef-page {
  /* Outer page padding lives at the app frame's .viewport > .shell rule
     (24px / --s-6, hoisted there so every page inherits the canon
     automatically). Do not re-set it here. */
  min-height: 100vh;
  background: var(--paper);
  font-family: var(--font-sans);
  color: var(--fg);
}

/* --------- Header (flat, not a card) --------- */
/* Top contextual-nav row, then the title row (prefix + name + state strip on
   the left, action-button cluster on the right). Flat with a hairline divider,
   matching the Composer-driven page head. */
.sef-header {
  max-width: min(1280px, calc(100vw - 64px));
  margin: 0 auto;
  background: var(--paper);
  padding: var(--s-3) 0 var(--s-3);
  border-bottom: 1px solid var(--border);
}

.sef-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-3);
}

.sef-header-top-right {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
}

.sef-back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 13px;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-input);
  transition: color 100ms ease-out, background 100ms ease-out;
}
.sef-back-link:hover { color: var(--fg); background: var(--surface-2); }
.sef-back-icon { width: 14px; height: 14px; }

.sef-home-link,
.sef-help-link {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 13px;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-input);
  transition: color 100ms ease-out, background 100ms ease-out;
}
.sef-home-link:hover,
.sef-help-link:hover { color: var(--fg); background: var(--surface-2); }

.sef-header-row {
  display: flex;
  align-items: flex-start;
  gap: var(--s-4);
  flex-wrap: wrap;
}

.sef-title-block {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

/* Record-type prefix — IBM Plex Mono, uppercase, tracked. Same treatment as
   the Compact Detail / Composer-driven page head. */
.sef-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-faint);
  line-height: 1.2;
  margin-bottom: var(--s-1);
}

/* Record name — 26 / 700 Inter. */
.sef-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--fg);
  margin: 0;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* State strip — two STATIC status badges (lifecycle + approval) below the
   name as metadata. Per DEC-2 this record keeps its dual-axis display and its
   explicit role-gated action buttons (CEO sign-off workflow, wired to Slack);
   the transitions are NOT folded into a self-service badge dropdown. */
.sef-state-strip {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-2);
  flex-wrap: wrap;
}

/* Action-button cluster — right-aligned, top-aligned, wraps under pressure. */
.sef-header-actions {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 100%;
  min-width: 0;
  margin-left: auto;
  padding-top: var(--s-1);
}
.sef-header-form { display: inline-block; margin: 0; }

/* --------- Flash --------- */
.sef-flash {
  max-width: min(1280px, calc(100vw - 64px));
  margin: var(--s-3) auto 0;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-card);
  font-size: 14px;
  border: 1px solid transparent;
}
.sef-flash-success { background: var(--color-success-bg); color: var(--color-success-text); border-color: var(--color-success-border, var(--color-success-text)); }
.sef-flash-error   { background: var(--color-danger-bg);  color: var(--color-danger-text);  border-color: var(--color-danger-border, var(--color-danger-text)); }
.sef-flash code {
  background: var(--surface-2);
  padding: 1px var(--s-1);
  border-radius: var(--r-input);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ============================================================================
   Split-pane workspace — doc pane | resizer | chat pane.
   Normal-flow bounded region (per composer-driven reference.html). It sits
   below the page head and fills the remaining viewport height; the panes scroll
   internally. NOT sticky/floating — a sticky-bottom workspace overlapped the
   page head on shorter viewports. The grid's third track is driven by
   --sp-chat-width (workspace_controller).
   ============================================================================ */
.sef-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 16px var(--sp-chat-width, 360px);
  gap: 0;
  max-width: min(1280px, calc(100vw - 64px));
  margin: var(--s-4) auto 0;
  align-items: stretch;
  height: min(calc(100vh - 240px), 860px);
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--paper);
  overflow: hidden;
}

/* Collapsed-chat: chat column shrinks to a 44px rail; resizer track hides. */
.sef-layout.sef-layout--chat-collapsed {
  grid-template-columns: minmax(360px, 1fr) 0 44px;
}

/* Mobile fallback: stack the panes; sticky-bottom + resizer don't apply. */
@media (max-width: 900px) {
  .sef-layout,
  .sef-layout.sef-layout--chat-collapsed {
    grid-template-columns: 1fr;
    position: static;
    height: auto;
    min-height: 0;
  }
  .sef-resizer { display: none; }
  .sef-chat-collapse-toggle { display: none; }
}

/* --------- Doc pane --------- */
/* Tabs at the top of the doc pane (Original / Formatted Output); the whole
   pane is a single scroll container so tabs scroll with the content. */
.sef-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--color-slate-50);
  flex-shrink: 0;
}
.sef-tab {
  padding: var(--s-3) var(--s-4);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 100ms ease-out, background 100ms ease-out;
}
.sef-tab:hover { color: var(--fg); }
.sef-tab.active {
  color: var(--fg);
  background: var(--paper);
  border-bottom-color: var(--fg);
  font-weight: 600;
}

/* The doc pane itself never scrolls — scrolling lives on the body inside each
   panel, so the per-tab footer bar stays pinned and never moves. */
.sef-panels {
  background: var(--paper);
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.sef-panel-stack {
  display: grid;
  grid-template-areas: "stack";
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.sef-panel {
  grid-area: stack;
  min-width: 0;
  min-height: 0;
  /* Flex column: a scrolling body (read text or the CKEditor) fills the pane,
     and the per-tab footer bar pins to the bottom (never moves). No padding —
     the editor fills edge-to-edge; the read body carries its own padding. */
  display: flex;
  flex-direction: column;
}
/* Inactive panel keeps reserving space so the column doesn't jump on switch. */
.sef-panel[hidden] {
  visibility: hidden;
  pointer-events: none;
}

/* ----- Doc-pane fill + footer-pin architecture -----
   The output panel nests its body/footer two wrappers deep
   (output-edit > readView/editView > form); stretch those into flex columns. */
.sef-panel > [data-controller="output-edit"],
.sef-panel > [data-controller="output-edit"] > [data-output-edit-target="readView"],
.sef-panel > [data-controller="output-edit"] > [data-output-edit-target="editView"],
.sef-panel .sef-output-edit-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* The scrolling body — formatted-email read column or the read-only draft. */
.sef-output-body,
.sef-draft-readonly {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* The CKEditor fills the pane (width + height) with internal scroll. The
   <ckeditor-component> custom element and .ck-editor both default to
   display:block, so force the flex chain through them (hence !important). */
.sef-draft-editor,
.sef-output-editor {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}
.sef-draft-editor ckeditor-component,
.sef-output-editor ckeditor-component,
.sef-draft-editor ckeditor-component > .ck.ck-editor,
.sef-output-editor ckeditor-component > .ck.ck-editor {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.sef-draft-editor .ck-editor__main,
.sef-output-editor .ck-editor__main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.sef-draft-editor .ck-editor__editable,
.sef-output-editor .ck-editor__editable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Per-tab footer bars pin to the pane bottom (never move). */
.sef-output-footer,
.sef-panel > .sp-revise-form { flex-shrink: 0; }
.sef-panel-help {
  font-size: 13px;
  color: var(--fg-muted);
  margin: 0 0 var(--s-4);
  line-height: 1.5;
}

/* --------- Resizer --------- */
.sef-resizer {
  grid-column: 2;
  position: relative;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: col-resize;
  touch-action: none;
}
.sef-resizer::before { content: ""; position: absolute; inset: 0 -8px; }
.sef-resizer::after {
  content: "";
  position: absolute;
  left: 50%; top: 0;
  transform: translateX(-50%);
  width: 1px; height: 100%;
  background: var(--border);
  transition: background 100ms ease-out, width 100ms ease-out;
}
.sef-resizer:hover::after,
.sef-resizer:focus-visible::after,
.sef-resizer.sef-resizer--dragging::after {
  background: var(--border-strong);
  width: 3px;
}
.sef-resizer:focus-visible { outline: 0; }
.sef-layout.sef-layout--resizing,
.sef-layout.sef-layout--resizing * {
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================================================
   Buttons — locked atom. Primary = filled slate-900; secondary = outlined;
   danger = outlined (solid red is reserved for the confirm dialog only).
   ============================================================================ */
.sef-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-2) var(--s-4);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  border-radius: var(--r-input);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 100ms ease-out, border-color 100ms ease-out, color 100ms ease-out;
}
.sef-btn-sm { padding: var(--s-1) var(--s-3); font-size: 12px; }

.sef-btn-primary { background: var(--color-slate-900); color: #fff; border-color: var(--color-slate-900); }
.sef-btn-primary:hover { background: var(--color-slate-800); border-color: var(--color-slate-800); }
.sef-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.sef-btn-secondary { background: var(--paper); color: var(--fg); border-color: var(--border-strong); }
.sef-btn-secondary:hover { background: var(--surface-2); }
.sef-btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.sef-btn-danger { background: var(--paper); color: var(--color-danger-text); border-color: var(--color-danger-border, var(--color-danger-text)); }
.sef-btn-danger:hover { background: var(--color-danger-bg); }

/* --------- Form elements --------- */
.sef-textarea {
  display: block;
  width: 100%;
  padding: var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--paper);
  resize: vertical;
  min-height: 20rem;
  transition: border-color 100ms ease-out, box-shadow 100ms ease-out;
}
.sef-textarea:focus {
  outline: none;
  border-color: var(--color-blue-600);
  box-shadow: 0 0 0 2px var(--color-blue-200) inset;
}

/* CKEditor editable typography (fill/scroll handled in the doc-pane section). */
.sef-draft-editor .ck-editor__editable {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
}

.sef-form-actions {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-4);
}

/* Read-only draft render (lockout Original tab). */
.sef-draft-readonly {
  padding: var(--s-6);
  background: var(--paper);
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 14px;
  color: var(--fg);
}
.sef-draft-readonly p { margin: 0 0 0.75em; }
.sef-draft-readonly p:last-child { margin-bottom: 0; }

/* ============================================================================
   Output panel — the formatted email. Reading column at 680px; the footer
   carries Copy / Edit / edited-at (doc-footer treatment).
   ============================================================================ */
.sef-output-placeholder {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--fg-faint);
  font-size: 14px;
}
.sef-output-error,
.sef-output-disabled {
  padding: var(--s-4);
  border-radius: var(--r-input);
  font-size: 14px;
}
.sef-output-error { background: var(--color-danger-bg); color: var(--color-danger-text); border: 1px solid var(--color-danger-border, var(--color-danger-text)); }
.sef-output-disabled { background: var(--color-warning-bg); color: var(--color-warning-text); border: 1px solid var(--color-warning-border); }
.sef-output-disabled code {
  background: var(--surface-2);
  padding: 1px var(--s-1);
  border-radius: var(--r-input);
  font-family: var(--font-mono);
  font-size: 12px;
}
.sef-output-header { display: flex; justify-content: flex-end; margin-bottom: var(--s-3); }

/* Doc-pane footer bar — full-width, pinned to the pane bottom, matching the
   chat composer bar (border-top + slate-50). Breaks out of the panel's
   horizontal padding via negative margins. Copy/Edit left, timestamp right. */
.sef-output-footer {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  padding: var(--s-3) var(--s-6);
  border-top: 1px solid var(--border);
  background: var(--color-slate-50);
}
.sef-output-edited-at {
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-left: auto;
}

/* Formatted email reading body — Inter, full pane width to match the editor so
   toggling read↔edit doesn't reflow. Scrolls internally (fill rules in the
   doc-pane section); carries its own padding since the panel has none. */
.sef-output-body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
  color: var(--fg);
  width: 100%;
  padding: var(--s-6);
}
.sef-output-body p { margin: 0 0 0.85em; }
.sef-output-body p:last-child { margin-bottom: 0; }
.sef-output-body h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 1.5em 0 0.5em;
  letter-spacing: 0.02em;
  color: var(--fg);
}
.sef-output-body h3:first-child { margin-top: 0; }
.sef-output-body ul,
.sef-output-body ol { margin: 0 0 0.85em; padding-left: 1.5em; }
.sef-output-body li { margin: 0.1em 0; }
.sef-output-body strong { font-weight: 600; }
.sef-output-body em { font-style: italic; }
.sef-output-body u { text-decoration: underline; }

/* Stale output during an in-flight rewrite — dim to signal it's about to be
   replaced (the chat progress steps carry the live signal). */
.sef-output-stale,
.sef-output-stale h3,
.sef-output-stale p,
.sef-output-stale li,
.sef-output-stale strong,
.sef-output-stale em,
.sef-output-stale u { color: var(--fg-faint); }

/* In-place output editor (CKEditor) — WYSIWYG parity with the read render.
   Keep these in sync with EMAIL_INLINE_STYLES (sponsor_email_formattings_helper). */
.sef-output-editor .ck-content {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--fg);
}
.sef-output-editor .ck-content p { margin: 0 0 0.9em; }
.sef-output-editor .ck-content h3 { font-size: 16px; font-weight: 700; margin: 1.4em 0 0.45em; letter-spacing: 0.02em; }
.sef-output-editor .ck-content h3:first-child { margin-top: 0; }
.sef-output-editor .ck-content ul { margin: 0 0 0.9em; padding-left: 1.5em; list-style: disc outside; }
.sef-output-editor .ck-content ol { margin: 0 0 0.9em; padding-left: 1.5em; list-style: decimal outside; }
.sef-output-editor .ck-content li { margin: 0.1em 0; }

/* --------- Policy flag (callout-style warning) --------- */
.sp-policy-flag,
.sef-policy-flag {
  margin-top: var(--s-4);
  margin-bottom: var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-border);
  border-left: 3px solid var(--color-warning-text);
  border-radius: var(--r-input);
  font-size: 14px;
  color: var(--color-warning-text);
}
.sp-policy-flag ul,
.sef-policy-flag-list { margin: var(--s-2) 0 0; padding-left: var(--s-4); list-style: disc; }
.sp-policy-flag li { margin: 0.1em 0; }
.sef-policy-flag-title { font-size: 14px; font-weight: 600; margin-bottom: var(--s-2); }
.sef-policy-flag-footer {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-top: var(--s-2);
  margin-top: var(--s-2);
  border-top: 1px dashed var(--color-warning-border);
}
.sp-formatter-note {
  margin-top: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--surface-2);
  border-radius: var(--r-input);
}
.sp-revise-form {
  flex-shrink: 0;
  padding: var(--s-3) var(--s-6);
  border-top: 1px solid var(--border);
  background: var(--color-slate-50);
}
.sp-revise-form .sef-form-actions { margin-top: 0; }

/* ============================================================================
   Progress steps — the AI's "thinking out loud" inside the chat log.
   ○ active → ✓ done, with a duration. Driven by real server-side
   formatting_steps; no synthetic timer (P0.6).
   ============================================================================ */
.sef-step {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--fg-muted);
}
.sef-step-indicator { font-family: var(--font-mono); color: var(--fg-faint); flex-shrink: 0; }
.sef-step-label { flex: 1; }
.sef-step-done .sef-step-indicator { color: var(--color-success); }
.sef-step-active .sef-step-indicator { color: var(--color-warning-text); }
.sef-step-duration,
.sef-elapsed {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

/* ============================================================================
   Chat pane — light. White paper, Inter body, IBM Plex Mono labels, five
   tinted voices. (Was a dark terminal pre-reskin.)
   ============================================================================ */
.sef-chat {
  background: var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 0;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--fg);
  position: relative;
  overflow: hidden;
}
.sef-chat-header { display: none; }

/* Chat header bar — "Chat" eyebrow at the top of the pane (the collapse toggle
   sits over its right edge). Keeps the toggle off the first chat message. */
.sef-chat-headbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
}
.sef-chat-headbar-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

/* Collapse toggle — small glyph, top-right of the chat pane. */
.sef-chat-collapse-toggle {
  position: absolute;
  top: var(--s-2);
  right: var(--s-2);
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-faint);
  cursor: pointer;
  border-radius: var(--r-input);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1;
  transition: color 100ms ease-out, background 100ms ease-out;
  z-index: 2;
}
.sef-chat-collapse-toggle:hover { color: var(--fg); background: var(--surface-2); }

/* Vertical "CHAT" rail label — visible only when collapsed. */
.sef-chat-rail-label { display: none; }
@media (min-width: 901px) {
  .sef-layout--chat-collapsed .sef-chat {
    cursor: pointer;
    align-items: center;
    justify-content: center;
    border-left: 1px solid var(--border);
  }
  .sef-layout--chat-collapsed .sef-chat-rail-label {
    display: block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    color: var(--fg-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.2em;
    font-weight: 700;
    text-transform: uppercase;
    user-select: none;
  }
  .sef-layout--chat-collapsed .sef-chat-headbar,
  .sef-layout--chat-collapsed .sef-chat-log,
  .sef-layout--chat-collapsed .sp-chat-input,
  .sef-layout--chat-collapsed .sef-chat-new-messages-pill { display: none; }
  .sef-layout--chat-collapsed .sef-chat-collapse-toggle {
    display: inline-flex;
    top: var(--s-2);
    right: 50%;
    transform: translateX(50%);
  }
}

/* Chat — matches the reconciled chat-thread atom
   (components/chat-thread/example.html): the mono tag renders INLINE at the start
   of each entry (never stacked above); user/rewrite = blue bubble, assistant =
   green-tinted bubble; event/system are bare italic inline lines. */
.sef-chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sef-chat-entry {
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: 3px;
  border: 1px solid transparent;
  color: var(--fg);
  /* Preserve the AI's line breaks (its lists use newlines); runs of blank lines
     are collapsed in the partial so the bubble doesn't read airy. */
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.sef-chat-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-right: 6px;
}
/* User — blue tag + blue bubble. */
.sef-chat-entry-user { background: var(--color-blue-50); border-color: var(--color-blue-200); }
.sef-chat-entry-user .sef-chat-label { color: var(--color-blue-700); }
/* Assistant — green tag + green-tinted bubble. */
.sef-chat-entry-assistant { background: var(--color-success-bg); border-color: var(--border); }
.sef-chat-entry-assistant .sef-chat-label { color: var(--color-success); }
/* Rewrite — pink tag + blue bubble (only the tag is pink). */
.sef-chat-entry-rewrite { background: var(--color-blue-50); border-color: var(--color-blue-200); }
.sef-chat-entry-rewrite .sef-chat-label { color: var(--chat-rewrite-tag-text); }
/* Event — amber italic, no bubble; bracketed status label. */
.sef-chat-entry-event {
  background: transparent;
  border: none;
  padding: 4px 10px;
  color: var(--color-warning-text);
  font-style: italic;
  font-size: 12px;
}
.sef-chat-entry-event .sef-chat-label { color: var(--color-warning-text); }
/* System — gray italic, no bubble. */
.sef-chat-entry-system {
  background: transparent;
  border: none;
  padding: 4px 10px;
  color: var(--fg-muted);
  font-style: italic;
  font-size: 12px;
}
.sef-chat-entry-system strong { color: var(--fg); font-style: normal; }
.sef-chat-entry-error {
  background: transparent;
  border: none;
  padding: 4px 10px;
  color: var(--color-danger-text);
  font-style: italic;
  font-size: 12px;
}
.sef-chat-placeholder { padding: 2rem var(--s-2); color: var(--fg-faint); font-size: 13px; text-align: center; }

/* New-messages pill — anchored just above the composer via --sef-composer-height. */
.sef-chat-new-messages-pill {
  position: absolute;
  left: 50%;
  bottom: calc(var(--sef-composer-height, 5.25rem) + var(--s-1));
  transform: translateX(-50%);
  background: var(--color-slate-900);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: var(--s-1) var(--s-3);
  border: 0;
  border-radius: var(--r-pill);
  box-shadow: var(--sh-card, 0 1px 3px rgba(15,23,42,0.18));
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  z-index: 2;
  transition: background 100ms ease-out;
}
.sef-chat-new-messages-pill:hover { background: var(--color-slate-800); }
.sef-chat-new-messages-pill[hidden] { display: none; }

/* --------- Chat input — one textarea, two submit buttons --------- */
.sp-chat-input {
  border-top: 1px solid var(--border);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  background: var(--color-slate-50);
  flex-shrink: 0;
}
.sp-chat-textarea {
  width: 100%;
  padding: var(--s-2) var(--s-3);
  background: var(--paper);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  font-family: var(--font-sans);
  font-size: 13px;
  resize: none;
  min-height: 56px;
  max-height: 8.75rem;
  overflow-y: auto;
  line-height: 1.5;
}
.sp-chat-textarea:focus {
  outline: none;
  border-color: var(--color-blue-600);
  box-shadow: 0 0 0 2px var(--color-blue-200) inset;
}
.sp-chat-textarea::placeholder { color: var(--fg-faint); }
.sp-chat-textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.sp-chat-buttons {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  flex-wrap: nowrap;
  min-width: 0;
}
.sp-chat-button-form { margin: 0; flex: 1 1 auto; min-width: 0; display: flex; }

/* Comment = secondary (outlined); Ask AI to rewrite = primary (filled slate). */
.sp-chat-input .sp-chat-btn {
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.sp-chat-input .sp-chat-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sp-chat-input .sp-chat-btn:focus-visible { outline: 2px solid var(--color-blue-600); outline-offset: 1px; }

/* ============================================================================
   Account picker (new + lockout). Filled input, results dropdown, selected
   chip. The :has() rule hides the input once a company is chosen.
   ============================================================================ */
.sef-new-form-container {
  max-width: min(1280px, calc(100vw - 64px));
  margin: var(--s-4) auto 0;
  background: var(--paper);
  padding: var(--s-5);
}
.sef-account-picker { margin-top: var(--s-4); position: relative; }
.sef-account-input {
  display: block;
  width: 100%;
  padding: 10px var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg);
  background: var(--paper);
  transition: border-color 100ms ease-out, box-shadow 100ms ease-out;
}
.sef-account-input::placeholder { color: var(--fg-faint); }
.sef-account-input:focus {
  outline: none;
  border-color: var(--color-blue-600);
  box-shadow: 0 0 0 2px var(--color-blue-200) inset;
}
.sef-account-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--paper);
  border: 1px solid var(--border-strong);
  border-top: none;
  border-radius: 0 0 var(--r-input) var(--r-input);
  box-shadow: var(--sh-overlay, 0 4px 12px rgba(15,23,42,0.12));
}
.sef-account-results:empty { display: none; }
.sef-account-picker:has(.sef-account-selected:not([hidden])) .sef-account-input { display: none; }
.sef-account-selected {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: var(--paper);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
}
.sef-account-selected-name { font-size: 14px; font-weight: 500; color: var(--fg); }

/* Inline sponsor picker in the right pane (email-in lockout). */
.sp-sponsor-picker { display: flex; flex-direction: column; }
.sp-sponsor-picker-form {
  padding: var(--s-3) var(--s-4) var(--s-4);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

/* --------- Intro copy --------- */
.sp-intro {
  max-width: min(1100px, calc(100vw - 64px));
  margin: var(--s-4) auto;
  text-align: center;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.6;
}

/* ============================================================================
   Index (queue) — Index archetype table. Faint horizontal dividers, flat.
   ============================================================================ */
.sp-empty {
  max-width: min(1280px, calc(100vw - 64px));
  margin: 3rem auto;
  text-align: center;
  color: var(--fg-muted);
  font-size: 15px;
}
.sp-queue-table {
  max-width: min(1280px, calc(100vw - 64px));
  margin: var(--s-3) auto;
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--paper);
}
.sp-queue-table thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-faint);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}
.sp-queue-table tbody td {
  padding: var(--s-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.sp-queue-table tbody tr:last-child td { border-bottom: none; }
.sp-queue-num { text-align: right; font-variant-numeric: tabular-nums; }
.sp-queue-row { cursor: pointer; transition: background 100ms ease-out; }
.sp-queue-row:hover { background: var(--surface-2); }
.sp-queue-row:focus-visible {
  outline: 2px solid var(--color-blue-600);
  outline-offset: -2px;
  background: var(--color-blue-50);
}
.sp-queue-inventory { color: var(--fg-muted); font-size: 13px; max-width: 320px; }

/* ============================================================================
   Status + approval badges — tinted treatment, square 4px, Title Case.
   STATIC (no border, no chevron) per foundations/status-colors.md: the label
   carries the meaning, color is the redundant channel (P-1).
   ============================================================================ */
.sp-badge-group { display: inline-flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.sp-status,
.sp-status-badge,
.sp-approval-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px var(--s-2);
  border-radius: var(--r-pill);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Lifecycle status */
.sp-status-pending_format    { background: var(--color-warning-bg); color: var(--color-warning-text); }
.sp-status-drafting          { background: var(--surface-2);        color: var(--fg-muted); }
.sp-status-submitted         { background: var(--color-info-bg);    color: var(--color-info-text); }
.sp-status-finalized         { background: var(--surface-2);        color: var(--fg-muted); }
.sp-status-failed            { background: var(--color-danger-bg);  color: var(--color-danger-text); }
.sp-status-legacy_submitted  { background: var(--surface-2);        color: var(--fg-muted); }
.sp-status-legacy_formatting { background: var(--color-warning-bg); color: var(--color-warning-text); }

/* Approval status */
.sp-approval-unknown      { background: var(--surface-2);        color: var(--fg-muted); }
.sp-approval-not_required { background: var(--color-info-bg);    color: var(--color-info-text); }
.sp-approval-pending      { background: var(--color-warning-bg); color: var(--color-warning-text); }
.sp-approval-approved     { background: var(--color-success-bg); color: var(--color-success-text); }
.sp-approval-denied       { background: var(--color-danger-bg);  color: var(--color-danger-text); }

/* ============================================================================
   Legacy SEF sessions list + chat-reply (kept for any old surfaces; retoned).
   ============================================================================ */
.sef-sessions-container { max-width: min(1280px, calc(100vw - 64px)); margin: 0 auto; }
.sef-sessions-table { width: 100%; background: var(--paper); border-collapse: collapse; font-size: 14px; }
.sef-sessions-table th {
  text-align: left; padding: var(--s-3); font-family: var(--font-mono);
  font-size: 11px; font-weight: 700; color: var(--fg-faint);
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.sef-sessions-table td { padding: var(--s-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.sef-sessions-table tr:last-child td { border-bottom: none; }
.sef-sessions-date { white-space: nowrap; color: var(--fg-muted); font-size: 13px; }
.sef-sessions-draft { color: var(--fg); max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sef-sessions-turns { text-align: center; color: var(--fg-muted); }
.sef-sessions-user { color: var(--fg-muted); font-size: 13px; }
.sef-sessions-actions { white-space: nowrap; display: flex; align-items: center; gap: var(--s-1); justify-content: flex-end; font-size: 13px; }
.sef-sessions-retention { font-size: 12px; color: var(--fg-faint); margin-top: var(--s-4); text-align: center; }
.sef-sessions-empty { text-align: center; padding: 3rem var(--s-4); color: var(--fg-faint); font-size: 14px; }
.sef-session-meta { font-size: 12px; color: var(--fg-faint); }

.sef-chat-reply { padding: var(--s-2) var(--s-3); border-top: 1px solid var(--border); }
.sef-chat-reply-form { display: flex; flex-direction: column; gap: var(--s-1); }
.sef-chat-reply-textarea {
  display: block; width: 100%; padding: var(--s-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-input);
  font-family: var(--font-sans); font-size: 13px; color: var(--fg);
  background: var(--paper); resize: none; overflow: hidden; min-height: 2.5rem; line-height: 1.5;
}
.sef-chat-reply-textarea:focus { outline: none; border-color: var(--color-blue-600); box-shadow: 0 0 0 2px var(--color-blue-200) inset; }
.sef-chat-reply-textarea::placeholder { color: var(--fg-faint); }
.sef-chat-reply-footer { display: flex; justify-content: flex-end; }
.sef-chat-reply-btn { background: var(--paper); border: 1px solid var(--border-strong); border-radius: var(--r-input); color: var(--fg); font-size: 12px; padding: var(--s-1) var(--s-3); cursor: pointer; }
.sef-chat-reply-btn:hover { background: var(--surface-2); }

/* ============================================================================
   New / lockout form (/new + email-ingestion lockout) — single-column create
   surface: intro, draft editor (paste box), full-width account search, Save.
   Same layout as the legacy page, with canon chrome.
   ============================================================================ */
.sef-new-form-container {
  max-width: min(1100px, calc(100vw - 64px));
  margin: var(--s-4) auto 0;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--sh-card, 0 1px 3px rgba(15, 23, 42, 0.06));
  padding: var(--s-5);
}

/* Here the draft editor is a fixed paste box, not the pane-filling show editor —
   override the doc-pane fill rules (which force flex through <ckeditor-component>). */
.sef-new-form-container .sef-draft-editor { flex: none; min-height: 0; margin: 0 0 var(--s-4); display: block; }
.sef-new-form-container .sef-draft-editor ckeditor-component,
.sef-new-form-container .sef-draft-editor ckeditor-component > .ck.ck-editor { display: block !important; flex: none; }
.sef-new-form-container .sef-draft-editor .ck-editor__editable { min-height: 320px; }

.sef-account-change { background: none; border: none; font-family: var(--font-mono); font-size: 10.5px; color: var(--color-blue-700); cursor: pointer; padding: 0; }

/* ===== Help page (sef-reader) ============================================
   Reader treatment for the module help page — ported from the canonical
   ae-reader pattern (audience_evaluation.css), tokens throughout. */
.sef-reader { max-width: 820px; margin: 0 auto; padding: 4px 0 64px; }
.sef-reader-head { margin-bottom: 18px; }
.sef-reader-prefix { font-family: var(--font-mono); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--fg-muted); margin-bottom: 4px; }
.sef-reader-name { font-size: 22px; font-weight: 700; color: var(--fg); margin: 0 0 2px; }
.sef-reader-sub { font-size: 13px; color: var(--fg-muted); }
.sef-reader-lead { font-size: 15px; line-height: 1.6; color: var(--fg); margin: 0; }
.sef-reader-section { border-top: 1px solid var(--border); margin-top: 22px; padding-top: 18px; }
.sef-reader-section h2 {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--fg-muted); margin: 0 0 11px;
}
.sef-reader-section p { font-size: 14px; line-height: 1.65; color: var(--fg); margin: 0 0 10px; }
.sef-reader-section p:last-child { margin-bottom: 0; }
.sef-reader-bullets { margin: 0 0 10px; padding-left: 18px; list-style: disc outside; }
.sef-reader-bullets li { font-size: 14px; line-height: 1.6; color: var(--fg); margin-bottom: 7px; }
.sef-reader-bullets li:last-child { margin-bottom: 0; }
.sef-reader-section strong { font-weight: 600; }
.sef-reader-section code { background: var(--surface-2); padding: 1px 5px; border-radius: var(--r-input); font-family: var(--font-mono); font-size: 12px; }

/* Quick-start callout — info-accented lead block */
.sef-reader-quickstart {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--color-info-icon);
  border-radius: var(--r-card); padding: 14px 18px; margin: 18px 0 6px;
}
.sef-reader-quickstart h2 {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--color-info-text); margin: 0 0 9px;
}
.sef-reader-quickstart ol { margin: 0; padding-left: 18px; list-style: decimal outside; }
.sef-reader-quickstart ol li { font-size: 14px; line-height: 1.6; color: var(--fg); margin-bottom: 4px; }
.sef-reader-quickstart ol li:last-child { margin-bottom: 0; }

/* Inline copy-to-clipboard next to a code chip (clipboard_controller.js) */
.sef-copy-inline { display: inline-flex; align-items: center; gap: 4px; }
.sef-copy-inline-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 4px;
  border: 1px solid transparent; background: transparent; color: var(--fg-muted);
  border-radius: var(--r-input); cursor: pointer; font-size: 12px; line-height: 1;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sef-copy-inline-btn:hover { color: var(--color-info-text); background: var(--color-info-bg); border-color: var(--color-info-border); }
.sef-copy-inline-btn.is-copied { color: var(--color-success-text); background: var(--color-success-bg); border-color: var(--color-success-border); }
