/* chat.css — the website assistant (1.45.0): launcher + panel. Loaded only when Settings → AI assistant → "Show the assistant" is on.
   Phone (≤767): a full-height bottom sheet; tablet/desktop: a 392 px card above the launcher. Tokens only (tokens.css); opaque surfaces, no glass.
   Contrast (scripts/contrast.py pairs): ink on paper-2 (bot bubble), on-deep on sage-deep (header + my bubble), sun-ink on sun (send, launcher),
   amber on paper-2 (links), ink-3 on paper (privacy line), err on paper-3 (errors).
   Unlayered on purpose: a layered reset/base can never beat these rules. */
.chat-launcher, .chat-panel { --chat-b: calc(16px + env(safe-area-inset-bottom, 0px) + var(--chat-lift, 0px)); font-family: var(--font-text); }

/* keep a focused control above the launcher / the sticky bars (WCAG 2.2 SC 2.4.11); only while the widget is on the page */
html.chat-on { scroll-padding-bottom: calc(96px + var(--chat-lift, 0px) + env(safe-area-inset-bottom, 0px)); }
html.chat-on.wiz-on { scroll-padding-bottom: calc(164px + env(safe-area-inset-bottom, 0px)); }

/* ---- launcher ------------------------------------------------------------------------------------------------------------------------ */
.chat-launcher { position: fixed; z-index: 860; right: max(16px, env(safe-area-inset-right, 0px)); bottom: var(--chat-b); display: flex; align-items: center; gap: 10px;
  padding: 0; border: 0; background: none; color: var(--ink); font: inherit; cursor: pointer; border-radius: 999px; -webkit-tap-highlight-color: transparent;
  transition: bottom .28s var(--ease, ease), opacity .2s, transform .2s; animation: chat-in .5s var(--ease-out, ease) both; }
.chat-launcher[hidden] { display: none; }
.chat-launcher.is-waiting { opacity: 0; transform: translateY(12px) scale(.9); pointer-events: none; }   /* 1.53.0: phones — after the first scroll */
.chat-launcher:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.chat-launcher__btn { position: relative; display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; background: var(--sun); color: var(--sun-ink);
  box-shadow: var(--shadow-2); transition: background .16s, transform .16s; }
.chat-launcher:hover .chat-launcher__btn { background: var(--sun-press); }
.chat-launcher:active .chat-launcher__btn { transform: scale(.95); }
.chat-launcher__av { display: block; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; background: var(--sun-soft); display: grid; place-items: center; }
.chat-launcher__av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-launcher__av .i { width: 28px; height: 28px; }
.chat-launcher__btn .chat-dot { position: absolute; top: 1px; right: 1px; width: 15px; height: 15px; border: 2.5px solid var(--paper); box-sizing: border-box; }
/* 1.46.0 desktop: the chat window collapsed, like a messenger (owner: "the icon on desktop should be like the chat window collapsed … support
   online shown") — the cat on duty, "<cat> is online 🐾", a chevron; it becomes the open window in the same corner */
.chat-bar { display: none; align-items: center; gap: 12px; width: 300px; box-sizing: border-box; padding: 10px 14px 10px 10px; border-radius: 18px 18px 6px 18px;
  background: var(--sage-deep); color: var(--on-deep); box-shadow: var(--shadow-2); text-align: left; transition: transform .16s, background .16s; }
.chat-launcher:hover .chat-bar { transform: translateY(-2px); }
.chat-bar__av { position: relative; flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--sun); display: grid; place-items: center; box-shadow: 0 0 0 2.5px var(--sun); }
.chat-bar__av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.chat-bar__av .i { width: 24px; height: 24px; color: var(--sun-ink); }
.chat-bar__av .chat-dot { position: absolute; right: -2px; bottom: -1px; width: 14px; height: 14px; border: 2.5px solid var(--sage-deep); box-sizing: border-box; background: #4CD08A; }
.chat-bar__av .chat-dot::after { display: none; }
.chat-bar__t { display: grid; gap: 1px; min-width: 0; flex: 1; }
.chat-bar__t b { font-family: var(--font-display); font-size: 1.08rem; font-weight: 650; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-bar__t small { font-size: .84rem; color: var(--on-deep-2); white-space: nowrap; }
.chat-bar__up { flex: none; width: 22px; height: 22px; transform: rotate(180deg); opacity: .85; }
.chat-dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); position: relative; }
.chat-dot::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid currentColor; color: var(--ok); opacity: 0; animation: chat-ping 2.4s ease-out infinite; }
.chat-launcher__btn .chat-dot::after { display: none; }
@media (min-width: 768px) {
  .chat-bar { display: inline-flex; }
  .chat-launcher__btn { display: none; }
}
.chat-launcher[aria-expanded="true"] { opacity: 0; pointer-events: none; }   /* the open window takes its place; not visibility:hidden — WebKit would refuse the focus we hand back on close */
body:has(dialog[open]) .chat-launcher { visibility: hidden; }

/* ---- panel --------------------------------------------------------------------------------------------------------------------------- */
.chat-panel { position: fixed; z-index: 1100; right: max(16px, env(safe-area-inset-right, 0px)); bottom: var(--chat-b); width: min(392px, calc(100vw - 32px));
  height: min(640px, 82vh, calc(100dvh - var(--chat-b) - 24px)); display: flex; flex-direction: column; overflow: hidden; background: var(--paper); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-md); box-shadow: var(--shadow-2); transform-origin: 100% 100%;
  opacity: 0; transform: translateY(14px) scale(.98); transition: opacity .22s var(--ease-out, ease), transform .26s var(--ease-out, ease), bottom .28s var(--ease, ease); }
.chat-panel[hidden] { display: none; }
.chat-panel.is-open { opacity: 1; transform: none; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 16px; background: var(--sage-deep); color: var(--on-deep); }
.chat-avatar { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--sun); color: var(--sun-ink); overflow: hidden; box-shadow: 0 0 0 2.5px var(--sun); }
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-avatar .i { width: 24px; height: 24px; }
.chat-head__t { min-width: 0; flex: 1; }
.chat-head h2 { margin: 0; font-family: var(--font-display); font-size: 1.15rem; font-weight: 650; line-height: 1.2; color: var(--on-deep); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head h2:focus { outline: none; }
.chat-head p { margin: 2px 0 0; display: flex; align-items: center; gap: 8px; font-size: .875rem; color: var(--on-deep-2); }
.chat-head .chat-dot { background: #4CD08A; }
.chat-head .chat-dot::after { color: #4CD08A; }
.chat-x { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--on-deep); cursor: pointer; }
.chat-x:hover { background: rgba(255, 248, 238, .14); }
.chat-x:focus-visible { outline: 3px solid var(--sun); outline-offset: -3px; }
.chat-x .i { width: 22px; height: 22px; }

.chat-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding: 16px 14px 8px; scroll-behavior: smooth; }
.chat-log:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.chat-msg { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 100%; animation: chat-pop .22s var(--ease-out, ease) both; }
.chat-msg--me { align-items: flex-end; }
.chat-bubble { max-width: 88%; padding: 10px 14px; border-radius: 18px 18px 18px 6px; background: var(--paper-2); color: var(--ink); font-size: 1rem; line-height: 1.5; overflow-wrap: anywhere; word-break: break-word; }
.chat-msg--me .chat-bubble { border-radius: 18px 18px 6px 18px; background: var(--sage-deep); color: var(--on-deep); white-space: pre-wrap; }
.chat-bubble a { color: var(--amber); font-weight: 700; text-underline-offset: .15em; }
.chat-bubble b { font-weight: 800; }
.chat-bubble--warn { background: var(--blush); }
.chat-bubble--warn a { color: var(--ink); }
.chat-vote { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-left: 2px; font-size: .875rem; color: var(--ink-3); }
.chat-vote button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 1.5px solid var(--line-strong); background: var(--paper-3); font-size: 1.1rem; line-height: 1; cursor: pointer; }
.chat-vote button:hover { background: var(--sun-soft); }
.chat-vote button[aria-pressed="true"] { background: var(--sun-soft); border-color: var(--sun-deep); }
.chat-vote button:focus-visible, .chat-chip:focus-visible, .chat-foot button:focus-visible, .chat-foot a:focus-visible, .chat-human button:focus-visible, .chat-send:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.chat-vote [data-thanks] { font-weight: 700; color: var(--ink-2); }

.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 4px; }
.chat-chip { box-sizing: border-box; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line-strong); background: var(--paper-3); color: var(--ink); font: 600 .95rem/1.25 var(--font-text); text-align: left; cursor: pointer; transition: background .15s, border-color .15s; }
.chat-chip:hover { background: var(--sun-soft); border-color: var(--sun-deep); }
/* 1.46.0: no dots — the whiskers grow one by one next to "Toofan is meowing…" (docs/DESIGN.md → Loading = whiskers) */
.chat-typing { display: inline-flex; gap: 10px; align-items: center; padding: 10px 16px 10px 12px; border-radius: 18px 18px 18px 6px; background: var(--paper-2); color: var(--ink-2); }
.chat-typing__t { font-size: .95rem; font-style: italic; font-weight: 600; }
.chat-whisk svg { display: block; width: 46px; height: 18px; overflow: visible; }
.chat-whisk .w { fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: chat-whisk 1.8s cubic-bezier(.2, .7, .2, 1) infinite; }
.chat-whisk .w2 { animation-delay: .12s; } .chat-whisk .w3 { animation-delay: .24s; } .chat-whisk .w4 { animation-delay: .36s; } .chat-whisk .w5 { animation-delay: .48s; } .chat-whisk .w6 { animation-delay: .6s; }
.chat-whisk .n { fill: var(--sun); stroke: currentColor; stroke-width: 1; }
.chat-msg--note { align-items: center; width: 100%; }
.chat-handover { margin: 2px 0; padding: 7px 14px; border-radius: 999px; background: var(--paper-3); border: 1px dashed var(--line-strong); color: var(--ink-2); font-size: .9rem; font-style: italic; text-align: center; max-width: 92%; }
.chat-who { display: inline-flex; align-items: center; gap: 6px; margin-left: 2px; font-size: .8rem; font-weight: 800; letter-spacing: .02em; color: var(--ink-2); }
.chat-who__av { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; overflow: hidden; background: var(--sun-soft); }
.chat-who__av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-who__av .i { width: 14px; height: 14px; }

/* ---- "Talk to a person" card -------------------------------------------------------------------------------------------------------- */
.chat-human { width: 100%; padding: 14px; border-radius: 18px; background: var(--paper-3); border: 1.5px solid var(--line-strong); display: grid; gap: 10px; }
.chat-human h3 { margin: 0; font-family: var(--font-display); font-size: 1.1rem; font-weight: 650; }
.chat-human p { margin: 0; font-size: .95rem; color: var(--ink-2); line-height: 1.45; }
.chat-field { display: grid; gap: 4px; border-radius: 14px; }
.chat-field label { font-size: .875rem; font-weight: 800; color: var(--ink-2); }
.chat-field input, .chat-field textarea, .chat-input { width: 100%; box-sizing: border-box; min-height: 46px; padding: 10px 13px; border-radius: 12px; border: 1.5px solid var(--line-strong); background: var(--paper);
  color: var(--ink); font: 400 1rem/1.4 var(--font-text); }
.chat-field textarea { min-height: 64px; resize: vertical; }
.chat-field input:focus, .chat-field textarea:focus, .chat-input:focus { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.chat-field[aria-invalid="true"] input { border-color: var(--err); }
.chat-field--hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.chat-err { margin: 0; font-size: .9rem; font-weight: 700; color: var(--err); }
.chat-glow { animation: chat-glow 2.6s ease-in-out; }
.chat-human__acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chat-go { min-height: 48px; padding: 0 20px; border: 0; border-radius: 999px; background: var(--sun); color: var(--sun-ink); font: 800 1rem var(--font-text); cursor: pointer; }
.chat-go:hover { background: var(--sun-press); }
.chat-go[disabled] { opacity: .6; cursor: wait; }
.chat-link { min-height: 44px; padding: 0 10px; border: 0; background: none; color: var(--ink); font: 700 .95rem var(--font-text); text-decoration: underline; text-underline-offset: .18em; cursor: pointer; }
.chat-human--done { background: var(--sage-tint); border-color: transparent; }
.chat-human--done h3 { display: flex; gap: 8px; align-items: center; }
.chat-human--done .i { width: 22px; height: 22px; color: var(--ok); }

/* ---- composer + footer -------------------------------------------------------------------------------------------------------------- */
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 6px; border-top: 1px solid var(--line); background: var(--paper); }
.chat-input { flex: 1; min-width: 0; max-height: 120px; resize: none; border-radius: 22px; padding: 11px 16px; min-height: 48px; }
.chat-send { display: grid; place-items: center; flex: none; width: 48px; height: 48px; border: 0; border-radius: 50%; background: var(--sun); color: var(--sun-ink); cursor: pointer; }
.chat-send:hover { background: var(--sun-press); }
.chat-send[disabled] { opacity: .5; cursor: default; }
.chat-send .i { width: 22px; height: 22px; stroke-width: 2.2; }
.chat-foot { padding: 0 12px calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--paper); }
.chat-foot__row { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: center; }
.chat-foot__row > * { display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; border: 0; background: none; color: var(--ink); font: 700 .9rem var(--font-text); text-decoration: underline; text-underline-offset: .18em; cursor: pointer; }
.chat-foot__row .chat-wa { color: var(--wa); }
.chat-foot__priv { margin: 0 0 2px; padding: 0 8px; font-size: var(--step--1, .875rem); line-height: 1.4; color: var(--ink-3); }
.chat-foot__priv a { color: var(--ink-2); }
.chat-panel.is-kb .chat-foot { display: none; }
.chat-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- phone: a full-height bottom sheet ---------------------------------------------------------------------------------------------- */
@media (max-width: 767px) {
  html.chat-open { overflow: hidden; }
  .chat-panel { left: 0; right: 0; bottom: auto; top: var(--chat-top, 0px); width: auto; height: var(--chat-vh, 100dvh); border-radius: 0; border: 0; transform: translateY(28px); transform-origin: 50% 100%; }
  .chat-head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .chat-log { padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
  .chat-bubble { max-width: 92%; }
  .chat-form { padding-bottom: 6px; }
  .chat-panel.is-kb .chat-form { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}
@media (min-width: 768px) and (max-height: 520px) { .chat-panel { height: calc(100dvh - var(--chat-b) - 20px); } }

@keyframes chat-in { from { opacity: 0; transform: translateY(10px) scale(.9); } }
@keyframes chat-pop { from { opacity: 0; transform: translateY(6px); } }
@keyframes chat-ping { 0% { opacity: .55; transform: scale(.6); } 70%, 100% { opacity: 0; transform: scale(1.5); } }
@keyframes chat-whisk { 0% { stroke-dashoffset: 1; opacity: 1; } 30% { stroke-dashoffset: 0; opacity: 1; } 80% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; } }
@keyframes chat-glow { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 20%, 80% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--err) 30%, transparent); } }
@media (prefers-reduced-motion: reduce) {
  .chat-launcher, .chat-panel, .chat-msg, .chat-launcher__btn, .chat-launcher__btn .i { animation: none !important; transition: none !important; }
  .chat-dot::after { display: none; }
  .chat-whisk .w { animation: none; stroke-dashoffset: 0; }
  .chat-log { scroll-behavior: auto; }
  .chat-glow { animation: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--err) 35%, transparent); }
}
@media print { .chat-launcher, .chat-panel { display: none !important; } }

/* 1.47.0 — the details gate: covers the whole window under the header before the first answer (no skip); the button looks off until a valid
   mobile or email is in, and a press then says what is missing (scroll + glow + focus). */
.chat-panel.has-gate .chat-form, .chat-panel.has-gate .chat-foot { visibility: hidden; }
.chat-gate { position: absolute; z-index: 3; inset: var(--chat-gate-top, 64px) 0 0 0; overflow-y: auto; overscroll-behavior: contain; background: var(--paper);
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px)); animation: chat-gate-in .24s var(--ease-out, ease) both; }
@keyframes chat-gate-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .chat-gate { animation: none; } }
.chat-gate__form { display: grid; gap: 12px; max-width: 420px; margin: 0 auto; }
.chat-gate__top { display: flex; align-items: center; gap: 12px; }
.chat-gate__av { flex: none; width: 44px; height: 44px; }
.chat-gate h3 { margin: 0; font-family: var(--font-display); font-size: 1.2rem; font-weight: 650; line-height: 1.25; }
.chat-gate__lead { margin: 0; color: var(--ink-2); font-size: .95rem; line-height: 1.45; }
.chat-gate__q { display: grid; gap: 2px; margin: 0; padding: 10px 12px; border-radius: 14px; background: var(--paper-2); font-size: .95rem; overflow-wrap: anywhere; }
.chat-gate__q span { color: var(--ink-3); font-size: .8rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.chat-gate__go { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.chat-gate__go .i { width: 18px; height: 18px; }
.chat-gate__go.is-off { background: var(--paper-3); color: var(--ink-3); box-shadow: inset 0 0 0 1.5px var(--line-strong); cursor: not-allowed; }
.chat-gate__go.is-off:hover { background: var(--paper-3); }

