/* ==========================================================================
   Pesquisa de Qualidade - Agente Comunitário de Saúde — identidade visual
   Paleta, tipografia, espaçamentos e componentes (Montserrat, azul + verde)
   ========================================================================== */
:root {
  --primary: #203b8f;
  --primary-dark: #152a68;
  --accent: #1c9c76;
  --accent-dark: #157b5d;
  --ink: #1b2340;
  --muted: #5b6480;
  --line: #dde3f0;
  --surface: #f4f6fb;
  --bg: #f2f4f7;
  --tint: #e6ecfa;
  --danger: #c0392b;
  --danger-bg: #fdece9;
  --warn: #b45309;
  --shadow-lg: 0 12px 32px rgba(21, 42, 104, .16);
  --topbar-h: 66px;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.45 Montserrat, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; }
a { color: var(--primary); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Botões ---------- */
button, .btn {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
button:active, .btn:active { transform: translateY(1px); }
button[disabled] { opacity: .55; cursor: not-allowed; }

.btn-primary, .btn-login { background: var(--accent); color: #fff; }
.btn-primary:hover, .btn-login:hover { background: var(--accent-dark); }

.btn-secondary { background: #fff; color: var(--primary); border: 1.5px solid var(--line); }
.btn-secondary:hover { border-color: var(--primary); }

.btn-login { width: 100%; padding: 12px; font-size: 15px; }
.btn-login[disabled] { cursor: wait; }

/* ---------- Formulários ---------- */
.form-group { margin-bottom: 16px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0 16px;
}
label { display: block; font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }

input, select, textarea {
  display: block;
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: #fff;
}
textarea { resize: vertical; }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 38px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'><path d='M1 1l5 5 5-5' fill='none' stroke='%23203b8f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
input:hover, select:hover, textarea:hover { border-color: #b9c3dd; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(32, 59, 143, .14);
}
/* Campos preenchidos pela extensão (somente leitura) */
input[readonly] { background: var(--surface); color: var(--muted); cursor: not-allowed; }
input[readonly]:hover { border-color: var(--line); }

.erro-msg {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13.5px;
}

/* ---------- Barra superior ---------- */
.app-topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  z-index: 220;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 26px 0 24px;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 17px;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.app-brand strong { font-size: 22px; font-weight: 800; }
.app-brand__divider { width: 1px; height: 24px; background: rgba(255, 255, 255, .28); }
.app-brand span:last-child { font-weight: 600; }

.app-actions { display: flex; align-items: center; gap: 8px; }
.user-role { font-size: 12px; font-weight: 600; color: #fff; opacity: .94; margin-right: 8px; }
.app-topbar .btn-secondary,
.app-topbar button {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, .35);
  padding: 8px 16px;
  font-size: 13.5px;
}
.app-topbar .btn-secondary:hover,
.app-topbar button:hover { background: rgba(255, 255, 255, .12); border-color: #fff; }

/* ---------- Página ---------- */
.page { padding: calc(var(--topbar-h) + 34px) 38px 70px; }
.page > * { max-width: 1380px; margin-left: auto; margin-right: auto; }
.page--narrow > * { max-width: 960px; }

.page__head { margin-bottom: 24px; }
.eyebrow {
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.page__title { font-size: 28px; font-weight: 800; color: var(--primary-dark); }
.page__subtitle { color: var(--muted); margin: 8px 0 0; font-size: 15px; }

/* ---------- Painéis ---------- */
.card, .panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 26px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--line);
}
.section-title { font-size: 16.5px; font-weight: 700; color: var(--primary-dark); margin: 28px 0 14px; }

/* ---------- Tela de login ---------- */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #fff;
}
.login-layout {
  width: 100%;
  max-width: 1080px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 64px;
  padding: 0 24px;
}
.login-hero { flex: 1; min-width: 0; max-width: 520px; }
.login-hero h1 {
  font-size: 40px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.01em;
  color: var(--primary-dark);
  margin-bottom: 16px;
}
.login-hero p { font-size: 17px; line-height: 1.55; color: var(--muted); max-width: 46ch; margin: 0; }

.login-card {
  width: 100%;
  max-width: 380px;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 32px 30px 28px;
}
.login-card h2 { text-align: center; font-size: 20px; font-weight: 800; color: var(--primary-dark); margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.5; margin-bottom: 22px; }

/* ---------- Dashboard ---------- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.card-metric {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}
.card-metric h3 { font-size: 14px; font-weight: 600; color: var(--muted); }
.card-metric p { font-size: 32px; font-weight: 800; color: var(--primary-dark); line-height: 1.2; margin: 6px 0 0; }
.card-metric.alerta p { color: var(--danger); }

/* ---------- Tabelas ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 720px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 12px;
  border-bottom: 1.5px solid var(--line);
}
td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--tint);
  color: var(--primary);
}
.badge-success { background: #e1f4ed; color: var(--accent-dark); }
.badge-warning { background: #fdf1de; color: var(--warn); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .login-layout { flex-direction: column; text-align: center; gap: 32px; }
  .login-hero { max-width: 100%; }
  .login-hero h1 { font-size: 28px; }
  .login-hero p { margin: 0 auto; }
}
@media (max-width: 760px) {
  .app-topbar { padding: 0 14px; }
  .app-brand { font-size: 12px; flex-direction: column; align-items: flex-start; gap: 0; white-space: normal; line-height: 1.15; }
  .app-brand strong { font-size: 16px; }
  .app-brand__divider { display: none; }
  .user-role { display: none; }
  .page { padding: calc(var(--topbar-h) + 24px) 16px 60px; }
  .card { padding: 20px 16px; }
}

/* Administração de usuários */
.admin-head { display:flex; align-items:flex-end; justify-content:space-between; gap:20px; }
.btn-small { padding:8px 10px; font-size:12px; margin-right:6px; margin-bottom:4px; }
.btn-danger { background:#fff; color:#b42318; border:1px solid #f0b4ae; }
.btn-danger:hover { background:#fff5f4; }
.modal-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.42); display:flex; align-items:center; justify-content:center; padding:20px; z-index:1000; }
.modal-card { width:min(760px,100%); max-height:90vh; overflow:auto; background:#fff; border-radius:16px; padding:24px; box-shadow:0 20px 60px rgba(0,0,0,.2); }
.modal-head { display:flex; align-items:flex-start; justify-content:space-between; gap:20px; margin-bottom:20px; }
.modal-head h2 { margin:4px 0 0; }
.modal-actions { display:flex; justify-content:flex-end; margin-top:20px; }
.form-group--full { grid-column:1/-1; }
.form-group small { display:block; margin-top:6px; color:#667085; font-size:12px; }
@media (max-width:700px) { .admin-head { align-items:stretch; flex-direction:column; } .modal-card { padding:18px; } }


/* Checkbox e radio: não herdam o estilo de campo de texto */
input[type="checkbox"], input[type="radio"] {
  display: inline-block;
  width: 18px;
  height: 18px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Títulos dentro de painéis */
.panel > h2 { font-size: 17px; font-weight: 700; color: var(--primary-dark); margin: 0 0 14px; }
.panel h3 { font-size: 15px; font-weight: 700; color: var(--primary-dark); margin: 0 0 10px; }
.panel > p { color: var(--muted); margin: 0 0 16px; }
.panel > p strong { color: var(--ink); }

/* Mensagens: erro (padrão), sucesso e informação */
.erro-msg.ok { background: #e1f4ed; color: var(--accent-dark); }
.erro-msg.info { background: var(--tint); color: var(--primary); }

/* Mailing: composição por equipe e microárea */
.checklist {
  max-height: 340px;
  overflow: auto;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 4px 16px;
  background: #fff;
  color: var(--muted);
}
.checklist .equipe {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.checklist .equipe:last-child { border-bottom: 0; }
.checklist .equipe > strong {
  flex: 0 0 100%;
  margin-bottom: 2px;
  font-size: 12.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--primary-dark);
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 7px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.check:hover { border-color: var(--primary); color: var(--primary); }
.check:has(input:checked) { background: var(--tint); border-color: var(--primary); color: var(--primary-dark); }
.check.todas { border-style: dashed; margin-right: 6px; }
.count {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
}
.check .count { padding: 1px 7px; border-radius: 999px; background: var(--surface); }
.check:has(input:checked) .count { background: #fff; color: var(--primary); }

.selection { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
@media (max-width: 760px) { .selection { grid-template-columns: 1fr; } }

/* Fila do mailing (operador) */
.mailing-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  background: #fff;
}
.mailing-bar__titulo { font-weight: 800; color: var(--primary-dark); }
.mailing-bar__info { font-size: 13px; color: var(--muted); margin-top: 2px; }
.hint { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }
#msg-form { margin: 0 0 16px; }

/* WhatsApp (tela de registrar ligação e página de mensagem) */
.btn-whats { background: #1fa855; color: #fff; text-decoration: none; margin: 8px 0 0; }
.btn-whats:hover { background: #178a45; }
.whats-modal .modal-card { width: min(560px, 100%); }
.whats-modal .modal-actions { gap: 8px; flex-wrap: wrap; }
.whats-modal .modal-actions .btn-whats { margin: 0; }
.whats-acoes { display: flex; gap: 8px; flex-wrap: wrap; }
.previa { background: #f4f7fb; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; }

/* Ícone do WhatsApp ao lado do telefone */
.tel-linha { display: flex; align-items: center; gap: 8px; }
.tel-linha input { flex: 1; min-width: 0; }
.whats-icon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; transition: transform .12s, background .12s; }
.whats-icon:hover { transform: scale(1.12); background: #e8f7ee; }
.whats-icon:focus-visible { outline: 2px solid #25D366; outline-offset: 2px; }
