/* ════════════════════════════════════════════════════
   WhatsApp Dark/Light Theme – Typebot Style
   ════════════════════════════════════════════════════ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --green:      #00a884;
  --dark-green: #008069;
  --panel:      #202c33;
  --bg:         #0b141a;
  --bot-bg:     #202c33;
  --user-bg:    #005c4b;
  --text:       #e9edef;
  --muted:      #8696a0;
  --input-bg:   #2a3942;
  --border:     #3b4a54;
  --tick-blue:  #53bdeb;
}

/* ── Light mode overrides ───────────────────────── */
body.light {
  --panel:    #f0f2f5;
  --bg:       #efeae2;
  --bot-bg:   #ffffff;
  --user-bg:  #d9fdd3;
  --text:     #111b21;
  --muted:    #667781;
  --input-bg: #ffffff;
  --border:   #d1d7db;
  background: #dfe5e7;
}

body.light .app {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
}

body.light .date-pill span,
body.light .encryption-notice {
  background: #d2ccc4;
  color: #667781;
}

body.light .chat {
  background-image: radial-gradient(rgba(0, 0, 0, 0.06) 1px, transparent 1px);
}

body.light .chat::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
}

/* ── Theme toggle button ────────────────────────── */
/* Dark mode: show sun icon (invite to go light)    */
.theme-btn .icon-moon { display: none; }
body.light .theme-btn .icon-sun  { display: none; }
body.light .theme-btn .icon-moon { display: block; }

/* ────────────────────────────────────────────────── */

html, body {
  height: 100%;
}

body {
  background: #111b21;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
  overflow: hidden;
}

/* ── App shell ──────────────────────────────────── */
.app {
  width: 100%;
  max-width: 440px;
  height: 100vh;
  height: 100dvh; /* dynamic viewport — compensa barra do Android/iOS */
  max-height: 880px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

@media (max-width: 440px) {
  .app {
    border-radius: 0;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
  }
}

/* ── Header ─────────────────────────────────────── */
.header {
  background: var(--panel);
  padding: 8px 10px 8px 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.icon-btn {
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

body.light .icon-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--dark-green), var(--green));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 8px rgba(0, 168, 132, 0.3);
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.header-status {
  font-size: 12px;
  color: var(--muted);
  transition: color 0.25s;
  line-height: 1.3;
}

.header-status.typing {
  color: var(--green);
}

.header-actions {
  display: flex;
}

/* ── Chat Area ──────────────────────────────────── */
.chat {
  flex: 1;
  min-height: 0; /* evita que o flexbox recuse encolher abaixo do conteúdo */
  overflow-y: auto;
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background-color: var(--bg);
  /* Subtle WhatsApp-like dot pattern */
  background-image: radial-gradient(rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  scroll-behavior: smooth;
  overflow-anchor: none;
}

.chat::-webkit-scrollbar {
  width: 5px;
}
.chat::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

/* Date badge */
.date-pill {
  display: flex;
  justify-content: center;
  margin: 4px 0 10px;
}

.date-pill span {
  background: #182229;
  color: var(--muted);
  font-size: 11.5px;
  padding: 4px 14px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  user-select: none;
}

/* Encryption notice */
.encryption-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: #182229;
  color: var(--muted);
  font-size: 11px;
  padding: 6px 16px;
  border-radius: 8px;
  text-align: center;
  margin: 0 auto 10px;
  max-width: 300px;
  line-height: 1.4;
  user-select: none;
}

/* ── Message Rows ────────────────────────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
}

/* Directional slide-in animations */
.msg-row.bot  {
  justify-content: flex-start;
  animation: slideFromLeft 0.22s ease;
}
.msg-row.user {
  justify-content: flex-end;
  animation: slideFromRight 0.22s ease;
}

/* Restored (session replay) messages: no animation */
.msg-row.no-anim {
  animation: none !important;
}

/* Group spacing */
.msg-row.bot  + .msg-row.bot  { margin-top: 1px; }
.msg-row.user + .msg-row.user { margin-top: 1px; }
.msg-row.bot  + .msg-row.user,
.msg-row.user + .msg-row.bot  { margin-top: 6px; }

/* ── In-chat choice buttons ──────────────────────── */
.chat-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 8px;
  align-self: flex-start;
  max-width: 92%;
  animation: slideFromLeft 0.22s ease;
}

.chat-choice-btn {
  background: transparent;
  border: 1.5px solid var(--green);
  color: var(--green);
  padding: 7px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
  line-height: 1.3;
  transition: background 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.chat-choice-btn:hover {
  background: var(--green);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 168, 132, 0.35);
}

.chat-choice-btn:active {
  transform: scale(0.95);
}

/* Botão de ação WhatsApp — dentro do chat */
.chat-choice-btn--whatsapp {
  background: #25D366;
  border-color: #25D366;
  color: #fff;
  font-size: 14.5px;
  padding: 11px 24px;
  width: 100%;
  text-align: center;
  animation: waPulse 1.8s ease-out infinite;
}

.chat-choice-btn--whatsapp:hover {
  background: #20bb5a;
  border-color: #20bb5a;
  color: #fff;
  box-shadow: 0 4px 18px rgba(37, 211, 102, 0.5);
}

@keyframes slideFromLeft {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideFromRight {
  from { opacity: 0; transform: translateX(14px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Bubbles ─────────────────────────────────────── */
.bubble {
  max-width: 73%;
  padding: 6px 10px 4px;
  border-radius: 8px;
  position: relative;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Bot bubble */
.msg-row.bot .bubble {
  background: var(--bot-bg);
  border-radius: 0 8px 8px 8px;
  color: var(--text);
}

/* Bot tail (top-left triangle) */
.msg-row.bot .bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  border-width: 0 8px 8px 0;
  border-style: solid;
  border-color: transparent var(--bot-bg) transparent transparent;
}

/* User bubble */
.msg-row.user .bubble {
  background: var(--user-bg);
  border-radius: 8px 0 8px 8px;
  color: var(--text);
}

/* User tail (top-right triangle) */
.msg-row.user .bubble::after {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  border-width: 8px 8px 0 0;
  border-style: solid;
  border-color: var(--user-bg) transparent transparent transparent;
}

/* Bubble text */
.bubble-text {
  font-size: 14.2px;
  line-height: 1.52;
  color: var(--text);
  white-space: pre-wrap;
}

.bubble-text strong { font-weight: 700; }
.bubble-text em     { font-style: italic; }
.bubble-text del    { text-decoration: line-through; opacity: 0.75; }
.bubble-text code   {
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  background: rgba(0,0,0,0.15);
  padding: 1px 5px;
  border-radius: 3px;
}

body.light .bubble-text code {
  background: rgba(0,0,0,0.08);
}

/* Bubble footer (time + ticks) */
.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 1px;
  float: right;
  margin-left: 8px;
  margin-bottom: -1px;
}

.bubble-time {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1;
}

.msg-row.user .bubble-time {
  color: rgba(233, 237, 239, 0.62);
}

body.light .msg-row.user .bubble-time {
  color: rgba(17, 27, 33, 0.55);
}

.bubble-ticks {
  display: flex;
  align-items: center;
}

/* ── Typing Indicator ────────────────────────────── */
.typing-bubble {
  background: var(--bot-bg);
  border-radius: 0 12px 12px 12px;
  padding: 10px 14px;
  position: relative;
  animation: slideFromLeft 0.15s ease;
}

.typing-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  border-width: 0 8px 8px 0;
  border-style: solid;
  border-color: transparent var(--bot-bg) transparent transparent;
}

.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: dotBounce 1.3s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s;   }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 65%, 100% { transform: translateY(0);    opacity: 0.45; }
  32%            { transform: translateY(-6px); opacity: 1;   }
}

/* ── Footer / Input Area ─────────────────────────── */
.footer {
  background: var(--panel);
  padding: 8px 12px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 56px;
}

/* ── Choice Buttons (quick reply) ────────────────── */
.choices-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 2px 0 2px;
}

.choice-btn {
  background: transparent;
  border: 1.5px solid var(--green);
  color: var(--green);
  padding: 8px 18px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
  line-height: 1.3;
}

.choice-btn:hover {
  background: var(--green);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 168, 132, 0.35);
}

.choice-btn:active {
  transform: scale(0.96);
}

/* Botão de ação WhatsApp */
.choice-btn--whatsapp {
  background: #25D366;
  border-color: #25D366;
  color: #fff;
  font-size: 14.5px;
  padding: 11px 22px;
  animation: waPulse 1.8s ease-out infinite;
}

.choice-btn--whatsapp:hover {
  background: #20bb5a;
  border-color: #20bb5a;
  color: #fff;
  box-shadow: 0 4px 18px rgba(37, 211, 102, 0.5);
}

@keyframes waPulse {
  0%   { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.55); }
  70%  { box-shadow: 0 0 0 12px rgba(37, 211, 102, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}

/* ── Input wrapper (holds row + error) ──────────── */
.input-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-error {
  font-size: 11.5px;
  color: #ff6b6b;
  text-align: center;
  padding: 2px 8px;
  animation: fadeIn 0.2s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

.input-shake {
  animation: shake 0.35s ease;
  border-color: #ff6b6b !important;
  box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.25) !important;
}

/* ── UF live validation indicator ───────────────── */
.uf-indicator {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s;
}

.uf-indicator.uf-ok  { color: #25d366; opacity: 1; }
.uf-indicator.uf-err { color: #ff6b6b; opacity: 1; }

/* ── Text Input Row ──────────────────────────────── */
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.emoji-btn {
  font-size: 23px;
  line-height: 1;
  background: transparent;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 4px;
  opacity: 0.75;
  transition: opacity 0.15s;
}

.emoji-btn:hover { opacity: 1; }

.chat-input {
  flex: 1;
  background: var(--input-bg);
  border: none;
  border-radius: 24px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14.2px;
  font-family: inherit;
  outline: none;
  caret-color: var(--green);
  min-width: 0;
  transition: box-shadow 0.2s;
}

.chat-input:focus {
  box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.25);
}

.chat-input::placeholder {
  color: var(--muted);
}

body.light .chat-input {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

body.light .chat-input:focus {
  box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.3);
}

.send-btn {
  width: 42px;
  height: 42px;
  background: var(--green);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 168, 132, 0.35);
}

.send-btn:hover:not(:disabled) {
  background: var(--dark-green);
  box-shadow: 0 4px 16px rgba(0, 168, 132, 0.5);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
  box-shadow: none;
}
