:root {
  --azul: #1d6fd8;
  --azul-escuro: #0f4c9c;
  --agua: #14b8a6;
  --agua-claro: #5eead4;
  --grad: linear-gradient(135deg, #1d6fd8 0%, #0ea5c6 50%, #14b8a6 100%);
  --grad-suave: linear-gradient(135deg, #e8f1fd 0%, #e6fbf8 100%);
  --bg: #f3f8fb;
  --card: #ffffff;
  --texto: #16324a;
  --texto-suave: #5b7388;
  --borda: #d9e6ef;
  --perigo: #d64545;
  --raio: 14px;
  --sombra: 0 4px 18px rgba(16, 76, 120, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Nunito", system-ui, sans-serif;
  background: var(--bg);
  color: var(--texto);
  line-height: 1.5;
}

a { color: var(--azul); }

/* ---------- Topo ---------- */
.topbar {
  background: var(--grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 12px 24px;
  box-shadow: 0 2px 12px rgba(15, 76, 156, .25);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none;
  font-weight: 800; font-size: 1.25rem;
}
.brand small { font-weight: 600; opacity: .85; }
.brand-logo {
  background: rgba(255,255,255,.2);
  border-radius: 50%;
  width: 40px; height: 40px;
  display: grid; place-items: center;
}
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  color: #fff; text-decoration: none; font-weight: 600;
  padding: 8px 14px; border-radius: 999px; opacity: .9;
}
.nav a:hover { background: rgba(255,255,255,.15); }
.nav a.ativo { background: rgba(255,255,255,.25); opacity: 1; }

.container { max-width: 1240px; margin: 0 auto; padding: 24px 16px 60px; }

/* ---------- Básicos ---------- */
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.sub { color: var(--texto-suave); margin: 0 0 20px; }

.card {
  background: var(--card);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  padding: 20px;
  margin-bottom: 18px;
  border: 1px solid var(--borda);
}

.cabecalho {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; flex-wrap: wrap; margin-bottom: 18px;
}

.btn {
  border: none; cursor: pointer; font: inherit; font-weight: 700;
  padding: 10px 18px; border-radius: 999px;
  background: var(--grad); color: #fff;
  box-shadow: 0 3px 10px rgba(14, 165, 198, .3);
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: transform .1s, box-shadow .1s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(14,165,198,.4); }
.btn.sec { background: #fff; color: var(--azul-escuro); border: 1.5px solid var(--borda); box-shadow: none; }
.btn.sec:hover { border-color: var(--agua); }
.btn.perigo { background: #fff; color: var(--perigo); border: 1.5px solid #f2c4c4; box-shadow: none; }
.btn.peq { padding: 6px 12px; font-size: .88rem; }
.btn-icone {
  border: none; background: transparent; cursor: pointer; font-size: 1.1rem;
  color: var(--texto-suave); padding: 4px 8px; border-radius: 8px;
}
.btn-icone:hover { background: #eef5f9; color: var(--perigo); }

label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input[type=date], input[type=email], input[type=tel], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--texto);
  padding: 10px 12px; border: 1.5px solid var(--borda); border-radius: 10px;
  background: #fbfdfe;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--agua); box-shadow: 0 0 0 3px rgba(20,184,166,.15);
}
textarea { min-height: 80px; resize: vertical; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.campo-full { grid-column: 1 / -1; }

/* ---------- Lista de pacientes ---------- */
.busca { max-width: 380px; }
.lista-pacientes { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.paciente-card {
  display: flex; gap: 12px; align-items: center;
  background: #fff; border: 1px solid var(--borda); border-radius: var(--raio);
  padding: 16px; text-decoration: none; color: inherit; box-shadow: var(--sombra);
  transition: border-color .15s, transform .15s;
}
.paciente-card:hover { border-color: var(--agua); transform: translateY(-2px); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: var(--grad); color: #fff; font-weight: 800;
  display: grid; place-items: center; font-size: 1.05rem;
}
.paciente-card .info small { color: var(--texto-suave); display: block; }
.vazio {
  text-align: center; padding: 48px 20px; color: var(--texto-suave);
  background: var(--grad-suave); border-radius: var(--raio); border: 1.5px dashed var(--borda);
}

/* ---------- Abas ---------- */
.abas { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; border-bottom: 2px solid var(--borda); }
.abas button {
  border: none; background: none; font: inherit; font-weight: 700; cursor: pointer;
  padding: 10px 16px; color: var(--texto-suave); border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.abas button.ativo { color: var(--azul-escuro); border-bottom-color: var(--agua); }

/* ---------- Anamnese ---------- */
.anamnese-layout { display: grid; grid-template-columns: 1fr 400px; gap: 18px; align-items: start; }
.painel-sugestoes { position: sticky; top: 86px; max-height: calc(100vh - 100px); overflow: auto; }
.painel-sugestoes .card { background: var(--grad-suave); }

.grupo-sintomas { margin-bottom: 14px; }
.grupo-sintomas h3 { color: var(--azul-escuro); font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--borda); background: #fff; border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font: inherit; font-size: .88rem; font-weight: 600; color: var(--texto);
}
.chip:hover { border-color: var(--agua); }
.chip.on { background: var(--grad); color: #fff; border-color: transparent; }

.sugestao {
  background: #fff; border-radius: 12px; padding: 12px; margin-bottom: 10px;
  border: 1px solid var(--borda); display: flex; gap: 10px; align-items: flex-start;
}
.sugestao .corpo { flex: 1; min-width: 0; }
.sugestao strong { display: block; }
.sugestao p { margin: 2px 0 0; font-size: .86rem; color: var(--texto-suave); }
.motivos { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.motivo { font-size: .74rem; background: #e6fbf8; color: #0f766e; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.forca { display: flex; gap: 2px; margin-top: 4px; }
.forca i { width: 14px; height: 5px; border-radius: 3px; background: #d9e6ef; }
.forca i.on { background: var(--agua); }
.btn-add {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--grad); color: #fff; font-size: 1.2rem; font-weight: 800;
}
.btn-add.ok { background: #e6fbf8; color: #0f766e; }

/* ---------- Ficha ---------- */
.item-ficha {
  display: grid; grid-template-columns: 1fr 1.3fr auto; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--borda);
}
.item-ficha:last-child { border-bottom: none; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #e8f1fd; color: var(--azul-escuro); }

.historico-item { border-left: 4px solid var(--agua); padding: 8px 14px; margin-bottom: 12px; background: #fbfdfe; border-radius: 0 10px 10px 0; }
.historico-item .acoes { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.aviso {
  background: #fff8e6; border: 1px solid #f5dfa3; color: #7a5a00;
  padding: 10px 14px; border-radius: 10px; font-size: .88rem; margin-bottom: 14px;
}

/* ---------- Tabelas catálogo ---------- */
.tabela { width: 100%; border-collapse: collapse; }
.tabela th, .tabela td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--borda); vertical-align: top; }
.tabela th { font-size: .82rem; text-transform: uppercase; color: var(--texto-suave); letter-spacing: .04em; }
.tabela td small { color: var(--texto-suave); }

/* ---------- Modal ---------- */
.modal-fundo {
  position: fixed; inset: 0; background: rgba(15, 40, 70, .45); z-index: 50;
  display: grid; place-items: center; padding: 16px;
}
.modal { background: #fff; border-radius: var(--raio); padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal .acoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #0f4c5c; color: #fff; padding: 10px 20px; border-radius: 999px; font-weight: 700;
  transition: transform .25s; z-index: 60;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Impressão ---------- */
#area-impressao { display: none; }
@media print {
  body { background: #fff; }
  body > *:not(#area-impressao) { display: none !important; }
  #area-impressao { display: block !important; padding: 10px 24px; }
  .imp-topo { border-bottom: 4px solid #14b8a6; padding-bottom: 10px; margin-bottom: 16px; }
  .imp-topo h1 { color: #0f4c9c; }
  .imp-tabela { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
  .imp-tabela th, .imp-tabela td { border: 1px solid #ccd; padding: 6px 8px; text-align: left; }
  .imp-assinatura { margin-top: 60px; text-align: center; }
  .imp-assinatura div { border-top: 1px solid #333; width: 280px; margin: 0 auto; padding-top: 4px; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 960px) {
  .anamnese-layout { grid-template-columns: 1fr; }
  .painel-sugestoes { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
  .item-ficha { grid-template-columns: 1fr; }
  .tabela .col-chaves { display: none; }
}

/* ---------- Æquilibrium ---------- */
.num {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px;
  margin-right: 8px; border-radius: 999px; background: var(--grad); color: #fff;
  font-size: .78rem; font-weight: 800; vertical-align: middle;
}
.alerta { color: #9a6700 !important; font-weight: 600; }
