:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: rgba(255, 255, 255, 0.95);
  --surface-strong: #ffffff;
  --text: #102033;
  --soft: #5d6b7d;
  --line: rgba(16, 32, 51, 0.12);
  --accent: #0f766e;
  --accent-strong: #0a4f49;
  --shadow: 0 28px 60px rgba(16, 32, 51, 0.14);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(245, 158, 11, 0.08), transparent 30%),
    linear-gradient(180deg, #eef4f8 0%, #f7fafc 45%, #edf2f7 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(16, 32, 51, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 32, 51, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
}

button, input, textarea, select { font: inherit; }

/* ── Hero card ────────────────────────────────────────────────────────────── */

.page-shell {
  min-height: 100vh;
  padding: 24px;
  position: relative;
}

.hero-card {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 32px;
  max-width: 960px;
  overflow: hidden;
  position: relative;
}

.hero-card::after {
  content: "";
  position: absolute;
  inset: auto -80px -120px auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(15, 118, 110, 0.18), transparent 70%);
  pointer-events: none;
}

.eyebrow,
.status-box span,
.input-bar span {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--soft);
}

.hero-card h1 {
  margin: 10px 0;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 0.98;
}

.lead { color: var(--soft); line-height: 1.6; }

.status-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 28px;
}

.status-box {
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.status-box strong {
  display: block;
  margin-top: 6px;
  font-size: 1rem;
  color: var(--text);
  word-break: break-all;
}

.input-bar {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.input-bar label { display: grid; gap: 8px; }

.input-bar textarea,
.primary-button {
  border-radius: 16px;
  padding: 14px 16px;
}

.input-bar textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 140px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  line-height: 1.4;
}

.input-bar textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

.primary-button {
  border: 0;
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
}

/* ── Floating launcher ────────────────────────────────────────────────────── */

.floating-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1001;
  border: 0;
  border-radius: 999px;
  min-height: 56px;
  padding: 0 22px;
  cursor: pointer;
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 8px 32px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform 0.15s, box-shadow 0.15s;
}

.floating-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px color-mix(in srgb, var(--accent) 50%, transparent);
}

/* ── Chat popup ───────────────────────────────────────────────────────────── */

.chat-popup {
  position: fixed;
  right: 24px;
  bottom: 92px;
  width: 380px;
  height: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  border-radius: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(16, 32, 51, 0.18);
  z-index: 1000;
  background: #f0f2f5;
}

/* ── Chat header ──────────────────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  flex-shrink: 0;
}

.chat-header-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.chat-header-identity strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
}

.online-status {
  font-size: 0.75rem;
  opacity: 0.85;
  font-weight: 500;
}

.icon-btn {
  border: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.28); }

/* ── Error alert ──────────────────────────────────────────────────────────── */

.alert {
  margin: 8px 12px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  font-size: 0.88rem;
  flex-shrink: 0;
}

/* ── Messages panel ───────────────────────────────────────────────────────── */

.messages-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.messages-panel::-webkit-scrollbar { width: 4px; }
.messages-panel::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

/* ── Bubbles ──────────────────────────────────────────────────────────────── */

.bubble {
  max-width: 78%;
  display: flex;
  flex-direction: column;
}

/* Visitor (user) — right aligned, accent color */
.bubble.visitor {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble.visitor .bubble-body {
  background: var(--accent);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

/* Agent / bot — left aligned, white */
.bubble.agent {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble.agent .bubble-body {
  background: #ffffff;
  color: var(--text);
  border-radius: 18px 18px 18px 4px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Welcome bubble: slight accent tint on left border */
.bubble.agent.welcome .bubble-body {
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, #ffffff);
}

.typing-bubble .typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  border-radius: 18px 18px 18px 4px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.typing-bubble .typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 72%, #6b7280);
  animation: typingDotPulse 1.2s infinite ease-in-out;
}

.typing-bubble .typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-bubble .typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typingDotPulse {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.bubble-body {
  padding: 10px 14px;
  font-size: 0.93rem;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.bubble-time {
  font-size: 0.7rem;
  color: var(--soft);
  margin-top: 3px;
  padding: 0 4px;
}

.bubble-meta {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
  padding: 0 4px;
}

.bubble-sender {
  font-size: 0.7rem;
  color: var(--soft);
  font-weight: 400;
  margin-bottom: 3px;
  padding: 0 4px;
}

/* ── Starter section ──────────────────────────────────────────────────────── */

.starter-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 0;
  flex-shrink: 0;
}

.prechat-fields-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prechat-field {
  display: block;
}

.starter-section input,
.starter-section select {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  padding: 11px 14px;
  outline: none;
  font-size: 0.93rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.starter-section input:focus,
.starter-section select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

/* ── Composer ─────────────────────────────────────────────────────────────── */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 14px;
  background: #f0f2f5;
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  min-height: 42px;
  /* 4 linhas: 4 × (0.93rem × 1.4) + padding top+bottom (11px × 2) ≈ 105px */
  max-height: calc(4 * 1.4 * 0.93rem + 22px);
  border: 1.5px solid var(--line);
  border-radius: 22px;
  background: #fff;
  color: var(--text);
  padding: 11px 16px;
  outline: none;
  resize: none;
  font-size: 0.93rem;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s, height 0.1s ease;
  overflow-y: auto;
}

.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

.send-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.08);
}

/* ── Chat footer ─────────────────────────────────────────────────────────── */

.chat-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 16px 10px;
  background: #f0f2f5;
  flex-shrink: 0;
}

.chat-footer-hint {
  font-size: 0.7rem;
  color: var(--soft);
  opacity: 0.7;
  letter-spacing: 0.01em;
}

.chat-footer-brand {
  font-size: 0.7rem;
  color: var(--soft);
  opacity: 0.75;
}

.chat-footer-brand strong {
  font-weight: 700;
  color: var(--accent);
  opacity: 1;
}

/* ── Utilities ────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 980px) {
  .status-grid, .input-bar { grid-template-columns: 1fr; }

  .chat-popup {
    right: 14px;
    bottom: 86px;
    width: calc(100vw - 28px);
    height: min(560px, calc(100vh - 110px));
  }
}

@media (max-width: 640px) {
  .page-shell { padding: 14px; }
  .hero-card { border-radius: 22px; padding: 18px; }

  .chat-popup {
    right: 0;
    bottom: 76px;
    width: 100vw;
    height: min(540px, calc(100vh - 90px));
    border-radius: 20px 20px 0 0;
  }

  .floating-launcher {
    right: 14px;
    bottom: 14px;
  }
}
