/* Chat web do assistente. Tema por omissão = identidade Enigmatic Velvet v3 (noir, creme, latão, teal de sinal,
   ferrugem de ação). Cada estúdio troca só a cor de ação (--brand) e o logótipo; o chat.js calcula as variantes. */

@font-face { font-family: "Manrope"; src: url("/chat/fonts/manrope-latin.woff2") format("woff2-variations"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Bricolage"; src: url("/chat/fonts/bricolage-latin.woff2") format("woff2-variations"); font-weight: 200 800; font-display: swap; }

:root {
  --brand: #e0561e;
  --brand-ink: #15100b;
  --brand-text: var(--brand-text-light, #b4441a);

  --bg: #f7f2e8;
  --surface: #fffdf8;
  --raised: #efe7d7;
  --text: #15100b;
  --muted: #62584c;
  --line: rgba(21, 16, 11, .12);
  --bubble: #fffdf8;
  --mine: color-mix(in srgb, var(--brand) 16%, var(--surface));
  --staff: #f3e3bf;
  --signal: #2f7a71;
  --brass: #9a7230;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(21, 16, 11, .14);

  --display: "Bricolage", ui-sans-serif, system-ui, sans-serif;
  --body: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-text: var(--brand-text-dark, #ff7a45);
    --bg: #15100b;
    --surface: #1b1510;
    --raised: #231b14;
    --text: #f3ead8;
    --muted: #a3988a;
    --line: rgba(243, 234, 216, .10);
    --bubble: #231b14;
    --mine: color-mix(in srgb, var(--brand) 26%, var(--surface));
    --staff: #3a2c18;
    --signal: #5fb3a9;
    --brass: #c99b47;
    --danger: #ff8a7a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  }
}

/* Esquema imposto pelo negócio (site claro ou escuro), por cima do do aparelho. */
:root[data-scheme="light"] {
  --brand-text: var(--brand-text-light, #b4441a);
  --bg: #f7f2e8; --surface: #fffdf8; --raised: #efe7d7; --text: #15100b; --muted: #62584c;
  --line: rgba(21, 16, 11, .12); --bubble: #fffdf8; --mine: color-mix(in srgb, var(--brand) 16%, var(--surface));
  --staff: #f3e3bf; --signal: #2f7a71; --brass: #9a7230; --danger: #b42318; --shadow: 0 10px 30px rgba(21, 16, 11, .14);
  color-scheme: light;
}
:root[data-scheme="dark"] {
  --brand-text: var(--brand-text-dark, #ff7a45);
  --bg: #15100b; --surface: #1b1510; --raised: #231b14; --text: #f3ead8; --muted: #a3988a;
  --line: rgba(243, 234, 216, .10); --bubble: #231b14; --mine: color-mix(in srgb, var(--brand) 26%, var(--surface));
  --staff: #3a2c18; --signal: #5fb3a9; --brass: #c99b47; --danger: #ff8a7a; --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* Demonstração: superfícies neutras com um toque da cor da marca, em vez dos tons da Enigmatic Velvet. */
:root[data-tint="brand"] {
  --bg: color-mix(in srgb, var(--brand) 5%, #f6f6f4); --surface: color-mix(in srgb, var(--brand) 2%, #ffffff);
  --raised: color-mix(in srgb, var(--brand) 9%, #f1f1ee); --bubble: #ffffff; --text: #16181a; --muted: #5d6166;
  --line: color-mix(in srgb, var(--brand) 14%, rgba(0, 0, 0, .10)); --signal: var(--brand-text);
  --staff: color-mix(in srgb, var(--brand) 14%, #ffffff);
}
@media (prefers-color-scheme: dark) {
  :root[data-tint="brand"]:not([data-scheme="light"]) {
    --bg: color-mix(in srgb, var(--brand) 7%, #0e0f10); --surface: color-mix(in srgb, var(--brand) 5%, #141516);
    --raised: color-mix(in srgb, var(--brand) 11%, #1b1c1e); --bubble: color-mix(in srgb, var(--brand) 9%, #1b1c1e);
    --text: #eef0f1; --muted: #a2a7ab; --line: color-mix(in srgb, var(--brand) 20%, rgba(255, 255, 255, .08));
    --staff: color-mix(in srgb, var(--brand) 22%, #1b1c1e);
  }
}
:root[data-tint="brand"][data-scheme="dark"] {
  --bg: color-mix(in srgb, var(--brand) 7%, #0e0f10); --surface: color-mix(in srgb, var(--brand) 5%, #141516);
  --raised: color-mix(in srgb, var(--brand) 11%, #1b1c1e); --bubble: color-mix(in srgb, var(--brand) 9%, #1b1c1e);
  --text: #eef0f1; --muted: #a2a7ab; --line: color-mix(in srgb, var(--brand) 20%, rgba(255, 255, 255, .08));
  --staff: color-mix(in srgb, var(--brand) 22%, #1b1c1e);
}

.card__demo { margin: 4px 0 6px; padding: 8px 10px; border-radius: 8px; font-size: .82rem; line-height: 1.4;
  background: color-mix(in srgb, #f0a030 16%, transparent); border: 1px solid color-mix(in srgb, #f0a030 45%, transparent); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; background: var(--bg); }

body {
  color: var(--text);
  font: 400 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 6px; }

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

@media (min-width: 760px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* Cabeçalho */
.top {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 8px 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.top__who { flex: 1; min-width: 0; }
.top__name { margin: 0; font: 650 1.02rem/1.25 var(--body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top__status { display: flex; align-items: center; gap: 6px; margin: 2px 0 0; font-size: .8rem; color: var(--muted); }

.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot--open { background: var(--signal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 25%, transparent); }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--brand);
  color: var(--brand-ink);
  font: 700 .95rem/1 var(--body);
  letter-spacing: .02em;
}
.avatar img { width: 100%; height: 100%; object-fit: contain; }
.avatar--logo { background: var(--raised); border: 1px solid var(--line); }
.avatar--lg { width: 72px; height: 72px; font-size: 1.5rem; }
.avatar--lg.avatar--logo { padding: 8px; }

.icon-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}
.icon-button:hover { background: var(--raised); color: var(--text); }
.icon-button svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 0; }
#close svg { fill: none; stroke-width: 2.2; stroke-linecap: round; }

.menu {
  position: absolute;
  z-index: 5;
  top: calc(100% - 6px);
  right: 10px;
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.menu > * {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  font-size: .95rem;
}
.menu > *:hover { background: var(--raised); }

/* Faixa de IA: sempre visível (AI Act, art. 50) */
.ai-strip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 6px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.3;
}
.ai-strip strong { color: var(--text); font-weight: 600; }
.ai-strip svg { flex: none; width: 14px; height: 14px; fill: var(--brass); }

.alert {
  flex: none;
  margin: 0;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  color: var(--text);
  font-size: .85rem;
  border-bottom: 1px solid var(--line);
}

/* Conversa */
.thread {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 12px 10px;
  scroll-padding-bottom: 12px;
}
.thread:focus { outline: none; }

.card {
  margin: 4px auto 14px;
  padding: 18px 16px 16px;
  max-width: 420px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.card .avatar { margin: 0 auto 10px; }
.card__name { margin: 0; font: 600 1.25rem/1.15 var(--display); letter-spacing: -.02em; }
.card__line { margin: 6px 0 0; color: var(--muted); font-size: .85rem; }

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.day {
  align-self: center;
  margin: 12px 0 8px;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .74rem;
  font-weight: 600;
}

.message {
  max-width: min(82%, 520px);
  margin-top: 10px;
  padding: 8px 12px 5px;
  border-radius: 18px;
  background: var(--bubble);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: .97rem;
  line-height: 1.45;
}
.message--grouped { margin-top: 3px; }
.message a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.message--assistant, .message--staff { align-self: flex-start; border-bottom-left-radius: 6px; }
.message--assistant.message--grouped, .message--staff.message--grouped { border-top-left-radius: 6px; }
.message--customer { align-self: flex-end; background: var(--mine); border-color: color-mix(in srgb, var(--brand) 30%, transparent); border-bottom-right-radius: 6px; }
.message--customer.message--grouped { border-top-right-radius: 6px; }
.message--staff { background: var(--staff); border-color: color-mix(in srgb, var(--brass) 55%, transparent); border-left: 3px solid var(--brass); }

/* Quem fala: assistente (IA) ou pessoa da equipa. Ícone + nome + etiqueta, nunca só a cor. */
.sender { display: flex; align-items: center; gap: 7px; margin: 14px 0 -4px 2px; font-size: .78rem; line-height: 1.2; }
.sender__avatar {
  display: grid; place-items: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: .62rem; font-weight: 800; letter-spacing: .02em;
}
.sender__avatar svg { width: 14px; height: 14px; fill: currentColor; }
.sender__avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.sender--assistant .sender__avatar { background: var(--raised); color: var(--brass); border: 1px solid var(--line); }
.sender--staff .sender__avatar { background: var(--brand); color: var(--brand-ink); }
.sender__name { font-weight: 700; color: var(--text); }
.sender__tag { padding: 1px 7px; border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .02em; }
.sender--assistant .sender__tag { background: var(--raised); color: var(--muted); border: 1px solid var(--line); }
.sender--staff .sender__tag { background: color-mix(in srgb, var(--brass) 22%, transparent); color: var(--text); }

.handover {
  align-self: center;
  max-width: 90%;
  margin: 16px 0 2px;
  padding: 4px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brass) 16%, var(--surface));
  color: var(--text);
  font-size: .78rem;
  font-weight: 600;
  text-align: center;
}
.message__meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 1px; color: var(--muted); font-size: .7rem; line-height: 1.4; white-space: nowrap; }
.message__meta svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.message--pending { opacity: .7; }
.message--failed { border-color: var(--danger); }
.retry {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin: 0;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: .82rem;
}
.retry u { font-weight: 700; text-underline-offset: 2px; }

/* A escrever: três pontos dentro da conversa */
.typing {
  display: inline-flex;
  margin-top: 10px;
  padding: 13px 15px;
  background: var(--bubble);
  border: 1px solid var(--line);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}
.typing__dots { display: flex; gap: 5px; }
.typing__dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typing 1.2s infinite ease-in-out; }
.typing__dots i:nth-child(2) { animation-delay: .15s; }
.typing__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.message--new { animation: rise .32s var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  .typing__dots i { animation: none; opacity: .75; }
  .message--new { animation: none; }
}

.jump {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* Passagem para a dona */
.handoff {
  flex: none;
  margin: 0;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--signal) 14%, var(--surface));
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: .82rem;
  line-height: 1.4;
}

/* Sugestões */
.suggestions { flex: none; padding: 6px 0 2px; background: var(--bg); }
.suggestions__row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 12px 6px; scrollbar-width: none; }
.suggestions__row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 40px;
  padding: 0 15px;
  border: 1.5px solid var(--brand);
  border-radius: 999px;
  background: var(--surface);
  color: var(--brand-text);
  font-size: .9rem;
  font-weight: 650;
  white-space: nowrap;
}
.chip:hover { background: var(--mine); }

/* Aviso antes de começar (no lugar da caixa de escrever) */
.consent {
  flex: none;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.45;
}
.consent__title { margin: 0 0 6px; color: var(--text); font: 650 .95rem/1.3 var(--body); }
.consent p { margin: 0 0 8px; }
.consent strong { color: var(--text); font-weight: 650; }
.consent a { color: var(--brand-text); font-weight: 600; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
}
.consent .button { width: 100%; margin-top: 4px; }
.button--ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.button:disabled { opacity: .6; cursor: default; }

/* Escrever */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 16px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--bg);
  font-size: 16px;
  line-height: 1.4;
}
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus-visible { outline: 2px solid var(--signal); outline-offset: 0; border-radius: 22px; }

.send {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
}
.send svg { width: 20px; height: 20px; fill: currentColor; }
.send:disabled { background: var(--raised); color: var(--muted); cursor: default; }
.send:focus-visible { border-radius: 50%; }

.dialog {
  max-width: min(360px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(21, 16, 11, .5); }
.dialog h2 { margin: 0 0 8px; font: 600 1.15rem/1.2 var(--display); letter-spacing: -.01em; }
.dialog p { margin: 0 0 16px; color: var(--muted); font-size: .92rem; }
.dialog__actions { display: flex; gap: 8px; justify-content: flex-end; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Dentro do widget (iframe) */
.embedded .app { max-width: none; border: 0; }

/* Cartões na conversa: verificação do contacto, horários e marcação */
.card {
  align-self: flex-start;
  max-width: min(88%, 420px);
  margin: 8px 0 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card__title { margin: 0; font: 700 1.02rem/1.3 var(--display); }
.card__text { margin: 0; color: var(--muted); }
.card__strong { color: var(--text); font-weight: 650; }
.card__code { margin: 0; font-size: .85rem; color: var(--muted); letter-spacing: .04em; }
.card__choices { display: flex; flex-wrap: wrap; gap: 8px; }
.card__qr { display: none; flex-direction: column; align-items: flex-start; gap: 6px; }
.card__qr svg { width: 156px; height: auto; background: #fff; padding: 8px; border-radius: 12px; }
.card__hint { font-size: .8rem; color: var(--muted); }
@media (min-width: 768px) and (pointer: fine) { .card__qr { display: flex; } }
.card--done { border-color: color-mix(in srgb, var(--signal) 55%, transparent); }
.card--done .card__title { color: var(--signal); }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  font: 650 .95rem/1 var(--body); text-decoration: none; cursor: pointer;
}
.btn--primary { background: var(--brand); color: var(--brand-ink); border: 0; }
.btn--primary:hover { filter: brightness(1.05); }
.btn--ghost { background: transparent; color: var(--brand-text); border: 1.5px solid var(--line); }
.btn:disabled, .chip:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, .chip:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
.chip--chosen { background: var(--mine); }
.notice { align-self: center; margin: 6px 0; font-size: .85rem; color: var(--muted); }

/* "Nova conversa" sempre à vista no topo (o menu ⋮ continua a ter a opção) */
.new-button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px; margin-left: auto;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--text);
  font: 650 .85rem/1 var(--body); cursor: pointer; white-space: nowrap;
}
.new-button:hover { background: var(--raised); }
.new-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.new-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
.new-button[hidden] { display: none; }
@media (max-width: 380px) { .new-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } .new-button { padding: 0 9px; } }

/* Cartão do código por e-mail */
.card__form { display: flex; gap: 8px; }
.card__input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text);
  font: 650 1.1rem/1 var(--body); letter-spacing: .3em;
}
.card__input:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 1px; }
.card__error { margin: 0; min-height: 1em; font-size: .85rem; color: var(--danger); }
.card__error:empty { display: none; }

/* Cartões de escolha já respondidos: o escolhido em destaque com ✓, os outros apagados e sem interação */
.card__choices .chip:disabled { opacity: .35; border-color: var(--line); color: var(--muted); background: var(--surface); cursor: default; }
.card__choices .chip:disabled:hover { background: var(--surface); }
.card__choices .chip--chosen, .card__choices .chip--chosen:disabled, .card__choices .chip--chosen:disabled:hover {
  opacity: 1; border-color: var(--brand); background: var(--brand); color: var(--brand-ink);
}
.card__choices .chip--chosen::before { content: "✓ "; }

/* Marcação substituída por uma remarcação */
.card--outdated { opacity: .55; }
.card--outdated .card__title { text-decoration: line-through; }
