/* "Talk to us": floating launcher + contact panel (I4). Markup: templates/_talk.html, behaviour: static/talk.js.
   Light-only, uses the site tokens from site.css. Phones get a bottom sheet; wider screens a floating card. */

.talk {
  --talk-gap: 16px;
  --talk-right: max(var(--talk-gap), calc(env(safe-area-inset-right, 0px) + var(--talk-gap)));
  --talk-bottom: max(var(--talk-gap), calc(env(safe-area-inset-bottom, 0px) + var(--talk-gap)));
  --talk-lift: 0px; /* set by talk.js while the footer's last line is on screen */
  font-family: var(--f-body);
}
@media (min-width: 720px) { .talk { --talk-gap: 24px; } }

/* hidden where it shouldn't be: opt-out pages, the account set-up overlay, the open phone menu, print */
body.no-talk .talk,
html.setup-open .talk,
body:has(.setup:not([hidden])) .talk { display: none !important; }
html:has(.mnav[open]) .talk-fab { visibility: hidden; }
@media print { .talk { display: none !important; } }

/* ---------- launcher ---------- */
.talk-fab {
  position: fixed; z-index: 60; right: var(--talk-right); bottom: var(--talk-bottom);
  /* the footer lift rides on the separate translate property: no layout shift, and the hover/open transforms still apply */
  translate: 0 calc(-1 * var(--talk-lift, 0px));
  display: inline-flex; align-items: center; gap: 9px; min-height: 52px; padding: 0 20px 0 15px; border-radius: 999px;
  color: #fff; text-decoration: none; font: 650 .96rem/1 var(--f-body); letter-spacing: -.005em; white-space: nowrap;
  background: linear-gradient(135deg, var(--btn-a, #5b4dff), #7a3fe8 55%, #c2378a);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .28) inset, 0 12px 28px -10px rgba(91, 61, 245, .7), 0 4px 10px -4px rgba(194, 55, 138, .45);
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease, visibility .2s;
  -webkit-tap-highlight-color: transparent;
}
.talk-fab:hover { color: #fff; text-decoration: none; transform: translateY(-2px); box-shadow: 0 1px 0 rgba(255, 255, 255, .28) inset, 0 16px 34px -12px rgba(91, 61, 245, .8), 0 6px 12px -4px rgba(194, 55, 138, .5); }
.talk-fab:active { transform: translateY(0); }
.talk-fab:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 999px; }
.talk-fab-ic { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.talk-fab-ic svg { display: block; }
.talk.is-open .talk-fab { opacity: 0; visibility: hidden; transform: scale(.9); pointer-events: none; }
@media (hover: hover) {
  .talk-fab:hover .talk-dot { animation: talk-blink 1.2s ease-in-out infinite; }
  .talk-fab:hover .talk-dot:nth-of-type(2) { animation-delay: .15s; }
  .talk-fab:hover .talk-dot:nth-of-type(3) { animation-delay: .3s; }
}
@keyframes talk-blink { 0%, 60%, 100% { opacity: 1; } 30% { opacity: .25; } }
@media (max-width: 379px) { .talk-fab { min-height: 48px; padding: 0 16px 0 11px; font-size: .92rem; gap: 7px; } }
/* phones: once the visitor scrolls into the page, the launcher shrinks to its icon so it covers less */
@media (max-width: 639px) {
  .talk-fab-lbl { transition: max-width .25s ease, opacity .2s ease; max-width: 9em; overflow: hidden; }
  .talk.is-compact .talk-fab { padding: 0; width: 52px; justify-content: center; gap: 0; }
  .talk.is-compact .talk-fab-lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; opacity: 0; }
  .talk.is-compact .talk-fab-ic { width: 34px; height: 34px; }
}

/* ---------- scrim ---------- */
.talk-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(20, 14, 40, .22); opacity: 0; transition: opacity .22s ease; }
.talk.is-open .talk-scrim { opacity: 1; }

/* ---------- panel (floating card on wide screens) ---------- */
.talk-panel {
  position: fixed; z-index: 71; right: var(--talk-right); bottom: var(--talk-bottom);
  width: min(408px, calc(100vw - 2 * var(--talk-gap)));
  max-height: min(800px, calc(100vh - var(--talk-bottom) - 20px));
  max-height: min(800px, calc(100dvh - var(--talk-bottom) - 20px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 2px 6px rgba(70, 45, 10, .06), 0 40px 80px -28px rgba(91, 61, 245, .38), 0 18px 36px -18px rgba(214, 51, 122, .25);
  transform-origin: 100% 100%;
  opacity: 0; transform: translateY(12px) scale(.97);
  transition: opacity .2s ease, transform .24s cubic-bezier(.2, .8, .2, 1);
}
.talk.is-open .talk-panel { opacity: 1; transform: none; }
.talk-grab { display: none; }

.talk-head {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 16px 14px 16px 18px; flex: none;
  background:
    radial-gradient(70% 140% at 0% 0%, rgba(255, 176, 32, .26), transparent 60%),
    radial-gradient(60% 140% at 100% 0%, rgba(255, 77, 141, .16), transparent 60%),
    linear-gradient(180deg, #fff6e6, #fffaf3);
  border-bottom: 1px solid rgba(255, 176, 32, .22);
}
.talk-av {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(106, 92, 255, .28), 0 6px 14px -6px rgba(91, 61, 245, .5);
}
.talk-av svg { display: block; }
.talk-av-sm { width: 28px; height: 28px; box-shadow: 0 0 0 1px var(--line-2), 0 2px 6px -3px rgba(91, 61, 245, .45); }
.talk-who { min-width: 0; flex: 1; }
.talk-from { margin: 0 0 2px; font: 600 .78rem/1.2 var(--f-body); letter-spacing: .02em; color: var(--ink-3); }
.talk-h { margin: 0; font: 700 1.14rem/1.2 var(--f-display); letter-spacing: -.02em; color: var(--ink); }
.talk-h:focus { outline: none; }
.talk-x {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; margin: -4px 0; border: 0; border-radius: 12px;
  background: transparent; color: var(--ink-2); cursor: pointer; transition: background-color .15s, color .15s;
}
.talk-x:hover { background: rgba(255, 255, 255, .8); color: var(--ink); }
.talk-x:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-radius: 12px; }

.talk-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 18px 14px; -webkit-overflow-scrolling: touch; }

/* chat bubbles */
.talk-chat { margin-bottom: 12px; }
.talk-msg { display: flex; align-items: flex-end; gap: 8px; margin: 0 0 10px; }
.talk-bubble {
  min-width: 0; max-width: 88%; padding: 11px 14px; border-radius: 16px 16px 16px 6px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: .93rem; line-height: 1.5; color: var(--ink-2);
}
.talk-bubble p { margin: 0; }
.talk-bubble p + p { margin-top: 6px; }
.talk-bubble b { color: var(--ink); }
.talk-wave { display: inline-block; vertical-align: -2px; color: #c2410c; transform-origin: 70% 80%; animation: talk-wave 1.6s ease-in-out .4s 2; }
.talk-wave svg { display: block; }
@keyframes talk-wave { 0%, 60%, 100% { transform: rotate(0); } 15%, 45% { transform: rotate(14deg); } 30% { transform: rotate(-8deg); } }
.talk-you { justify-content: flex-end; }
.talk-you .talk-bubble { border-radius: 16px 16px 6px 16px; background: linear-gradient(135deg, #5b4dff, #6a3fe0); border-color: transparent; color: #fff; }
.talk-you-topic { font: 650 .74rem/1.2 var(--f-body) !important; letter-spacing: .04em; text-transform: uppercase; opacity: .85; margin-bottom: 4px !important; }
.talk-you-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.talk-typing { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: .9rem; }
.talk-dots { display: inline-flex; gap: 4px; }
.talk-dots i { width: 7px; height: 7px; border-radius: 50%; background: #9a8cff; animation: talk-bounce 1.1s ease-in-out infinite; }
.talk-dots i:nth-child(2) { animation-delay: .15s; background: #e070a8; }
.talk-dots i:nth-child(3) { animation-delay: .3s; background: #f0a040; }
@keyframes talk-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .6; } 30% { transform: translateY(-4px); opacity: 1; } }

/* form */
.talk-form { display: grid; gap: 13px; }
.talk-alert {
  display: block; margin: 0; padding: 11px 13px; border-radius: 12px;
  background: var(--bad-soft); border: 1px solid rgba(239, 68, 68, .3); color: var(--bad-ink); font-size: .9rem; line-height: 1.45;
}
.talk-alert:focus { outline: none; box-shadow: 0 0 0 3px rgba(239, 68, 68, .25); }
.talk-alert a { color: inherit; font-weight: 650; }
.talk-topics { margin: 0; padding: 0; border: 0; min-width: 0; }
.talk-legend { padding: 0; margin: 0 0 9px; font-weight: 650; font-size: .9rem; color: var(--ink); }
.talk-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.talk-chip { position: relative; display: inline-flex; cursor: pointer; }
.talk-chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.talk-chip span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font: 600 .88rem/1 var(--f-body);
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.talk-chip:hover span { border-color: color-mix(in srgb, var(--accent) 50%, var(--line-2)); color: var(--ink); }
.talk-chip input:checked + span { background: #f1eeff; border-color: #6a5cff; color: #3d2fd6; box-shadow: 0 0 0 1px #6a5cff inset; }
.talk-chip input:checked + span::before {
  content: ""; width: 14px; height: 14px; margin: 0 6px 0 -3px; flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 10.5l3 3 7-7.5' fill='none' stroke='%233d2fd6' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.talk-chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.talk-hint { margin: 9px 0 0; color: var(--ink-3); font-size: .84rem; line-height: 1.45; }

.talk-row { display: grid; gap: 14px; }
@media (min-width: 420px) { .talk-row { grid-template-columns: 1fr 1fr; gap: 12px; } }
.talk-field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.talk-field label { font-weight: 600; font-size: .88rem; color: var(--ink); }
.talk-field input, .talk-field select, .talk-field textarea {
  width: 100%; min-height: 46px; padding: 10px 13px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font: 400 16px/1.35 var(--f-body);
  transition: border-color .15s, box-shadow .15s; -webkit-appearance: none; appearance: none;
}
.talk-field select {
  padding-right: 36px; background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 8l4 4 4-4' fill='none' stroke='%235c637a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.talk-field textarea { min-height: 92px; resize: vertical; max-height: 260px; }
.talk-field input:hover, .talk-field select:hover, .talk-field textarea:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line-2)); }
.talk-field input:focus, .talk-field select:focus, .talk-field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(106, 92, 255, .2); }
.talk-field [aria-invalid="true"] { border-color: var(--bad); background: #fffafa; }
.talk-field [aria-invalid="true"]:focus { box-shadow: 0 0 0 4px rgba(239, 68, 68, .18); }
.talk-err { display: flex; gap: 6px; margin: 0; color: var(--bad-ink); font-size: .84rem; line-height: 1.4; }
.talk-err::before { content: "!"; flex: none; display: grid; place-items: center; width: 16px; height: 16px; margin-top: 1px; border-radius: 50%; background: var(--bad-ink); color: #fff; font: 800 .7rem/1 var(--f-body); }
.talk-meta { display: flex; justify-content: space-between; gap: 10px; margin: 0; color: var(--ink-3); font-size: .82rem; }
.talk-count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.talk-count.is-near { color: var(--warn-ink); font-weight: 600; }

.talk-more { border-radius: 12px; }
.talk-more > summary {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; cursor: pointer; list-style: none;
  color: var(--accent-ink); font: 600 .88rem/1.3 var(--f-body); border-radius: 8px;
}
.talk-more > summary::-webkit-details-marker { display: none; }
.talk-more > summary::before {
  content: ""; width: 16px; height: 16px; flex: none; transition: transform .15s;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 4.5v11M4.5 10h11' fill='none' stroke='%234f3ff0' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.talk-more[open] > summary::before { transform: rotate(45deg); }
.talk-more > summary span { color: var(--ink-3); font-weight: 500; }
.talk-more > .talk-row { margin-top: 8px; }

.talk-hp { position: absolute !important; left: -10000px !important; top: auto; width: 1px; height: 1px; overflow: hidden; }
.talk-send { --h: 50px; font-size: 1rem; }
.talk-send svg { transition: transform .2s ease; }
.talk-send:hover svg { transform: translateX(3px); }
.talk-legal { margin: -4px 0 0; text-align: center; color: var(--ink-3); font-size: .8rem; line-height: 1.45; }
.talk-legal a { color: var(--ink-2); }

/* sent */
.talk-convo { padding-top: 2px; }
.talk-convo .talk-msg { animation: talk-in .28s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes talk-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.talk-done {
  margin: 16px 0 4px; padding: 22px 18px 18px; text-align: center; border-radius: 18px;
  background: linear-gradient(180deg, #effaf5, #f7fdfa); border: 1px solid rgba(18, 184, 134, .25);
  animation: talk-in .32s cubic-bezier(.2, .8, .2, 1) both;
}
.talk-done-ic {
  display: inline-grid; place-items: center; width: 52px; height: 52px; margin-bottom: 10px; border-radius: 50%;
  color: #fff; background: linear-gradient(135deg, #12b886, #0ea472); box-shadow: 0 10px 22px -10px rgba(18, 184, 134, .8);
  animation: talk-pop .4s cubic-bezier(.3, 1.6, .5, 1) .05s both;
}
.talk-done-ic svg { stroke-width: 3; }
@keyframes talk-pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.talk-done-h { margin: 0 0 6px; font: 700 1.06rem/1.35 var(--f-display); letter-spacing: -.015em; color: var(--ink); overflow-wrap: anywhere; }
.talk-done-h:focus { outline: none; }
.talk-done-p { margin: 0 0 14px; color: var(--ink-2); font-size: .9rem; line-height: 1.5; }
.talk-done-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.talk-done-btns .btn { --h: 44px; }

.talk-foot {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; padding: 12px 18px;
  border-top: 1px solid var(--line); background: var(--surface-2); color: var(--ink-3); font-size: .86rem;
}
.talk-foot svg { flex: none; color: var(--ink-3); }
.talk-foot a { color: var(--accent-ink); font-weight: 600; overflow-wrap: anywhere; }

/* ---------- phones: bottom sheet ---------- */
@media (max-width: 639px) {
  .talk-scrim { background: rgba(20, 14, 40, .38); }
  .talk-panel {
    left: 0; right: 0; bottom: 0; width: auto;
    max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px);
    border-radius: 22px 22px 0 0; border-bottom: 0;
    transform-origin: 50% 100%; transform: translateY(40px);
  }
  .talk-grab { display: block; position: absolute; z-index: 1; top: 7px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(70, 45, 10, .2); }
  .talk-head { padding-top: 20px; }
  .talk-body { padding: 14px 16px 12px; }
  .talk-foot { padding-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 8px)); }
  html.talk-lock, html.talk-lock body { overflow: hidden; }
}

/* ---------- reduced motion: no movement, just appear ---------- */
@media (prefers-reduced-motion: reduce) {
  .talk-fab, .talk-panel, .talk-scrim, .talk-send svg { transition: none; }
  .talk-panel, .talk.is-open .talk-panel { transform: none; }
  .talk-fab:hover { transform: none; }
  .talk-wave, .talk-dots i, .talk-convo .talk-msg, .talk-done, .talk-done-ic, .talk-fab:hover .talk-dot { animation: none !important; }
  .talk-dots i { opacity: .8; }
}
