/* Tokens de tema claro/escuro — MESMO padrao aprovado no estudo visual
   (canvas de identidade e demos): atributo unico na raiz, um bloco de
   tokens por tema. Nao redeclarar cor solta em nenhuma tela: sempre var(). */

:root {
  --font-display: 'Bricolage Grotesque', Georgia, serif;
  --font-body: 'Public Sans', Arial, sans-serif;
}

[data-rsr-theme="light"] {
  --bg: #F8F7F4;
  --bg-raised: #FFFFFF;
  --bg-sunken: #F0EFEA;
  --sidebar-bg: #1B1F3B;
  --sidebar-text: #D5D8EE;
  --sidebar-text-soft: #8A8FBD;
  --text: #1B1F3B;
  --text-soft: #5A5F7D;
  --border: #DEDCE8;
  --accent: #5B4BDB;
  --accent-text: #FFFFFF;
  --accent-soft: #EDEBFC;
  --coral: #FF8A65;
  --mint: #2E9E75;
}

[data-rsr-theme="dark"] {
  --bg: #12142A;
  --bg-raised: #1B1F3B;
  --bg-sunken: #0D0E1F;
  --sidebar-bg: #0D0E1F;
  --sidebar-text: #DCDEF2;
  --sidebar-text-soft: #6E73A0;
  --text: #F1F1F6;
  --text-soft: #A6ABCB;
  --border: #2C3057;
  --accent: #8F84F2;
  --accent-text: #12142A;
  --accent-soft: #242759;
  --coral: #FF9E7E;
  --mint: #6FD9AC;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  /* Nunca permitir rolagem horizontal (regra mobile-first do mapeamento). */
  overflow-x: hidden;
}

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

.rsr-btn {
  cursor: pointer;
  border: none;
  font-family: var(--font-body);
  border-radius: 10px;
}

.rsr-btn-primario {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  height: 48px;
  font-size: 15px;
}

.rsr-input {
  width: 100%;
  height: 44px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
  font-family: var(--font-body);
}

.rsr-label {
  font-size: 13px;
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
}

.rsr-erro {
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(255, 138, 101, .12);
  color: var(--coral);
  font-size: 13px;
}

/* ---- App shell (usado a partir da tela do painel) ---- */
.rsr-shell { display: flex; min-height: 100vh; }

.rsr-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rsr-navitem {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 14px;
  text-decoration: none;
  color: var(--sidebar-text);
}

.rsr-navitem.ativo { background: var(--accent); color: #fff; font-weight: 600; }

.rsr-main { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }

.rsr-topbar {
  height: 68px;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-raised);
}

.rsr-conteudo { flex-grow: 1; padding: 28px; }

.rsr-rodape {
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---- Componentes reaproveitados pelos modulos (municipios, usuarios,
   indicadores, central de atualizacoes) — a partir da Fase 2 ---- */
.rsr-btn-secundario {
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  height: 44px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
}

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

.rsr-toolbar h1 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
}

.rsr-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}

.rsr-card + .rsr-card { margin-top: 16px; }

.rsr-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.rsr-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; }

.rsr-table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--bg-raised); }

.rsr-table th, .rsr-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.rsr-table th { color: var(--text-soft); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.rsr-table tr:last-child td { border-bottom: none; }

.rsr-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}

.rsr-badge-mint { background: rgba(46, 158, 117, .14); color: var(--mint); }
.rsr-badge-coral { background: rgba(255, 138, 101, .14); color: var(--coral); }
.rsr-badge-neutro { background: var(--bg-sunken); color: var(--text-soft); }

.rsr-vazio {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-soft);
  font-size: 14px;
}

.rsr-sucesso {
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(46, 158, 117, .12);
  color: var(--mint);
  font-size: 13px;
}

/* ---- Cabecalho de entidade (municipio): brasao + nome, reaproveitavel
   em qualquer tela que precise identificar visualmente uma entidade ---- */
.rsr-entidade-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.rsr-brasao {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: contain;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 4px;
  flex-shrink: 0;
}

.rsr-entidade-header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0;
  line-height: 1.2;
}

.rsr-entidade-header .rsr-entidade-sub {
  font-size: 13px;
  color: var(--text-soft);
  margin-top: 2px;
}

/* ---- Secoes tematicas dentro de um card (ex.: blocos de dados publicos) --- */
.rsr-secao + .rsr-secao { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }

.rsr-secao-titulo {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rsr-secao-titulo .rsr-secao-numero {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ---- Grid de estatisticas: cartoes individuais, nunca texto solto ---- */
.rsr-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.rsr-stat {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 0;
}

.rsr-stat-rotulo {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-soft);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rsr-stat-valor {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
  word-break: break-word;
}

.rsr-stat-fonte {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 6px;
}

/* Mobile-first: menu lateral vira overlay, nunca empurra o conteudo. */
@media (max-width: 860px) {
  .rsr-sidebar {
    position: fixed;
    inset: 0 20% 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .rsr-sidebar.aberta { transform: translateX(0); }
  .rsr-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 20;
  }
  .rsr-scrim.visivel { display: block; }

  .rsr-stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .rsr-stat { padding: 12px; }
  .rsr-stat-valor { font-size: 19px; }
  .rsr-entidade-header h1 { font-size: 19px; }
  .rsr-brasao { width: 40px; height: 40px; }
  .rsr-conteudo { padding: 16px; }
  .rsr-card { padding: 16px; }
}
