:root {
    /* Cores Institucionais TCM Bahia */
    --primary: #003d82;           /* Azul TCM Principal */
    --primary-dark: #002856;      /* Azul TCM Escuro */
    --primary-light: #0055b8;     /* Azul TCM Claro */
    --secondary: #005eb8;         /* Azul Secundário */
    --accent: #d4a84a;            /* Dourado/Amarelo Institucional */
    --success: #2e7d32;
    --warning: #f57c00;
    --danger: #c62828;
    --bg-light: #f8f9fa;
    --bg-white: #ffffff;
    --text-primary: #212121;
    --text-secondary: #6c757d;
    --border: #dee2e6;
    --shadow-sm: 0 2px 4px rgba(0,61,130,0.08);
    --shadow-md: 0 4px 8px rgba(0,61,130,0.12);
    --shadow-lg: 0 8px 24px rgba(0,61,130,0.15);
}

[data-theme="dark"] {
    --bg-light: #1e1e1e;
    --bg-white: #2d2d2d;
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --border: #404040;
}

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

body {
    font-family: 'Roboto', 'Segoe UI', Arial, sans-serif;
    background: var(--bg-light);
    color: var(--text-primary);
    line-height: 1.6;
    zoom: 90%;
}

/* Header Superior */
.top-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    padding: 1rem 2rem;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.top-header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.logo-tcm {
    display: flex;
    align-items: center;
    animation: fadeIn 0.6s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.title-group h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.title-group p {
    font-size: 0.85rem;
    opacity: 0.92;
    font-weight: 400;
}

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

/* Navegação com Tabs */
.nav-tabs {
    background: white;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 76px;
    z-index: 999;
    box-shadow: var(--shadow-sm);
}

.nav-tabs-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    padding: 0 2rem;
}

.tab-item {
    padding: 1rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    font-weight: 500;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-item svg {
    transition: transform 0.3s;
}

.tab-item:hover {
    color: var(--primary);
    background: rgba(0, 61, 130, 0.04);
}

.tab-item:hover svg {
    transform: translateY(-2px);
}

.tab-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(0, 61, 130, 0.06);
    font-weight: 600;
}

/* Filtros Superiores */
.top-filters {
    background: linear-gradient(to bottom, #ffffff, #f8f9fa);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    border-left: 4px solid var(--primary);
}

.filter-header {
    max-width: 1600px;
    margin: 0 auto 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.filter-header h3 {
    color: var(--primary);
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    margin: 0;
}

.filters-grid {
    max-width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    align-items: end;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.filter-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.filter-field label svg {
    opacity: 0.7;
}

.filter-field select,
.filter-field input {
    padding: 0.65rem 0.85rem;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.3s;
    background: white;
    color: var(--text-primary);
}

.filter-field select:hover,
.filter-field input:hover {
    border-color: var(--primary-light);
}

.filter-field select:focus,
.filter-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 61, 130, 0.1);
}

.filter-actions {
    display: flex !important;
    flex-direction: row !important;
    gap: 0.75rem;
    align-items: center;
}

/* Select com Busca - Município */
.custom-select-search {
    position: relative;
    width: 100%;
}

.custom-select-search .select-search-input {
    width: 100%;
    padding: 0.65rem 2.5rem 0.65rem 0.85rem;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.3s;
    background: white;
    color: var(--text-primary);
    cursor: text;
}

.custom-select-search .select-search-input::placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

.custom-select-search .select-search-input:hover {
    border-color: var(--primary-light);
}

.custom-select-search .select-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 61, 130, 0.1);
}

.custom-select-search .select-search-input.has-value {
    font-weight: 500;
    color: var(--primary-dark);
}

.custom-select-search .select-search-arrow {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.custom-select-search.open .select-search-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.custom-select-search .select-search-clear {
    position: absolute;
    right: 2.2rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 0.3rem;
    line-height: 1;
    display: none;
}

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

.custom-select-search.has-selection .select-search-clear {
    display: block;
}

.custom-select-search .select-search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    display: none;
    scrollbar-width: thin;
}

.custom-select-search.open .select-search-dropdown {
    display: block;
    animation: dropdownSlide 0.15s ease-out;
}

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

.custom-select-search .select-search-dropdown::-webkit-scrollbar {
    width: 6px;
}

.custom-select-search .select-search-dropdown::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 3px;
}

.custom-select-search .select-search-dropdown::-webkit-scrollbar-thumb {
    background: var(--primary-light);
    border-radius: 3px;
}

.custom-select-search .select-search-option {
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.15s;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.custom-select-search .select-search-option:last-child {
    border-bottom: none;
}

.custom-select-search .select-search-option:hover,
.custom-select-search .select-search-option.highlighted {
    background: rgba(0, 61, 130, 0.08);
    color: var(--primary-dark);
}

.custom-select-search .select-search-option.selected {
    background: var(--primary);
    color: white;
    font-weight: 500;
}

.custom-select-search .select-search-option .option-all {
    font-weight: 600;
    color: var(--primary);
}

.custom-select-search .select-search-option.selected .option-all {
    color: white;
}

.custom-select-search .select-search-no-results {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-style: italic;
}

.custom-select-search .select-search-count {
    padding: 0.4rem 0.85rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: #f8f9fa;
    border-bottom: 1px solid var(--border);
    text-align: right;
}

[data-theme="dark"] .custom-select-search .select-search-input {
    background: var(--bg-white);
    color: var(--text-primary);
}

[data-theme="dark"] .custom-select-search .select-search-dropdown {
    background: var(--bg-white);
    border-color: var(--primary-light);
}

[data-theme="dark"] .custom-select-search .select-search-option {
    border-bottom-color: var(--border);
}

[data-theme="dark"] .custom-select-search .select-search-option:hover,
[data-theme="dark"] .custom-select-search .select-search-option.highlighted {
    background: rgba(0, 94, 184, 0.2);
}

[data-theme="dark"] .custom-select-search .select-search-count {
    background: var(--bg-light);
}

/* Container Principal */
.main-container {
    max-width: 98%;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

/* Cards de Métricas */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary);
    transition: all 0.3s;
}

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

.metric-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
}

.metric-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Grid de Visualizações */
.viz-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.viz-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.viz-card.span-6 { grid-column: span 6; }
.viz-card.span-4 { grid-column: span 4; }
.viz-card.span-8 { grid-column: span 8; }
.viz-card.span-12 { grid-column: span 12; }

.viz-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border);
}

.viz-content {
    position: relative;
    min-height: 300px;
}

/* Tabela Avançada */
.data-table-container {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

.table-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.table-wrapper::-webkit-scrollbar {
    height: 12px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 6px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 6px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

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

.data-table thead {
    background: var(--bg-light);
}

.data-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
}

.data-table tbody tr {
    transition: background 0.2s;
}

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

/* Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.badge-success {
    background: #e8f5e9;
    color: var(--success);
}

.badge-warning {
    background: #fff3e0;
    color: var(--warning);
}

.badge-info {
    background: #e3f2fd;
    color: var(--secondary);
}

/* Responsivo */
@media (max-width: 1200px) {
    .viz-card.span-6,
    .viz-card.span-4,
    .viz-card.span-8 {
        grid-column: span 12;
    }

    .main-container {
        padding: 0 0.5rem 2rem;
    }
}

@media (max-width: 992px) {
    body {
        zoom: 85%;
    }

    .top-header {
        padding: 0.75rem 1rem;
    }

    .title-group h1 {
        font-size: 1.2rem;
    }

    .title-group p {
        font-size: 0.75rem;
    }

    .logo-tcm img {
        height: 50px !important;
    }
}

@media (max-width: 768px) {
    body {
        zoom: 80%;
    }

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

    .logo-title {
        flex-direction: column;
        gap: 0.75rem;
    }

    .title-group h1 {
        font-size: 1.1rem;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
    }

    .nav-tabs-content {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs-content::-webkit-scrollbar {
        height: 6px;
    }

    .tab-item {
        font-size: 0.85rem;
        padding: 0.85rem 1.25rem;
        white-space: nowrap;
    }

    .top-filters {
        padding: 1rem;
    }

    .filters-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .filter-actions {
        grid-column: 1 / -1;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .metric-card {
        padding: 1.25rem;
    }

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

    .table-actions {
        width: 100%;
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .data-table {
        font-size: 0.8rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.65rem 0.4rem;
    }

    .viz-content {
        min-height: 250px;
    }
}

@media (max-width: 480px) {
    body {
        zoom: 75%;
    }

    .title-group h1 {
        font-size: 1rem;
    }

    .title-group p {
        font-size: 0.7rem;
    }

    .metric-value {
        font-size: 1.25rem;
    }

    .data-table {
        font-size: 0.75rem;
    }

    .viz-title {
        font-size: 1rem;
    }
}

/* Loading */
.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.text-center {
    text-align: center;
}

/* Tooltips */
.tooltip-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 16px;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
    margin-left: 4px;
    position: relative;
}

.tooltip-icon:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: normal;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.tooltip-icon:hover::before {
    content: '';
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
}

/* Utilidades */
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-secondary { color: var(--text-secondary); }

.fw-bold { font-weight: 700; }
.fw-semibold { font-weight: 600; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

/* Estilos para o Mapa Leaflet */
.municipio-tooltip {
    background: rgba(0, 61, 130, 0.95) !important;
    border: none !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
    color: white !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    padding: 4px 8px !important;
}

.municipio-tooltip::before {
    border-top-color: rgba(0, 61, 130, 0.95) !important;
}

/* Estilo do mapa */
#mapaBahia {
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

/* Popup customizado do Leaflet */
.leaflet-popup-content-wrapper {
    border-radius: 8px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2) !important;
}

.leaflet-popup-tip {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
}

/* MODAL DE DETALHAMENTO */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
    overflow-y: auto;
    padding: 2rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-container {
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 1200px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    border-bottom: 2px solid var(--border);
    background: linear-gradient(135deg, var(--primary) 0%, #0066cc 100%);
    border-radius: 16px 16px 0 0;
}

.modal-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
    padding: 0;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
}

/* Scrollbar customizada para o modal */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #0066cc;
}

/* Responsivo */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 1rem;
    }

    .modal-container {
        max-height: 95vh;
    }

    .modal-header {
        padding: 1rem 1.5rem;
    }

    .modal-title {
        font-size: 1.25rem;
    }

    .modal-body {
        padding: 1.5rem;
    }
}
