/*
  Estilos do widget de chat da Kooldent.
  ---
  Tudo está prefixado com .kd-chat-* para evitar colisões com o CSS do site.
  As cores estão alinhadas com brand.json (accent #77227f, ink_900 #16181c).
  Suporta dark theme do utilizador via prefers-color-scheme.
*/

/* === Tokens locais (sincronizados com brand.json) === */
.kd-chat-root {
  /* Cores Kooldent */
  --kd-accent: #77227f;
  --kd-accent-hover: #5a1860;
  --kd-accent-soft: #f4ecf9;
  --kd-ink-900: #16181c;
  --kd-ink-700: #2a2d35;
  --kd-ink-500: #5b606c;
  --kd-ink-200: #dadde3;
  --kd-ink-100: #eef0f4;
  --kd-ink-50: #f7f8fa;
  --kd-white: #ffffff;

  /* Tipografia (herda do site se disponível) */
  --kd-font: "Satoshi", "Geist", system-ui, -apple-system, sans-serif;

  /* Geometria */
  --kd-radius: 14px;
  --kd-radius-pill: 9999px;
  --kd-shadow: 0 20px 60px -25px rgba(12, 13, 16, 0.25);

  /* Posição na viewport — bubble bottom-right */
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999999;
  font-family: var(--kd-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--kd-ink-900);
}

/* === Botão flutuante (estado fechado) === */
.kd-chat-bubble {
  width: 88px;
  height: 88px;
  border-radius: var(--kd-radius-pill);
  background: var(--kd-white);
  border: 3px solid var(--kd-accent);
  cursor: pointer;
  box-shadow: var(--kd-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 150ms ease;
}
.kd-chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 24px 64px -20px rgba(119, 34, 127, 0.35);
}
.kd-chat-bubble:focus-visible {
  outline: 3px solid var(--kd-accent-soft);
  outline-offset: 3px;
}
.kd-chat-bubble-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  border-radius: var(--kd-radius-pill);

}

/* === Painel de chat (estado aberto) === */
.kd-chat-panel {
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--kd-white);
  border-radius: var(--kd-radius);
  box-shadow: var(--kd-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--kd-ink-200);
}
.kd-chat-root[data-open="true"] .kd-chat-panel {
  display: flex;
}
.kd-chat-root[data-open="true"] .kd-chat-bubble {
  display: none;
}

/* === Cabeçalho do painel === */
.kd-chat-header {
  background: var(--kd-accent);
  color: var(--kd-white);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.kd-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
/* Avatar da Kooly no cabeçalho */
.kd-chat-header-avatar-wrap {
  width: 44px;
  height: 44px;
  border-radius: var(--kd-radius-pill);
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}
.kd-chat-header-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;

}
.kd-chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kd-chat-header-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.kd-chat-header-subtitle {
  font-size: 12px;
  opacity: 0.85;
}
.kd-chat-close {
  background: transparent;
  border: none;
  color: var(--kd-white);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 150ms ease, background 150ms ease;
}
.kd-chat-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}
.kd-chat-close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* === Área de mensagens === */
.kd-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--kd-ink-50);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.kd-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--kd-radius);
  word-wrap: break-word;
  white-space: pre-wrap;
}
.kd-chat-msg-bot {
  background: var(--kd-white);
  border: 1px solid var(--kd-ink-200);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.kd-chat-msg-user {
  background: var(--kd-accent);
  color: var(--kd-white);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.kd-chat-msg a {
  color: inherit;
  text-decoration: underline;
}

/* Indicador "a escrever..." */
.kd-chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.kd-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--kd-ink-500);
  animation: kd-bounce 1.2s infinite ease-in-out;
}
.kd-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.kd-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes kd-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* === Card de confirmação de marcação === */
.kd-chat-booking-card {
  background: var(--kd-accent-soft);
  border: 1px solid var(--kd-accent);
  border-radius: var(--kd-radius);
  padding: 14px 16px;
  margin-top: 4px;
  align-self: stretch;
}
.kd-chat-booking-card h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--kd-accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kd-chat-booking-card dl {
  margin: 0 0 12px 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 13px;
}
.kd-chat-booking-card dt {
  color: var(--kd-ink-500);
  font-weight: 500;
}
.kd-chat-booking-card dd {
  margin: 0;
  color: var(--kd-ink-900);
}
.kd-chat-booking-actions {
  display: flex;
  gap: 8px;
}
.kd-chat-booking-actions button {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 150ms ease;
}
.kd-chat-booking-confirm {
  background: var(--kd-accent);
  color: var(--kd-white);
  border: none;
}
.kd-chat-booking-confirm:hover {
  background: var(--kd-accent-hover);
}
.kd-chat-booking-cancel {
  background: var(--kd-white);
  color: var(--kd-ink-700);
  border: 1px solid var(--kd-ink-200);
}
.kd-chat-booking-cancel:hover {
  background: var(--kd-ink-100);
}
.kd-chat-booking-success {
  color: var(--kd-accent);
  font-weight: 600;
  font-size: 13px;
  text-align: center;
}

/* === Barra de input === */
.kd-chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--kd-white);
  border-top: 1px solid var(--kd-ink-200);
  flex-shrink: 0;
}
.kd-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--kd-ink-200);
  border-radius: var(--kd-radius-pill);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 150ms ease;
}
.kd-chat-input:focus {
  border-color: var(--kd-accent);
}
.kd-chat-input:disabled {
  background: var(--kd-ink-100);
  cursor: not-allowed;
}
.kd-chat-send {
  background: var(--kd-accent);
  color: var(--kd-white);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--kd-radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms ease;
}
.kd-chat-send:hover:not(:disabled) {
  background: var(--kd-accent-hover);
}
.kd-chat-send:disabled {
  background: var(--kd-ink-300);
  cursor: not-allowed;
}
.kd-chat-send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* === Rodapé legal === */
.kd-chat-footer {
  padding: 6px 12px 8px;
  background: var(--kd-white);
  font-size: 11px;
  color: var(--kd-ink-500);
  text-align: center;
  border-top: 1px solid var(--kd-ink-100);
}
.kd-chat-footer a {
  color: var(--kd-ink-500);
  text-decoration: underline;
}

/* === Responsivo: telemóvel === */
@media (max-width: 480px) {
  .kd-chat-root {
    bottom: 12px;
    right: 12px;
  }
  .kd-chat-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 80px);
  }
}

/* === Acessibilidade: respeita reduced motion === */
@media (prefers-reduced-motion: reduce) {
  .kd-chat-bubble,
  .kd-chat-typing span,
  .kd-chat-greeting {
    transition: none;
    animation: none;
  }
}

/* === Saudação — mascote em destaque + texto solto, sem caixa === */
.kd-chat-greeting {
  position: absolute;
  right: 0;
  bottom: 104px; /* 88px do bubble + 16px de gap */
  display: flex;
  align-items: center;
  gap: 8px;
  /* width: max-content é obrigatório. Esta caixa é absoluta com apenas `right`
     definido, por isso o browser dimensiona-a contra a largura do contentor —
     e o .kd-chat-root mede só o botão (88px). Sem isto, a mascote não encolhe
     (flex-shrink: 0) e o texto era esmagado para ~95px de largura por 128px de
     altura: uma coluna de sete linhas colada à direita, que lia como se
     estivesse cortada pelo ecrã. O max-width impede o efeito contrário —
     transbordar para fora da viewport num telemóvel estreito. */
  width: max-content;
  max-width: calc(100vw - 24px);
  /* Sem fundo, sem borda — composição "aberta", a mascote é o protagonista */
  background: transparent;
  /* Estado inicial */
  opacity: 0;
  transform: translateY(14px) scale(.94);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 360ms cubic-bezier(.2,.8,.2,1),
              transform 420ms cubic-bezier(.2,.8,.2,1);
}
/* Mostrado / a esconder / escondido */
.kd-chat-greeting[data-greeting-state="shown"] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.kd-chat-greeting[data-greeting-state="hiding"] {
  opacity: 0;
  transform: translateY(8px) scale(.97);
  pointer-events: none;
}
.kd-chat-greeting[data-greeting-state="hidden"] { visibility: hidden; }

/* Mascote — grande, redonda, com sombra suave para destacar do fundo */
.kd-chat-greeting__mascot {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  flex-shrink: 0;
  filter: drop-shadow(0 12px 24px rgba(119, 34, 127, .28))
          drop-shadow(0 4px 8px rgba(12, 13, 16, .12));
  /* Animação de entrada própria — bounce subtil para reforçar o destaque */
  animation: kd-mascot-pop 600ms cubic-bezier(.34,1.56,.64,1) 80ms backwards;
}
.kd-chat-greeting[data-greeting-state="hidden"] .kd-chat-greeting__mascot,
.kd-chat-greeting[data-greeting-state="hiding"] .kd-chat-greeting__mascot { animation: none; }
@keyframes kd-mascot-pop {
  from { transform: scale(.6) rotate(-8deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

/* Texto — pílula minimal, ligeiramente inclinada (efeito diagonal/sticker) */
.kd-chat-greeting__text {
  margin: 0;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--kd-ink-900);
  font-weight: 500;
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  backdrop-filter: saturate(1.4) blur(8px);
  /* Canto inferior-esquerdo apontando para a mascote (que está à esquerda) */
  border-radius: 14px 14px 14px 4px;
  box-shadow: 0 8px 24px -10px rgba(12, 13, 16, .18);
  max-width: 200px;
  /* Inclinação subtil — efeito diagonal pedido */
  transform: rotate(-5deg);
  transform-origin: left center;
  transition: transform 200ms ease;
}
.kd-chat-greeting__text:hover { transform: rotate(-2deg); }

/* Botão X — no canto superior-direito da pílula (texto agora está à direita) */
.kd-chat-greeting__close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: var(--kd-white);
  color: var(--kd-ink-500);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 8px rgba(12, 13, 16, .18);
  transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
.kd-chat-greeting__close:hover {
  background: var(--kd-ink-100);
  color: var(--kd-ink-900);
  transform: scale(1.08);
}
.kd-chat-greeting__close svg { fill: currentColor; }

@media (max-width: 480px) {
  /* Botão a 56px: é a medida padrão de botão flutuante em iOS e Android.
     A 88px ocupava 23% da largura de um iPhone SE e assentava exactamente
     por cima do CTA do hero. 56px continua muito acima do alvo táctil
     mínimo (44px) e devolve 32px de altura à zona do botão principal. */
  .kd-chat-bubble { width: 56px; height: 56px; border-width: 2px; }
  /* A saudação assenta sobre o botão — se o botão encolhe, ela desce com ele.
     56px do botão + 16px de intervalo. */
  .kd-chat-greeting { bottom: 72px; }
  .kd-chat-greeting__mascot { width: 88px; height: 88px; }
  .kd-chat-greeting__text { max-width: 160px; font-size: 12.5px; }
}
