/**
 * Agent UI — Right-edge slide-in chat panel.
 *
 * Stream 4 — replaces the pre-Stream-4 centred floating pill with a Linear /
 * Intercom-style panel that slides in from the right edge. Two states:
 *   data-state="closed"  → fully off-screen, no chrome
 *   data-state="open"    → on-screen, 360px wide (desktop), full-screen <640px
 *
 * Uses tokens from global.css / broker-portal.css. Zero hard-coded brand colours.
 */

/* ==========================================================================
   Backdrop — visible only when panel is OPEN, on tablet/mobile only.
   On desktop ≥1280px the panel doesn't need a backdrop because content
   underneath stays visible and click-outside-to-close is the only ergonomic.
   ========================================================================== */

.agent-ui-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--agent-ui-z, 900) - 1);
  background: rgba(11, 22, 54, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.agent-ui-backdrop[data-state="open"] {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 1280px) {
  .agent-ui-backdrop {
    /* Desktop pushes content rather than overlays — no backdrop ever. */
    display: none;
  }
}

/* ==========================================================================
   Panel root — slide-in from the right edge.
   ========================================================================== */

.agent-ui {
  /* Accent the whole panel off one variable so the broker portal can flip the
     entire surface pink→navy on a Frankie→underwriter handoff (item 22) without
     touching every rule. Defaults to the existing pink → zero change for the
     staff QuoteApp/Lead panels. */
  --agent-ui-accent: var(--bp-accent, #e6007e);
  --agent-ui-accent-hover: var(--bp-accent-hover, var(--fta-pink-hover, #c40069));
  --agent-ui-accent-ring: rgba(232, 6, 140, 0.12);
  --agent-ui-accent-subtle: var(--bp-accent-subtle, rgba(232, 6, 140, 0.08));
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100vw;
  z-index: var(--agent-ui-z, 900);
  display: flex;
  flex-direction: column;
  background: var(--body-surface, #fff);
  border-left: 1px solid var(--body-border, var(--bp-border, #e5e7eb));
  box-shadow: -16px 0 40px -16px rgba(11, 22, 54, 0.12);
  transform: translateX(100%);
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--body-text, var(--bp-text, #0a192f));
  visibility: hidden;
}

.agent-ui[data-state="open"] {
  transform: translateX(0);
  visibility: visible;
}

/* Mid-range — slightly wider on big tablets / small desktops. */
@media (min-width: 768px) {
  .agent-ui {
    width: 400px;
  }
}

/* Mobile — full-screen takeover so the keyboard has room. */
@media (max-width: 639px) {
  .agent-ui {
    width: 100vw;
    border-left: 0;
  }
}

/* ==========================================================================
   Header — sticky top, title + actions.
   ========================================================================== */

.agent-ui-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-md);
  border-bottom: 1px solid var(--body-border, var(--bp-border, #e5e7eb));
  background: var(--body-surface, #fff);
}

.agent-ui-title {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--body-text, var(--bp-text, #0a192f));
}

.agent-ui-header-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

/* Item 9 — "AI" badge by the Frankie name + a one-line AI disclosure under the
   header. Broker-only (added in agent-ui.js when cfg.isBroker). */
.agent-ui-ai-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: var(--bp-radius-full, 9999px);
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: var(--fta-pink, #e6007e);
  line-height: 1.4;
}

.agent-ui-ai-disclosure {
  padding: 6px var(--space-md);
  font-size: 0.6875rem;
  line-height: 1.35;
  color: var(--body-text-muted, var(--bp-text-muted, #6b7280));
  background: var(--bp-accent-subtle, rgba(230, 0, 126, 0.06));
  border-bottom: 1px solid var(--body-border, var(--bp-border, #e5e7eb));
}

.agent-ui-new-chat-btn,
.agent-ui-close-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--bp-radius-sm, 6px);
  padding: 6px var(--space-sm);
  color: var(--bp-text-muted, #6b7280);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.8125rem;
  transition: background 150ms;
}

.agent-ui-new-chat-btn:hover,
.agent-ui-close-btn:hover {
  background: var(--bp-surface-hover, var(--body-surface-alt, #f4f6f8));
  color: var(--bp-text, #0a192f);
}

.agent-ui-close-btn {
  padding: 6px;
}

/* ==========================================================================
   Body — scrolling messages + thinking indicator.
   ========================================================================== */

.agent-ui-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.agent-ui-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.agent-ui-msg {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
}

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

.agent-ui-msg-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--bp-radius-full, 9999px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--agent-ui-accent-subtle);
}

.agent-ui-msg-bubble {
  max-width: 85%;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--bp-radius-lg, 12px);
  font-size: 0.875rem;
  line-height: 1.55;
}

.agent-ui-msg--user .agent-ui-msg-bubble {
  background: var(--agent-ui-accent);
  color: #fff;
  border-bottom-right-radius: var(--bp-radius-sm, 6px);
}

.agent-ui-msg--ai .agent-ui-msg-bubble {
  background: var(--body-surface-alt, var(--bp-surface-muted, #f4f6f8));
  color: var(--body-text, var(--bp-text, #0a192f));
  border-bottom-left-radius: var(--bp-radius-sm, 6px);
}

.agent-ui-msg-content code {
  background: rgba(11, 22, 54, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--bp-font-mono, ui-monospace, monospace);
  font-size: 0.85em;
}

/* Report-card embed (Iris reports etc.) */
.agent-ui-report-card {
  margin: var(--space-sm) 0;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--bp-border, #e5e7eb);
  border-radius: var(--bp-radius, 10px);
  background: var(--body-surface, #fff);
}
.agent-ui-report-card a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  text-decoration: none;
  color: var(--bp-text, #0a192f);
}
.agent-ui-report-card a span {
  color: var(--bp-accent, #e6007e);
  font-size: 0.8125rem;
}

/* ── Thinking spinner ── */
.agent-ui-thinking {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-md) var(--space-sm);
  font-size: 0.8125rem;
  color: var(--bp-text-muted, #6b7280);
}
/* `display:flex` (specificity 0,1,0) beats the UA `[hidden]{display:none}`,
 * so hideThinking()'s `el.hidden = true` left the "Thinking…" spinner
 * permanently visible after the answer resolved (BUG-22 — same trap as the
 * stuck record skeleton). Restore the hidden contract explicitly. */
.agent-ui-thinking[hidden] {
  display: none;
}

.agent-ui-thinking-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bp-border, #e5e7eb);
  border-top-color: var(--agent-ui-accent);
  animation: agent-ui-spin 700ms linear infinite;
}

@keyframes agent-ui-spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   Footer / input — suggestion chips + textarea + send.
   ========================================================================== */

.agent-ui-input {
  border-top: 1px solid var(--body-border, var(--bp-border, #e5e7eb));
  padding: var(--space-sm) var(--space-md) var(--space-md);
  background: var(--body-surface, #fff);
}

/* Persistent "hand to a human" button above the input (broker surface only).
   Navy register so it reads as the human/underwriter channel, distinct from
   Frankie's pink. */
.agent-ui-divert-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-bottom: var(--space-sm);
  padding: 8px 12px;
  border: 1px solid var(--bp-navy, #0a192f);
  border-radius: 8px;
  background: var(--bp-navy, #0a192f);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.agent-ui-divert-btn:hover { opacity: 0.9; }
.agent-ui-divert-btn:disabled { opacity: 0.5; cursor: default; }

.agent-ui-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding-bottom: var(--space-sm);
}

.agent-ui-suggestion-chip {
  background: var(--body-surface-alt, var(--bp-surface-muted, #f4f6f8));
  border: 1px solid var(--bp-border, #e5e7eb);
  border-radius: var(--bp-radius-full, 9999px);
  padding: 6px var(--space-md);
  font: inherit;
  font-size: 0.75rem;
  color: var(--bp-text, #0a192f);
  cursor: pointer;
  transition: background 150ms, border-color 150ms;
}

.agent-ui-suggestion-chip:hover {
  background: var(--body-surface, #fff);
  border-color: var(--bp-border-strong, var(--bp-text-muted, #6b7280));
}

.agent-ui-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  background: var(--body-surface, #fff);
  border: 1px solid var(--bp-border, #e5e7eb);
  border-radius: var(--bp-radius, 10px);
  padding: var(--space-xs);
  transition: border-color 150ms, box-shadow 150ms;
}

.agent-ui-input-wrap:focus-within {
  border-color: var(--agent-ui-accent);
  box-shadow: 0 0 0 3px var(--agent-ui-accent-ring);
}

.agent-ui-textarea {
  flex: 1;
  min-height: 32px;
  max-height: 140px;
  resize: none;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.875rem;
  color: var(--body-text, var(--bp-text, #0a192f));
  outline: none;
  padding: 6px var(--space-sm);
}

.agent-ui-textarea::placeholder {
  color: var(--bp-text-placeholder, #c0c5ce);
}

.agent-ui-send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--bp-radius, 10px);
  background: var(--agent-ui-accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms;
}

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

/* ==========================================================================
   Field-flash animation — used by handleToolResult when Weaver mutates
   a quote-editor field. Pulses pink for 2.5s then fades back.
   ========================================================================== */

.agent-ui-field-flash {
  animation: agent-ui-flash 2.5s ease-out;
}

@keyframes agent-ui-flash {
  0%   { box-shadow: 0 0 0 2px rgba(232, 6, 140, 0.5); border-color: #e6007e; }
  20%  { box-shadow: 0 0 0 3px rgba(232, 6, 140, 0.3); }
  100% { box-shadow: 0 0 0 0 rgba(232, 6, 140, 0); border-color: transparent; }
}

/* ==========================================================================
   Toast — agent shows "record updated" / similar notifications outside
   the panel chrome. Bottom-centred, slides up.
   ========================================================================== */

.agent-ui-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fta-navy, #0a192f);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--bp-radius, 10px);
  font-size: 0.8125rem;
  z-index: calc(var(--agent-ui-z, 900) + 5);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 300ms;
}

/* NOTE: broker-only Frankie-panel styling (drawer parity, pink→navy handoff,
   rich-text list markers) lives in broker-portal.css — NOT here — so it ships
   only on broker pages and stays off this global stylesheet's critical-path
   byte budget. See the "Workstream E — Frankie panel" block there. */

