/*
 * Smart-Intake v2 — in-SPA view (S2). Ported from the standalone page's inline styles and
 * SCOPED under `.si-view` so nothing leaks into the editor/dashboard (and the SPA's global
 * button/typography rules don't bleed in). One continuous chat: draft → questions → report.
 * Final visual design is a later pass; this re-houses the proven standalone layout.
 */
.si-view {
  --si-primary: var(--color-primary);
  --si-primary-d: var(--legacy-1d4ed8);
  --si-ok: var(--legacy-10b981);
  --si-muted: var(--legacy-6b7280);
  --si-line: var(--legacy-e5e7eb);
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 16px 96px;
  color: var(--legacy-1f2937);
  box-sizing: border-box;
}
.si-view *, .si-view *::before, .si-view *::after { box-sizing: border-box; }

.si-view .si-topbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
}
.si-view .si-back {
  background: transparent; border: none; color: var(--si-muted); cursor: pointer;
  font: inherit; padding: 6px 8px; border-radius: 8px;
}
.si-view .si-back:hover { background: var(--legacy-f1f5f9); }
.si-view .si-title { font-size: 1.1rem; color: var(--legacy-374151); margin: 0; font-weight: 600; }

.si-view button {
  font: inherit; cursor: pointer; border: none; border-radius: 8px; padding: 10px 18px;
  background: var(--legacy-eef2ff); color: var(--legacy-1e3a8a);
}
.si-view button.primary { background: var(--brand); color: var(--legacy-fff); }
.si-view button.copied { background: var(--brand); color: var(--legacy-fff); }
.si-view button.skip { background: transparent; color: var(--si-muted); padding: 6px 10px; }
.si-view button:hover { filter: brightness(.97); }
.si-view button:disabled { opacity: .5; cursor: not-allowed; filter: none; }

/* Coarse progress header — slim, sticky above the chat; deliberately approximate ("~"). */
.si-view .si-progress {
  position: sticky; top: 0; z-index: 5; text-align: center;
  padding: 7px 12px; margin: 6px 0; border-radius: 8px; font-size: .85rem; font-weight: 600;
  background: var(--legacy-eef2ff); color: var(--legacy-1e40af); border: 1px solid var(--legacy-dbeafe);
}
.si-view .si-progress.ok { background: var(--legacy-ecfdf5); color: var(--legacy-065f46); border-color: var(--legacy-a7f3d0); }

/* Chat transcript — grows with the page so the whole conversation is visible/screenshot-able. */
.si-view .si-chat { display: flex; flex-direction: column; gap: 10px; min-height: 40vh; padding: 10px 2px; }
/* Leave room under the sticky progress header when a scroll/focus lands on an element. */
.si-view .bubble, .si-view .chat-actions, .si-view .review-panel, .si-view .report-card,
.si-view .auto-flags { scroll-margin-top: 64px; }
.si-view .review-panel:focus, .si-view .report-card:focus { outline: none; }
.si-view .bubble {
  max-width: 82%; padding: 11px 14px; border-radius: 16px; line-height: 1.5; white-space: pre-wrap;
  animation: si-rise .18s ease-out;
}
@keyframes si-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.si-view .bubble.ai { align-self: flex-start; background: var(--legacy-fff); border: 1px solid var(--si-line); border-bottom-left-radius: 5px; }
.si-view .bubble.you {
  align-self: flex-end; color: var(--legacy-fff); border-bottom-right-radius: 5px;
  background: var(--brand);
}
.si-view .bubble.typing { display: flex; gap: 5px; align-items: center; }
.si-view .bubble.typing .tlabel { font-style: normal; color: var(--si-muted); }
.si-view .bubble.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--si-muted); animation: si-blink 1.2s infinite both; }
.si-view .bubble.typing span:nth-child(2) { animation-delay: .2s; }
.si-view .bubble.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes si-blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.si-view .chat-actions { align-self: flex-start; margin-top: 4px; }

/* End-of-conversation summary — readable blocks + bullet lists. */
.si-view .bubble.summary { max-width: 88%; }
.si-view .bubble.summary p { margin: 0; }
.si-view .bubble.summary .sum-block { margin-top: 11px; }
.si-view .bubble.summary .sum-block strong { display: block; margin-bottom: 3px; }
.si-view .bubble.summary ul { margin: 0; padding-left: 20px; }
.si-view .bubble.summary li { margin: 4px 0; line-height: 1.45; }
.si-view .bubble.summary .warn-block strong { color: var(--legacy-92400e); }
.si-view .bubble.summary .warn-block li { color: var(--legacy-7c2d12); }
.si-view .bubble.summary .sum-cta { margin-top: 13px; }

/* The generated report — a distinct card with its own actions. */
.si-view .report-card {
  align-self: stretch; background: var(--legacy-fff); border: 1px solid var(--si-line); border-radius: 14px;
  padding: 16px 18px; margin: 6px 0; box-shadow: var(--shadow-1);
}
.si-view .report-text { white-space: pre-wrap; line-height: 1.55; }
.si-view .report-edit-area {
  width: 100%; min-height: 240px; box-sizing: border-box; resize: vertical;
  font: inherit; line-height: 1.55; color: inherit;
  border: 1px solid var(--si-line); border-radius: 10px; padding: 12px 14px;
}
.si-view .report-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* Composer */
.si-view .si-composer { margin-top: 14px; border-top: 1px solid var(--si-line); padding-top: 12px; }
.si-view .si-composer textarea {
  width: 100%; padding: 12px 12px 28px; border: 2px solid var(--si-line); border-radius: 10px; font: inherit;
  resize: none; overflow-y: auto; max-height: 240px;
}
.si-view .si-composer textarea:focus { outline: none; border-color: var(--si-primary); box-shadow: 0 0 0 4px rgba(15,107,98, .12); }
.si-view .si-composer textarea.attention { border-color: var(--legacy-ef4444); animation: si-shake .3s ease-in-out; }
@keyframes si-shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Example teaser — collapsed to 3 lines, expands inline on click (never fills the textarea). */
.si-view .si-example {
  border: 1px dashed var(--legacy-d1d5db); background: var(--legacy-f9fafb); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px;
}
.si-view .si-example-toggle {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px;
  background: transparent; border: none; padding: 0; border-radius: 0; cursor: pointer;
}
.si-view .si-example-toggle:hover { filter: none; }
.si-view .si-example-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--si-muted);
}
.si-view .si-example-more { font-size: .78rem; color: var(--si-primary); white-space: nowrap; }
.si-view .si-example-text {
  margin-top: 6px; font-style: italic; color: var(--si-muted); font-size: .88rem;
  line-height: 1.5; white-space: pre-wrap; cursor: pointer;
}
.si-view .si-example-text.collapsed {
  display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
}

/* Char counter — bottom-right inside the textarea; amber ≥90%, red at the limit. */
.si-view .si-input-wrap { position: relative; }
.si-view .si-counter {
  position: absolute; right: 10px; bottom: 8px; pointer-events: none;
  font-size: .75rem; color: var(--legacy-9ca3af); background: rgba(255, 255, 255, .85);
  padding: 1px 6px; border-radius: 6px;
}
.si-view .si-counter.warn { color: var(--legacy-b45309); font-weight: 600; }
.si-view .si-counter.max { color: var(--legacy-ef4444); font-weight: 700; }

/* Inline composer feedback (empty submit, char limit) — no alert(). */
.si-view .si-inline-note {
  margin-top: 6px; padding: 7px 10px; border-radius: 8px; font-size: .84rem; line-height: 1.4;
  background: var(--legacy-fffbeb); color: var(--legacy-92400e); border: 1px solid var(--legacy-fde68a);
}
/* Item 1.2 quick-reply chips — one tap resolves the asked batch without typing. Sit ABOVE the
   input (the spot users reach for first), so the margin now spaces them from the textarea below. */
.si-view .si-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
.si-view .si-chips[hidden] { display: none; }
.si-view button.si-chip {
  background: var(--legacy-f1f5f9); color: var(--legacy-334155); border: 1px solid var(--legacy-cbd5e1);
  border-radius: 999px; padding: 5px 12px; font-size: .82rem; font-weight: 600;
}
.si-view button.si-chip:hover { background: var(--legacy-e2e8f0); filter: none; }

.si-view .composer-actions { display: flex; gap: 10px; margin-top: 8px; align-items: center; }
.si-view .composer-actions .grow { flex: 1; }
.si-view .composer-actions .hint { color: var(--si-muted); font-size: .8rem; }

/* Error bar — dismissible red strip above the chat (network/API failures). */
.si-view .si-error-bar {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--legacy-fef2f2); color: var(--legacy-991b1b); border: 1px solid var(--legacy-fecaca);
  border-radius: 8px; padding: 9px 12px; margin: 6px 0; font-size: .9rem; line-height: 1.4;
}
.si-view .si-error-bar[hidden] { display: none; }
.si-view .si-error-bar .x { margin-left: auto; cursor: pointer; padding: 0 4px; }

/* Connection-loss banner — persistent (no dismiss), slate; auto-hides on reconnect-reconcile. */
.si-view .si-offline {
  background: var(--legacy-f1f5f9); color: var(--legacy-334155); border: 1px solid var(--legacy-cbd5e1);
  border-radius: 8px; padding: 9px 12px; margin: 6px 0; font-size: .9rem; line-height: 1.4;
}
.si-view .si-offline[hidden] { display: none; }

/* Degraded-mode banner (D) — calm amber, dismissible, auto-hides when service recovers. */
.si-view .si-degraded {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--legacy-fffbeb); color: var(--legacy-92400e); border: 1px solid var(--legacy-fde68a);
  border-radius: 8px; padding: 9px 12px; margin: 6px 0; font-size: .9rem; line-height: 1.4;
}
.si-view .si-degraded[hidden] { display: none; }
.si-view .si-degraded-x {
  margin-left: auto; flex: none; background: transparent; color: var(--legacy-92400e);
  padding: 0 4px; border-radius: 4px; line-height: 1.4;
}

/* Review gate (B + C) — checklist of defense-exploitable points + human sign-off.
   Deliberately calm: informative card, not an alarm. */
.si-view .review-panel {
  align-self: stretch; background: var(--legacy-fff); border: 1px solid var(--si-line);
  border-radius: 14px; padding: 14px 16px; margin: 6px 0;
}
.si-view .review-panel .review-head { margin: 0 0 8px; font-weight: 600; color: var(--legacy-374151); }
.si-view .review-warn {
  background: var(--legacy-fffbeb); border: 1px solid var(--legacy-fde68a); border-radius: 10px; padding: 10px 12px;
}
.si-view .review-warn .review-head { color: var(--legacy-92400e); }
.si-view .review-item {
  display: flex; gap: 9px; align-items: flex-start; margin: 7px 0;
  cursor: pointer; line-height: 1.45; color: var(--legacy-7c2d12);
}
.si-view .review-item input { margin: 3px 0 0; flex: none; accent-color: var(--legacy-b45309); }
.si-view .review-uncaptured { margin-top: 12px; }
.si-view .review-uncaptured ul { margin: 0; padding-left: 20px; color: var(--si-muted); }
.si-view .review-uncaptured li { margin: 3px 0; line-height: 1.45; }
/* Automatic safety net made visible — re-reader + identifier + negation guards (advisory). */
.si-view .auto-flags {
  align-self: stretch; background: var(--legacy-fffbeb); border: 1px solid var(--legacy-fde68a); border-radius: 12px;
  padding: 12px 14px; margin: 8px 0; color: var(--legacy-92400e);
}
.si-view .auto-flags-head { margin: 0 0 6px; font-weight: 600; }
.si-view .auto-flags ul { margin: 0; padding-left: 20px; }
.si-view .auto-flags li { margin: 4px 0; line-height: 1.45; }
.si-view .signoff-item {
  display: flex; gap: 9px; align-items: flex-start; margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--si-line); cursor: pointer; line-height: 1.45; color: var(--legacy-374151);
}
.si-view .signoff-item input { margin: 3px 0 0; flex: none; accent-color: var(--si-primary); }

/* Why-is-copy-locked note, next to the report actions. */
.si-view .copy-gate-note { font-size: .84rem; color: var(--si-muted); align-self: center; }
.si-view .copy-gate-note[hidden] { display: none; }

/* Test-export row (bottom of the view). */
.si-view .si-export-row { margin-top: 10px; text-align: right; }
.si-view .si-export { background: transparent; color: var(--si-muted); font-size: .85rem; padding: 6px 8px; }

/* Respect prefers-reduced-motion: kill the bubble rise, typing blink, shake (JS scrolls already
   switch to 'auto' via _motion()). */
@media (prefers-reduced-motion: reduce) {
  .si-view *, .si-view *::before, .si-view *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
