/* ============================================================
   RegulaBio Chat Widget
   Mobile-first, cores do design system
   ============================================================ */

:root {
  --rb-petroleo:  #1B3A4B;
  --rb-ambar:     #8B5E3C;
  --rb-dourado:   #B8975A;
  --rb-creme:     #F5F0EB;
  --rb-creme-d:   #E8E0D8;
  --rb-font:      'Inter', sans-serif;
  --rb-radius:    14px;
  --rb-shadow:    0 8px 32px rgba(27,58,75,0.18);
}

/* --- Botão flutuante --- */
#rb-chat-toggle {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  height: 52px;
  padding: 0 20px 0 16px;
  border-radius: 26px;
  background: var(--rb-dourado);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(184,151,90,0.5), 0 2px 8px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s, opacity 0.3s;
  white-space: nowrap;
}
#rb-chat-toggle:hover {
  background: #c9a660;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(184,151,90,0.6), 0 3px 10px rgba(0,0,0,0.2);
}
#rb-chat-toggle svg { width: 22px; height: 22px; fill: #fff; flex-shrink: 0; }
#rb-chat-toggle-label {
  font-family: var(--rb-font);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.2px;
}

/* Badge de notificação */
#rb-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--rb-dourado);
  border: 2px solid white;
  display: none;
}
#rb-chat-badge.visible { display: block; }

/* --- Tela de consentimento --- */
#rb-consent-screen {
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  flex: 1;
  overflow-y: auto;
}
#rb-consent-icon {
  width: 52px; height: 52px;
  background: var(--rb-petroleo);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
#rb-consent-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--rb-petroleo);
  line-height: 1.3;
}
#rb-consent-desc {
  font-size: 13px;
  color: #666;
  line-height: 1.6;
  margin: 0;
}
#rb-consent-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  font-size: 12px;
  color: #555;
  line-height: 1.5;
  cursor: pointer;
  width: 100%;
  background: var(--rb-creme);
  padding: 12px;
  border-radius: 8px;
}
#rb-consent-check input[type="checkbox"] {
  margin-top: 1px;
  width: 15px; height: 15px;
  flex-shrink: 0;
  accent-color: var(--rb-petroleo);
  cursor: pointer;
}
/* Links dos termos e privacidade — fora do container clicável do checkbox,
   para evitar que clicks no label "vazem" para os links em mobile. */
#rb-consent-links {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: #666;
}
#rb-consent-links a {
  color: var(--rb-dourado);
  font-weight: 600;
  text-decoration: none;
}
#rb-consent-links a:hover { text-decoration: underline; }
#rb-consent-btn {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  background: var(--rb-petroleo);
  color: white;
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s;
}
#rb-consent-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#rb-consent-btn:not(:disabled):hover { opacity: 0.88; }

/* --- Janela do chat --- */
#rb-chat-window {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 9999;
  width: 400px;
  max-width: calc(100vw - 32px);
  max-height: 640px;
  height: calc(100vh - 100px);
  background: white;
  border-radius: var(--rb-radius);
  box-shadow: var(--rb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--rb-font);
  transform: scale(0.95) translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s, opacity 0.2s;
}
#rb-chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
#rb-chat-header {
  background: var(--rb-petroleo);
  color: var(--rb-creme);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#rb-chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--rb-dourado);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
#rb-chat-header-info { flex: 1; min-width: 0; }
#rb-chat-header-name { font-size: 14px; font-weight: 700; }
#rb-chat-header-status { font-size: 11px; color: rgba(245,240,235,0.65); }
#rb-chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(245,240,235,0.7);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  transition: color 0.15s;
}
#rb-chat-close:hover { color: var(--rb-creme); }
#rb-chat-close svg { width: 18px; height: 18px; }

/* Mensagens */
#rb-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--rb-creme);
}
#rb-chat-messages::-webkit-scrollbar { width: 4px; }
#rb-chat-messages::-webkit-scrollbar-thumb { background: var(--rb-creme-d); border-radius: 4px; }

.rb-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 88%;
}
.rb-msg--assistant { align-self: flex-start; }
.rb-msg--user     { align-self: flex-end; flex-direction: row-reverse; }

.rb-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--rb-petroleo);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.rb-msg__bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
}
.rb-msg--assistant .rb-msg__bubble {
  background: white;
  color: var(--rb-petroleo);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.rb-msg--user .rb-msg__bubble {
  background: var(--rb-petroleo);
  color: var(--rb-creme);
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.rb-typing .rb-msg__bubble {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}
.rb-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rb-ambar);
  animation: rb-bounce 1.2s infinite;
}
.rb-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.rb-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes rb-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-5px); opacity: 1; }
}

/* Banner de classificação */
.rb-classification-banner {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  border: 1.5px solid;
}
.rb-classification-banner--com_passivo {
  background: #fff7ed;
  border-color: #fb923c;
  color: #c2410c;
}
.rb-classification-banner--sem_passivo {
  background: #f0fdf4;
  border-color: #4ade80;
  color: #166534;
}
.rb-classification-banner--incerto {
  background: #fefce8;
  border-color: #facc15;
  color: #854d0e;
}

/* Card CTA pós-diagnóstico */
.rb-cta-card {
  background: white;
  border: 1.5px solid var(--rb-dourado);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 4px;
}
.rb-cta-card__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--rb-petroleo);
  margin-bottom: 6px;
}
.rb-cta-card__text {
  font-size: 12px;
  color: #666;
  line-height: 1.5;
  margin-bottom: 12px;
}
.rb-cta-btn {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--rb-dourado);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s;
  box-sizing: border-box;
}
.rb-cta-btn:hover { background: #a07840; }

/* Input */
#rb-chat-footer {
  padding: 12px;
  border-top: 1px solid var(--rb-creme-d);
  background: white;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
#rb-chat-input {
  flex: 1;
  border: 1.5px solid var(--rb-creme-d);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: var(--rb-font);
  font-size: 13px;
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 100px;
  transition: border-color 0.15s;
}
#rb-chat-input:focus { border-color: var(--rb-petroleo); }
#rb-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--rb-petroleo);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  align-self: flex-end;
}
#rb-chat-send:hover { background: #243f52; }
#rb-chat-send:disabled { background: var(--rb-creme-d); cursor: not-allowed; }
#rb-chat-send svg { width: 16px; height: 16px; fill: white; }

/* Markdown dentro das mensagens */
.rb-msg__bubble strong {
  font-weight: 700;
  color: inherit;
}
.rb-msg__bubble em {
  font-style: italic;
}
.rb-msg__bubble .rb-md-heading {
  font-size: 14px;
  font-weight: 700;
  margin: 8px 0 3px;
  color: inherit;
}
.rb-msg__bubble hr {
  border: none;
  border-top: 1px solid rgba(0,0,0,0.1);
  margin: 8px 0;
}
.rb-msg__bubble .rb-md-li {
  display: block;
  padding-left: 14px;
  position: relative;
  margin-top: 4px;
}
.rb-msg__bubble .rb-md-li::before {
  content: '•';
  position: absolute;
  left: 2px;
  font-weight: 700;
  color: var(--rb-dourado);
}

/* Disclaimer */
#rb-chat-disclaimer {
  text-align: center;
  font-size: 10px;
  color: #aaa;
  padding: 6px 12px 10px;
  background: white;
}

/* Backdrop (desktop — fecha o painel ao clicar fora) */
.rb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27,58,75,0.15);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9997;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.rb-backdrop.visible {
  opacity: 1;
  pointer-events: all;
}

/* Desktop: painel lateral (slide-in da direita, 50% da tela) */
@media (min-width: 481px) {
  #rb-chat-window {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: 50vw;
    max-width: none;
    max-height: none;
    height: 100vh;
    border-radius: 0;
    box-shadow: -6px 0 24px rgba(27,58,75,0.12);
    transform: translateX(100%);
    transition: transform 0.3s ease-out, opacity 0.3s;
  }
  #rb-chat-window.open {
    transform: translateX(0);
  }
}

/* Mobile: ocupa tela inteira */
@media (max-width: 480px) {
  #rb-chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
  #rb-chat-header {
    padding: max(54px, calc(14px + env(safe-area-inset-top))) 16px 14px 16px;
  }
  #rb-chat-footer {
    padding: 12px 12px max(24px, calc(12px + env(safe-area-inset-bottom))) 12px;
  }
  #rb-chat-toggle { bottom: 84px; right: 16px; height: 48px; padding: 0 16px 0 13px; }
  #rb-chat-toggle-label { font-size: 13px; }
  .rb-backdrop { display: none; }
}
