/* ── Reset e base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --azul: #1a56db;
  --azul-claro: #e8f0fe;
  --azul-hover: #1e40af;
  --verde: #16a34a;
  --verde-claro: #dcfce7;
  --amarelo: #d97706;
  --amarelo-claro: #fef3c7;
  --vermelho: #dc2626;
  --cinza-bg: #f8fafc;
  --cinza-borda: #e2e8f0;
  --cinza-msg: #f1f5f9;
  --texto: #1e293b;
  --texto-leve: #64748b;
  --branco: #ffffff;
  --sombra: 0 1px 3px rgba(0,0,0,.08);
  --radius: 12px;
}

body[data-theme="dark"] {
  --azul: #3b82f6;
  --azul-claro: #172554;
  --azul-hover: #60a5fa;
  --verde: #22c55e;
  --verde-claro: #052e16;
  --amarelo: #f59e0b;
  --amarelo-claro: #451a03;
  --vermelho: #f87171;
  --cinza-bg: #0f172a;
  --cinza-borda: #334155;
  --cinza-msg: #111827;
  --texto: #f8fafc;
  --texto-leve: #cbd5e1;
  --branco: #111827;
  --sombra: 0 1px 3px rgba(0,0,0,.35);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--cinza-bg);
  color: var(--texto);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Layout principal ─────────────────────────────────────────────────────── */
.app {
  width: 100%;
  max-width: 760px;
  height: 100vh;
  max-height: 900px;
  background: var(--branco);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--azul);
  color: white;
  flex-shrink: 0;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 22px; }
.logo-text { font-size: 17px; color: rgba(255,255,255,.9); }
.logo-text strong { color: white; font-size: 18px; }

.header-right { display: flex; align-items: center; gap: 12px; }

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.15);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #94a3b8;
  transition: background .3s;
}
.status-dot.ativo   { background: #4ade80; }
.status-dot.base    { background: #fbbf24; }
.status-dot.offline { background: #f87171; }

/* Botão admin + sair no header */
.btn-admin {
  background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background .2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn-admin:hover { background: rgba(255,255,255,.3); }

.btn-sair-chat {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  color: rgba(255,255,255,.85);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .2s;
}
.btn-sair-chat:hover { background: rgba(255,80,80,.35); }

/* Label do usuário logado */
.usuario-label {
  font-size: 12px;
  color: rgba(255,255,255,.7);
  margin-left: 8px;
  border-left: 1px solid rgba(255,255,255,.2);
  padding-left: 10px;
}

/* Barra de setor fixo (usuários não-admin) */
.setor-fixo-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  flex-shrink: 0;
}
.setor-fixo-icon { font-size: 16px; }
.setor-fixo-nome { font-size: 13px; font-weight: 600; color: #1d4ed8; }

.btn-nova {
  background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background .2s;
}
.btn-nova:hover { background: rgba(255,255,255,.3); }

.btn-tema-chat {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  color: rgba(255,255,255,.9);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .2s;
}
.btn-tema-chat:hover { background: rgba(255,255,255,.3); }

/* ── Barra de setores ─────────────────────────────────────────────────────── */
.setores-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--cinza-bg);
  border-bottom: 1px solid var(--cinza-borda);
  flex-shrink: 0;
}

.setores-label { font-size: 13px; color: var(--texto-leve); }

.btn-setor {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--cinza-borda);
  background: white;
  color: var(--texto-leve);
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}
.btn-setor:hover { border-color: var(--azul); color: var(--azul); }
.btn-setor.ativo {
  background: var(--azul);
  border-color: var(--azul);
  color: white;
  font-weight: 600;
}

.setor-ativo-label {
  margin-left: auto;
  font-size: 12px;
  color: var(--texto-leve);
  font-style: italic;
}

/* ── Área de chat ─────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--cinza-borda); border-radius: 4px; }

/* ── Mensagens ────────────────────────────────────────────────────────────── */
.mensagem {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 85%;
  animation: fadeIn .25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mensagem.usuario {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--azul);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mensagem.usuario .avatar { background: var(--texto-leve); }

.balao {
  padding: 12px 16px;
  border-radius: 0 12px 12px 12px;
  background: var(--cinza-msg);
  font-size: 14px;
  line-height: 1.6;
  max-width: 100%;
  word-wrap: break-word;
}

.mensagem.usuario .balao {
  background: var(--azul);
  color: white;
  border-radius: 12px 0 12px 12px;
}

.balao p { margin-bottom: 6px; }
.balao p:last-child { margin-bottom: 0; }
.balao ul { margin: 6px 0 6px 16px; }
.balao li { margin-bottom: 4px; }
.balao strong { font-weight: 600; }
.balao em { color: var(--texto-leve); font-size: 12px; }
.mensagem.usuario .balao em { color: rgba(255,255,255,.7); }

.msg-acoes {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.btn-revisar-info {
  border: 1px solid var(--cinza-borda);
  background: white;
  color: var(--azul);
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  transition: all .2s;
}

.btn-revisar-info:hover {
  background: var(--azul-claro);
  border-color: var(--azul);
}

/* Badge de modo IA/base */
.badge-modo {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 6px;
  font-weight: 500;
}
.badge-ia   { background: var(--verde-claro);  color: var(--verde); }
.badge-base { background: var(--amarelo-claro); color: var(--amarelo); }

/* ── Indicador de digitação ───────────────────────────────────────────────── */
.digitando {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pontos {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--cinza-msg);
  border-radius: 0 12px 12px 12px;
}

.pontos span {
  width: 7px; height: 7px;
  background: var(--texto-leve);
  border-radius: 50%;
  animation: pulsar 1.2s infinite;
}
.pontos span:nth-child(2) { animation-delay: .2s; }
.pontos span:nth-child(3) { animation-delay: .4s; }

@keyframes pulsar {
  0%, 80%, 100% { transform: scale(.8); opacity: .5; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* ── Sugestões rápidas ────────────────────────────────────────────────────── */
.sugestoes {
  display: flex;
  gap: 8px;
  padding: 8px 20px;
  overflow-x: auto;
  flex-shrink: 0;
  border-top: 1px solid var(--cinza-borda);
}
.sugestoes::-webkit-scrollbar { display: none; }

.btn-sugestao {
  white-space: nowrap;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--cinza-borda);
  background: white;
  color: var(--azul);
  font-size: 12px;
  cursor: pointer;
  transition: all .2s;
}
.btn-sugestao:hover {
  background: var(--azul-claro);
  border-color: var(--azul);
}

/* ── Preview de foto pendente ─────────────────────────────────────────────── */
.foto-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--azul-claro);
  border-top: 1px solid var(--cinza-borda);
  flex-shrink: 0;
  font-size: 13px;
}
.foto-preview-bar img {
  height: 40px;
  width:  40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--cinza-borda);
}
.foto-preview-bar span { flex: 1; color: var(--texto); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-remover-foto {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--texto-leve);
  font-size: 15px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-remover-foto:hover { background: var(--cinza-borda); }

/* ── Área de input ────────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--cinza-borda);
  background: white;
  flex-shrink: 0;
}

.input-msg {
  flex: 1;
  border: 1.5px solid var(--cinza-borda);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--texto);
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color .2s;
}
.input-msg:focus { border-color: var(--azul); }
.input-msg::placeholder { color: #94a3b8; }

/* ── Botão de foto ────────────────────────────────────────────────────────── */
.btn-foto {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: white;
  border: 1.5px solid var(--cinza-borda);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
}
.btn-foto:hover  { border-color: var(--azul); background: var(--azul-claro); }
.btn-foto.com-foto { border-color: var(--verde); background: var(--verde-claro); }

/* ── Imagem no balão do chat ──────────────────────────────────────────────── */
.foto-chat {
  max-width: 220px;
  max-height: 160px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 8px;
  display: block;
}
.mensagem.assistente .foto-chat { border: 1px solid var(--cinza-borda); }
.mensagem.usuario    .foto-chat { border: 1px solid rgba(255,255,255,.4); }

.btn-enviar {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--azul);
  color: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s;
}
.btn-enviar:hover { background: var(--azul-hover); }
.btn-enviar:disabled { background: var(--cinza-borda); cursor: not-allowed; }

/* ── Modal de feedback ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .2s ease;
}

.modal-feedback {
  background: white;
  border-radius: 20px;
  padding: 36px 32px 28px;
  width: min(440px, 92vw);
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
  text-align: center;
}

.modal-feedback h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--texto);
  margin-bottom: 6px;
}

.modal-sub {
  font-size: 13px;
  color: var(--texto-leve);
  margin-bottom: 24px;
}

.estrelas-container {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}

.estrela {
  background: none;
  border: none;
  font-size: 38px;
  line-height: 1;
  cursor: pointer;
  color: #d1d5db;
  transition: color .12s, transform .1s;
  padding: 2px 4px;
}
.estrela:hover  { transform: scale(1.15); }
.estrela.ativa  { color: #f59e0b; }
.estrela.hover  { color: #fbbf24; }

.estrela-label {
  font-size: 12px;
  color: var(--texto-leve);
  height: 18px;
  margin-bottom: 16px;
}

#comentarioFeedback {
  width: 100%;
  border: 1.5px solid var(--cinza-borda);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--texto);
  resize: none;
  margin-bottom: 20px;
  outline: none;
  transition: border-color .2s;
}
#comentarioFeedback:focus { border-color: var(--azul); }

.modal-acoes {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.btn-pular {
  background: none;
  border: none;
  color: var(--texto-leve);
  font-size: 14px;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 8px;
  transition: background .2s;
}
.btn-pular:hover { background: var(--cinza-bg); color: var(--texto); }

.btn-enviar-feedback {
  flex: 1;
  background: var(--azul);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.btn-enviar-feedback:disabled { background: var(--cinza-borda); cursor: not-allowed; }
.btn-enviar-feedback:not(:disabled):hover { background: var(--azul-hover); }

/* ── Responsividade ───────────────────────────────────────────────────────── */
.cliente-card-wrapper { max-width: 96%; }

.cliente-card {
  width: min(560px, 100%);
  background: #ffffff;
  border: 1px solid var(--cinza-borda);
  border-left: 4px solid var(--azul);
  border-radius: 8px;
  box-shadow: var(--sombra);
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
}

.cliente-card-kicker {
  color: var(--azul);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.cliente-card h3 {
  font-size: 16px;
  line-height: 1.25;
  margin-bottom: 8px;
  color: var(--texto);
}

.cliente-card-texto { color: var(--texto-leve); margin-top: 6px; }

.cliente-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.cliente-card-meta span {
  background: var(--cinza-bg);
  border: 1px solid var(--cinza-borda);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--texto-leve);
  font-size: 12px;
}

.cliente-card-linha {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  margin-top: 6px;
}

.cliente-card-linha strong { color: var(--texto); }

.cliente-card-sugestao {
  background: var(--azul-claro);
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e3a8a;
  margin-top: 10px;
  padding: 8px 10px;
}

.cliente-card-detalhes {
  background: var(--cinza-bg);
  border: 1px solid var(--cinza-borda);
  border-radius: 8px;
  margin-top: 10px;
  padding: 10px;
}

.cliente-card-lista { margin: 8px 0 0 16px; }
.cliente-card-lista li { margin-bottom: 4px; }

.cliente-card-acoes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.cliente-card-acoes button {
  background: white;
  border: 1px solid var(--cinza-borda);
  border-radius: 8px;
  color: var(--texto);
  cursor: pointer;
  font-size: 12px;
  padding: 6px 9px;
}

.cliente-card-acoes button:hover {
  border-color: var(--azul);
  color: var(--azul);
  background: var(--azul-claro);
}

@media (max-width: 600px) {
  body { align-items: stretch; }
  .app { max-height: none; border-radius: 0; height: 100vh; height: 100dvh; }
  .mensagem { max-width: 92%; }
  /* Header: deixa quebrar e encolhe — não estoura a tela do celular. */
  .header { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .header-right { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .logo-text { font-size: 14px; }
  .logo-text strong { font-size: 15px; }
  .header-right button { padding: 5px 9px; font-size: 12px; }
  .status-badge { font-size: 11px; padding: 3px 9px; }
  /* Barra de setores: rola na horizontal em vez de quebrar a tela. */
  .setores-bar { padding: 8px 12px; gap: 6px; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .setores-bar::-webkit-scrollbar { display: none; }
  .btn-setor { flex-shrink: 0; padding: 6px 12px; }
  .setores-label { display: none; }
  /* Sugestões e área de envio mais compactas. */
  .sugestoes { padding: 8px 12px; }
  .input-area { padding: 10px 12px; gap: 8px; }
  /* Evita o ZOOM automático do iOS ao focar o campo (acontece com fonte < 16px). */
  .input-msg { font-size: 16px; }
}

/* Tema escuro do chat */
body[data-theme="dark"] .app,
body[data-theme="dark"] .input-area,
body[data-theme="dark"] .modal-feedback,
body[data-theme="dark"] .cliente-card {
  background: var(--branco);
  color: var(--texto);
  border-color: var(--cinza-borda);
}

body[data-theme="dark"] .setores-bar,
body[data-theme="dark"] .sugestoes,
body[data-theme="dark"] .foto-preview-bar,
body[data-theme="dark"] .setor-fixo-bar {
  background: #0f172a;
  border-color: var(--cinza-borda);
}

body[data-theme="dark"] .balao,
body[data-theme="dark"] .pontos,
body[data-theme="dark"] .cliente-card-detalhes,
body[data-theme="dark"] .cliente-card-meta span {
  background: #0f172a;
  border-color: var(--cinza-borda);
  color: var(--texto);
}

body[data-theme="dark"] .mensagem.usuario .balao {
  background: var(--azul);
  color: white;
}

body[data-theme="dark"] .btn-setor,
body[data-theme="dark"] .btn-sugestao,
body[data-theme="dark"] .btn-revisar-info,
body[data-theme="dark"] .btn-foto,
body[data-theme="dark"] .cliente-card-acoes button,
body[data-theme="dark"] .btn-tema-chat {
  background: #111827;
  border-color: #475569;
  color: #f8fafc;
}

body[data-theme="dark"] .btn-tema-chat {
  background: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.25);
}

body[data-theme="dark"] .btn-setor:hover,
body[data-theme="dark"] .btn-sugestao:hover,
body[data-theme="dark"] .btn-revisar-info:hover,
body[data-theme="dark"] .btn-foto:hover,
body[data-theme="dark"] .cliente-card-acoes button:hover {
  background: var(--azul-claro);
  border-color: var(--azul);
  color: #bfdbfe;
}

body[data-theme="dark"] .btn-setor.ativo {
  background: var(--azul);
  border-color: var(--azul);
  color: white;
}

body[data-theme="dark"] .input-msg,
body[data-theme="dark"] #comentarioFeedback,
body[data-theme="dark"] #modalReportarInfo input,
body[data-theme="dark"] #modalReportarInfo select,
body[data-theme="dark"] #modalReportarInfo textarea {
  background: #0f172a !important;
  border-color: #475569 !important;
  color: #f8fafc !important;
}

body[data-theme="dark"] .input-msg::placeholder,
body[data-theme="dark"] #comentarioFeedback::placeholder,
body[data-theme="dark"] #modalReportarInfo input::placeholder,
body[data-theme="dark"] #modalReportarInfo textarea::placeholder {
  color: #94a3b8 !important;
}

body[data-theme="dark"] .cliente-card h3,
body[data-theme="dark"] .cliente-card-linha strong {
  color: #f8fafc;
}

body[data-theme="dark"] .cliente-card-texto,
body[data-theme="dark"] .cliente-card-meta span,
body[data-theme="dark"] .cliente-card-lista,
body[data-theme="dark"] .modal-sub,
body[data-theme="dark"] .estrela-label,
body[data-theme="dark"] .setores-label,
body[data-theme="dark"] .setor-ativo-label {
  color: #cbd5e1;
}

body[data-theme="dark"] .cliente-card-sugestao,
body[data-theme="dark"] .badge-base {
  background: #172554;
  border-color: #1d4ed8;
  color: #bfdbfe;
}

/* ── Alfa 01: feedback inline ────────────────────────────────────── */
.alfa-feedback { margin-top: 8px; border-top: 1px solid rgba(0,0,0,.06); padding-top: 8px; }
.alfa-fb-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alfa-fb-label { font-size: 12px; color: #94a3b8; }
.alfa-fb-btn { font-size: 12px; padding: 4px 10px; border-radius: 16px; border: 1.5px solid #e2e8f0; background: transparent; cursor: pointer; transition: all .15s; }
.alfa-fb-btn.positivo:hover { background: #dcfce7; border-color: #22c55e; color: #166534; }
.alfa-fb-btn.negativo:hover { background: #fee2e2; border-color: #ef4444; color: #991b1b; }
.alfa-fb-btn:disabled { opacity: .5; cursor: not-allowed; }
.alfa-fb-correcao { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.alfa-fb-input { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid #e2e8f0; font-size: 13px; font-family: inherit; resize: vertical; outline: none; }
.alfa-fb-input:focus { border-color: #3b82f6; }
.alfa-fb-enviar { align-self: flex-end; padding: 6px 14px; border-radius: 8px; background: #3b82f6; color: #fff; border: none; font-size: 12px; font-weight: 700; cursor: pointer; }
body[data-theme="dark"] .alfa-fb-btn { border-color: #334155; color: #cbd5e1; }
body[data-theme="dark"] .alfa-fb-input { background: #0f172a; color: #f1f5f9; border-color: #334155; }
body[data-theme="dark"] .alfa-feedback { border-color: #334155; }
