/* ──────────────────────────────────────────────
   iddchatai — Widget de chat flutuante
   ────────────────────────────────────────────── */

:root {
  --iddchat-primary:   #1a56db;
  --iddchat-primary-h: #1648c0;
  --iddchat-bg:        #ffffff;
  --iddchat-surface:   #f3f4f6;
  --iddchat-text:      #111827;
  --iddchat-muted:     #6b7280;
  --iddchat-border:    #e5e7eb;
  --iddchat-shadow:    0 8px 32px rgba(0,0,0,.18);
  --iddchat-radius:    16px;
  --iddchat-z:         9999;
}

/* ── Contentor raiz ── */
#iddchat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--iddchat-z);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Botão toggle ── */
#iddchat-toggle {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--iddchat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--iddchat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .2s;
}
#iddchat-toggle:hover { background: var(--iddchat-primary-h); transform: scale(1.05); }
#iddchat-toggle:focus-visible { outline: 3px solid var(--iddchat-primary); outline-offset: 3px; }

/* Badge de notificação não lida */
.iddchat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* ── Painel do chat ── */
#iddchat-box {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 360px;
  max-height: 520px;
  background: var(--iddchat-bg);
  border: 1px solid var(--iddchat-border);
  border-radius: var(--iddchat-radius);
  box-shadow: var(--iddchat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity .2s, transform .2s;
}
#iddchat-box[hidden] {
  display: none;
}
@media (max-width: 420px) {
  #iddchat-box {
    width: calc(100vw - 32px);
    right: -8px;
    bottom: 72px;
    max-height: 70vh;
  }
}

/* ── Cabeçalho ── */
#iddchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--iddchat-primary);
  color: #fff;
  border-radius: var(--iddchat-radius) var(--iddchat-radius) 0 0;
  flex-shrink: 0;
}
#iddchat-title {
  font-weight: 600;
  font-size: 15px;
}
/* Favicon do site antes do título */
#iddchat-favicon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: cover;
  background: #fff;
  margin-right: 9px;
  flex-shrink: 0;
  vertical-align: middle;
}
#iddchat-header #iddchat-title {
  flex: 1;
}
/* Faixa "Powered by" — lateral esquerda do painel, texto vertical, centrado
   na altura da caixa de diálogo. Sem rebordo, apenas o texto.
   Acompanha a altura real da caixa (que cresce/encolhe com a conversa):
   partilha o mesmo bottom e o mesmo limite superior (max-height) da caixa,
   e o flex-center trata do resto. */
#iddchat-powered {
  position: absolute;
  right: 360px;               /* encostado à esquerda do painel (width 360) */
  bottom: 68px;               /* mesmo bottom do painel */
  top: auto;
  max-height: 520px;          /* mesmo limite do painel */
  height: auto;               /* acompanha o conteúdo, não fixa */
  min-height: 180px;          /* garante presença mesmo com pouca conversa */
  display: flex;
  align-items: center;        /* CENTRADO na altura da caixa */
  justify-content: center;
  padding: 0 4px;
  pointer-events: none;       /* só o link é clicável */
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10.5px;
  line-height: 1;
  color: var(--iddchat-muted, #9aa0a6);
  letter-spacing: .3px;
  white-space: nowrap;
}
#iddchat-powered a {
  color: var(--iddchat-primary);
  text-decoration: none;
  pointer-events: auto;       /* o link volta a ser clicável */
}
#iddchat-powered a:hover {
  text-decoration: underline;
}
/* Quando o painel está escondido, a faixa também. */
#iddchat-box[hidden] ~ #iddchat-powered {
  display: none;
}
@media (max-width: 420px) {
  /* Em ecrãs estreitos, a faixa lateral rouba espaço — escondemo-la. */
  #iddchat-powered { display: none; }
}
#iddchat-close {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
#iddchat-close:hover { color: #fff; }

/* ── Área de mensagens ── */
#iddchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Bolhas */
.iddchat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.55;
  word-break: break-word;
  animation: iddchat-pop .15s ease;
}
@keyframes iddchat-pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.iddchat-msg--user {
  align-self: flex-end;
  background: var(--iddchat-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.iddchat-msg--assistant {
  align-self: flex-start;
  background: var(--iddchat-surface);
  color: var(--iddchat-text);
  border-bottom-left-radius: 4px;
}
/* Formatação simples no texto do assistente */
.iddchat-msg--assistant strong { font-weight: 600; }
.iddchat-msg--assistant em    { font-style: italic; }

/* ── Indicador de digitação ── */
#iddchat-typing {
  padding: 0 16px 8px;
  display: flex;
  gap: 4px;
  align-items: center;
}
#iddchat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--iddchat-muted);
  animation: iddchat-bounce 1.2s infinite;
}
#iddchat-typing span:nth-child(2) { animation-delay: .2s; }
#iddchat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes iddchat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}
#iddchat-typing[hidden] { display: none; }

/* ── Formulário ── */
#iddchat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--iddchat-border);
  flex-shrink: 0;
  background: var(--iddchat-bg);
}
#iddchat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--iddchat-border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--iddchat-text);
  background: var(--iddchat-surface);
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
  transition: border-color .15s;
}
#iddchat-input:focus {
  outline: none;
  border-color: var(--iddchat-primary);
  background: #fff;
}
#iddchat-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--iddchat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}
#iddchat-send:hover  { background: var(--iddchat-primary-h); }
#iddchat-send:disabled { opacity: .5; cursor: not-allowed; }

/* ── Rodapé ── */
#iddchat-footer {
  font-size: 11px;
  color: var(--iddchat-muted);
  text-align: center;
  padding: 4px 12px 8px;
  background: var(--iddchat-bg);
  flex-shrink: 0;
}

/* ── Formulário de contacto ── */
.iddchat-form-wrap {
  margin: 8px 0;
  padding: 14px;
  background: #f7f8fa;
  border: 1px solid #e3e6ea;
  border-radius: 12px;
}
.iddchat-cform { display: flex; flex-direction: column; gap: 8px; }
.iddchat-field {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #cfd4da;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
  background: #fff;
  color: #222;
}
.iddchat-field:focus {
  outline: none;
  border-color: var(--iddchat-primary, #1a56db);
}
textarea.iddchat-field { resize: vertical; min-height: 60px; }
.iddchat-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: #555;
  cursor: pointer;
}
.iddchat-consent input { margin-top: 2px; flex-shrink: 0; }
.iddchat-consent a { color: var(--iddchat-primary, #1a56db); }
.iddchat-form-send {
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--iddchat-primary, #1a56db);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.iddchat-form-send:disabled { opacity: .6; cursor: default; }
.iddchat-form-msg {
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
}
.iddchat-form-msg--error { background: #fdecec; color: #c0281f; }
.iddchat-form-msg--ok { background: #eafaf1; color: #1a7f43; }
