/* SA Chat – loaded inside the widget's Shadow DOM, so site styles do not leak in or out. */
:host { all: initial; }

.w {
  --accent: #16887e;
  --accent-hover: #1b655f;
  --brand: #00aba0;
  --accent-soft: #d8eeeb;
  --navy: #192a42;
  --navy-deep: #121823;
  --welcome: #192a42;
  --welcome-end: rgba(0, 0, 0, .45);
  --welcome-btn: var(--brand);
  --welcome-btn-text: var(--navy-deep);
  --sand: #f2f0ec;
  --line: #e2ded6;
  --ink: #2a2f36;
  --ink-soft: #5d6570;
  --wa: #25d366;
  --wa-hover: #1fbd5a;
  --error: #b3261e;
  --sa-bottom: 20px;

  position: fixed;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: calc(var(--sa-bottom) + env(safe-area-inset-bottom, 0px));
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-align: left;
}
.w *, .w *::before, .w *::after { box-sizing: border-box; }
.w [hidden] { display: none !important; }
.w button { font: inherit; }
.w :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.w a { color: var(--accent); }

/* ---------- launcher + avatar ---------- */
.launcher {
  width: 58px; height: 58px; border-radius: 50%; border: 3px solid #fff; padding: 0;
  background: var(--accent); cursor: pointer; position: relative; overflow: visible;
  box-shadow: 0 6px 18px rgba(18, 24, 35, .28); transition: transform .15s;
  display: grid; place-items: center;
}
.launcher:hover { transform: scale(1.05); }
.launcher > svg { width: 62%; height: 62%; }
/* Out of the grid flow: as a grid item a non-square photo sets the track size and turns oval. */
.launcher > img, .avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; object-position: center top; }
.dot { position: absolute; right: -1px; top: -1px; width: 14px; height: 14px; border-radius: 50%; background: #2bd06b; border: 2px solid #fff; }

.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); flex: none; display: grid; place-items: center; position: relative; }
.avatar > svg { width: 70%; height: 70%; }
.has-photo .launcher { border: 0; background: none; }
.has-photo .avatar { background: none; }

/* ---------- teaser ---------- */
.teaser {
  width: 300px; max-width: calc(100vw - 40px); background: #fff; border-radius: 14px;
  box-shadow: 0 12px 34px rgba(18, 24, 35, .22); padding: 34px 18px 18px;
  /* Out of the flow: growing .w when the teaser appears would count as a layout shift (CLS). */
  position: absolute; right: 0; bottom: calc(100% + 12px);
  text-align: center; animation: sa-pop .25s ease-out;
}
.teaser .avatar { position: absolute; top: -26px; left: 50%; transform: translateX(-50%); width: 54px; height: 54px; border: 3px solid #fff; }
.has-photo .teaser .avatar { border: 0; }
.t-title { margin: 0 0 2px; font-size: 16px; color: var(--navy); font-weight: 700; line-height: 1.3; }
.t-sub { margin: 0 0 14px; color: var(--ink-soft); font-size: 13px; }
.x {
  position: absolute; top: -12px; right: -10px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: #fff; box-shadow: 0 2px 8px rgba(18, 24, 35, .2); cursor: pointer; display: grid; place-items: center; color: var(--ink); padding: 0;
}
.x svg { width: 12px; height: 12px; }

.stack { display: grid; gap: 8px; }
.cta {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; width: 100%;
  border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  cursor: pointer; padding: 0 14px; text-decoration: none; transition: background .15s;
}
.cta:hover { background: var(--accent-hover); }
.cta.wa { background: var(--wa); color: #fff; }
.cta.wa:hover { background: var(--wa-hover); }
.cta svg { width: 16px; height: 16px; flex: none; }
.cta[disabled] { opacity: .6; cursor: progress; }

/* ---------- panel ---------- */
.panel {
  width: 370px; height: min(640px, calc(100vh - 110px)); background: #fff; border-radius: 16px;
  box-shadow: 0 18px 50px rgba(18, 24, 35, .3); display: flex; flex-direction: column; overflow: hidden;
  animation: sa-pop .22s ease-out;
}
@keyframes sa-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fff; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who b { display: block; font-size: 14px; color: var(--navy); line-height: 1.2; }
.who span.sub { font-size: 12px; color: var(--ink-soft); }
.who .dot { width: 11px; height: 11px; }
.icons { display: flex; gap: 6px; }
.icon-btn { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--sand); color: var(--ink); display: grid; place-items: center; cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--line); }
.icon-btn svg { width: 15px; height: 15px; }

/* welcome */
.welcome { flex: 1; display: flex; flex-direction: column; background: linear-gradient(180deg, transparent 0%, var(--welcome-end) 100%), var(--welcome); color: #fff; overflow: auto; position: relative; }
.welcome .top { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 0 18px; }
.welcome .brand { font-weight: 800; letter-spacing: .02em; font-size: 14px; }
.welcome .logo { display: block; width: auto; height: auto; max-width: 210px; max-height: 48px; }
/* Light glow behind the logo, so a dark logo stands out from the photo or the navy. */
.welcome.has-logo::before {
  content: ""; position: absolute; top: 0; left: 0; width: 340px; height: 140px; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse 100% 100% at 0 0, rgba(255, 255, 255, .98) 0%, rgba(255, 255, 255, .95) 35%, rgba(255, 255, 255, .8) 52%, rgba(255, 255, 255, .5) 68%, rgba(255, 255, 255, .2) 84%, rgba(255, 255, 255, 0) 100%);
}
.welcome.has-logo .top { z-index: 2; }
.welcome .icon-btn { background: rgba(255, 255, 255, .12); color: #fff; }
.welcome .icon-btn:hover { background: rgba(255, 255, 255, .2); }
/* Without a photo the texts and buttons sit at the bottom, next to the footer. */
.welcome:not(.has-hero) .body { margin-top: auto; }
.welcome:not(.has-hero) .foot { margin-top: 0; }
.hero { flex: none; height: 240px; position: relative; }
/* The photo fades out with a mask, so it blends into any background colour. */
.hero img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  -webkit-mask-image: linear-gradient(180deg, #000 45%, transparent 100%); mask-image: linear-gradient(180deg, #000 45%, transparent 100%);
}
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(18, 24, 35, .35) 0%, rgba(18, 24, 35, 0) 30%); }
.welcome.has-hero .top { position: absolute; top: 0; left: 0; right: 0; z-index: 1; }
.welcome.has-hero .icon-btn { background: rgba(18, 24, 35, .55); }
.welcome.has-hero .icon-btn:hover { background: rgba(18, 24, 35, .75); }
.welcome.has-hero .body { position: relative; margin-top: -56px; }
.welcome.has-hero h2 { text-shadow: 0 1px 6px rgba(18, 24, 35, .6); }
.welcome .body { padding: 6px 22px 18px; display: grid; gap: 14px; }
.welcome h2 { margin: 0; font-size: 20px; line-height: 1.25; font-weight: 800; color: #fff; }
.welcome .lead { margin: -6px 0 0; color: rgba(255, 255, 255, .78); font-size: 14px; }
.welcome .cta { background: var(--welcome-btn); color: var(--welcome-btn-text); }
.welcome .cta:hover { background: var(--welcome-btn); filter: brightness(1.12); }
.welcome .cta.wa { background: var(--wa); color: #fff; }
.welcome .cta.wa:hover { background: var(--wa-hover); filter: none; }
.welcome .foot { margin-top: auto; padding: 12px 22px 16px; font-size: 12px; color: rgba(255, 255, 255, .68); display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.welcome .foot a { color: rgba(255, 255, 255, .85); font-size: 11px; }

/* conversation */
.convo { flex: 1; display: flex; flex-direction: column; min-height: 0; background: linear-gradient(180deg, #fff 55%, var(--accent-soft) 100%); }
.thread { flex: 1; overflow-y: auto; padding: 16px 14px 20px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; animation: sa-pop .2s ease-out; }
.msg.bot .bubble { background: var(--sand); color: var(--ink); border-radius: 14px 14px 14px 4px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--accent); color: #fff; border-radius: 14px 14px 4px 14px; font-weight: 500; }
.bubble { padding: 9px 13px; max-width: 78%; overflow-wrap: anywhere; }
.bubble.typing-wrap { padding: 0; }
.msg.bot .avatar { width: 28px; height: 28px; }
.spacer { width: 28px; flex: none; }
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #9aa3ad; animation: sa-blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes sa-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.choices { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; padding-left: 36px; }
.chip {
  border: 1.5px solid var(--accent); background: #fff; color: var(--accent); border-radius: 999px;
  padding: 7px 13px; font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; transition: background .15s, color .15s; line-height: 1.3;
}
.chip:hover { background: var(--accent); color: #fff; }
.chip.quiet { border-color: var(--line); color: var(--ink-soft); }
.chip.quiet:hover { background: var(--sand); color: var(--ink); }
.chip.wa { border-color: var(--wa); color: var(--navy-deep); }
.chip.wa:hover { background: var(--wa); color: #fff; }
.chip svg { width: 12px; height: 12px; }

.card { margin-left: 36px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 12px; box-shadow: 0 2px 8px rgba(18, 24, 35, .05); }
.field { display: grid; gap: 4px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--navy); }
.field .req { color: var(--error); margin-left: 2px; }
.field .opt { color: var(--ink-soft); font-weight: 400; }
.field input, .field textarea {
  width: 100%; border: 1px solid #cfcac0; border-radius: 6px; padding: 9px 11px; font: inherit; font-size: 16px;
  color: var(--ink); background: #fff; margin: 0; -webkit-appearance: none; appearance: none;
}
@media (min-width: 521px) { .field input, .field textarea { font-size: 14px; } }
.field textarea { min-height: 64px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0, 171, 160, .18); }
.field.bad input, .field.bad textarea { border-color: var(--error); }
.field.good input { border-color: #8cc9a0; }
.err { font-size: 12px; color: var(--error); }
.err:empty { display: none; }
.hint { font-size: 12px; color: var(--ink-soft); }
.reg { text-transform: uppercase; letter-spacing: .06em; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink); }
.check input { margin-top: 3px; accent-color: var(--accent); }
.privacy { margin: 0; font-size: 11.5px; color: var(--ink-soft); }
.form-error { font-size: 13px; color: var(--error); background: #fbeceb; border-radius: 6px; padding: 8px 10px; }
.hp { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; }

.drop { display: block; border: 1.5px dashed #bdb7ab; border-radius: 10px; padding: 14px; text-align: center; color: var(--ink-soft); font-size: 13px; cursor: pointer; background: #fbfaf8; }
.drop:hover, .drop.over { border-color: var(--brand); background: var(--accent-soft); color: var(--navy); }
.drop b { color: var(--navy); }
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.thumbs:empty { display: none; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; max-width: 100%; display: block; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cta.secondary { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }
.cta.secondary:hover { background: var(--accent-soft); }

.foot-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 14px; font-size: 11.5px; color: var(--ink-soft); border-top: 1px solid var(--line); background: #fff; }
.foot-line a { color: var(--ink-soft); font-size: 10.5px; }

/* ---------- phone: full-screen panel ---------- */
@media (max-width: 520px) {
  .w { right: calc(14px + env(safe-area-inset-right, 0px)); }
  .w.open { inset: 0; right: 0; bottom: 0; gap: 0; align-items: stretch; }
  .w.open .panel {
    width: 100%; height: 100%; border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .w.open .launcher, .w.open .teaser { display: none; }
  .bubble { max-width: 84%; }
}

@media (prefers-reduced-motion: reduce) {
  .teaser, .panel, .msg { animation: none; }
  .launcher { transition: none; }
}
