:root {
  --bg: #f4f6f8;
  --sidebar-bg: #A311BA;
  --sidebar-fg: #ecd9f0;
  --sidebar-active: #A311BA;
  --accent: #2a9d8f;
  --accent-dark: #21867a;
  --border: #e1e5ea;
  --text: #2b3440;
  --danger: #d9534f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  padding: 24px 16px;
  transition: width .2s ease, padding .2s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 24px;
}
.sidebar .logo {
  font-size: 20px;
  margin: 0;
  color: #fff;
  white-space: nowrap;
}
.sidebar-toggle {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.sidebar-toggle:hover { background: rgba(255, 255, 255, 0.24); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-fg);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  white-space: nowrap;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sidebar nav a.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 #fff;
}
.sidebar nav a.active:hover { background: rgba(255, 255, 255, 0.22); }
html.sidebar-collapsed .sidebar nav a.active { box-shadow: inset 0 -3px 0 #fff; }
.sidebar .icon { width: 20px; text-align: center; flex-shrink: 0; }

/* Estado recolhido */
html.sidebar-collapsed .sidebar { width: 64px; padding: 24px 10px; }
html.sidebar-collapsed .sidebar-top { flex-direction: column; gap: 12px; }
html.sidebar-collapsed .sidebar .label { display: none; }
html.sidebar-collapsed .sidebar nav a { justify-content: center; padding: 10px 0; }

/* Topbar + drawer (apenas no celular; ocultos por padrão) */
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }

/* Content */
.content { flex: 1; padding: 32px 40px; min-width: 0; }

/* Wrapper de tabela (scroll horizontal em telas médias) */
.tabela-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Enquanto o formulário estiver aberto em #form-area, esconde a tabela
   para mostrar só o formulário; ao fechar (área vazia) a tabela reaparece. */
#form-area:has(form) ~ .tabela-wrap,
#form-area:has(form) ~ .filtro-barra { display: none; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
h2 { margin: 0 0 4px; }

/* Home — guia de orientação */
.home-hero { max-width: 720px; }
.home-hero h2 { font-size: 26px; }
.home-hero p { color: #6b7684; margin: 4px 0 0; line-height: 1.5; }

.guia-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 28px;
}
.guia-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 22px 56px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.guia-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--c, var(--accent));
}
.guia-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 28px rgba(0,0,0,.10);
  border-color: var(--c, var(--accent));
}
.guia-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 24px;
  background: color-mix(in srgb, var(--c, var(--accent)) 14%, #fff);
}
.guia-card strong { font-size: 17px; }
.guia-desc { color: #6b7684; font-size: 14px; }
.guia-lista {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.guia-lista li {
  position: relative;
  padding-left: 20px;
  font-size: 13.5px;
  line-height: 1.4;
  color: #4a5461;
}
.guia-lista li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 700;
  color: var(--c, var(--accent));
}
.guia-cta {
  position: absolute;
  left: 22px;
  bottom: 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--c, var(--accent));
}

/* Table */
.tabela {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.tabela th, .tabela td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.tabela th { background: #fafbfc; font-weight: 600; color: #4a5664; }
.tabela tr:last-child td { border-bottom: none; }
.acoes-col { white-space: nowrap; width: 1%; }
.vazio { color: #8a94a2; font-style: italic; }

/* Tabela com rolagem interna: o cabeçalho fica fixo no topo enquanto rola. */
.tabela-scroll {
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
/* Página de lista que preenche a altura da tela: a tabela ocupa todo o espaço
   restante e só rola o que não couber. */
.content-fill {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.content-fill .tabela-scroll { flex: 1 1 auto; min-height: 0; }
/* Com o formulário aberto, volta ao fluxo normal para o form poder rolar. */
.content-fill:has(#form-area form) { height: auto; overflow: visible; }
.tabela-scroll .tabela { border: none; border-radius: 0; }
.tabela-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  /* mantém a linha inferior do cabeçalho visível durante a rolagem */
  box-shadow: inset 0 -1px 0 var(--border);
}

/* Form */
.form-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 20px;
}
.form-card h3 { margin: 0 0 16px; }
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.grid label { display: flex; flex-direction: column; font-size: 13px; color: #4a5664; gap: 4px; }
.grid .span-2 { grid-column: span 2; }
/* Endereço + número (estreito) + complemento na mesma linha */
.linha-endereco {
  display: grid;
  grid-template-columns: 1fr 96px 1.1fr;
  gap: 14px;
}
/* CEP + bairro + cidade + UF na mesma linha */
.linha-cep {
  display: grid;
  grid-template-columns: 120px 1fr 1fr 72px;
  gap: 14px;
}
.grid input, .grid select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.grid input:focus, .grid select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }

/* Anamnese (bloco de perguntas no cadastro de paciente) */
.form-card .form-secao {
  margin: 24px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 16px;
}
.anamnese { display: flex; flex-direction: column; gap: 14px; }
.anam-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px 12px;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
}
.anam-item legend {
  font-size: 13px;
  font-weight: 600;
  color: #4a5664;
  padding: 0;
  width: 100%;
  margin-bottom: 4px;
}
.anam-item .radio, .check-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.anam-item .radio input, .check-inline input { width: auto; margin: 0; }
.anam-qual {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #4a5664;
  width: 100%;
  margin-top: 4px;
}
.anam-qual input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.anam-check-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 18px;
  width: 100%;
}
@media (max-width: 640px) {
  .anam-check-grid { grid-template-columns: 1fr; }
}

/* Buttons */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: var(--accent-dark); }
.btn-secondary {
  background: #eef1f4;
  color: #4a5664;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.btn-secondary:hover { background: #e2e6ea; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }
.btn-link.copiado { color: var(--accent-dark); font-weight: 600; }

/* Botão só com ícone (olho de "ver detalhes") */
.btn-icone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: #9aa3ad;
  padding: 2px 6px;
  vertical-align: middle;
  transition: color 0.15s;
}
.btn-icone:hover { color: var(--accent); }
.btn-icone svg { display: block; }

/* Modal de detalhes */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 36, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-card {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 24px 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-card h3 { margin: 0 32px 16px 0; }
.modal-fechar {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: #6b7480;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.modal-fechar:hover { background: #f0f2f5; color: var(--text); }
.modal-dados {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  margin: 0;
}
.modal-dados .span-2 { grid-column: span 2; }
.modal-subtitulo {
  margin: 20px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
}
.modal-dados dt { font-size: 12px; color: #6b7480; margin-bottom: 2px; }
.modal-dados dd { margin: 0; font-size: 14px; color: var(--text); }
@media (max-width: 640px) {
  .modal-dados { grid-template-columns: 1fr; }
  .modal-dados .span-2 { grid-column: span 1; }
}

/* Barra de filtro acima da tabela de modelos */
.snippets-filtro, .filtro-barra {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}
.snippets-filtro .chat-search, .filtro-barra .chat-search { flex: 1; min-width: 180px; }
.filtro-barra { align-items: center; }
.filtro-campo {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: #6b7480;
  flex: 1;
  min-width: 180px;
}
.filtro-campo .chat-search { flex: none; min-width: 0; width: 100%; }
.filtro-barra > .btn-secondary { align-self: flex-end; }

/* Toast (aviso de modelo copiado) */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  max-width: min(520px, calc(100vw - 32px));
  background: #273142;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Textarea no grid de formulários */
.grid textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.grid textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.grid label.check { flex-direction: row; align-items: center; gap: 8px; }
.grid label.check input { width: auto; }

/* Cabeçalho com múltiplas ações */
.header-actions { display: flex; gap: 10px; align-items: center; }
.hint { color: #6b7684; font-size: 13px; margin: 0 0 16px; }
.hint.warn { color: #9a6700; }
.hint.ok { color: var(--accent-dark); }
.hint code { background: #eef1f4; padding: 1px 5px; border-radius: 4px; }
.texto-col { max-width: 340px; white-space: pre-wrap; color: #4a5664; }
.status-dot { font-size: 13px; font-weight: 600; }
.status-dot.ok { color: #1f9d55; }
.status-dot.off { color: #8a94a2; }
.erro-inline { color: var(--danger); font-size: 13px; }
.config-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.qr-area { margin-top: 14px; }
.qr-img { width: 240px; height: 240px; border: 1px solid var(--border); border-radius: 8px; }

/* Chat (Conversas) — WhatsApp Web embutido, edge-to-edge ao lado da sidebar */
.content-flush { padding: 18px; max-width: none; height: 100vh; overflow: hidden; }
.wa {
  display: flex;
  height: 100%;
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
}
.chat-list {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
  background: #f0f2f5;
}
.chat-list-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px;
  background: #fff;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.chat-list-top strong { font-size: 17px; }
.chat-list-top-actions { display: flex; align-items: center; gap: 4px; }
.chat-list-top-actions .status-dot { font-size: 12px; margin-right: 2px; }
.chat-list-top-actions a {
  color: #4a5664;
  text-decoration: none;
  font-size: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.chat-list-top-actions a:hover { background: #eef1f4; }
.chat-aviso {
  background: #fff6e5;
  color: #9a6700;
  font-size: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.chat-list-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.chat-search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
}
.chat-search:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.nova-conversa { width: 100%; padding: 9px 12px; font-size: 13px; }
.chat-items {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f0f2f5;
}
.chat-vazio { padding: 16px; text-align: center; }

.chat-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow .15s, transform .05s;
}
.chat-item:hover { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12); }
.chat-item.active { box-shadow: inset 0 0 0 2px var(--accent); background: #f3fbf8; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.chat-item-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-item-nome {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-preview {
  color: #8a94a2;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.chat-item-hora { color: #8a94a2; font-size: 11px; }
.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}
/* Status do agendamento: bolinha colorida + rótulo */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  white-space: nowrap;
}
.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: none;
  background: #9aa4b2;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.04);
}
.status-agendado   .status-dot { background: #9b51e0; }  /* roxo  – ainda não respondeu */
.status-confirmado .status-dot { background: #27ae60; }  /* verde – confirmado          */
.status-atencao    .status-dot { background: #f1b300; }  /* amarelo – precisa resolver  */

.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: #ece5dd; }
.chat-empty {
  margin: auto;
  color: #8a94a2;
  text-align: center;
  font-size: 15px;
  line-height: 2;
}

/* Painel "Nova conversa" */
.novos { display: flex; flex-direction: column; height: 100%; min-height: 0; padding: 12px; }
.novos-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.novos-lista { flex: 1; overflow-y: auto; min-height: 0; margin-top: 8px; }

/* Thread */
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; }
.thread-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.thread-header-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.thread-tel { color: #8a94a2; font-size: 13px; }
.btn-voltar {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  padding: 0 4px;
}
.thread-mensagens {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  background: #ece5dd;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 72%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.35;
}
.bubble-texto { white-space: pre-wrap; }
.bubble.saida { align-self: flex-end; background: #d9fdd3; border-bottom-right-radius: 4px; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.bubble.entrada { align-self: flex-start; background: #fff; border-bottom-left-radius: 4px; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.bubble.falha { background: #fbe3e2; }
.bubble-meta { font-size: 11px; color: #8a94a2; margin-top: 4px; text-align: right; }
.bubble-erro { font-size: 12px; color: var(--danger); margin-top: 4px; }

.snippet-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 10px 14px;
  background: #f0f2f5;
  border-top: 1px solid var(--border);
  overflow-x: auto;
  min-width: 0;
}
.chip {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  cursor: pointer;
  color: #4a5664;
  white-space: nowrap;
  flex-shrink: 0;
}
.chip:hover { background: #eef1f4; }
.compose {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #f0f2f5;
}
.compose textarea {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 22px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
}
.compose textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.btn-enviar {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.btn-enviar:hover { background: var(--accent-dark); }
.btn-enviar svg { margin-left: 2px; }

/* ===========================================================================
   TABLET / telas médias (≤ 1024px): sidebar vira trilho de ícones
   =========================================================================== */
@media (max-width: 1024px) and (min-width: 641px) {
  .content { padding: 24px 28px; }
  .content-flush { padding: 14px; }
  .sidebar { width: 64px; padding: 24px 10px; }
  .sidebar-top { flex-direction: column; gap: 12px; }
  .sidebar .label { display: none; }
  .sidebar nav a { justify-content: center; padding: 10px 0; }
  .sidebar-toggle { display: none; }
  .chat-list { width: 300px; }
}

/* ===========================================================================
   CELULAR (≤ 640px): menu em drawer, tabelas em cards, chat painel único
   =========================================================================== */
@media (max-width: 640px) {
  body { display: block; }

  /* Barra superior fixa com botão de menu */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--sidebar-bg);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 40;
  }
  .hamburger {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
  }
  .mobile-topbar-title { font-size: 18px; font-weight: 600; white-space: nowrap; }

  /* Sidebar como gaveta deslizante (off-canvas) */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    height: 100vh;
    padding: 24px 16px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 60;
  }
  html.drawer-open .sidebar { transform: translateX(0); }
  .sidebar-toggle { display: none; }

  /* Neutraliza o estado "recolhido" do desktop dentro do drawer */
  .sidebar .label,
  html.sidebar-collapsed .sidebar .label { display: inline; }
  html.sidebar-collapsed .sidebar { width: 260px; padding: 24px 16px; }
  html.sidebar-collapsed .sidebar-top { flex-direction: row; }
  .sidebar nav a,
  html.sidebar-collapsed .sidebar nav a { justify-content: flex-start; padding: 12px 12px; }

  /* Overlay escurecido atrás do drawer */
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease;
    z-index: 50;
  }
  html.drawer-open .sidebar-overlay { opacity: 1; visibility: visible; }

  /* Conteúdo ocupa toda a largura */
  .content { padding: 16px; max-width: none; }
  /* No celular a tabela rola junto com a página (sem altura fixa). */
  .content-fill { height: auto; overflow: visible; }
  .content-fill .tabela-scroll { flex: none; }
  .page-header { flex-wrap: wrap; gap: 12px; }
  .header-actions { flex-wrap: wrap; }

  /* Home: cards empilhados */
  .guia-cards { grid-template-columns: 1fr; }

  /* Formulários em uma coluna */
  .grid { grid-template-columns: 1fr; }
  .grid .span-2 { grid-column: span 1; }
  .linha-endereco { grid-template-columns: 1fr; }
  .linha-cep { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }

  /* Tabelas → cards empilhados */
  .tabela-wrap { overflow-x: visible; }
  .tabela { border: none; background: transparent; border-radius: 0; }
  .tabela thead { display: none; }
  .tabela, .tabela tbody, .tabela tr, .tabela td { display: block; width: 100%; }
  .tabela tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 4px 2px;
  }
  .tabela td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    text-align: right;
  }
  .tabela tr td:last-child { border-bottom: none; }
  .tabela td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #4a5664;
    text-align: left;
    flex-shrink: 0;
  }
  .tabela td[data-label=""]::before,
  .tabela td:not([data-label])::before { display: none; }
  .tabela td.texto-col {
    max-width: none;
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    gap: 4px;
  }
  .tabela td.acoes-col {
    justify-content: flex-end;
    gap: 8px;
    white-space: normal;
    width: 100%;
  }
  .tabela td.acoes-col::before { display: none; }
  .tabela .btn-link { padding: 8px 10px; }
  .tabela td.vazio { justify-content: center; text-align: center; }

  /* Chat em painel único */
  .content-flush { padding: 0; height: auto; overflow: visible; }
  .wa { flex-direction: column; height: auto; border: none; border-radius: 0; box-shadow: none; }
  .chat-list { width: 100%; border-right: none; }
  .chat-items { max-height: 60vh; }
  .chat-pane { display: none; }
  .wa.mostrando-conversa .chat-list { display: none; }
  .wa.mostrando-conversa .chat-pane { display: flex; min-height: 80vh; }
  .thread, .novos { height: 80vh; }
  .btn-voltar { display: block; }
}

/* --------------------------------------------------------------------------- */
/* Login / bloqueio de acesso                                                  */
/* --------------------------------------------------------------------------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #f4f6f8 0%, #efe3f2 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(163, 17, 186, 0.12);
  padding: 40px 32px;
  text-align: center;
}
.auth-brand { margin: 0 0 24px; }
.auth-brand-name {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--sidebar-bg);
  margin: 0;
  line-height: 1.1;
}
.auth-brand-sigla {
  font-family: "Playfair Display", Georgia, serif;
  font-style: italic;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text);
  margin: 4px 0 0;
}
.auth-brand-sub {
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #6b7280;
  margin: 6px 0 0;
}
.auth-title { margin: 0 0 6px; font-size: 24px; }
.auth-subtitle { margin: 0 0 24px; color: #6b7280; font-size: 15px; }

.auth-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-label { font-size: 13px; font-weight: 600; color: #4b5563; }
.auth-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
}
.auth-input:focus {
  outline: none;
  border-color: var(--sidebar-bg);
  box-shadow: 0 0 0 3px rgba(163, 17, 186, 0.15);
}

.auth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}
.auth-btn-primary {
  margin-top: 6px;
  background: var(--sidebar-bg);
  color: #fff;
}
.auth-btn-primary:hover { background: #8a0e9e; }

.auth-divisor {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: #9ca3af;
  font-size: 13px;
}
.auth-divisor::before,
.auth-divisor::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-btn-google {
  background: #fff;
  color: #3c4043;
  border: 1px solid var(--border);
}
.auth-btn-google:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.auth-google-icon { width: 18px; height: 18px; }
.auth-hint { margin: 10px 0 0; font-size: 12px; color: #9ca3af; }

.auth-bloqueio-icone { font-size: 48px; margin-bottom: 8px; }

/* --------------------------------------------------------------------------- */
/* Lembretes (card + notas estilo post-it, inspirado no agendaMEO)             */
/* --------------------------------------------------------------------------- */
/* Lista ocupa toda a largura e, com content-fill, toda a altura restante
   (mesmo enquadramento das rotas de pacientes/agendamentos). */
.lembretes-lista {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  overflow-y: auto;
}
.content-fill .lembretes-lista { flex: 1 1 auto; min-height: 0; }
/* Com o formulário aberto em #form-area, esconde a lista para dar lugar a ele. */
#form-area:has(form) ~ .lembretes-lista { display: none; }
.nota {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 3px solid #e7c84b;
  border-radius: 8px;
  padding: 8px 12px;
}
.nota:hover { background: #fcfbf5; }
.nota-texto {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: #4a5664;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.nota-acoes { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.nota-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nota-btn svg { width: 15px; height: 15px; }
.nota-btn.editar { color: #8a94a2; }
.nota-btn.editar:hover { background: #eef1f4; color: var(--accent); }
.nota-btn.excluir { color: #8a94a2; }
.nota-btn.excluir:hover { background: #fbe9e9; color: var(--danger); }

/* Modais (criar/editar e confirmação) */
dialog.dlg {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: none;
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .2);
}
dialog.dlg::backdrop { background: rgba(0, 0, 0, .4); }
dialog.dlg .form-card { margin: 0; border: none; box-shadow: none; padding: 24px; }
.dlg-conteudo { padding: 24px; }
.dlg-conteudo h3 { margin: 0 0 8px; }
.dlg-conteudo p { margin: 0 0 20px; color: #6b7684; font-size: 14px; }
.dlg-sub { margin: -8px 0 16px; color: #6b7684; font-size: 13px; }
.dlg-acoes { display: flex; justify-content: flex-end; gap: 10px; }
.btn-perigo {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: #ef4444;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}
.btn-perigo:hover { background: #f87171; }

/* --------------------------------------------------------------------------
   Agendamentos — calendário (FullCalendar) e barra do dia selecionado
   -------------------------------------------------------------------------- */
.page-header-acoes { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-header-titulo { display: flex; align-items: center; gap: 12px; }
.page-header-titulo h2 { margin: 0; }

.calendario-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}

/* Com o formulário aberto, esconde o calendário (como já acontece com a tabela) */
#form-area:has(form) ~ .calendario-wrap { display: none; }
/* ...e esconde as ações do cabeçalho ("Ver todos / filtros avançados" e "+ Novo"),
   que ficam ANTES do #form-area — por isso o :has() no ancestral .content. */
.content:has(#form-area form) .page-header-acoes { display: none; }

/* Campo de hora por selects (HH : MM 00/15/30/45) no novo agendamento */
.hora-selects { display: flex; align-items: center; gap: 6px; }
.hora-selects select { flex: 1; min-width: 0; }
.hora-sep { color: #6b7480; }

/* Mensagens de erro no formulário de agendamento (bloqueio de data/hora passada) */
.form-erro {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, #fff);
  color: var(--danger);
  font-size: 13px;
}
.form-erro-inline {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
}

/* Botão "Mês" ativo no filtro de /agendamentos/todos-agendamentos */
.btn-secondary.btn-ativo {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-secondary.btn-ativo:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

/* Tema do FullCalendar alinhado às cores do app */
.calendario-wrap .fc { --fc-border-color: var(--border); }
.calendario-wrap .fc .fc-button-primary {
  background: var(--accent);
  border-color: var(--accent);
}
.calendario-wrap .fc .fc-button-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.calendario-wrap .fc .fc-button-primary:not(:disabled).fc-button-active,
.calendario-wrap .fc .fc-button-primary:not(:disabled):active {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}
.calendario-wrap .fc .fc-button-primary:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, #fff); }
.calendario-wrap .fc .fc-daygrid-day.fc-day-today,
.calendario-wrap .fc .fc-timegrid-col.fc-day-today {
  background: color-mix(in srgb, var(--accent) 12%, #fff);
}
.calendario-wrap .fc .fc-event {
  background: var(--accent);
  border-color: var(--accent);
  cursor: pointer;
}
.calendario-wrap .fc a.fc-col-header-cell-cushion,
.calendario-wrap .fc a.fc-daygrid-day-number { color: var(--text); }

@media (max-width: 640px) {
  .calendario-wrap { padding: 10px; }
  .calendario-wrap .fc .fc-toolbar { flex-direction: column; gap: 8px; }
  .calendario-wrap .fc .fc-toolbar-title { font-size: 1.1em; }
}
