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

:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-glow: rgba(16, 185, 129, 0.15);
  --bg-app: #09090b;
  --bg-chat: #0f0f12;
  --bg-card: #18181b;
  --bg-bubble-bot: #1c1c22;
  --bg-bubble-user: #10b981;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-user-bubble: #fff;
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --input-bg: #1c1c22;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --radius: 16px;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
}

/* Background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(16, 185, 129, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

#chat-container {
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
  overflow: hidden;
}

@media (min-width: 501px) {
  #chat-container {
    border-radius: 24px;
    height: 92dvh;
    max-height: 780px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow), 0 0 80px rgba(16, 185, 129, 0.06);
  }
}

/* ── Header ── */
#chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

#chat-header::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 0;
  right: 0;
  height: 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.15), transparent);
  pointer-events: none;
}

@media (min-width: 501px) {
  #chat-header {
    border-radius: 24px 24px 0 0;
  }
}

.header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  position: relative;
  flex-shrink: 0;
}

.online-dot {
  width: 10px;
  height: 10px;
  background: #4ade80;
  border-radius: 50%;
  border: 2px solid var(--primary);
  position: absolute;
  bottom: -2px;
  right: -2px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(74, 222, 128, 0); }
}

.header-info h1 {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

.header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Messages ── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar {
  width: 3px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: msgIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message.bot {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
}

.message-bubble {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.bot .message-bubble {
  background: var(--bg-bubble-bot);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  border: 1px solid var(--border);
}

.message.user .message-bubble {
  background: var(--bg-bubble-user);
  color: var(--text-user-bubble);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  box-shadow: 0 2px 12px rgba(16, 185, 129, 0.2);
}

.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble a {
  color: #34d399;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid rgba(52, 211, 153, 0.3);
  transition: border-color 0.2s;
}

.message.user .message-bubble a {
  color: #fff;
  border-bottom-color: rgba(255, 255, 255, 0.4);
}

.message-bubble a:hover {
  border-bottom-color: currentColor;
}

.message-bubble strong {
  font-weight: 600;
  color: #fff;
}

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 6px;
  opacity: 0.7;
}

.message.user .message-time {
  align-self: flex-end;
}

/* ── Typing indicator ── */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 4px 2px;
  align-items: center;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
  opacity: 0.7;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

/* ── Quick topics (inside chat as suggestions, stacked) ── */
#quick-topics {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0;
  max-width: 82%;
  animation: msgIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  animation-delay: 0.15s;
  animation-fill-mode: backwards;
}

.topic-btn {
  padding: 10px 16px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 14px;
  background: rgba(16, 185, 129, 0.06);
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
}

.topic-btn:hover {
  background: var(--primary-glow);
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.15);
}

.topic-btn:active {
  transform: translateY(0);
}

#quick-topics.hidden {
  display: none;
}

/* ── Anchor Ad Space ── */
#anchor-ad-space {
  flex-shrink: 0;
  width: 100%;
  min-height: 0;
  transition: min-height 0.3s ease;
}

/* When anchor ad is active, reserve space so it doesn't overlap input */
body.has-anchor-ad #anchor-ad-space {
  min-height: 60px; /* Standard mobile anchor: 50px + 10px breathing room */
}

@media (min-width: 501px) {
  body.has-anchor-ad #anchor-ad-space {
    min-height: 70px; /* Desktop anchors can be taller */
  }
}

/* ── Input ── */
#chat-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-chat);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10; /* Stay above anchor ad */
}

@media (min-width: 501px) {
  #chat-input {
    border-radius: 0 0 24px 24px;
  }
}

#message-input {
  flex: 1;
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

#message-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

#message-input::placeholder {
  color: var(--text-secondary);
}

#send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

#send-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

#send-btn:active {
  transform: scale(0.95);
}

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Ad Slots ── */
.ad-slot {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-slot:empty {
  display: none; /* Hide when no ad loaded — no blank space */
}

/* Top banner ad (below header) */
.ad-slot-banner {
  width: 100%;
  min-height: 50px;
  max-height: 90px;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border);
}

/* In-chat native ad (injected between messages) */
.ad-slot-native {
  margin: 8px 0;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  min-height: 100px;
  max-width: 100%;
}

.ad-slot-native::before {
  content: 'Publicidade';
  display: block;
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  opacity: 0.6;
}

/* ── CTA Link Cards (article recommendations) ── */
.message-bubble .cta-card {
  display: block;
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.2s ease;
}

.message-bubble .cta-card:hover {
  background: rgba(16, 185, 129, 0.14);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.cta-card .cta-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  font-weight: 600;
}

.cta-card .cta-title {
  font-size: 14px;
  font-weight: 600;
  margin-top: 2px;
  color: #fff;
}
