* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* === CORES TCM-BA === */
    --primary: #1e3a8a;
    --primary-dark: #0f172a;
    --primary-light: #1e40af;
    --accent: #059669;
    --accent-light: #10b981;
    --danger: #991b1b;
    --danger-light: #dc2626;
    --warning: #d97706;
    --warning-light: #f59e0b;
    --info: #0369a1;
    --info-light: #0ea5e9;

    /* === TEXTO === */
    --text-dark: #1a202c;
    --text-secondary: #52525b;
    --text-muted: #71717a;
    --text-tertiary: #a1a1aa;

    /* === FUNDOS === */
    --bg-light: #f7fafc;
    --bg-subtle: #fafafa;
    --bg-card: #ffffff;
    --bg-hover: #f4f5f7;

    /* === BORDAS === */
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    /* === RAIOS === */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-2xl: 16px;
    --radius-full: 9999px;

    /* === TIPOGRAFIA === */
    --text-xs: 0.72rem;
    --text-sm: 0.82rem;
    --text-base: 0.92rem;
    --text-md: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.35rem;
    --text-2xl: 1.65rem;
    --text-3xl: 2rem;

    /* === SOMBRAS === */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);

    /* === TRANSICOES === */
    --transition: 0.15s ease;
}

/* Dark mode — tema institucional sóbrio */
[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #1e3a8a;
    --primary-light: #60a5fa;
    --accent: #10b981;
    --accent-light: #34d399;
    --text-dark: #e5e7eb;
    --text-secondary: #cbd5e1;
    --text-muted: #9ca3af;
    --text-tertiary: #6b7280;
    --bg-light: #0f172a;
    --bg-subtle: #0b1220;
    --bg-card: #1e293b;
    --bg-hover: #243042;
    --border: #334155;
    --border-strong: #475569;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] body { background: var(--bg-light); color: var(--text-dark); }
[data-theme="dark"] .data-info,
[data-theme="dark"] .mapa-legenda { background: #0b1220; }
[data-theme="dark"] .chart-container,
[data-theme="dark"] .card-section,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .kpi-card { background: var(--bg-card); color: var(--text-dark); }
[data-theme="dark"] .card-section-title,
[data-theme="dark"] .chart-title,
[data-theme="dark"] .kpi-value { color: var(--text-dark); }
[data-theme="dark"] .nav { background: var(--bg-card); border-bottom-color: var(--border); }
[data-theme="dark"] .nav a:hover { background: #0b1220; }
[data-theme="dark"] .nav a.active { background: rgba(59, 130, 246, 0.12); color: var(--primary-light); }

/* Botao toggle tema */
.theme-toggle {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.theme-toggle:hover { background: rgba(255,255,255,0.22); }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

body {
    font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    font-size: 14px;
}

/* Header Institucional */
.header {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 30%, #991b1b 100%);
    color: white;
    padding: 0;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 50%, #dc2626 100%);
}

.header-content {
    max-width: 100%;
    margin: 0 auto;
    padding: 0.75rem 3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.5px;
    line-height: 1.15;
}

.header-subtitle {
    opacity: 0.8;
    font-size: 0.75rem;
    font-weight: 400;
    margin-top: 0.05rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Garante que atributo hidden tenha prioridade sobre display: flex dos componentes */
[hidden] { display: none !important; }

/* === Barra de filtro global (linha dedicada abaixo do nav) === */
.global-filter-bar {
    background: linear-gradient(180deg, var(--bg-subtle) 0%, var(--bg-light) 100%);
    border-bottom: 1px solid var(--border);
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.03);
}
.global-filter-bar-inner {
    max-width: 100%;
    margin: 0 auto;
    padding: 0.9rem 3rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.global-filter-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}
.global-filter-label [data-lucide] {
    color: var(--primary);
}
.global-filter-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-left: auto;
    font-style: italic;
    white-space: nowrap;
}

/* Seletor: input principal da barra */
.global-municipio-selector {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.9rem 0.55rem 1rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-full);
    flex: 1;
    max-width: 560px;
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition), border-color var(--transition);
}
.global-municipio-selector:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15);
}
.global-municipio-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}
.global-municipio-input {
    flex: 1;
    background: transparent !important;
    border: none !important;
    color: var(--text-dark) !important;
    padding: 0.25rem 0 !important;
    font-size: var(--text-base) !important;
    font-weight: 500 !important;
    outline: none;
    min-width: 0;
}
.global-municipio-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}
.global-municipio-input:hover {
    border: none !important;
}
.global-municipio-clear {
    background: var(--bg-hover);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}
.global-municipio-clear:hover {
    background: var(--danger-light);
    color: #fff;
}
.global-municipio-sugestoes {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    z-index: 1100;
}

/* === Badge de município filtrado (abaixo do header) === */
.municipio-filtro-badge {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.15rem;
    margin-bottom: 1.25rem;
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.12) 0%, rgba(16, 185, 129, 0.04) 100%);
    border: 1px solid rgba(16, 185, 129, 0.35);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    color: var(--text-dark);
    box-shadow: var(--shadow-xs);
}
.municipio-filtro-badge [data-lucide] {
    color: var(--accent);
}
.municipio-filtro-badge strong {
    color: var(--primary);
    font-weight: 600;
}
.municipio-filtro-regiao {
    color: var(--text-muted);
    font-size: var(--text-xs);
    padding: 0.15rem 0.5rem;
    background: var(--bg-hover);
    border-radius: var(--radius-full);
}
.municipio-filtro-regiao:empty {
    display: none;
}
.municipio-filtro-limpar {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    cursor: pointer;
    transition: all var(--transition);
}
.municipio-filtro-limpar:hover {
    border-color: var(--danger-light);
    color: var(--danger-light);
}

/* Responsivo: barra empilhada em telas menores */
@media (max-width: 900px) {
    .global-filter-bar-inner {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.6rem;
    }
    .global-municipio-selector {
        max-width: 100%;
    }
    .global-filter-hint {
        display: none;
    }
}

/* Dark mode para barra global */
[data-theme="dark"] .global-filter-bar {
    background: linear-gradient(180deg, var(--bg-subtle) 0%, var(--bg-card) 100%);
    border-bottom-color: var(--border);
}
[data-theme="dark"] .global-municipio-selector {
    background: var(--bg-card);
    border-color: var(--border);
}

/* =========================================================
   COMPONENTES SEMÂNTICOS REUTILIZÁVEIS
   Objetivo: substituir os blocos inline spalhados pelo HTML.
   Uso progressivo — as abas serão refatoradas para consumir
   estas classes ao invés de style="" inline.
   ========================================================= */

/* Painel de seção: caixa branca com cabeçalho e conteúdo */
.section-panel {
    background: var(--bg-card);
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    margin-top: 0.75rem;
}
.section-panel--muted {
    background: var(--bg-subtle);
}
.section-panel--accent   { border-left: 3px solid var(--primary); }
.section-panel--success  { border-left: 3px solid var(--accent); }
.section-panel--warning  { border-left: 3px solid var(--warning-light); }
.section-panel--danger   { border-left: 3px solid var(--danger-light); }
.section-panel--info     { border-left: 3px solid var(--info-light); }

.section-panel-title {
    font-size: var(--text-sm);
    font-weight: 600;
    margin: 0 0 0.6rem 0;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.section-panel-title [data-lucide] {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}
.section-panel-hint {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: 400;
    font-style: italic;
}
.section-panel-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.75rem;
}
.section-panel-heading {
    font-size: var(--text-lg);
    font-weight: 600;
    margin: 0;
    color: var(--text-dark);
    letter-spacing: -0.2px;
}
.section-panel-subtitle {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin: 0.3rem 0 0 0;
}
.section-panel-subtitle strong {
    color: var(--text-secondary);
    font-weight: 600;
}
.section-panel-sep {
    margin: 0 0.5rem;
    color: var(--text-tertiary);
}

/* Cabeçalho municipal: contexto forte quando viewing um município */
.municipio-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: white;
    border-radius: var(--radius-lg);
    gap: 1rem;
}
.municipio-header h2 {
    font-size: var(--text-xl);
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.3px;
}
.municipio-header-meta {
    display: flex;
    gap: 1.25rem;
    margin-top: 0.4rem;
    font-size: var(--text-sm);
    opacity: 0.92;
}
.municipio-header-meta strong {
    font-weight: 600;
    opacity: 1;
}

/* Metric card semântico — substitui stat-card com background inline por tipo */
.metric-card {
    background: var(--bg-card);
    padding: 1rem 1.15rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    transition: transform var(--transition), box-shadow var(--transition);
}
.metric-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.metric-card--neutral  { border-left-color: var(--text-tertiary); }
.metric-card--info     { border-left-color: var(--info-light); }
.metric-card--success  { border-left-color: var(--accent); }
.metric-card--warning  { border-left-color: var(--warning-light); }
.metric-card--danger   { border-left-color: var(--danger-light); }
.metric-card--clickable { cursor: pointer; }
.metric-card--clickable:hover { border-color: var(--primary-light); }

.metric-card-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1.1;
}
.metric-card-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 0.25rem;
}
.metric-card-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Dark mode para componentes semânticos */
[data-theme="dark"] .section-panel { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .metric-card   { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .metric-card-value { color: var(--text-dark); }
[data-theme="dark"] .municipio-filtro-badge {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.12) 0%, rgba(59, 130, 246, 0.03) 100%);
    border-color: rgba(59, 130, 246, 0.3);
}

.header-sync-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.1);
    border-radius: var(--radius-lg);
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.9);
}

.header-sync-info svg {
    opacity: 0.7;
}

/* Card section header — icones alinhados */
.card-section-title [data-lucide],
.card-section-title .lucide {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

/* Inputs com estilo moderno e consistente */
input[type="text"],
input[type="search"],
input[type="number"],
select {
    font-family: inherit;
    font-size: var(--text-base);
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-dark);
    transition: all var(--transition);
}
input[type="text"]:hover,
select:hover {
    border-color: var(--border-strong);
}

/* Navigation */
.nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.nav ul {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    list-style: none;
    padding: 0 3rem;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    border-bottom: 4px solid transparent;
    transition: all 0.15s;
    position: relative;
}

.nav a:hover {
    color: var(--primary);
    background: var(--bg-light);
}

.nav a.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: linear-gradient(180deg, transparent 0%, rgba(30, 58, 138, 0.08) 100%);
    font-weight: 600;
}

.nav a.active svg { stroke: var(--primary); }
.nav a [data-lucide], .nav a .lucide { width: 18px; height: 18px; }

/* Container */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 1.5rem 3rem;
}

/* Data Info */
.data-info {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.data-info strong {
    color: var(--text-dark);
}

/* Tab Content */
.tab-content {
    display: none !important;
}

.tab-content.active {
    display: block !important;
}

/* Alertas Banner */
.alertas-banner {
    background: linear-gradient(135deg, #fffaf0 0%, #fef3c7 100%);
    border: 1px solid var(--warning);
    border-left: 4px solid var(--warning);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
}

.alerta-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.alertas-banner span {
    font-size: 0.9rem;
    color: #744210;
}

.alerta-link {
    margin-left: auto;
    color: #975a16;
    font-weight: 600;
    text-decoration: none;
    font-size: 0.875rem;
    white-space: nowrap;
}

.alerta-link:hover {
    text-decoration: underline;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--border);
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    opacity: 0.45;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card.highlight {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    border: none;
}

.stat-card.highlight::before {
    background: var(--accent);
}

.stat-card.highlight .stat-value,
.stat-card.highlight .stat-label,
.stat-card.highlight .stat-change {
    color: white;
}

/* Card clicável (drill-down para lista/detalhe) */
.stat-card--clickable {
    cursor: pointer;
}
.stat-card--clickable:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}
.stat-card--clickable:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.stat-card-arrow {
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
    opacity: 0.5;
    transition: opacity var(--transition), color var(--transition), transform var(--transition);
    pointer-events: none;
}
.stat-card--clickable:hover .stat-card-arrow {
    opacity: 1;
    color: var(--primary);
    transform: translate(2px, -2px);
}

/* === Modal de estabelecimentos (lista) === */
.modal-estab {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 10000;
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
    backdrop-filter: blur(2px);
}
.modal-estab-dialog {
    background: var(--bg-card);
    width: 100%;
    max-width: 1000px;
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    animation: modalEstabFadeIn 0.18s ease-out;
}
@keyframes modalEstabFadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.modal-estab-header {
    padding: 1.25rem 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: #fff;
    gap: 1rem;
}
.modal-estab-title {
    margin: 0;
    font-size: var(--text-xl);
    font-weight: 600;
    letter-spacing: -0.3px;
}
.modal-estab-subtitle {
    margin: 0.3rem 0 0 0;
    font-size: var(--text-sm);
    opacity: 0.9;
}
.modal-estab-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}
.modal-estab-close:hover {
    background: rgba(255, 255, 255, 0.28);
}
.modal-estab-loading {
    padding: 3rem;
    text-align: center;
}
.modal-estab-loading p {
    margin-top: 1rem;
    color: var(--text-muted);
}
.modal-estab-spinner {
    display: inline-block;
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
.modal-estab-body {
    max-height: 70vh;
    overflow-y: auto;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.stat-icon {
    font-size: 1.5rem;
    opacity: 0.9;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.4px;
    margin-bottom: 0.2rem;
    color: var(--text-dark);
    line-height: 1.15;
}

.stat-label {
    font-size: 0.72rem;
    opacity: 0.75;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.stat-change {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.stat-change.positive {
    color: var(--accent);
}

.stat-change.negative {
    color: var(--danger);
}

/* Mini Stat Cards */
.stat-card-mini {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    text-align: center;
    transition: all 0.2s;
}

.stat-card-mini:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-mini-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.stat-mini-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.chart-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-title::before {
    content: '';
    width: 4px;
    height: 18px;
    background: var(--accent);
    border-radius: 2px;
}

.chart-wrapper {
    height: 280px;
    position: relative;
}

/* Table */
.table-container {
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.table-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.table-title::before {
    content: '';
    width: 4px;
    height: 18px;
    background: var(--accent);
    border-radius: 2px;
}

.table-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.search-input,
.filter-select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    background: white;
    color: var(--text-dark);
    transition: border-color 0.2s;
}

.search-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--primary);
}

.search-input {
    width: 200px;
}

.btn-export {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-export:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(56, 161, 105, 0.4);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.875rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg-light);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tbody tr {
    transition: background 0.15s;
}

tbody tr:hover {
    background: var(--bg-light);
}

tbody tr:last-child td {
    border-bottom: none;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem;
    font-size: 0.9rem;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.excelente {
    background: #f0fff4;
    color: var(--accent);
    border: 1px solid #c6f6d5;
}

.badge.bom {
    background: #e6fffa;
    color: #319795;
    border: 1px solid #b2f5ea;
}

.badge.atencao {
    background: #fffaf0;
    color: var(--warning);
    border: 1px solid #fef3c7;
}

.badge.critico {
    background: #fff5f5;
    color: var(--danger);
    border: 1px solid #fed7d7;
}

/* Footer */
.footer {
    background: var(--primary-dark);
    color: rgba(255,255,255,0.7);
    padding: 1.5rem 3rem;
    margin-top: 2rem;
}

.footer-content {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer p {
    font-size: 0.8rem;
    margin: 0;
}

.footer-links {
    display: flex;
    gap: 1.5rem;
}

.footer-links a {
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    font-size: 0.8rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: white;
}

/* Responsive */
@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        padding: 1rem 1.5rem;
    }

    .nav ul {
        flex-wrap: wrap;
        justify-content: center;
        padding: 0 1.5rem;
    }

    .nav a {
        padding: 0.75rem 1rem;
    }

    .container {
        padding: 1rem 1.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .footer-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    th, td {
        padding: 0.75rem 1rem;
        font-size: 0.75rem;
    }

    .table-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-input {
        width: 100%;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-light);
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* ===================================
   BUSCA DE MUNICÍPIO PRINCIPAL
   =================================== */

.search-municipio-principal {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.search-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.search-header svg {
    width: 28px;
    height: 28px;
    color: var(--primary);
}

.search-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-dark);
    font-weight: 600;
}

.search-box-container {
    position: relative;
    margin-bottom: 1.5rem;
}

.search-box-large {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-light);
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 0 1.25rem;
    transition: all 0.2s ease;
}

.search-box-large:focus-within {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

.search-box-large svg {
    width: 24px;
    height: 24px;
    color: var(--text-muted);
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.search-box-large input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 1.25rem 0;
    font-size: 1.125rem;
    color: var(--text-dark);
    outline: none;
}

.search-box-large input::placeholder {
    color: var(--text-muted);
}

.clear-search {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    transition: all 0.2s ease;
    display: none;
}

.clear-search:hover {
    color: var(--danger);
}

.search-box-large input:not(:placeholder-shown) ~ .clear-search {
    display: block;
}

.select-municipio-large {
    width: 100%;
    padding: 1.25rem 1.5rem;
    font-size: 1.125rem;
    color: var(--text-dark);
    background: var(--bg-light);
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

.select-municipio-large:hover {
    border-color: #cbd5e0;
}

.select-municipio-large:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

.search-suggestions {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    max-height: 500px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-suggestions.active {
    display: block;
}

.suggestion-item {
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    border-bottom: 1px solid #e2e8f0;
    transition: all 0.15s ease;
    position: relative;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: linear-gradient(90deg, #f7fafc 0%, #edf2f7 100%);
    border-left: 4px solid var(--primary);
    padding-left: calc(1.5rem - 4px);
}

.suggestion-item:active {
    background: #e2e8f0;
}

.suggestion-item-nome {
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.35rem;
    font-size: 1.05rem;
}

.suggestion-item-regiao {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.municipio-selecionado {
    background: linear-gradient(135deg, var(--primary) 0%, #1e4976 100%);
    border-radius: 12px;
    padding: 1.75rem;
    color: white;
    display: none;
}

.municipio-selecionado.show {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.municipio-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.municipio-header h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.75rem;
    font-weight: 700;
}

.municipio-header p {
    margin: 0;
    font-size: 1rem;
    opacity: 0.9;
}

.municipio-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.mini-stat {
    background: rgba(255, 255, 255, 0.15);
    padding: 1rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.mini-stat-label {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.mini-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Sugestões de Município */
.sugestoes-municipio {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid var(--primary);
    border-top: none;
    border-radius: 0 0 12px 12px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.sugestao-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #e2e8f0;
    transition: background 0.15s;
}

.sugestao-item:last-child {
    border-bottom: none;
}

.sugestao-item:hover {
    background: #f7fafc;
}

.sugestao-item-nome {
    font-weight: 600;
    color: var(--text-dark);
}

.sugestao-item-regiao {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.sugestao-item-dados {
    font-size: 0.75rem;
    color: var(--primary);
    margin-top: 4px;
}

.hospital-tipo-card {
    background: rgba(255,255,255,0.15);
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
}

/* ==========================================
   KPI Cards (topo Visão Geral)
   ========================================== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Hero: primeiro KPI destacado */
.kpi-card.kpi-hero {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 60%, #991b1b 100%);
    border: none;
    color: white;
    position: relative;
    overflow: hidden;
}
.kpi-card.kpi-hero::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #fbbf24, #f59e0b, #dc2626);
}
.kpi-card.kpi-hero .kpi-icon { background: rgba(255,255,255,0.15); color: white; width: 56px; height: 56px; }
.kpi-card.kpi-hero .kpi-value { color: white; font-size: 2.25rem; }
.kpi-card.kpi-hero .kpi-label { color: rgba(255,255,255,0.85); }

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-content {
    min-width: 0;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-dark);
    line-height: 1.15;
}

.kpi-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 500;
    margin-top: 0.2rem;
}

@media (max-width: 1200px) {
    .kpi-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .kpi-value { font-size: 1.25rem; }
}

/* ==========================================
   Legenda do mapa — gradiente contínuo
   ========================================== */
.mapa-legenda-gradient {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.mapa-legenda-bar {
    flex: 1;
    height: 10px;
    border-radius: 4px;
    background: linear-gradient(90deg, #dbeafe 0%, #93c5fd 25%, #60a5fa 50%, #3b82f6 75%, #1e40af 100%);
    position: relative;
}
.mapa-legenda-min, .mapa-legenda-max {
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
}

/* ==========================================
   Footer institucional
   ========================================== */
.site-footer {
    background: var(--primary-dark);
    color: rgba(255,255,255,0.85);
    margin-top: 3rem;
    padding: 1.75rem 3rem 1.25rem;
    border-top: 4px solid;
    border-image: linear-gradient(90deg, #fbbf24, #f59e0b, #dc2626) 1;
}
.site-footer-inner {
    max-width: 100%;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.site-footer h4 {
    color: white;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
    font-weight: 600;
}
.site-footer p, .site-footer li {
    font-size: 0.82rem;
    line-height: 1.6;
}
.site-footer ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.site-footer a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
}
.site-footer a:hover { color: #fbbf24; text-decoration: underline; }
.site-footer-bottom {
    padding-top: 1rem;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
}
@media (max-width: 768px) {
    .site-footer { padding: 1.5rem 1.5rem 1rem; }
    .site-footer-inner { grid-template-columns: 1fr; gap: 1.25rem; }
}

/* Mapa responsivo */
@media (max-width: 768px) {
    .mapa-container { height: 320px !important; }
}

/* ==========================================
   Card Sections (mapa, conteúdo genérico)
   ========================================== */
.card-section {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.select-indicador {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    background: white;
    transition: border-color 0.2s;
}

.select-indicador:focus {
    border-color: var(--primary);
    outline: none;
}

/* ==========================================
   Mapa
   ========================================== */
.mapa-container {
    height: 600px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.mapa-legenda {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 6px;
    flex-wrap: wrap;
}

.mapa-legenda-titulo {
    font-size: 0.85rem;
    font-weight: 600;
    color: #64748b;
}

.mapa-legenda-faixas {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.legenda-faixa {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: #64748b;
}

.legenda-cor {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    display: inline-block;
    border: 1px solid rgba(0,0,0,0.1);
}

.mapa-legenda-dica {
    margin-left: auto;
    font-size: 0.8rem;
    color: #94a3b8;
    font-style: italic;
}

/* ==========================================
   Sub-abas (Financeiro)
   ========================================== */
.subtabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 4px;
}

.subtab {
    flex: 1;
    padding: 0.75rem 1.25rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.subtab:hover {
    color: var(--text-dark);
    background: rgba(255,255,255,0.5);
}

.subtab.active {
    background: white;
    color: var(--primary);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.subtab-content {
    display: none;
}

.subtab-content.active {
    display: block;
}

/* ==========================================
   Input e hints genéricos
   ========================================== */
.input-busca {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.input-busca:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

.input-hint {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: #94a3b8;
}

/* ==========================================
   Toast Notifications
   ========================================== */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    padding: 0.875rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastEntrar 0.3s ease;
    max-width: 420px;
    min-width: 280px;
}

.toast-erro {
    background: var(--danger);
    color: white;
    border-left: 4px solid #7f1d1d;
}

.toast-saindo {
    animation: toastSair 0.3s ease forwards;
}

@keyframes toastEntrar {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSair {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ==========================================
   DESIGN SYSTEM — Botoes, Zebra, Focus, Empty
   ========================================== */

/* Icones Lucide — peso e tamanho consistentes */
[data-lucide], .lucide {
    width: 18px;
    height: 18px;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    flex-shrink: 0;
}
.icon-lg [data-lucide], .icon-lg.lucide { width: 22px; height: 22px; }
.icon-xl [data-lucide], .icon-xl.lucide { width: 28px; height: 28px; }
.icon-sm [data-lucide], .icon-sm.lucide { width: 14px; height: 14px; }

/* Botoes — sistema unificado */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: inherit;
    line-height: 1.3;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
    white-space: nowrap;
    text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn [data-lucide] { width: 15px; height: 15px; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-light); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover:not(:disabled) { background: var(--accent-light); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-danger { background: transparent; color: var(--danger-light); border-color: var(--danger-light); }
.btn-danger:hover:not(:disabled) { background: rgba(220, 38, 38, 0.08); }

.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-dark); border-color: var(--border-strong); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: var(--text-xs); }
.btn-lg { padding: 0.75rem 1.5rem; font-size: var(--text-md); }

/* Zebra striping em tabelas — escopado (nao afeta analise e alguns customs) */
table.data-table tbody tr:nth-child(even) td { background: var(--bg-subtle); }
[data-theme="dark"] table.data-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.025); }

/* Focus rings globais acessiveis */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.12);
    outline: none;
}
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Empty states */
.empty-state {
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border-radius: var(--radius-xl);
    border: 2px dashed var(--border);
}
.empty-state [data-lucide],
.empty-state .lucide {
    width: 48px;
    height: 48px;
    stroke-width: 1.5;
    color: var(--text-tertiary);
    margin: 0 auto 1rem;
}
.empty-state h3 {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 0.35rem;
}
.empty-state p {
    font-size: var(--text-sm);
    margin: 0;
}

/* Skeleton loading */
.skeleton {
    display: inline-block;
    background: linear-gradient(90deg, var(--bg-hover) 0%, var(--bg-light) 50%, var(--bg-hover) 100%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s infinite;
    border-radius: var(--radius-sm);
    color: transparent;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Card highlight (substitui gradientes inline) */
.card-highlight {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border: 1px solid #bfdbfe;
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
}
.card-highlight-success {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border: 1px solid #86efac;
    border-left: 4px solid var(--accent);
}
.card-highlight-warn {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1px solid #fde68a;
    border-left: 4px solid var(--warning-light);
}
[data-theme="dark"] .card-highlight {
    background: rgba(59, 130, 246, 0.08);
    border-color: rgba(59, 130, 246, 0.3);
}
[data-theme="dark"] .card-highlight-success {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.3);
}
[data-theme="dark"] .card-highlight-warn {
    background: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.3);
}

/* Header actions — sync por fonte */
.header-sync-sources {
    display: flex;
    gap: 0.5rem;
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.85);
    align-items: center;
}
.header-sync-sources .sync-chip {
    padding: 0.25rem 0.6rem;
    background: rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-variant-numeric: tabular-nums;
}
.header-sync-sources .sync-chip strong { font-weight: 600; opacity: 0.95; }

/* ==========================================
   Aba Análises — overrides escopados em #resultadosAnalise
   Estiliza o HTML inline gerado por app-analise.js sem reescrever o JS
   ========================================== */
#resultadosAnalise > div {
    margin-top: 2rem;
}

/* Cabecalho do municipio analisado */
#resultadosAnalise > div > div:first-child {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%) !important;
    color: white !important;
    border: none !important;
    border-radius: 12px !important;
    padding: 1.75rem 2rem !important;
    margin-bottom: 1.5rem !important;
    box-shadow: var(--shadow-lg) !important;
    position: relative !important;
    overflow: hidden !important;
}
#resultadosAnalise > div > div:first-child::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #fbbf24, #f59e0b, #dc2626);
}
#resultadosAnalise > div > div:first-child h2 {
    color: white !important;
    font-size: 1.75rem !important;
    letter-spacing: -0.5px !important;
    margin-bottom: 0.75rem !important;
}
#resultadosAnalise > div > div:first-child div,
#resultadosAnalise > div > div:first-child strong {
    color: rgba(255, 255, 255, 0.92) !important;
}

/* Secoes — cards */
#resultadosAnalise > div > div:not(:first-child) {
    background: white !important;
    border: 1px solid var(--border) !important;
    border-radius: 12px !important;
    padding: 1.5rem 1.75rem !important;
    margin-bottom: 1.25rem !important;
    box-shadow: var(--shadow) !important;
    transition: box-shadow 0.2s;
}
#resultadosAnalise > div > div:not(:first-child):hover {
    box-shadow: var(--shadow-lg) !important;
}

/* Titulos das secoes — faixa colorida a esquerda */
#resultadosAnalise h3 {
    font-size: 0.78rem !important;
    font-weight: 700 !important;
    letter-spacing: 1.2px !important;
    text-transform: uppercase !important;
    color: var(--primary) !important;
    border-bottom: 2px solid var(--border) !important;
    padding: 0 0 0.75rem 0.9rem !important;
    margin: 0 0 1.25rem 0 !important;
    position: relative;
}
#resultadosAnalise h3::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.1rem;
    bottom: 0.9rem;
    width: 4px;
    background: var(--primary);
    border-radius: 2px;
}

/* Tabelas */
#resultadosAnalise table {
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}
#resultadosAnalise thead tr {
    background: var(--bg-light) !important;
}
#resultadosAnalise thead th {
    padding: 0.7rem 0.9rem !important;
    font-size: 0.7rem !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    color: var(--text-muted) !important;
    border-bottom: 2px solid var(--border) !important;
}
#resultadosAnalise thead th:first-child { border-top-left-radius: 6px; }
#resultadosAnalise thead th:last-child { border-top-right-radius: 6px; }

#resultadosAnalise tbody tr {
    transition: background 0.15s;
}
#resultadosAnalise tbody tr:hover {
    background: var(--bg-light) !important;
}
#resultadosAnalise tbody td {
    padding: 0.7rem 0.9rem !important;
    border-bottom: 1px solid var(--border) !important;
    font-size: 0.88rem !important;
}
#resultadosAnalise tbody tr:last-child td {
    border-bottom: none !important;
}

/* Destaque coluna do municipio (2a coluna) */
#resultadosAnalise tbody td:nth-child(2) {
    background: rgba(30, 58, 138, 0.04) !important;
    border-left: 3px solid var(--primary) !important;
    color: var(--primary-dark) !important;
    font-weight: 700 !important;
}
#resultadosAnalise thead th:nth-child(2) {
    color: var(--primary) !important;
    background: rgba(30, 58, 138, 0.06) !important;
    border-left: 3px solid var(--primary) !important;
}

/* Colunas de comparacao (3a,4a,5a) */
#resultadosAnalise tbody td:nth-child(n+3) {
    color: var(--text-muted) !important;
    font-variant-numeric: tabular-nums;
}

/* Dark mode na aba analises */
[data-theme="dark"] #resultadosAnalise > div > div:not(:first-child) {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
}
[data-theme="dark"] #resultadosAnalise thead tr { background: #0b1220 !important; }
[data-theme="dark"] #resultadosAnalise tbody tr:hover { background: #0b1220 !important; }
[data-theme="dark"] #resultadosAnalise tbody td:nth-child(2) {
    background: rgba(59, 130, 246, 0.12) !important;
    color: var(--primary-light) !important;
}
[data-theme="dark"] #resultadosAnalise thead th:nth-child(2) {
    background: rgba(59, 130, 246, 0.15) !important;
}

/* Empty state mais sutil */
#analiseAguardando {
    border: 2px dashed var(--border) !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 3.5rem 2rem !important;
}
#analiseAguardando h3 {
    font-size: 0.95rem !important;
    font-weight: 500 !important;
}

/* Busca de municipio — mais polida */
#tab-analises .alertas-banner {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%) !important;
    border: 1px solid #bfdbfe !important;
    border-left: 4px solid var(--primary) !important;
}
#tab-analises .alertas-banner span { color: var(--primary-dark) !important; }

@media (max-width: 768px) {
    #resultadosAnalise table { font-size: 0.8rem; }
    #resultadosAnalise tbody td,
    #resultadosAnalise thead th { padding: 0.5rem !important; }
    #resultadosAnalise > div > div:first-child { padding: 1.25rem !important; }
    #resultadosAnalise > div > div:first-child h2 { font-size: 1.35rem !important; }
    #resultadosAnalise > div > div:not(:first-child) { padding: 1rem !important; }
}
