/* ── Variáveis ──────────────────────────────────────────── */
:root {
  --azul: #0077B6;
  --azul-hover: #005f92;
  --azul-claro: #CDE7F4;
  --azul-fundo: #F0F8FF;
  --pessego: #FFD8B5;
  --pessego-hover: #ffc898;
  --creme: #FFF9F2;
  --creme-borda: #F0E8DC;
  --texto-escuro: #1A2C3D;
  --texto-suave: #5A6A7A;
  --texto-muito-suave: #9AABB8;
  --accent: #E8985E;
  --verde-status: #34D399;
  --sombra: 0 2px 16px rgba(0, 119, 182, 0.10);
  --sombra-forte: 0 4px 32px rgba(0, 119, 182, 0.16);
  --radius: 18px;
  --radius-sm: 10px;
  --panel-width: 300px;
}

/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  background: var(--azul-fundo);
  color: var(--texto-escuro);
  overflow: hidden;
}

body {
  display: flex;
  height: 100vh;
  height: 100dvh; /* celular: acompanha a barra do navegador e o teclado */
  /* iOS não encolhe o layout quando o teclado abre: o JS mede a área visível
     (visualViewport) e grava aqui, para a lista de mensagens ficar acima dele. */
  height: var(--app-h, 100dvh);
}

button, .suggestion-btn { -webkit-tap-highlight-color: transparent; }

/* Foco visível para navegação por teclado (mouse/toque não mostram anel) */
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--azul);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Painel lateral da Dóris ────────────────────────────── */
.doris-panel {
  width: var(--panel-width);
  flex-shrink: 0;
  background: var(--creme);
  border-right: 1px solid var(--creme-borda);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 24px;
  gap: 0;
  box-shadow: 2px 0 20px rgba(0,0,0,0.04);
}

.doris-avatar-wrap {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#doris-img {
  width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 20px;
  transition: opacity 0.35s ease;
  filter: drop-shadow(0 8px 24px rgba(0,119,182,0.15));
}

#doris-img.fade-out { opacity: 0; }
#doris-img.fade-in  { opacity: 1; }

.doris-info {
  text-align: center;
  padding: 16px 0 12px;
  width: 100%;
}

.doris-name {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--azul);
}

.doris-subtitle {
  font-size: 0.78rem;
  color: var(--texto-suave);
  margin-top: 2px;
  letter-spacing: 0.04em;
}

.emotion-badge-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  background: white;
  border: 1px solid var(--creme-borda);
  border-radius: 99px;
  padding: 4px 12px 4px 8px;
  box-shadow: var(--sombra);
}

.emotion-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  transition: background 0.4s ease;
}

.emotion-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--texto-escuro);
  text-transform: capitalize;
  transition: opacity 0.3s;
}

.btn-reset {
  margin-top: 16px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  background: white;
  color: var(--texto-suave);
  border: 1.5px solid var(--creme-borda);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-reset:hover {
  background: var(--azul-fundo);
  border-color: var(--azul-claro);
  color: var(--azul);
}

.watermark {
  margin-top: auto;
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  opacity: 0.38;
  transition: opacity 0.2s;
}

.watermark:hover { opacity: 0.65; }

.watermark span {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--texto-suave);
  text-align: center;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

/* ── Painel do chat ─────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--azul-fundo);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: white;
  border-bottom: 1px solid #E8F4FB;
  box-shadow: 0 1px 8px rgba(0,119,182,0.06);
  flex-shrink: 0;
}

.header-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--texto-escuro);
}

.header-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--verde-status);
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--verde-status);
}

.header-status.thinking {
  color: var(--accent);
}

.header-status.thinking::before {
  background: var(--accent);
  animation: pulse 1s infinite;
}

.btn-tts {
  margin-left: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  color: var(--texto-suave);
  border: 1.5px solid var(--creme-borda);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-tts:hover {
  background: var(--azul-fundo);
  color: var(--azul);
  border-color: var(--azul-claro);
}

.btn-tts.muted {
  color: var(--texto-muito-suave);
  border-color: var(--creme-borda);
  opacity: 0.55;
}

/* Área de mensagens */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 16px;
  scroll-behavior: smooth;
  min-height: 0;
}

.messages-wrap::-webkit-scrollbar { display: none; }
.messages-wrap { -ms-overflow-style: none; scrollbar-width: none; }

/* Balões */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  margin-bottom: 16px;
  animation: fadeSlideIn 0.25s ease;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
  margin-left: auto;
}

.msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

#messages {
  display: flex;
  flex-direction: column;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.55;
  word-break: break-word;
  /* Testadores copiam a resposta para a ficha: seleção sempre liberada. */
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.msg.user .bubble {
  background: var(--azul-claro);
  border-bottom-right-radius: 4px;
  color: var(--texto-escuro);
}

.msg.assistant .bubble {
  background: var(--pessego);
  border-bottom-left-radius: 4px;
  color: var(--texto-escuro);
  box-shadow: var(--sombra);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 0 4px;
}

/* "Copiar" ao lado da hora: no celular selecionar texto num balão é chato. */
.msg-copy {
  border: none;
  background: none;
  color: var(--texto-muito-suave);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 6px;
  min-height: 24px;
}
.msg-copy:hover { color: var(--azul); background: var(--azul-fundo); }
.msg-copy.done { color: var(--azul); }

.msg-time {
  font-size: 0.7rem;
  color: var(--texto-muito-suave);
  font-weight: 500;
}

/* Markdown dentro dos balões */
.bubble p { margin: 0 0 0.3em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble p:empty { display: none; }
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }
.bubble ol,
.bubble ul { margin: 0.3em 0; padding-left: 1.3em; }
.bubble li { margin-bottom: 0.2em; line-height: 1.45; }
.bubble li:last-child { margin-bottom: 0; }
.bubble li > p { margin: 0; }
.bubble code {
  background: rgba(0,0,0,0.07);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.88em;
  font-family: 'Courier New', monospace;
}

/* Indicador "digitando" */
.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--pessego);
  padding: 9px 13px;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  box-shadow: var(--sombra);
  line-height: 1;
}

.typing-bubble span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
  flex-shrink: 0;
}

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

/* Sugestões */
.suggestions-wrap {
  padding: 10px 28px 12px;
  border-top: 1px solid #E8F4FB;
  background: white;
  flex-shrink: 0;
}

.suggestions-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--texto-muito-suave);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 8px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.suggestion-btn {
  background: var(--azul-fundo);
  border: 1.5px solid var(--azul-claro);
  border-radius: 99px;
  color: var(--azul);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.suggestion-btn:hover {
  background: var(--azul-claro);
  border-color: var(--azul);
}

/* Área de input */
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 24px 18px;
  background: white;
  border-top: 1px solid #E8F4FB;
  flex-shrink: 0;
}

#user-input {
  flex: 1;
  border: 1.5px solid var(--azul-claro);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--texto-escuro);
  background: var(--azul-fundo);
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
  line-height: 1.5;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

#user-input::-webkit-scrollbar { display: none; }

#user-input:focus {
  outline: none;
  border-color: var(--azul);
  background: white;
}

#user-input::placeholder { color: var(--texto-muito-suave); }

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--azul);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.btn-send:hover { background: var(--azul-hover); }
.btn-send:active { transform: scale(0.93); }
.btn-send:disabled { background: var(--azul-claro); cursor: not-allowed; }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 50, 0.35);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: white;
  border-radius: var(--radius);
  padding: 32px 36px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: var(--sombra-forte);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-icon {
  font-size: 2.2rem;
  margin-bottom: 12px;
  color: var(--azul);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--texto-escuro);
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.88rem;
  color: var(--texto-suave);
  line-height: 1.5;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn-modal-cancel {
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--creme-borda);
  background: white;
  color: var(--texto-suave);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-modal-cancel:hover { background: var(--azul-fundo); }

.btn-modal-confirm {
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--azul);
  color: white;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-modal-confirm:hover { background: var(--azul-hover); }

/* Código de acesso (reusa .modal-overlay/.modal) */
.access-input {
  width: 100%;
  border: 1.5px solid var(--azul-claro);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--texto-escuro);
  background: var(--azul-fundo);
  text-align: center;
  letter-spacing: 0.06em;
  outline: none;
  transition: border-color 0.2s;
}

.access-input:focus { border-color: var(--azul); }

.modal-error {
  min-height: 1.2em;
  font-size: 0.82rem;
  color: #C0392B;
  margin: 8px 0 14px;
}

/* ── Animações ──────────────────────────────────────────── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Responsivo ─────────────────────────────────────────── */
/* Tablet e celular: painel da Dóris vira uma barra no topo; o chat ocupa o
   resto da altura real da tela (100dvh) e só a lista de mensagens rola. */
@media (max-width: 860px) {
  body { flex-direction: column; overflow: hidden; }

  .doris-panel {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    gap: 12px;
    border-right: none;
    border-bottom: 1px solid var(--creme-borda);
    box-shadow: 0 1px 8px rgba(0,0,0,0.04);
    flex-shrink: 0;
  }

  .doris-avatar-wrap {
    width: 56px;
    height: 56px;
    flex: 0 0 56px;
  }

  #doris-img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 14px;
    filter: none;
  }

  .doris-info {
    padding: 0;
    text-align: left;
    flex: 1;
    min-width: 0;
  }

  .doris-name { font-size: 1.05rem; letter-spacing: 0.12em; line-height: 1.1; }
  .doris-subtitle { display: none; }

  .emotion-badge-wrap { margin-top: 5px; padding: 3px 10px 3px 7px; }
  .emotion-label { font-size: 0.74rem; }

  /* Botão "Nova conversa" só com o ícone, tamanho de toque confortável */
  .btn-reset {
    margin-top: 0;
    width: 42px;
    height: 42px;
    padding: 0;
    gap: 0;
    border-radius: 50%;
    justify-content: center;
    flex-shrink: 0;
  }
  .btn-reset svg { width: 18px; height: 18px; }
  .btn-reset-label { display: none; }

  .watermark { display: none; }

  .chat-panel { flex: 1; min-height: 0; }

  /* O nome já está na barra de cima: o header do chat vira uma faixa fina
     com o status ("online"/"digitando...") e o botão de voz. */
  .chat-header { padding: 6px 14px; gap: 8px; }
  .header-icon, .header-title { display: none; }
  .header-status { font-size: 0.74rem; }
  .btn-tts { width: 38px; height: 38px; }

  .messages-wrap { padding: 14px 12px 8px; }
  .msg { max-width: 88%; margin-bottom: 12px; }
  .bubble { font-size: 0.95rem; padding: 11px 14px; }

  /* Sugestões numa linha rolável; somem depois da primeira mensagem */
  .suggestions-wrap { padding: 8px 12px; }
  .suggestions-label { display: none; }
  .suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .suggestions::-webkit-scrollbar { display: none; }
  .suggestion-btn { padding: 8px 14px; font-size: 0.82rem; flex-shrink: 0; }
  body.has-conversation .suggestions-wrap { display: none; }

  .input-wrap {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  /* 16px evita o zoom automático do iOS ao focar o campo */
  #user-input { font-size: 16px; padding: 10px 14px; }
  .btn-send { width: 46px; height: 46px; }

  .modal { padding: 26px 20px; width: calc(100% - 32px); max-width: 380px; }
  .modal-actions { flex-wrap: wrap; }
  .btn-modal-cancel, .btn-modal-confirm { padding: 11px 20px; font-size: 0.95rem; }
  .access-input { font-size: 16px; padding: 12px 14px; }
}

/* Celular deitado ou tela muito baixa: esconde o avatar para sobrar chat */
@media (max-width: 860px) and (max-height: 480px) {
  .doris-avatar-wrap { display: none; }
  .doris-panel { padding: 6px 12px; }
  .emotion-badge-wrap { display: none; }
  .suggestions-wrap { display: none; }
}

/* Telas bem estreitas (320–360px) */
@media (max-width: 360px) {
  .doris-name { font-size: 0.95rem; letter-spacing: 0.08em; }
  .messages-wrap { padding: 10px 8px 6px; }
  .msg { max-width: 92%; }
  .bubble { font-size: 0.92rem; }
}
