:root {
  --bg: #cdd5e2;
  --card: #f8fafc;
  --primary: #4f3ea8;
  --primary-strong: #44358f;
  --accent: #1f9d57;
  --text: #0f172a;
  --muted: #475569;
  --line: #cbd5e1;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hero {
  background: linear-gradient(140deg, #6b50df, #4a3ca8);
  color: #fff;
  text-align: center;
  padding: 28px 16px;
  position: relative;
}
.logo {
  position: absolute;
  top: 24px;
  left: 24px;
  height: 45px;
  width: auto;
}
.hero h1 { margin: 0; font-size: 36px; line-height: 1.15; }
.hero p { margin: 8px 0 0; font-size: 18px; opacity: 0.9; }
.container { max-width: 1700px; margin: 26px auto; padding: 0 16px 32px; }
.panel {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  padding: 24px;
}
.search-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
}
.field label { display: block; font-weight: 700; margin-bottom: 8px; font-size: 18px; }
.field select {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
  padding: 0 12px;
}
.actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 14px;
  align-items: center;
}
.btn {
  border: 0;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); }
.btn-success { background: var(--accent); color: #fff; }
.btn-success[disabled] { opacity: 0.5; cursor: not-allowed; }
.results-panel { margin-top: 20px; }
.accordion { margin-top: 10px; border-radius: 10px; overflow: visible; border: 1px solid var(--line); background: #fff; }
.accordion > summary {
  list-style: none;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  padding: 14px 16px;
  cursor: pointer;
}
.accordion > summary::-webkit-details-marker { display: none; }
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 65vh;
  background: #fff;
  border-top: 1px solid var(--line);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1400px; }
th, td {
  border-bottom: 1px solid #e2e8f0;
  padding: 12px 10px;
  text-align: left;
  font-size: 14px;
  line-height: 1.45;
  vertical-align: top;
}
th {
  background: #ebf2ff;
  font-size: 14px;
  position: sticky;
  z-index: 5;
  box-shadow: 0 1px 0 #d7deee;
}
/* Linhas finas dividindo as colunas apenas no cabeçalho */
thead th { border-right: 1px solid var(--line); }
thead th:last-child { border-right: none; }
/* Primeira linha do cabeçalho (grupos + colunas com rowspan) fixa no topo */
thead tr:first-child th { top: 0; }
/* Segunda linha (sub-colunas) fixa logo abaixo da linha de grupo.
   O top precisa casar com a altura fixa da linha de grupo (.th-group). */
thead tr:nth-child(2) th { top: 63px; }
/* Group header row (TIPOS DE ATENDIMENTO / REDES DE ATENDIMENTO).
   Texto roxo sobre fundo claro; altura fixa (>= 2 linhas) para o sticky
   da sub-linha casar de forma deterministica. */
.th-group {
  background: #ebf2ff;
  color: var(--primary);
  text-align: center;
  vertical-align: middle;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.6px;
  height: 64px;
}
/* Name column sticky header (mais estreita, deixa mais espaço p/ tipos e redes) */
.th-name { vertical-align: middle; width: 180px; white-space: normal; }
/* Sem as 5 colunas de "Tipos de Atendimento" (Laboratorio, Clinica, Centro de
   Imagem), a coluna de nome pode ser mais larga para evitar quebras. */
.tbl-outros .th-name { width: 420px; }
/* Sub-cabeçalho de "Redes disponíveis" centralizado e com mais espaço */
.th-redes { text-align: center; min-width: 240px; }
/* Sub-header columns for atendimento types */
.th-tipo {
  text-align: center;
  vertical-align: bottom;
  padding-bottom: 10px;
  white-space: normal;
  max-width: 110px;
}
.th-tipo i {
  display: block;
  font-size: 22px;
  margin-top: 6px;
  color: var(--primary);
}
/* Bool icon cells */
.td-bool { text-align: center; vertical-align: middle; }
.bool-yes { color: #16a34a; font-size: 22px; }
.bool-no  { color: #dc2626; font-size: 22px; }
/* Redes disponíveis cell */
.redes-cell { min-width: 240px; }
.redes-cell ul { margin: 0; padding-left: 18px; }
.redes-cell li { font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.7; }
/* Lista colapsavel: mostra ~7 redes; o restante fica acessivel via scroll. */
.redes-list.is-collapsible {
  max-height: 150px;
  overflow: hidden;
}
.redes-list.is-collapsible.scrolling {
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
}
.redes-list.is-collapsible.scrolling::-webkit-scrollbar { width: 6px; }
.redes-list.is-collapsible.scrolling::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
.redes-empty { color: var(--muted); }
.badge-mais {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 9px;
  border-radius: 6px;
  background: #ebf2ff;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--primary);
  user-select: none;
}
.badge-mais:hover { background: var(--primary); color: #fff; }
.badge-mais.is-open { background: var(--primary); color: #fff; }
.empty { font-size: 16px; color: var(--muted); }

/* Paginação por tipo */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}
.pagination-info { font-size: 13px; color: var(--muted); font-weight: 600; }
.pagination-controls { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pagination-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.pagination-btn:hover:not(:disabled):not(.is-active) { background: #ebf2ff; }
.pagination-btn.is-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  cursor: default;
}
.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination-gap { padding: 0 4px; color: var(--muted); font-weight: 700; }

/* Observação: botão "?" e tooltip ao clicar */
.obs-cell { text-align: center; }
.obs-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: #ebf2ff;
  color: var(--primary);
  border: 1px solid var(--primary);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.obs-info:hover { background: var(--primary); color: #fff; }
#obsTooltip {
  position: fixed;
  display: none;
  max-width: 280px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  white-space: normal;
  z-index: 1000;
}
#obsTooltip.visible { display: block; }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.loading-overlay.visible {
  display: flex;
}

.loading-card {
  width: min(460px, 100%);
  background: #ffffff;
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.25);
}

.loading-card h2 {
  margin: 0;
  font-size: 20px;
}

.loading-card p {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #6b50df, #4f3ea8);
  transition: width 0.2s ease;
}

.progress-label {
  margin-top: 8px;
  font-size: 13px;
  color: #334155;
  text-align: right;
}

.btn[disabled],
.btn.is-loading {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

@media (max-width: 1100px) {
  .hero {
    padding-top: 80px;
  }
  .logo {
    left: 50%;
    transform: translateX(-50%);
    top: 20px;
  }
  .hero h1 { font-size: 28px; }
  .hero p { font-size: 16px; }
  .search-grid { grid-template-columns: 1fr; }
  .field label { font-size: 16px; }
  .field select { font-size: 15px; height: 44px; }
  .btn { font-size: 16px; width: 100%; }
  .actions { flex-direction: column; }
  .accordion > summary { font-size: 16px; }
  th, td { font-size: 14px; }
  th { font-size: 14px; }
  .loading-card { padding: 18px; }
}
