/* =============================================================
   Solutaq Saúde · M-TERR — Design System compartilhado
   Tokens, tipografia, componentes comuns a todas as páginas
   do portal de Territorialização.
   Importar ANTES dos estilos específicos de cada página.
   ============================================================= */

/* ── Google Fonts ───────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Tokens (Solutaq Saúde Design System) ─────────────────────── */
:root {
  /* Paleta teal institucional */
  --teal-50:  #f0f6f5;
  --teal-100: #d9e8e6;
  --teal-200: #b3d0cc;
  --teal-300: #7fb0a9;
  --teal-400: #4f8e85;
  --teal-500: #2d6e65;
  --teal-600: #1f564f;
  --teal-700: #18443f;
  --teal-800: #123430;
  --teal-900: #0d2623;

  /* Neutros */
  --ink-50:  #f7f8f9;
  --ink-100: #eef0f2;
  --ink-200: #dde1e6;
  --ink-300: #c3c9d0;
  --ink-400: #9ba2ac;
  --ink-500: #6b7280;
  --ink-600: #4b5563;
  --ink-700: #323842;
  --ink-800: #20242c;
  --ink-900: #12151b;

  /* Semânticas */
  --red-bg:     #fdf2f1;
  --red-fg:     #9b1c1c;
  --red-border: #f3c9c5;
  --red-solid:  #c0392b;

  --amber-bg:     #fdf6e3;
  --amber-fg:     #8a5a0b;
  --amber-border: #ecd9a6;
  --amber-solid:  #b97f15;

  --green-bg:     #f0f7f1;
  --green-fg:     #1f5f33;
  --green-border: #c8dfce;
  --green-solid:  #2b7a3f;

  --blue-bg:     #eff4f9;
  --blue-fg:     #1e4976;
  --blue-border: #c8d9ea;
  --blue-solid:  #2d5e94;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(18,21,27,0.04), 0 0 0 1px rgba(18,21,27,0.06);
  --shadow-md: 0 2px 4px rgba(18,21,27,0.04), 0 1px 2px rgba(18,21,27,0.06), 0 0 0 1px rgba(18,21,27,0.05);
  --shadow-lg: 0 8px 24px rgba(18,21,27,0.08), 0 0 0 1px rgba(18,21,27,0.06);

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 16px;

  /* Espaçamento */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Tipografia */
  --font-sans: 'Inter Tight', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
  --text-h1: 22px;
  --text-h2: 16px;
  --text-body: 14px;
  --text-small: 12px;
  --text-micro: 11px;

  /* Motion */
  --ease-out: cubic-bezier(0.2, 0.7, 0.3, 1);
  --duration-fast: 120ms;
  --duration-base: 180ms;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ───────────────────────────────────────────────────── */
body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  background: var(--ink-50);
  color: var(--ink-800);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

/* ── Navbar ─────────────────────────────────────────────────── */
#terr-navbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--teal-600);
  color: white;
  padding: 0.6rem 1.4rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.nav-logo {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.nav-logo span { opacity: 0.6; font-weight: 400; }
.nav-links { display: flex; align-items: center; gap: 0.2rem; flex: 1; }
.nav-links a {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  padding: 0.32rem 0.7rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background var(--duration-fast) ease, color var(--duration-fast) ease;
}
.nav-links a:hover,
.nav-links a.ativo {
  background: rgba(255,255,255,0.15);
  color: white;
}
.nav-dropdown { position: relative; }
.nav-dropdown button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  padding: 0.32rem 0.7rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  transition: background var(--duration-fast) ease, color var(--duration-fast) ease;
}
.nav-dropdown:hover button {
  background: rgba(255,255,255,0.15);
  color: white;
}
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  z-index: 200;
  border: 1px solid var(--ink-200);
}
.nav-dropdown:hover .nav-dropdown-menu { display: flex; flex-direction: column; }
.nav-dropdown-menu a {
  color: var(--ink-800);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background var(--duration-fast) ease;
}
.nav-dropdown-menu a:hover { background: var(--ink-50); }
.nav-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  font-size: 0.8rem;
}
.nav-perfil-badge {
  background: rgba(255,255,255,0.18);
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.01em;
}
.nav-sair {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.8rem;
  transition: color var(--duration-fast) ease;
}
.nav-sair:hover { color: white; }

/* ── Layout de página ───────────────────────────────────────── */
.page { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.25rem; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink-900);
  letter-spacing: -0.01em;
}
.page-sub {
  font-size: 0.82rem;
  color: var(--ink-500);
  margin-top: 0.15rem;
}

/* ── KPI cards ──────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  background: white;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}
.kpi-valor {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink-900);
  font-variant-numeric: tabular-nums;
}
.kpi-valor.verde    { color: var(--green-fg); }
.kpi-valor.vermelho { color: var(--red-solid); }
.kpi-valor.azul     { color: var(--teal-600); }
.kpi-sub {
  font-size: 0.72rem;
  color: var(--ink-400);
  margin-top: 0.3rem;
}

/* ── Filtros ────────────────────────────────────────────────── */
.filtros {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: center;
}
.filtros input,
.filtros select {
  padding: 0.42rem 0.75rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
  font-size: 0.83rem;
  font-family: var(--font-sans);
  background: white;
  color: var(--ink-800);
  outline: none;
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.filtros input { min-width: 220px; }
.filtros input:focus,
.filtros select:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(45,110,101,0.1);
}
.filtros label {
  font-size: 0.8rem;
  color: var(--ink-600);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ── Botões ─────────────────────────────────────────────────── */
.btn-export {
  padding: 0.42rem 0.9rem;
  background: var(--teal-600);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  margin-left: auto;
  transition: background var(--duration-fast) ease, transform var(--duration-base) var(--ease-out);
}
.btn-export:hover {
  background: var(--teal-700);
  transform: translateY(-1px);
}

.btn-vincular {
  padding: 0.28rem 0.65rem;
  background: var(--teal-600);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration-fast) ease;
}
.btn-vincular:hover { background: var(--teal-700); }

.btn-desvincular {
  padding: 0.28rem 0.65rem;
  background: white;
  color: var(--red-solid);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration-fast) ease;
}
.btn-desvincular:hover { background: var(--red-bg); }

/* ── Tabela wrapper ─────────────────────────────────────────── */
.tabela-wrap {
  background: white;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.tabela-info {
  padding: 0.55rem 1rem;
  font-size: 0.78rem;
  color: var(--ink-500);
  border-bottom: 1px solid var(--ink-100);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
thead th {
  background: var(--ink-50);
  color: var(--ink-600);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.62rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--ink-200);
  border-top: 1px solid var(--ink-200);
  white-space: nowrap;
  user-select: none;
}
thead th[data-sort], thead th.sorted-asc, thead th.sorted-desc { cursor: pointer; }
thead th:hover { background: var(--ink-100); }
thead th.sorted-asc::after  { content: ' ↑'; color: var(--teal-600); }
thead th.sorted-desc::after { content: ' ↓'; color: var(--teal-600); }
tbody tr { border-bottom: 1px solid var(--ink-100); transition: background var(--duration-fast) ease; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--ink-50); }
tbody td { padding: 0.58rem 0.75rem; vertical-align: middle; color: var(--ink-800); }

/* Células comuns */
.cor-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.4rem; vertical-align: middle; }
.nome-cell { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.equipe-cell { color: var(--ink-500); max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.78rem; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

/* Cobertura */
.badge.critica   { background: var(--red-bg);    color: var(--red-fg);    border-color: var(--red-border); }
.badge.baixa     { background: var(--amber-bg);  color: var(--amber-fg);  border-color: var(--amber-border); }
.badge.ok        { background: var(--green-bg);  color: var(--green-fg);  border-color: var(--green-border); }
.badge.plena     { background: var(--teal-50);   color: var(--teal-700);  border-color: var(--teal-200); }
.badge.sem-dado  { background: var(--ink-100);   color: var(--ink-500);   border-color: var(--ink-200); }

/* Vínculo ACS */
.badge.vinculado { background: var(--green-bg);  color: var(--green-fg);  border-color: var(--green-border); }
.badge.pendente  { background: var(--amber-bg);  color: var(--amber-fg);  border-color: var(--amber-border); }
.badge.inativo   { background: var(--ink-100);   color: var(--ink-500);   border-color: var(--ink-200); }

/* Geom */
.badge-geom { font-size: 0.68rem; padding: 0.15rem 0.45rem; border-radius: 10px; flex-shrink: 0; font-weight: 600; }
.badge-geom.sim { background: var(--green-bg); color: var(--green-fg); }
.badge-geom.nao { background: var(--red-bg);   color: var(--red-fg); }

/* UBS */
.ubs-badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.18rem 0.55rem; border-radius: var(--radius-sm); font-size: 0.7rem; font-weight: 600; border: 1px solid transparent; }
.ubs-badge.ok     { background: var(--green-bg); color: var(--green-fg); border-color: var(--green-border); }
.ubs-badge.baixa_precisao { background: var(--amber-bg); color: var(--amber-fg); border-color: var(--amber-border); }
.ubs-badge.falhou { background: var(--red-bg);   color: var(--red-fg);   border-color: var(--red-border); }

/* ── Barras de progresso ────────────────────────────────────── */
.barra-wrap { width: 80px; background: var(--ink-100); border-radius: var(--radius-sm); height: 7px; display: inline-block; vertical-align: middle; margin-right: 0.35rem; overflow: hidden; }
.barra-fill { height: 100%; border-radius: var(--radius-sm); transition: width 280ms var(--ease-out); }
.pct-label  { font-weight: 600; font-size: 0.8rem; font-variant-numeric: tabular-nums; }

/* ── Paginação ──────────────────────────────────────────────── */
.paginacao {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--ink-100);
}
.paginacao button {
  padding: 0.32rem 0.6rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-md);
  background: white;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font-sans);
  color: var(--ink-600);
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease;
}
.paginacao button:hover:not(:disabled) { background: var(--ink-50); }
.paginacao button.ativo { background: var(--teal-600); color: white; border-color: var(--teal-600); }
.paginacao button:disabled { opacity: 0.4; cursor: not-allowed; }
.paginacao-info { font-size: 0.78rem; color: var(--ink-500); margin-left: auto; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-800);
  color: white;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 9999;
  display: none;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
}
#toast.ok   { background: var(--green-solid); }
#toast.erro { background: var(--red-solid); }

/* ── Inputs gerais ──────────────────────────────────────────── */
input, select, textarea {
  font-family: var(--font-sans);
}

/* ── Scrollbars sutis ───────────────────────────────────────── */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--ink-200); border-radius: 4px; border: 2px solid var(--ink-50); }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-300); }

/* ── Ícones SVG (sprite local terr-icons.svg) ─────────────────
   Uso: <svg class="ic ic-sm"><use href="terr-icons.svg#ic-foo"/></svg>
   Padrão Lucide: viewBox 24x24, stroke aplicado via CSS (currentColor). */
.ic {
  vertical-align: middle;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic-sm { width: 16px; height: 16px; }
.ic-md { width: 20px; height: 20px; }
.ic-lg { width: 24px; height: 24px; }
.ic-spin { animation: ic-spin-rot 1s linear infinite; transform-origin: center; }
@keyframes ic-spin-rot { to { transform: rotate(360deg); } }
