/* CRM Climipp — layout de aplicativo: topo fixo, colunas com rolagem própria, resposta sempre visível. */
:root {
  --fundo: #f3f5f7; --superficie: #ffffff; --superficie-2: #f7f9fa; --texto: #1d2733; --sutil: #66727f;
  --borda: #e1e6eb; --primaria: #0f766e; --primaria-hover: #0b5f58; --primaria-texto: #ffffff;
  --entrada: #ffffff; --saida: #d8f0eb; --realce: #e7f4f1;
  --alerta-fundo: #fdecec; --alerta-texto: #a12626; --aviso-fundo: #fff4e0; --aviso-texto: #8a5300;
  --ok: #15803d; --off: #b91c1c; --sombra: 0 1px 2px rgb(16 24 40 / .06);
  --raio: 10px; --topo: 52px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #0f1419; --superficie: #171d24; --superficie-2: #1c232b; --texto: #e6ebf0; --sutil: #93a0ad;
    --borda: #29323c; --primaria: #2bb3a3; --primaria-hover: #3cc6b6; --primaria-texto: #062320;
    --entrada: #1f2730; --saida: #12453f; --realce: #15302c;
    --alerta-fundo: #3b1a1a; --alerta-texto: #f3b4b4; --aviso-fundo: #3a2b10; --aviso-texto: #f5cf8a;
    --ok: #4ade80; --off: #f87171; --sombra: none;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14.5px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo); color: var(--texto);
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.25rem; margin: .2rem 0 .8rem; }
button {
  font: inherit; font-weight: 500; background: var(--primaria); color: var(--primaria-texto);
  border: 1px solid transparent; border-radius: 8px; padding: .45rem .9rem; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--primaria-hover); }
button.secundario { background: transparent; color: var(--primaria); border-color: var(--borda); }
button.secundario:hover { background: var(--realce); }
button.link { background: none; color: var(--primaria); padding: 0; border: 0; }
button.link:hover { text-decoration: underline; }
button.perigo { color: var(--off); }
input, textarea, select {
  font: inherit; color: var(--texto); background: var(--superficie); border: 1px solid var(--borda);
  border-radius: 8px; padding: .45rem .65rem; width: 100%;
}
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--primaria); outline-offset: 1px; }
textarea { resize: vertical; }
.sutil { color: var(--sutil); font-size: .85em; }
.alerta { background: var(--alerta-fundo); color: var(--alerta-texto); padding: .45rem .7rem; border-radius: 8px; margin: 0; }
.alerta.faixa { border-radius: 0; flex: none; }
.sucesso { color: var(--ok); font-weight: 600; margin: 0; }
.vazio { color: var(--sutil); padding: 1.2rem 1rem; list-style: none; text-align: center; margin: 0; }
.linha { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.chip {
  display: inline-block; background: var(--realce); color: var(--texto); border-radius: 999px;
  font-size: .72rem; padding: .05rem .5rem; white-space: nowrap;
}
.etiquetas { display: flex; flex-wrap: wrap; gap: .25rem; }

/* ---------- topo ---------- */
.topo {
  flex: none; height: var(--topo); display: flex; align-items: center; gap: 1.2rem; padding: 0 16px;
  background: var(--superficie); border-bottom: 1px solid var(--borda);
}
.topo > strong { white-space: nowrap; }
.menu { display: flex; gap: .2rem; overflow-x: auto; scrollbar-width: none; }
.menu a { color: var(--sutil); padding: .35rem .6rem; border-radius: 6px; white-space: nowrap; }
.menu a:hover { color: var(--texto); background: var(--superficie-2); }
.menu a.atual { color: var(--texto); background: var(--realce); font-weight: 600; }
#sessao { flex: 1; min-width: 0; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.on { color: var(--ok); }
.status.off { color: var(--off); font-weight: 600; text-decoration: underline; }
.sair { display: flex; gap: .6rem; align-items: center; white-space: nowrap; }

/* ---------- caixa de entrada ---------- */
.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: 330px minmax(0, 1fr); }
.lateral {
  min-height: 0; display: flex; flex-direction: column; background: var(--superficie);
  border-right: 1px solid var(--borda);
}
.novo { flex: none; padding: .55rem 16px; border-bottom: 1px solid var(--borda); }
.novo summary { cursor: pointer; color: var(--primaria); font-weight: 600; list-style: none; }
.novo summary::-webkit-details-marker { display: none; }
.novo form { display: grid; gap: .45rem; margin-top: .55rem; }
.busca { flex: none; border-radius: 0; border-width: 0 0 1px; padding: .6rem 16px; background: var(--superficie); }
#lista { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.abas {
  flex: none; display: flex; flex-wrap: wrap; gap: .15rem; padding: .4rem 10px; border-bottom: 1px solid var(--borda);
  overflow-x: auto; scrollbar-width: none; font-size: .82rem;
}
.abas a { color: var(--sutil); padding: .25rem .5rem; border-radius: 6px; white-space: nowrap; }
.abas a.atual { color: var(--texto); background: var(--realce); font-weight: 600; }
.abas .n { color: var(--sutil); font-weight: 400; margin-left: .15rem; }
.lista { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 0; }
.lista li a {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .1rem .5rem; align-items: center;
  padding: .6rem 16px; border-bottom: 1px solid var(--borda);
}
.lista li a:hover { background: var(--superficie-2); }
.lista li.ativa a { background: var(--realce); box-shadow: inset 3px 0 0 var(--primaria); }
.lista .nome { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista li.nova .nome { font-weight: 700; }
.lista .quando { color: var(--sutil); font-size: .75rem; }
.lista .previa { color: var(--sutil); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista .badge {
  background: var(--primaria); color: var(--primaria-texto); border-radius: 999px; font-size: .72rem;
  min-width: 1.3rem; text-align: center; padding: 0 .35rem; justify-self: end;
}
.lista .info { grid-column: 1 / -1; font-size: .74rem; color: var(--sutil); }
.st::before { content: "●"; margin-right: .25rem; font-size: .7em; vertical-align: middle; }
.st-aberta::before { color: #e5484d; }
.st-aguardando::before { color: #f5a524; }
.st-resolvida::before { color: var(--ok); }

/* ---------- conversa ---------- */
.painel { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.painel > .vazio { margin: auto; }
.conversa { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cabecalho {
  flex: none; display: flex; align-items: center; gap: .8rem; padding: .55rem 16px;
  background: var(--superficie); border-bottom: 1px solid var(--borda);
}
.voltar { display: none; font-size: 1.3rem; padding: 0 .2rem; }
.quem { flex: 1; min-width: 0; display: grid; gap: .1rem; }
.quem strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quem .sutil { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acoes { flex: none; display: flex; gap: .4rem; align-items: center; }
.acoes-sel { order: 2; }
.acoes-btn { order: 3; }
.acoes select { width: auto; max-width: 160px; padding: .35rem .5rem; font-size: .85rem; }
.acoes button { padding: .35rem .7rem; font-size: .85rem; }

#ficha:empty, #menu-respostas:empty { display: none; }
.ficha, .menu-respostas {
  flex: none; max-height: 45%; overflow-y: auto; background: var(--superficie);
  border-bottom: 1px solid var(--borda); padding: .7rem 16px; display: grid; gap: .5rem;
}
.menu-respostas { border-top: 1px solid var(--borda); border-bottom: 0; }
.ficha form { display: grid; gap: .6rem; }
.ficha-topo { display: flex; justify-content: space-between; align-items: center; gap: .8rem; }
.ficha-topo span { display: flex; gap: .8rem; align-items: center; }
.campos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem .9rem; }
.campos label { display: grid; gap: .2rem; font-size: .8rem; color: var(--sutil); }
.campos .largo { grid-column: 1 / -1; }
.ficha button[type=submit] { justify-self: start; }

.mensagens {
  flex: 1; min-height: 35%; overflow-y: auto; padding: 1rem 16px; display: flex; flex-direction: column; gap: .45rem;
}
.msg {
  max-width: min(72%, 620px); padding: .45rem .7rem .3rem; border-radius: 12px; background: var(--entrada);
  border: 1px solid var(--borda); box-shadow: var(--sombra); align-self: flex-start;
}
.msg.out { align-self: flex-end; background: var(--saida); border-color: transparent; }
.msg.falhou { outline: 2px solid var(--off); }
.msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .tipo { display: block; font-style: italic; color: var(--sutil); font-size: .8rem; margin-bottom: .1rem; }
.msg .meta { display: block; text-align: right; color: var(--sutil); font-size: .7rem; margin-top: .2rem; }
.opcoes-msg { display: flex; flex-wrap: wrap; gap: .3rem; list-style: none; margin: .4rem 0 0; padding: 0; }
.opcoes-msg li { border: 1px solid var(--primaria); color: var(--primaria); border-radius: 999px; padding: .05rem .6rem; font-size: .8rem; }

/* sugestão da IA */
.sugestao-caixa {
  flex: 0 1 auto; min-height: 0; max-height: 40%; overflow-y: auto; background: var(--superficie-2);
  border-top: 1px solid var(--borda); padding: .55rem 16px; display: grid; gap: .4rem;
}
.sugestao-topo { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.sugestao-texto { margin: 0; white-space: pre-wrap; background: var(--saida); border-radius: 10px; padding: .45rem .7rem; }
.aviso-transferir { margin: 0; color: var(--aviso-texto); background: var(--aviso-fundo); border-radius: 8px; padding: .35rem .6rem; font-size: .88rem; }
.botoes button { padding: .3rem .7rem; font-size: .85rem; }
.dados-ia { margin: 0; font-size: .78rem; }

/* resposta */
.resposta {
  flex: none; display: flex; gap: .5rem; align-items: flex-end; padding: .55rem 16px;
  background: var(--superficie); border-top: 1px solid var(--borda);
}
.resposta textarea { resize: none; min-height: 2.6rem; max-height: 9rem; }
.resposta button.secundario { padding: .45rem .6rem; }

/* formulário de mensagem com opções */
.form-interativa { display: grid; gap: .5rem; }
.form-interativa label { display: grid; gap: .2rem; font-size: .82rem; color: var(--sutil); }
.form-interativa .tipos { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .3rem .9rem; }
.form-interativa .tipos label, .form-interativa label.nao-enquete { display: flex; gap: .35rem; align-items: center; color: var(--texto); }
.form-interativa input[type=radio], .form-interativa input[type=checkbox] { width: auto; }
.form-interativa:not([data-tipo="lista"]) .so-lista { display: none; }
.form-interativa[data-tipo="enquete"] .nao-enquete { display: none; }
.form-interativa button[type=submit] { justify-self: start; }
.item-resposta {
  display: grid; gap: .1rem; text-align: left; background: var(--superficie); color: var(--texto);
  border: 1px solid var(--borda); white-space: normal; font-weight: 400;
}
.item-resposta:hover { background: var(--realce); }
.item-resposta span { color: var(--sutil); font-size: .82rem; }

/* ---------- páginas (pacientes, respostas, agente, whatsapp) ---------- */
.pagina { flex: 1; min-height: 0; overflow-y: auto; width: 100%; max-width: 760px; margin: 0 auto; padding: 1rem 16px 2rem; }
.pagina.larga { max-width: 1000px; }
.pagina ol { padding-left: 1.2rem; }
.filtros { display: flex; gap: .6rem; margin: .2rem 0 .8rem; }
.filtros select { width: auto; min-width: 190px; }
.pacientes { list-style: none; margin: 0; padding: 0; background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); overflow: hidden; }
.pacientes li a { display: grid; gap: .15rem; padding: .7rem 1rem; border-bottom: 1px solid var(--borda); }
.pacientes li a:hover { background: var(--superficie-2); }
.pacientes li:last-child a, .pacientes li:last-child { border-bottom: 0; }
.pacientes .nome { font-weight: 600; }
.pacientes .quando { color: var(--sutil); font-size: .76rem; }
.cartao-form {
  display: grid; gap: .65rem; background: var(--superficie); border: 1px solid var(--borda);
  border-radius: var(--raio); padding: 1rem; margin-bottom: 1rem;
}
.cartao-form label { display: grid; gap: .25rem; font-size: .85rem; color: var(--sutil); }
.cartao-form button[type=submit] { justify-self: start; }
.cartao-form details ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.resposta-item { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem 1rem; border-bottom: 1px solid var(--borda); }
.resposta-item p { margin: .2rem 0 0; white-space: pre-wrap; }
.qr { width: min(300px, 100%); height: auto; background: #fff; padding: 8px; border-radius: 8px; display: block; }

/* ---------- funil ---------- */
.funil-pagina { flex: 1; min-height: 0; padding: 1rem 16px; display: flex; flex-direction: column; }
#funil { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.quadro { flex: 1; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: .8rem; overflow-x: auto; }
.coluna { background: var(--superficie-2); border: 1px solid var(--borda); border-radius: var(--raio); padding: .6rem; overflow-y: auto; }
.coluna h2 { font-size: .9rem; margin: .1rem .2rem .6rem; display: flex; justify-content: space-between; }
.coluna .n { color: var(--sutil); font-weight: 400; }
.cartao-funil {
  display: grid; gap: .3rem; background: var(--superficie); border: 1px solid var(--borda); border-radius: 8px;
  padding: .55rem .6rem; margin-bottom: .5rem; box-shadow: var(--sombra);
}
.cartao-funil .nome { font-weight: 600; }
.cartao-funil select { padding: .3rem .4rem; font-size: .8rem; }
.rodape-funil { margin: .6rem 0 0; flex: none; }

/* ---------- login ---------- */
.login { flex: 1; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.cartao {
  background: var(--superficie); border: 1px solid var(--borda); border-radius: 12px; padding: 1.5rem;
  width: min(360px, 100%); display: grid; gap: .8rem; box-shadow: var(--sombra);
}
.cartao h1 { margin: 0; }
.cartao label { display: grid; gap: .3rem; font-size: .9rem; }

/* ---------- telas médias ---------- */
@media (max-width: 1100px) {
  .inbox { grid-template-columns: 290px minmax(0, 1fr); }
  .acoes select { max-width: 130px; }
  .topo { gap: .8rem; }
  .sair .sutil { display: none; }
}

/* ---------- celular ---------- */
@media (max-width: 760px) {
  :root { --topo: auto; }
  .topo { flex-wrap: wrap; gap: .3rem .8rem; padding: .45rem 12px; }
  .menu { order: 3; flex-basis: 100%; }
  #sessao { order: 2; flex: 1; font-size: .78rem; }
  .sair { order: 2; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox.com-conversa .lateral { display: none; }
  .inbox:not(.com-conversa) .painel { display: none; }
  .lateral { border-right: 0; }
  .voltar { display: inline; }
  .cabecalho { flex-wrap: wrap; padding: .45rem 12px; gap: .35rem .6rem; }
  .cabecalho .etiquetas { display: none; }
  .acoes-btn { order: 2; }
  .acoes-sel { order: 3; flex-basis: 100%; }
  .msg { max-width: 88%; }
  .mensagens, .resposta, .sugestao-caixa, .ficha, .menu-respostas { padding-left: 12px; padding-right: 12px; }
  .campos { grid-template-columns: 1fr; }
  .filtros { flex-direction: column; }
  .filtros select { width: 100%; }
  .funil-pagina { overflow-y: auto; display: block; }
  #funil { display: block; }
  .quadro { display: grid; grid-auto-flow: row; grid-auto-columns: auto; overflow: visible; }
  .coluna { overflow: visible; }
  /* conversa: mensagens primeiro; sugestão e menus compactos */
  .acoes-sel select { flex: 1 1 0; min-width: 0; max-width: none; }
  .sugestao-caixa { max-height: 34%; gap: .3rem; padding-top: .4rem; padding-bottom: .4rem; }
  .sugestao-texto { max-height: 5.5em; overflow-y: auto; }
  .dados-ia { display: none; }
  .ficha, .menu-respostas { max-height: 55%; }
  .menu a { padding: .3rem .45rem; }
}
