:root {
  --bg: #0f172a;
  --panel: #f7f8fa;
  --bubble-user: #2563eb;
  --bubble-user-text: #ffffff;
  --bubble-agent: #ffffff;
  --bubble-agent-text: #1c2333;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--panel);
  color: var(--bubble-agent-text);
  -webkit-font-smoothing: antialiased;
}

/* ----------------------------- Portão ----------------------------- */
.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.gate-card h1 {
  font-size: 1.35rem;
  margin: 0 0 6px;
}

.gate-sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 20px;
}

#gate-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#gate-form input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  outline: none;
}

#gate-form input:focus {
  border-color: var(--accent);
}

#gate-btn {
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

#gate-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.gate-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
  margin: 16px 0 0;
  text-align: left;
}

.gate-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 14px 0 0;
}

/* ------------------------------ Chat ------------------------------ */
.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel);
}

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  padding-top: max(14px, env(safe-area-inset-top));
}

.chat-header .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 1rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.bubble.agent {
  align-self: flex-start;
  background: var(--bubble-agent);
  color: var(--bubble-agent-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 5px;
}

/* Indicador "digitando…" */
.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 14px 16px;
  background: var(--bubble-agent);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa3b2;
  animation: blink 1.4s infinite both;
}

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

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

/* Aviso de sistema (limite, erros) */
.system-note {
  align-self: center;
  max-width: 90%;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  background: #eef1f6;
  border-radius: 12px;
  padding: 8px 12px;
}

/* Compositor */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--border);
}

#text-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.4;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  outline: none;
}

#text-input:focus {
  border-color: var(--accent);
}

#send-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

#send-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

#mic-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: #eef2f7;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

#mic-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

#mic-btn.recording {
  color: #fff;
  background: #dc2626;
  animation: micpulse 1.2s ease-in-out infinite;
}

/* Botão de foto (mesmo visual do microfone) */
#photo-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: #eef2f7;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
#photo-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Pré-visualização da foto escolhida, logo acima do compositor */
.photo-preview {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #fff;
  border-top: 1px solid var(--border);
}
#photo-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}
#photo-remove {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: #e5e7eb;
  color: #374151;
  font-size: 0.85rem;
  cursor: pointer;
}
.photo-hint {
  color: #6b7280;
  font-size: 0.85rem;
}

/* Foto enviada, dentro da bolha do usuário */
.bubble-img {
  display: block;
  margin-top: 8px;
  max-width: 100%;
  border-radius: 10px;
}

@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}
