/* The Help widget (support-chat.ts, markup in index.html): Robin, a panel
 * docked to the right edge from under the top bar to the bottom of the
 * viewport (#3455, Figma 1:18429 in 1:17731). It overlays the page, which does
 * not reflow; a bottom sheet on phones. Below the dialog (70) and view-as
 * banner (60) layers, above the page and the drawer scrim's content (so it
 * stays tappable) but under side panels (50). Values are Figma's unless a
 * comment says otherwise; dark is not in Figma and follows the tokens. */

/* The Help button is a <button> in the nav: same look as the nav links. */
.nav button {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-sm);
  background: none; font: inherit; font-weight: 500; color: var(--fg-muted); cursor: pointer; text-align: left;
}
.nav button:hover, .nav button[aria-expanded="true"] { background: var(--surface-sunken); color: var(--fg); }

/* A text-sized button that reads as a link (footer, inline "message the team"). */
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--primary-text); text-decoration: underline; cursor: pointer; }
.link-btn:disabled { color: var(--fg-muted); cursor: not-allowed; text-decoration: none; }
.link-btn:focus-visible, .sw-chip:focus-visible, .sw-jump:focus-visible, .sw-quick-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }

/* ---- The panel (1:18429): 320 wide, white, a left border and a soft drop shadow ---- */
.support-widget {
  --sw-width: 320px;
  --sw-shadow: 0 4px 3px rgba(0, 0, 0, 0.05), 0 2px 10px rgba(0, 0, 0, 0.05);
  position: fixed; z-index: 45; top: var(--topbar-height); right: 0; bottom: 0;
  box-sizing: border-box; width: min(var(--sw-width), 100vw);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); color: var(--fg); border: 0; border-left: 1px solid var(--border-strong);
  box-shadow: var(--sw-shadow); font-family: var(--font-sans);
  animation: sw-in var(--motion-slow) var(--ease-out);
}
.support-widget[hidden], .support-widget [hidden] { display: none; }
.support-widget:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
/* Closing (support-history.ts adds .sw-leaving, then hides the panel 150ms later). */
.support-widget.sw-leaving { animation: sw-out var(--motion-base) var(--ease-out) forwards; pointer-events: none; }
/* The view-as banner is fixed along the bottom edge: sit above it. */
body:has(.view-as-banner:not([hidden])) .support-widget { bottom: 56px; }
/* Expanded (not in Figma): the same docked panel, twice as wide. */
.support-widget.sw-expanded { --sw-width: 640px; }
@keyframes sw-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes sw-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(16px); } }
@keyframes sw-sheet-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes sw-sheet-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(16px); } }
@keyframes sw-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sw-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* ---- Header (1:18430): 60 tall, the sparkle tile, "Robin", the Online pill, then today's actions ---- */
.sw-head {
  flex: none; display: flex; align-items: center; gap: 0; box-sizing: border-box; height: 60px;
  padding: 0 var(--space-3) 0 var(--space-5); border-bottom: 1px solid var(--border-strong); background: var(--surface);
}
/* The tile is decorative (the name beside it says who this is): the sparkle on the brand, as drawn. */
.sw-badge { flex: none; margin-right: 10px; display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius); background: var(--brand); color: var(--ink-fg); }
.sw-badge svg { display: block; width: 15px; height: 15px; }
.sw-head h2 { flex: 0 1 auto; min-width: 0; margin: 0 10px 0 0; font: 700 16px/24px var(--font-sans); color: var(--fg-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sw-status {
  flex: none; display: inline-flex; align-items: center; gap: var(--space-1); margin: 0 var(--space-1) 0 auto; padding: 2px var(--space-2);
  border-radius: var(--radius-pill); background: var(--accent-tint); color: var(--live-text); font: var(--type-label); white-space: nowrap;
}
.sw-status-dot { width: 6px; height: 6px; border-radius: var(--radius-pill); background: var(--brand); }
/* Today's actions (back, clear, expand, minimize, close) are not in Figma; Q30 keeps them as ghost icon
   buttons after the pill. 24px (the issue says 28) so all five fit beside the pill in 320. */
.sw-head .btn-icon { flex: none; width: 24px; height: 24px; min-height: 24px; border-radius: var(--radius-md); color: var(--fg-muted); }
.sw-head .btn-icon svg { width: 14px; height: 14px; }
.sw-head .btn-icon:hover:not(:disabled) { background: var(--surface-sunken); color: var(--fg-strong); }

/* ---- Body (1:18440): padding 16, gap 20, scrolls ---- */
.sw-body { position: relative; flex: 1; min-height: 0; display: flex; }
.sw-log { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-5); padding: var(--space-4); scroll-behavior: auto; }
.sw-log:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.sw-row { display: flex; gap: var(--space-3); align-items: flex-start; max-width: 100%; animation: sw-bubble var(--motion-base) var(--ease-out); }
.sw-row.sw-user { justify-content: flex-end; }
.sw-col { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; max-width: calc(100% - 40px); }
.sw-col-user { align-items: flex-end; max-width: 86%; }
/* Robin's avatar (1:18442): 28 circle, the bot glyph at 12. */
.sw-av { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-pill); background: var(--surface-sunken); color: var(--fg-muted); }
.sw-av svg { display: block; width: 12px; height: 12px; }
/* Bubbles (1:18445): Robin's is the page tint, its top-left corner 2; the person's is dark, top-right 2 (the issue's). */
.sw-msg { box-sizing: border-box; padding: 9px 25px 10.6px 14px; border-radius: 2px var(--radius-2xl) var(--radius-2xl) var(--radius-2xl); font: 700 14px/22.75px var(--font-sans); overflow-wrap: anywhere; }
.sw-msg.sw-assistant { max-width: 244px; background: var(--bg); color: var(--fg-strong); }
.support-widget.sw-expanded .sw-msg.sw-assistant { max-width: 100%; }
.sw-msg.sw-user { max-width: 100%; padding: 9px 14px 10.6px; white-space: pre-wrap; border-radius: var(--radius-2xl) 2px var(--radius-2xl) var(--radius-2xl); background: var(--sidebar-bg); color: var(--sidebar-fg); border: 1px solid var(--sidebar-hover); font-weight: 400; }
/* Answers are prose: the welcome is bold as drawn, longer answers read at regular weight. */
.sw-msg.sw-assistant p, .sw-msg.sw-assistant li { font-weight: 400; }
.sw-log > .sw-row:first-child .sw-msg.sw-assistant p { font-weight: 700; }
.sw-msg p { margin: 0; } .sw-msg p + p, .sw-msg ul, .sw-msg ol { margin-top: var(--space-2); }
.sw-msg ul, .sw-msg ol { margin-bottom: 0; padding-left: var(--space-5); }
.sw-msg li + li { margin-top: var(--space-1); }
.sw-msg ol { list-style: none; counter-reset: sw-step; padding-left: 0; }
.sw-msg ol > li { counter-increment: sw-step; position: relative; padding-left: 28px; }
.sw-msg ol > li::before {
  content: counter(sw-step); position: absolute; left: 0; top: 0.2em; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font: var(--type-label); background: var(--primary); color: var(--primary-fg);
}
.sw-msg code { font-family: var(--font-mono); font-size: 0.88em; padding: 1px 5px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border-strong); }
.sw-msg a { color: var(--primary-text); text-decoration: underline; text-underline-offset: 2px; }
.sw-msg a:hover { text-decoration-thickness: 2px; }
.sw-time { display: block; font: var(--type-meta); color: var(--fg-muted); }

/* ---- Quick actions (1:18447): the eyebrow, then full-width outlined buttons ---- */
.sw-quick { display: flex; flex-direction: column; gap: var(--space-2); }
/* Figma's #9ca3af is 2.5:1 on white: the muted token (7:1) instead. */
.sw-quick-title { margin: 0; padding: 0 var(--space-1); font: 700 12px/16px var(--font-sans); letter-spacing: 0.3px; text-transform: uppercase; color: var(--fg-muted); }
.sw-quick-btn {
  display: flex; align-items: center; gap: var(--space-3); box-sizing: border-box; width: 100%; padding: 11px 13px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--fg-secondary);
  font: 700 14px/20px var(--font-sans); text-align: left; cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out);
}
.sw-quick-btn svg { flex: none; width: 14px; height: 14px; color: var(--fg-muted); }
/* Hover (not in Figma; the issue's): the page tint and the control border. */
.sw-quick-btn:hover { background: var(--bg); border-color: var(--border-control); }

/* Guide buttons and the escalation / receipt cards (not in Figma): the same outline and radius. */
.sw-nav { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.sw-offer:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sw-offer { padding: var(--space-3); border: 1px solid var(--border-strong); border-left: 3px solid var(--brand); border-radius: var(--radius); background: var(--surface); font: var(--type-body); color: var(--fg-strong); }
.sw-offer p { margin: 0; } .sw-offer-title { font-weight: 700; } .sw-offer-sum { margin-top: var(--space-1) !important; }
.sw-offer-fine { margin-top: var(--space-1) !important; color: var(--fg-muted); font: var(--type-meta); }
.sw-offer-btns { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.sw-offer-btns:empty { display: none; }

/* Typing (not in Figma): three dots in Robin's bubble. */
.sw-thinking .sw-msg { padding: 9px 14px 10.6px; }
.sw-dots { display: inline-flex; gap: 4px; align-items: center; height: 22.75px; }
.sw-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-muted); animation: sw-bounce 1.2s infinite var(--ease-standard); }
.sw-dots i:nth-child(2) { animation-delay: 0.15s; } .sw-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes sw-bounce { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes sw-bubble { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.sw-jump {
  position: absolute; left: 50%; bottom: var(--space-3); transform: translateX(-50%); z-index: 1;
  font: 700 12px/16px var(--font-sans); padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--fg-strong); box-shadow: var(--sw-shadow);
}
.sw-jump:hover { background: var(--bg); }

/* Page-aware starter questions (not in Figma, kept): small outlined chips over the composer. */
.sw-chips { flex: none; display: flex; flex-wrap: wrap; gap: var(--space-2); padding: 0 var(--space-4) var(--space-3); }
.sw-chips:empty { display: none; }
.sw-chip {
  max-width: 100%; padding: var(--space-1) 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--fg-secondary); font: 400 12px/16px var(--font-sans); text-align: left; cursor: pointer;
}
.sw-chip:hover:not(:disabled) { background: var(--bg); border-color: var(--border-control); }
.sw-chip:disabled { opacity: 0.6; cursor: default; }

.sw-banner { flex: none; margin: 0 var(--space-4) var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--danger-bg); color: var(--danger-fg); font: var(--type-body); }
.sw-banner p { margin: 0; }
.sw-banner-btns { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.sw-banner a { color: inherit; text-decoration: underline; }
.sw-note { flex: none; margin: 0; padding: 0 var(--space-4) var(--space-3); font: var(--type-body); color: var(--fg-muted); }
.sw-note:empty { display: none; }

/* ---- Composer (1:18473): attach, the input, the send ---- */
.sw-form { flex: none; display: flex; align-items: flex-end; gap: var(--space-2); padding: 13px var(--space-3) var(--space-3); border-top: 1px solid var(--border-strong); background: var(--surface); }
.sw-field { position: relative; flex: 1; min-width: 0; display: flex; }
.sw-form textarea, .sw-compose textarea {
  flex: 1; min-width: 0; width: 100%; box-sizing: border-box; resize: none;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--fg-strong);
  font: 400 14px/17px var(--font-sans);
}
.sw-form textarea { min-height: 38px; max-height: 9.5em; padding: 10px 13px; overflow-y: auto; }
.sw-compose textarea { padding: var(--space-2) var(--space-3); line-height: 20px; }
/* Figma's placeholder #9ca3af is 2.5:1 on white: the muted token, as the design system's inputs do. */
.sw-form textarea::placeholder, .sw-compose textarea::placeholder { color: var(--fg-muted); opacity: 1; font-weight: 700; }
.sw-compose textarea::placeholder { font-weight: 400; }
.sw-form textarea:focus-visible, .sw-compose textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--brand); }
.sw-form textarea:disabled, .sw-compose textarea:disabled { opacity: 0.6; }
.sw-count { position: absolute; right: var(--space-2); top: -1.4em; font: var(--type-meta); color: var(--fg-muted); }
.sw-count-max { color: var(--danger-fg); font-weight: 700; }
/* Attach (1:18474): 22 x 36, outlined; disabled today, as before. */
.sw-form .sw-attach {
  flex: none; width: 22px; height: 36px; min-height: 36px; padding: 0; margin-bottom: 1px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--fg-muted);
}
.sw-form .sw-attach svg { width: 12px; height: 13px; }
.sw-form .sw-attach:disabled { opacity: 1; cursor: not-allowed; }
/* Send (1:18480): 39 x 36, filled. Figma's #10b981 under a white glyph is 2.5:1 (under 3:1 for a
   control's graphic): --primary instead (white on #047857, 5.5:1; dark: the brand under a dark glyph). */
.sw-form [data-sw-send] {
  flex: none; width: 39px; height: 36px; min-height: 36px; padding: 0; margin-bottom: 1px;
  border: 0; border-radius: var(--radius); background: var(--primary); color: var(--primary-fg); box-shadow: none;
}
.sw-form [data-sw-send] svg { width: 13px; height: 14.5px; color: currentColor; }
.sw-form [data-sw-send]:hover:not(:disabled) { background: color-mix(in srgb, var(--primary) 85%, var(--fg-strong)); box-shadow: none; }
/* Disabled (the issue's #a7f3d0). */
.sw-form [data-sw-send]:disabled { background: var(--success-border); color: var(--surface); opacity: 1; cursor: not-allowed; }

/* "Message the team" (not in Figma): the composer's border and fields. */
.sw-compose { flex: none; display: flex; flex-direction: column; gap: var(--space-2); padding: 13px var(--space-3) var(--space-3); border-top: 1px solid var(--border-strong); }
.sw-compose label { font: 700 14px/20px var(--font-sans); color: var(--fg-strong); }
.sw-hint { margin: 0; font: var(--type-meta); color: var(--fg-muted); }
.sw-compose-error { margin: 0; font: var(--type-body); color: var(--danger-fg); }
.sw-compose-btns { display: flex; gap: var(--space-2); }

/* ---- Earlier conversations (support-history.ts): the list that stands in for the log ---- */
.sw-history { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-4); }
.sw-history-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.sw-history h3 { margin: 0; padding: 0 var(--space-1); font: 700 12px/16px var(--font-sans); letter-spacing: 0.3px; text-transform: uppercase; color: var(--fg-muted); }
.sw-history h3:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.sw-hnote { margin: 0; font: var(--type-body); color: var(--fg-muted); }
.sw-hnote:empty { display: none; }
.sw-hlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.sw-hrow { display: flex; align-items: center; gap: var(--space-1); padding-right: var(--space-1); border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); transition: background-color var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out); }
.sw-hrow:hover:not(.sw-hrow-confirm) { background: var(--bg); border-color: var(--border-control); }
.sw-hopen {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 10px 13px;
  font: inherit; text-align: left; color: var(--fg-strong); background: none; border: 0; border-radius: var(--radius); cursor: pointer;
}
.sw-hopen:disabled { cursor: default; opacity: 0.7; }
.sw-hopen:focus-visible, .sw-harchive:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.sw-htitle { font: 700 14px/20px var(--font-sans); color: var(--fg-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-hmeta { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-2); font: var(--type-meta); color: var(--fg-muted); }
.sw-hmeta > span + span::before { content: "\00b7"; margin-right: var(--space-2); }
.sw-hmeta > .sw-hbadge::before { content: none; margin: 0; }
.sw-hbadge { padding: 0 var(--space-2); border-radius: var(--radius-pill); background: var(--accent-tint); color: var(--live-text); font: var(--type-label); }
.sw-harchive { flex: none; width: 28px; height: 28px; min-height: 28px; color: var(--fg-muted); }

/* "AI answers can be wrong. Talk to a human" (not in Figma, kept): a quiet line under the composer. */
.sw-foot { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); margin: -4px 0 0; padding: 0 var(--space-3) var(--space-3); font: var(--type-meta); color: var(--fg-muted); }
.sw-foot .link-btn { color: var(--fg-strong); text-underline-offset: 3px; }

/* ---- Phones: a full-width bottom sheet, as before ---- */
@media (max-width: 860px) {
  .support-widget, .support-widget.sw-expanded, .shell[data-collapsed] .support-widget {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: min(82vh, 680px);
    border-left: 0; border-top: 1px solid var(--border-strong); border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    animation-name: sw-sheet-in;
  }
  .support-widget.sw-leaving { animation-name: sw-sheet-out; }
  body:has(.view-as-banner:not([hidden])) .support-widget { bottom: 56px; }
  .sw-size { display: none; }
  .sw-msg.sw-assistant { max-width: 100%; }
  .sw-form textarea, .sw-compose textarea { font-size: 16px; } /* no zoom on focus in iOS */
}

/* ---- Reduced motion: the panel fades, nothing slides or bounces ---- */
@media (prefers-reduced-motion: reduce) {
  .support-widget, .support-widget.sw-expanded { animation-name: sw-fade-in; }
  .support-widget.sw-leaving { animation-name: sw-fade-out; }
  .sw-row, .sw-dots i { animation: none; }
  .sw-dots i { opacity: 0.7; }
  .sw-quick-btn, .sw-hrow { transition: none; }
}
:root[data-motion="reduce"] :is(.support-widget, .support-widget.sw-expanded) { animation-name: sw-fade-in; }
:root[data-motion="reduce"] .support-widget.sw-leaving { animation-name: sw-fade-out; }
:root[data-motion="reduce"] :is(.sw-row, .sw-dots i) { animation: none; }
:root[data-motion="reduce"] :is(.sw-quick-btn, .sw-hrow) { transition: none; }
