/* ============================================
   Chatbot IA Clarify - Widget Styles v2
   ============================================ */

#clarify-chatbot *,
#clarify-chatbot *::before,
#clarify-chatbot *::after {
  box-sizing: border-box;
  margin: 0;
}

#clarify-chatbot {
  --cb-primary: #4F46E5;
  --cb-primary-dark: #4338CA;
  --cb-primary-darker: #3730A3;
  --cb-primary-light: #EEF2FF;
  --cb-primary-glow: rgba(99, 102, 241, 0.35);
  --cb-accent: #F59E0B;
  --cb-text: #1E293B;
  --cb-text-mid: #475569;
  --cb-text-light: #94A3B8;
  --cb-bg: #FFFFFF;
  --cb-bg-chat: #F1F5F9;
  --cb-border: #E2E8F0;
  --cb-radius: 20px;
  --cb-shadow: 0 25px 50px -12px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.03);
  --cb-bubble-shadow: 0 8px 30px rgba(79, 70, 229, 0.4);

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--cb-text);
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999998;
}

/* ============================================
   BOLHA FLUTUANTE
   ============================================ */

.cb-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cb-primary) 0%, var(--cb-primary-darker) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--cb-bubble-shadow);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  animation: cb-bubbleIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.cb-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 10px 40px rgba(79, 70, 229, 0.5);
}

.cb-bubble:active {
  transform: scale(0.93);
}

/* Esconder bolha quando chat está aberto */
.cb-bubble.cb-open {
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
}

.cb-bubble svg {
  width: 26px;
  height: 26px;
  fill: #FFFFFF;
}

/* Pulse ring na bolha */
.cb-bubble::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--cb-primary);
  opacity: 0;
  animation: cb-pulseRing 3s ease-out infinite;
}

.cb-bubble.cb-open::before {
  display: none;
}

/* Preview tooltip */
.cb-bubble-preview {
  position: absolute;
  bottom: 68px;
  right: 0;
  background: white;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  padding: 14px 18px;
  padding-right: 32px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
  max-width: 270px;
  font-size: 13px;
  color: var(--cb-text);
  line-height: 1.45;
  animation: cb-previewIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  cursor: pointer;
}

.cb-bubble-preview::after {
  content: '';
  position: absolute;
  bottom: -5px;
  right: 20px;
  width: 10px;
  height: 10px;
  background: white;
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(0,0,0,0.04);
}

.cb-bubble-preview-close {
  position: absolute;
  top: 6px;
  right: 10px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--cb-text-light);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.cb-bubble-preview-close:hover {
  background: #F1F5F9;
  color: var(--cb-text-mid);
}

/* ============================================
   JANELA DO CHAT
   ============================================ */

.cb-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 48px);
  max-width: calc(100vw - 48px);
  background: var(--cb-bg);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: cb-windowIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.cb-window.cb-visible {
  display: flex;
}

/* Header */
.cb-header {
  background: linear-gradient(135deg, var(--cb-primary) 0%, var(--cb-primary-darker) 100%);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
}

.cb-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(0,0,0,0.1);
}

.cb-header-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.18);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.cb-header-avatar svg {
  width: 20px;
  height: 20px;
  fill: white;
}

/* Green dot - online */
.cb-header-avatar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  background: #22C55E;
  border-radius: 50%;
  border: 2px solid var(--cb-primary-darker);
}

.cb-header-info {
  flex: 1;
  min-width: 0;
}

.cb-header-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.cb-header-subtitle {
  font-size: 11px;
  opacity: 0.8;
  line-height: 1.3;
  margin-top: 1px;
}

.cb-header-actions {
  display: flex;
  gap: 2px;
}

.cb-header-btn {
  background: transparent;
  border: none;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  color: rgba(255,255,255,0.7);
}

.cb-header-btn:hover {
  background: rgba(255,255,255,0.15);
  color: white;
}

.cb-header-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Chat area */
.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--cb-bg-chat);
  scroll-behavior: smooth;
}

.cb-messages::-webkit-scrollbar {
  width: 5px;
}

.cb-messages::-webkit-scrollbar-track {
  background: transparent;
}

.cb-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 10px;
}

.cb-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.2);
}

/* Mensagens */
.cb-msg {
  display: flex;
  gap: 6px;
  max-width: 85%;
  animation: cb-msgIn 0.3s ease both;
}

.cb-msg-bot {
  align-self: flex-start;
}

.cb-msg-visitor {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.cb-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.cb-msg-avatar svg {
  width: 16px;
  height: 16px;
  fill: var(--cb-primary);
}

.cb-msg-visitor .cb-msg-avatar {
  display: none;
}

.cb-msg-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cb-msg-text {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.cb-msg-bot .cb-msg-text {
  background: white;
  color: var(--cb-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.cb-msg-visitor .cb-msg-text {
  background: linear-gradient(135deg, var(--cb-primary) 0%, var(--cb-primary-dark) 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.cb-msg-time {
  font-size: 10px;
  color: var(--cb-text-light);
  padding: 0 6px;
}

.cb-msg-visitor .cb-msg-time {
  text-align: right;
}

/* Markdown dentro das mensagens */
.cb-msg-text strong {
  font-weight: 600;
}

.cb-msg-text em {
  font-style: italic;
}

/* Quick replies */
.cb-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 4px 32px;
  animation: cb-msgIn 0.3s ease 0.15s both;
}

.cb-quick-btn {
  background: white;
  border: 1.5px solid var(--cb-primary);
  color: var(--cb-primary);
  border-radius: 22px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  box-shadow: 0 1px 4px rgba(79, 70, 229, 0.1);
  white-space: nowrap;
}

.cb-quick-btn:hover {
  background: var(--cb-primary);
  color: white;
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.3);
  transform: translateY(-1px);
}

/* Indicador de digitação */
.cb-typing {
  display: flex;
  gap: 6px;
  align-self: flex-start;
  max-width: 85%;
  animation: cb-msgIn 0.3s ease both;
}

.cb-typing-dots {
  background: white;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.cb-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--cb-text-light);
  border-radius: 50%;
  animation: cb-typingBounce 1.4s infinite;
}

.cb-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.cb-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

/* Input area */
.cb-input-area {
  padding: 14px 16px 16px;
  background: var(--cb-bg);
  border-top: 1px solid var(--cb-border);
  flex-shrink: 0;
}

.cb-input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.cb-input {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 46px;
  max-height: 100px;
  line-height: 1.45;
  color: var(--cb-text);
  background: var(--cb-bg-chat);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cb-input:focus {
  border-color: var(--cb-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  background: var(--cb-bg);
}

.cb-input::placeholder {
  color: var(--cb-text-light);
}

.cb-send-btn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--cb-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

.cb-send-btn:hover {
  background: var(--cb-primary-dark);
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.cb-send-btn:active {
  transform: scale(0.93);
}

.cb-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.cb-send-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  margin-left: 2px;
}

/* Footer brand */
.cb-footer-brand {
  text-align: center;
  padding: 6px;
  font-size: 10px;
  color: var(--cb-text-light);
  background: var(--cb-bg);
  letter-spacing: 0.02em;
}

/* ============================================
   ANIMACOES
   ============================================ */

@keyframes cb-bubbleIn {
  0% { transform: scale(0) rotate(-45deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes cb-pulseRing {
  0% { transform: scale(1); opacity: 0.5; }
  70% { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

@keyframes cb-windowIn {
  0% { transform: translateY(16px) scale(0.97); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes cb-msgIn {
  0% { transform: translateY(6px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes cb-typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes cb-previewIn {
  0% { transform: translateY(8px) scale(0.96); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* ============================================
   RESPONSIVO (mobile)
   ============================================ */

@media (max-width: 480px) {
  #clarify-chatbot {
    bottom: 0;
    right: 0;
    left: 0;
  }

  .cb-bubble {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 999998;
  }

  .cb-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-width: 100vw;
    border-radius: 0;
  }

  .cb-bubble-preview {
    position: fixed;
    right: 16px;
    bottom: 82px;
    max-width: calc(100vw - 48px);
  }
}

/* Ocultar */
#clarify-chatbot.cb-hidden {
  display: none !important;
}
