:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #e6f4f2;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --ok: #067647;
  --ok-soft: #dcfae6;
  --wellhub: #d92d75;
  --totalpass: #1d4ed8;
  --radius: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .9rem; margin: 0 0 8px; }
code { font-size: .8rem; background: var(--bg); padding: 2px 6px; border-radius: 6px; word-break: break-all; }

/* topo */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; padding: 12px 20px 4px; font-weight: 600; }
.logo { background: var(--brand); color: #fff; border-radius: 8px; width: 30px; height: 30px; display: grid; place-items: center; font-size: .8rem; }
.tabs { display: flex; gap: 4px; padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.badge { background: var(--danger); color: #fff; border-radius: 99px; font-size: .7rem; padding: 1px 7px; margin-left: 4px; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.toolbar.small { margin-bottom: 8px; }
.toolbar.small h2 { margin: 0; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: .85rem; margin: -6px 0 14px; }
.vazio { color: var(--muted); font-size: .85rem; text-align: center; padding: 14px 4px; }

/* controles */
input, select, textarea, button { font: inherit; }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; color: var(--text); }
button:hover { background: var(--bg); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-2); }
button.danger { color: var(--danger); border-color: var(--danger-soft); }
button.sm { padding: 4px 10px; font-size: .85rem; }
button.link { border: 0; background: none; color: var(--brand); padding: 0; }
button:disabled { opacity: .5; cursor: wait; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); margin-bottom: 10px; flex: 1; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
label.narrow { flex: 0 0 90px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > label { min-width: 140px; }
.actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }

/* agenda */
.semana { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; }
.dia { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 6px; min-height: 160px; }
.dia h3 { text-transform: uppercase; letter-spacing: .04em; font-size: .72rem; color: var(--muted); }
.slot { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 8px; border-top: 0; border-right: 0; border-bottom: 0; }
.slot:hover { filter: brightness(.97); background: var(--brand-soft); }
.slot.quase { border-left-color: var(--warn); background: var(--warn-soft); }
.slot.lotado { border-left-color: var(--danger); background: var(--danger-soft); }
.slot.inativo { opacity: .5; }
.slot .hora { font-weight: 700; font-size: .85rem; }
.slot .mod { font-size: .9rem; }
.slot .prof { font-size: .75rem; color: var(--muted); }
.slot .ocup { display: flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); margin-top: 4px; }
.bar { flex: 1; height: 5px; background: rgba(0,0,0,.08); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: currentColor; }
.slot .bar span { background: var(--brand); }
.slot.quase .bar span { background: var(--warn); }
.slot.lotado .bar span { background: var(--danger); }
.add-dia { margin-top: auto; border-style: dashed; color: var(--muted); font-size: .8rem; padding: 6px; }

/* tabelas */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
#tabela-alunos tbody tr[data-id] { cursor: pointer; }
#tabela-alunos tbody tr[data-id]:hover { background: var(--bg); }
tr.inativo { opacity: .55; }
td small { color: var(--muted); }
td select { width: auto; font-size: .85rem; padding: 4px 6px; }
.dir { text-align: right; white-space: nowrap; }

.origem { font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.origem.wellhub { background: #fde7f0; color: var(--wellhub); }
.origem.totalpass { background: #e0e9ff; color: var(--totalpass); }
.status { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.status.pendente { background: var(--warn-soft); color: var(--warn); }
.status.confirmado { background: var(--ok-soft); color: var(--ok); }
.status.erro, .status.rejeitado { background: var(--danger-soft); color: var(--danger); }
.status.expirado { background: var(--bg); color: var(--muted); }

/* planos */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.card .nome { font-weight: 600; }
.card .valor { font-size: 1.4rem; font-weight: 700; color: var(--brand); }
.card .valor small { font-size: .8rem; color: var(--muted); font-weight: 400; }
.card .mods { font-size: .8rem; color: var(--muted); }
.card .desc { font-size: .85rem; }
.card .tag { font-size: .7rem; color: var(--muted); }
.card.inativo { opacity: .55; }

/* academia */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel.info { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; margin-bottom: 12px; }
.previa { white-space: pre-wrap; font-size: .82rem; background: var(--bg); padding: 12px; border-radius: 8px; margin: 0; max-height: 70vh; overflow: auto; }

/* diálogos */
dialog { border: 0; border-radius: 14px; padding: 20px; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(16,24,40,.45); }
.chips { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow: auto; }
.chips li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--bg); border-radius: 8px; font-size: .9rem; }
.chips li span { flex: 1; }
.chips .x { border: 0; background: none; font-size: 1.1rem; line-height: 1; padding: 0 4px; color: var(--muted); }
.chips .x:hover { color: var(--danger); }
.add-aluno .combo { flex: 1; position: relative; min-width: 0; }
.combo-lista { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; list-style: none; margin: 0; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(16,24,40,.15); max-height: 240px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; user-select: none; }
.combo-lista li { display: flex; align-items: baseline; gap: 10px; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: .9rem; }
.combo-lista li .nome { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-lista li .tel { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.combo-lista li.ativo, .combo-lista li:hover { background: var(--brand-soft); }
.combo-lista li.vazio { cursor: default; background: none; justify-content: center; }
#bloco-alunos { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: .9rem; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.erro { background: var(--danger); }

@media (max-width: 900px) {
  main { padding: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .semana { grid-template-columns: 1fr; }
  .dia { min-height: 0; }
  .toolbar input, .toolbar select { flex: 1; min-width: 140px; }
}

/* ---------- sessão e perfis ---------- */
.brand { padding-right: 20px; }
.brand .usuario { font-size: .82rem; color: var(--muted); font-weight: 400; }
.perfil-recepcao .so-admin { display: none !important; }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--text); }

.tela-login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 4px; box-shadow: 0 10px 40px rgba(16,24,40,.08); }
.login-box .brand { padding: 0 0 16px; font-size: 1.1rem; }
.login-box button { margin-top: 8px; padding: 10px; }
.erro-login { color: var(--danger); font-size: .85rem; margin: 0; }

.hint-inline { font-size: .82rem; color: var(--muted); }
.info-lista { display: flex; flex-direction: column; gap: 8px; font-size: .88rem; }
.panel h2 { margin-bottom: 8px; }
.grid-2 > .panel { min-width: 0; }

/* ---------- conversas ---------- */
.chat-layout { display: grid; grid-template-columns: 300px 1fr; gap: 12px; height: calc(100vh - 190px); min-height: 420px; }
.lista-conversas { padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conversa-item { text-align: left; border: 0; border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 2px; background: none; width: 100%; }
.conversa-item small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversa-item .linha1 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.conversa-item.ativa { background: var(--brand-soft); }
.conversa-item.simulador { border: 1px dashed var(--line); margin-bottom: 6px; }
.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat > #chat-vazio { margin: auto; }
#chat-conteudo { display: flex; flex-direction: column; height: 100%; min-height: 0; }
#chat-conteudo[hidden] { display: none; }
.chat-topo { padding: 12px 14px 0; }
#chat-motivo { margin: 4px 14px 0; }
.mensagens { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f0f2f5; margin-top: 8px; }
.msg { display: flex; flex-direction: column; max-width: 75%; }
.msg.entrada { align-self: flex-start; }
.msg.saida { align-self: flex-end; align-items: flex-end; }
.balao { padding: 8px 12px; border-radius: 12px; font-size: .9rem; line-height: 1.4; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); word-wrap: break-word; }
.msg.saida .balao { background: #d9fdd3; }
.msg.saida.atendente .balao { background: #e0e9ff; }
.msg small { font-size: .7rem; color: var(--muted); margin-top: 2px; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .lista-conversas { max-height: 220px; }
  .chat { min-height: 480px; }
  .brand { flex-wrap: wrap; }
}

/* cobrança */
#resumo-cobranca { margin-bottom: 12px; }
.card.resumo.destaque { border-color: var(--brand); }
#aviso-sem-plano { display: block; line-height: 1.6; }
#aviso-sem-plano[hidden] { display: none; }
#campo-plano-aluno[hidden] { display: none; }
