/* ── Reset & base ───────────────────────────────────────────────────────── */
#cw-root *,
#cw-root *::before,
#cw-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Montserrat", sans-serif;
}

/* ── Floating launcher button ───────────────────────────────────────────── */
#cw-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cw-accent, #22C55E);
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  transition: transform .2s ease, box-shadow .2s ease;
  border: none;
  outline: none;
}
#cw-launcher:hover  { transform: scale(1.08); box-shadow: 0 6px 24px rgba(0,0,0,.3); }
#cw-launcher:active { transform: scale(.96); }

#cw-launcher-avatar {
  width: 100%;
  height: 100%;
  border-radius: 100%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .5px;
  overflow: hidden;
  flex-shrink: 0;
}
#cw-launcher-avatar img { width: 100%; height: 100%; object-fit: contain; }

#cw-launcher-dot {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cw-accent, #22C55E);
  border: 2px solid #fff;
}

#cw-launcher-close {
  display: none;
  font-size: 22px;
  color: #fff;
  line-height: 1;
}

/* ── Chat window ────────────────────────────────────────────────────────── */
#cw-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 420px;
  max-height: min(600px, calc(100dvh - 100px));
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.22);
  background: #fff;

  opacity: 0;
  transform: translateY(20px) scale(.96);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#cw-window.cw-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#cw-header {
  background: var(--cw-brand, #1B5E35);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#cw-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  overflow: hidden;
}
#cw-header-avatar img { width: 100%; height: 100%; object-fit: contain; }

#cw-header-info { flex: 1; }
#cw-header-name {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}
#cw-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
#cw-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cw-accent, #22C55E);
  flex-shrink: 0;
}
#cw-status-text { color: rgba(255,255,255,.85); font-size: 12px; }

#cw-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.75);
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  border-radius: 50%;
  transition: color .15s, background .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}
#cw-close-btn:hover { color: #fff; background: rgba(255,255,255,.15); }

/* ── Messages area ──────────────────────────────────────────────────────── */
#cw-messages {
  flex: 1;
  overflow-y: auto;
  /* right padding is 22px: accommodates even a 17px system scrollbar + 5px gap */
  padding: 16px 22px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: #f7f7f7;
  scrollbar-gutter: stable;
}
#cw-messages::-webkit-scrollbar       { width: 4px; }
#cw-messages::-webkit-scrollbar-track { background: transparent; }
#cw-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* ── Rows & bubbles ─────────────────────────────────────────────────────── */
.cw-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: cwFadeUp .2s ease both;
}
.cw-row.cw-user { flex-direction: row-reverse; }

@keyframes cwFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cw-avatar-sm {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 10px;
  flex-shrink: 0;
  overflow: hidden;
  align-self: flex-end;
}
.cw-avatar-sm img { width: 100%; height: 100%; object-fit: contain; }

#cw-root .cw-bubble {
  max-width: 85%;
  width: fit-content;
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.cw-row.cw-bot .cw-bubble {
  background: #fff;
  color: #1f2937;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.cw-row.cw-user .cw-bubble {
  background: var(--cw-brand, #1B5E35);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Typing indicator ───────────────────────────────────────────────────── */
.cw-typing .cw-bubble {
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}
.cw-typing .cw-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: cwBounce 1.2s infinite ease-in-out;
}
.cw-typing .cw-dot:nth-child(2) { animation-delay: .2s; }
.cw-typing .cw-dot:nth-child(3) { animation-delay: .4s; }

@keyframes cwBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* ── Quick replies ──────────────────────────────────────────────────────── */
#cw-quick-replies {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 14px 14px;
  background: #f7f7f7;
  flex-shrink: 0;
}
#cw-root .cw-qr-btn {
  background: var(--cw-brand, #1B5E35);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  line-height: 1.35;
  transition: opacity .15s, transform .1s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#cw-root .cw-qr-btn:hover  { opacity: .88; }
#cw-root .cw-qr-btn:active { transform: scale(.98); }
#cw-root .cw-qr-btn::after { content: '→'; flex-shrink: 0; font-size: 15px; }

/* ── Input area ─────────────────────────────────────────────────────────── */
#cw-input-area {
  display: none;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}
#cw-input-area.cw-visible { display: flex; }

#cw-input {
  flex: 1;
  border: 1.5px solid #e5e7eb;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color .15s;
  background: #f9fafb;
  color: #1f2937;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}
#cw-input::-webkit-scrollbar       { width: 4px; }
#cw-input::-webkit-scrollbar-track { background: transparent; }
#cw-input::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
#cw-input:focus { border-color: var(--cw-brand, #1B5E35); background: #fff; }
#cw-input::placeholder { color: #9ca3af; }

#cw-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--cw-brand, #1B5E35);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s, transform .1s;
}
#cw-send-btn:hover  { opacity: .85; }
#cw-send-btn:active { transform: scale(.93); }
#cw-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ── Redirect countdown bubble ──────────────────────────────────────────── */
.cw-redirect-bubble {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cw-redirect-text {
  font-size: 14px;
  line-height: 1.45;
}
.cw-redirect-cancel {
  align-self: flex-start;
  background: none;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  color: #6b7280;
  transition: border-color .15s, color .15s;
}
.cw-redirect-cancel:hover { border-color: #ef4444; color: #ef4444; }

/* ── Teaser bubble ──────────────────────────────────────────────────────── */
#cw-teaser {
  position: fixed;
  bottom: 22px;
  right: 100px; /* 24px (right) + 60px (launcher) + 10px gap */
  z-index: 9997;
  background: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  max-width: 280px;
  font-size: 15px;
  line-height: 1.5;
  color: #42484d;
  cursor: pointer;
  opacity: 0;
  transform: translateX(10px);
  pointer-events: none;
  transition: opacity .35s ease, transform .35s ease;
}
#cw-teaser.cw-teaser-visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: all;
}
#cw-teaser::after {
  content: '';
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 8px solid #fff;
}
#cw-teaser-name { font-weight: 700; }

#cw-teaser-close {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #d1cfcf;
  color: #000000;
  border: none;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background .15s;
}
#cw-teaser-close:hover { background: #969aa0e8; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 420px) {
  #cw-window {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }

  /* Move launcher acima do indicador home em iPhones com notch */
  #cw-launcher {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }

  /* Teaser mobile: estica entre margem esquerda e o launcher, alinha verticalmente */
  #cw-teaser {
    left: 8px;
    right: 86px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    max-width: none;
    font-size: 13px;
  }

  /* Evita zoom automático do iOS Safari ao focar o textarea */
  #cw-input { font-size: 16px; }

  /* Touch targets mínimos de 44×44px para mobile */
  #cw-close-btn { width: 44px; height: 44px; }
  #cw-send-btn  { width: 44px; height: 44px; }

  /* Scrollbars no mobile são sobrepostas – não reservar espaço de gutter */
  #cw-messages { scrollbar-gutter: auto; padding-right: 14px; }

  /* Empurrar área de input acima do indicador home em iPhones com notch */
  #cw-input-area { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
}
