/* Chatbot de clientes da Lavanda do Amial — widget flutuante.
   Usa as cores de styles.css (--primary, --primary-700…) com valores de reserva. */

.lav-chat {
  --lc-primary: var(--primary, var(--lav, #8a3da0));
  --lc-primary-dark: var(--primary-700, var(--lav-dark, #5a1f72));
  --lc-primary-100: var(--primary-100, #f3e8f7);
  --lc-text: var(--text, #1d1526);
  --lc-text-2: var(--text-2, #5a5266);
  --lc-border: var(--border, #e6e0ed);
  --lc-surface: var(--surface, #ffffff);
  --lc-surface-2: var(--surface-2, #f7f5fa);
  --lc-ring: var(--ring, #8a3da0);
  --lc-font: var(--font-body, "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: var(--lc-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--lc-text);
}

.lav-chat *,
.lav-chat *::before,
.lav-chat *::after { box-sizing: border-box; }

/* Botão flutuante */
.lav-chat__fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 999px;
  background: var(--lc-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(61, 31, 80, .28);
  transition: transform .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.lav-chat__fab:hover { background: var(--lc-primary-dark); transform: translateY(-2px); }
.lav-chat__fab:focus-visible { outline: 3px solid var(--lc-ring); outline-offset: 3px; }
.lav-chat__fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lav-chat__fab .lav-chat__icon-close { display: none; }
.lav-chat.is-open .lav-chat__fab .lav-chat__icon-chat { display: none; }
.lav-chat.is-open .lav-chat__fab .lav-chat__icon-close { display: block; }

/* Janela */
.lav-chat__panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: min(380px, calc(100vw - 40px));
  height: min(560px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(61, 31, 80, .22);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(.98);
  transform-origin: bottom right;
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}
.lav-chat.is-open .lav-chat__panel {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity .2s ease, transform .2s ease, visibility 0s;
}

.lav-chat__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--lc-primary);
  color: #fff;
}
.lav-chat__header-text { flex: 1; min-width: 0; }
.lav-chat__title { font-weight: 700; font-size: 16px; margin: 0; }
.lav-chat__subtitle { font-size: 12.5px; opacity: .85; margin: 2px 0 0; }
.lav-chat__hbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
  transition: background-color .15s ease;
}
.lav-chat__hbtn:hover { background: rgba(255, 255, 255, .26); }
.lav-chat__hbtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.lav-chat__hbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Mensagens */
.lav-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--lc-surface-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}
.lav-chat__msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.lav-chat__msg--bot {
  align-self: flex-start;
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  border-bottom-left-radius: 6px;
}
.lav-chat__msg--user {
  align-self: flex-end;
  background: var(--lc-primary);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.lav-chat__msg a { color: var(--lc-primary-dark); text-decoration: underline; font-weight: 600; }
.lav-chat__msg--user a { color: #fff; }
.lav-chat__msg--error {
  background: #fff4f4;
  border-color: #f3c6c6;
  color: #7a1f1f;
}

/* "a escrever…" */
.lav-chat__typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  color: var(--lc-text-2);
  font-size: 13px;
}
.lav-chat__typing[hidden] { display: none; }
.lav-chat__dots { display: inline-flex; gap: 3px; }
.lav-chat__dots i {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--lc-primary);
  opacity: .35;
  animation: lav-chat-dot 1.1s infinite ease-in-out;
}
.lav-chat__dots i:nth-child(2) { animation-delay: .15s; }
.lav-chat__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes lav-chat-dot { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Formulário */
.lav-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--lc-border);
  background: var(--lc-surface);
}
.lav-chat__input {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--lc-border);
  border-radius: 14px;
  font: inherit;
  color: inherit;
  background: var(--lc-surface);
}
.lav-chat__input:focus-visible { outline: 2px solid var(--lc-ring); outline-offset: 1px; border-color: transparent; }
.lav-chat__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  background: var(--lc-primary);
  color: #fff;
  cursor: pointer;
  transition: background-color .15s ease, opacity .15s ease;
}
.lav-chat__send:hover { background: var(--lc-primary-dark); }
.lav-chat__send:disabled { opacity: .5; cursor: default; }
.lav-chat__send:focus-visible { outline: 3px solid var(--lc-ring); outline-offset: 2px; }
.lav-chat__send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lav-chat__note {
  margin: 0;
  padding: 0 12px 8px;
  font-size: 11.5px;
  color: var(--lc-text-2);
  background: var(--lc-surface);
}
.lav-chat__note a { color: inherit; }

.lav-chat__sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Telemóvel: ocupa o ecrã inteiro */
@media (max-width: 600px) {
  .lav-chat { right: 16px; bottom: 16px; }
  .lav-chat.is-open .lav-chat__fab { display: none; }
  .lav-chat__panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    height: 100dvh;
    border-radius: 0;
    border: 0;
    transform-origin: bottom center;
  }
  .lav-chat__header { padding-top: max(14px, env(safe-area-inset-top)); }
  .lav-chat__form { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .lav-chat__input { font-size: 16px; } /* evita zoom automático no iOS */
}

@media (prefers-reduced-motion: reduce) {
  .lav-chat__fab,
  .lav-chat__panel,
  .lav-chat__send,
  .lav-chat__hbtn { transition: none; }
  .lav-chat__dots i { animation: none; opacity: .8; }
}
