body { display: flex; align-items: center; justify-content: center; padding: 24px; }

.chat-app {
  width: 100%; max-width: 480px;
  height: min(94vh, 820px);
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}

/* ---------- Cabeçalho ---------- */
.chat-header {
  display: flex; align-items: center; padding: 16px 18px;
  background: var(--primary-grad); color: #fff;
  position: relative;
}
.chat-header::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: rgba(255, 255, 255, .16);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-avatar {
  width: 44px; height: 44px; border-radius: 14px;
  background: rgba(255, 255, 255, .18);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
}
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: .2px; }
.brand-status { font-size: 12px; opacity: .95; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; display: inline-block; box-shadow: 0 0 0 3px rgba(74, 222, 128, .3); }

/* ---------- Banner de conexão ---------- */
.conn-banner {
  padding: 8px 16px; font-size: 12.5px; text-align: center; font-weight: 600;
  background: var(--amber-soft); color: var(--amber); border-bottom: 1px solid #fde3b0;
}

/* ---------- Painéis ---------- */
.panel { padding: 24px; display: flex; flex-direction: column; gap: 16px; flex: 1; overflow-y: auto; }
#chat.panel { padding: 0; overflow: hidden; }

/* Pré-chat */
#prechat { justify-content: center; }
.prechat-icon {
  width: 74px; height: 74px; margin: 0 auto; border-radius: 24px;
  background: var(--primary-grad); color: #fff; font-size: 34px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 28px rgba(79, 70, 229, .30);
}
#prechat h2 { margin: 6px 0 0; font-size: 21px; text-align: center; font-weight: 800; }
#prechat p { margin: 0; text-align: center; font-size: 14px; }
#prechat form { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.erp-notice {
  background: var(--amber-soft); color: var(--amber); border: 1px solid #fde3b0;
  padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45;
}
.erp-notice strong { font-weight: 700; }

.protocol-bar {
  padding: 8px 16px; font-size: 12.5px; text-align: center; font-weight: 600;
  background: var(--primary-soft); color: var(--primary-600);
  border-bottom: 1px solid #dfe6ff;
}
.protocol-bar strong { font-weight: 800; letter-spacing: .3px; }

.queue-bar {
  padding: 8px 16px; font-size: 12.5px; text-align: center; font-weight: 600;
  background: var(--amber-soft); color: var(--amber);
  border-bottom: 1px solid #fde3b0;
}

/* ---------- Thread ---------- */
.messages { flex: 1; overflow-y: auto; padding: 18px 14px; display: flex; flex-direction: column; gap: 7px; background: linear-gradient(180deg, #f7f8fc 0%, #eef1f7 100%); }

/* ---------- Composer ---------- */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { flex: 1; resize: none; max-height: 130px; min-height: 42px; border: none; box-shadow: none; padding: 10px 12px; }
.composer textarea:focus { box-shadow: none; border-color: transparent; }
.send-btn { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 16px; flex: none; }

/* ---------- Encerramento / avaliação ---------- */
#closed { align-items: center; text-align: center; }
#closed .big-icon { font-size: 52px; }
#closed h2 { margin: 0; font-size: 20px; font-weight: 800; }
#closed p { margin: 0; font-size: 14px; }
.rating-label { text-align: center; font-size: 13px; color: var(--text-2); font-weight: 600; margin-top: 6px; }
.stars { display: flex; gap: 6px; justify-content: center; }
.stars button { font-size: 36px; color: #d1d5db; transition: color .12s ease, transform .12s ease; }
.stars button.on { color: #f59e0b; }
.stars button:hover { transform: scale(1.14); }
#closed textarea { min-height: 60px; }
#closed .btn { margin-top: 4px; }

@media (max-width: 520px) {
  body { padding: 0; }

  .chat-app {
    height: 100vh;
    height: 100dvh; /* altura dinâmica (barra do navegador do celular) */
    max-width: none;
    border-radius: 0;
    box-shadow: none;
  }

  /* Cabeçalho compacto + área segura (notch/home bar do iPhone) */
  .chat-header { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .brand-avatar { width: 38px; height: 38px; font-size: 19px; border-radius: 12px; }
  .brand-name { font-size: 15px; }
  .brand-status { font-size: 11px; }

  /* Pré-chat */
  .panel { padding: 18px 16px; }
  .prechat-icon { width: 64px; height: 64px; font-size: 30px; border-radius: 20px; }
  #prechat h2 { font-size: 19px; }
  #prechat input { font-size: 16px; } /* evita zoom automático no iOS */

  /* Mensagens */
  .messages { padding: 12px 10px; gap: 6px; }
  .bubble { max-width: 84%; }
  .bubble .text { font-size: 15px; }
  .attach-img { max-width: 180px; max-height: 180px; }

  /* Composer */
  .composer {
    gap: 6px;
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .composer .emoji-wrap { display: none; } /* o teclado do celular já tem emoji */
  .icon-btn { width: 36px; height: 36px; font-size: 16px; }
  .send-btn { width: 40px; height: 40px; font-size: 15px; }
  .composer textarea { font-size: 16px; padding: 9px 12px; }

  /* Popups dentro da tela */
  .ai-pop { left: auto; right: 0; width: min(300px, calc(100vw - 20px)); }
  .emoji-pop { width: min(264px, calc(100vw - 20px)); }

  /* Encerramento / avaliação */
  #closed h2 { font-size: 18px; }
  .stars button { font-size: 34px; }
}
