/* =========================================
   1. RESET & GLOBAIS
   ========================================= */
* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Cantarell', sans-serif;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

button, input, select, textarea {
    font-family: inherit;
}

.leaflet-container {
    font-family: 'Cantarell', sans-serif;
}

/* Utilitário: Efeito Glassmorphism (Vidro) */
.glass-effect {
    background: rgba(255, 255, 255, 0.75) !important;
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
}

/* Utilitário: Scrollbars Personalizados */
.scroll-styled::-webkit-scrollbar { width: 8px; display: block; }
.scroll-styled::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }
.scroll-styled::-webkit-scrollbar-thumb { background: #7a1d3a; border-radius: 10px; border: 2px solid #f1f1f1; }
.scroll-styled::-webkit-scrollbar-thumb:hover { background: #5a152a; }

.scroll-styled {
    scrollbar-width: thin;
    scrollbar-color: #7a1d3a #f1f1f1;
}

/* =========================================
   2. HEADER (BANNER)
   ========================================= */
.header-banner {
    width: 100%;
    height: 100px;
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: relative;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.banner-img { height: 50%; width: auto; display: block; }

.header-subtitle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.subtitle-img { height: 60px; width: auto; transition: opacity 0.2s; }
.subtitle-img:hover { opacity: 0.8; }
.copyright-text { color: #7a1d3ab3; font-size: 0.75rem; white-space: nowrap; }

.subtitle-link { position: relative; display: inline-block; }
.subtitle-link:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 110%; left: 50%; transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8); color: white;
    padding: 5px 10px; border-radius: 4px; font-size: 0.7rem;
    white-space: nowrap; z-index: 100;
}

/* =========================================
   3. LAYOUT PRINCIPAL
   ========================================= */
.main-container {
    display: flex;
    width: 100%;
    height: calc(100vh - 100px);
    position: relative;
    overflow: hidden;
}

/* =========================================
   4. SIDEBAR ESQUERDA (TEMAS)
   ========================================= */
.sidebar-temas {
    position: absolute;
    top: 0; left: -320px;
    width: 320px; height: 100%;
    z-index: 3000;
    transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.3);
}

.sidebar-temas.active { left: 0; }

.btn-toggle-temas {
    position: absolute; right: -90px; top: 0;
    background: #7a1d3a; color: white;
    border: none; padding: 12px 15px;
    border-radius: 0 0 10px 0;
    cursor: pointer; font-weight: bold;
    box-shadow: 4px 0 10px rgba(0,0,0,0.1);
    z-index: 3001;
}

.temas-content {
    height: 100%;
    overflow-y: auto;
    padding: 10px;
}

#container-temas-custom .leaflet-control-layers {
    box-shadow: none !important;
    background: transparent !important;
    border: none !important;
    margin: 0 !important;
    width: 100%;
}

.leaflet-control-layers-group-name {
    display: flex !important; justify-content: space-between; align-items: center;
    width: 100%; padding: 8px; margin-top: 15px;
    background: rgba(122, 29, 58, 0.05); border-radius: 5px;
    font-weight: bold; color: #7a1d3a; cursor: pointer;
}

.leaflet-control-layers-selector {
    accent-color: #7a1d3a; width: 16px; height: 16px; cursor: pointer;
}

/* Sliders */
.slider-camada-container {
    display: none; flex-direction: column;
    padding: 0 10px 10px 45px; width: 100%;
}
.slider-camada-container.active { display: flex !important; }

.mini-slider {
    width: 100%; height: 4px; cursor: pointer;
    accent-color: #7a1d3a; background: #ddd;
    border-radius: 2px; -webkit-appearance: none;
}
.mini-slider::-webkit-slider-thumb {
    -webkit-appearance: none; height: 12px; width: 12px;
    border-radius: 50%; background: #7a1d3a; border: 2px solid #fff;
    box-shadow: 0 0 2px rgba(0,0,0,0.3); margin-top: -4px;
}

.btn-timeline-trigger {
    border: none; background: none; color: #7a1d3a;
    padding: 4px 8px; transition: all 0.2s ease; cursor: pointer;
}
.btn-timeline-trigger.active {
    background-color: #7a1d3a !important; color: white !important;
    border-radius: 4px; box-shadow: 0 0 5px rgba(122, 29, 58, 0.4);
}
.btn-timeline-trigger.disabled { opacity: 0.3; cursor: not-allowed !important; filter: grayscale(1); }

/* =========================================
   5. MAPA E ELEMENTOS FLUTUANTES
   ========================================= */
#mapCanvas {
    flex-grow: 1; height: 100%; position: relative; z-index: 1;
}

.map-statusbar {
    position: absolute; bottom: 10px; left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(2px);
    z-index: 1000;
    padding: 4px 15px;
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    display: flex; gap: 15px;
    font-size: 11px; color: #444;
    pointer-events: none; white-space: nowrap;
}

#legenda-flutuante {
    position: absolute; bottom: 30px; right: 20px;
    width: 320px; z-index: 2000;
    border-radius: 12px;
    display: flex; flex-direction: column;
}

.legenda-header {
    padding: 8px 12px; background: rgba(122, 29, 58, 0.9);
    color: white; border-radius: 12px 12px 0 0;
    cursor: move; display: flex; justify-content: space-between;
    font-weight: bold; font-size: 0.85rem;
}
.btn-min-max { cursor: pointer; font-size: 16px; }

.legenda-corpo {
    padding: 12px; max-height: 400px; overflow-y: auto; width: 100%;
}
.legenda-corpo img { max-width: 100%; height: auto; }

.leaflet-top.leaflet-right .leaflet-bar {
    border: none !important; box-shadow: 0 4px 15px rgba(0,0,0,0.15) !important;
    margin-right: 20px; margin-top: 20px;
}
.leaflet-bar a {
    color: #7a1d3a !important; background: rgba(255,255,255,0.8) !important;
    backdrop-filter: blur(5px);
}
.leaflet-bar a:hover { background: #fff !important; color: #5a152a !important; }

/* =========================================
   6. SIDEBAR DIREITA (ESTATÍSTICAS)
   ========================================= */
.sidebar-content {
    width: 400px; min-width: 400px; max-width: 400px;
    height: 100%;
    display: flex; flex-direction: column;
    overflow-y: auto; overflow-x: hidden;
    background: white;
    box-shadow: -2px 0 5px rgba(0,0,0,0.1);
    z-index: 1000;
}

#titulo-sidebar {
    position: sticky; top: 0;
    background: white; margin: 0; padding: 20px;
    z-index: 1010; font-size: 1.2rem; color: #7a1d3a;
    border-bottom: 2px solid #7a1d3a;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.stats-body { padding: 15px; }

.card {
    background: #fff; margin-bottom: 15px; padding: 10px;
    border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #f0f0f0;
}

.distritos-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 5px;
}
.btn-distrito {
    background: #f0f0f0; border: 1px solid #ccc;
    border-radius: 4px; padding: 5px; font-size: 0.85rem;
    cursor: pointer; transition: all 0.2s;
}
.btn-distrito:hover { background: #e0e0e0; }
.btn-distrito.active { background: #7a1d3a; color: white; border-color: #7a1d3a; }

.table-scroll-container {
    max-height: 300px; overflow-y: auto;
    border: 1px solid #eee; border-radius: 4px; margin-top: 10px;
}

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }

thead th {
    position: sticky; top: 0; background: #f9f9f9; z-index: 2;
    padding: 8px 5px; text-align: left;
    box-shadow: 0 1px 0 #ddd;
}

tbody tr { border-bottom: 1px solid #eee; }
tbody tr:hover { background-color: #f5f5f5; cursor: pointer; }

.linha-ativa {
    background-color: #fce4ec !important;
    border-left: 4px solid #7a1d3a !important;
    font-weight: bold;
}

canvas { max-width: 100% !important; height: auto !important; }

/* =========================================
   7. TIMELINE (PLAYER)
   ========================================= */
.timeline-wrapper {
    display: none;
    position: absolute; bottom: 30px; left: 20px;
    z-index: 2000;
    width: 350px;
    border-radius: 30px;
    padding: 15px 25px;
    transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: timelineEntrada 0.5s ease forwards;
}

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

.timeline-track { display: flex; flex-direction: column; width: 100%; }

#timeline-slider {
    width: 100%; accent-color: #7a1d3a; cursor: pointer; margin-bottom: 5px;
}

.timeline-labels {
    display: flex; justify-content: space-between; width: 100%;
    font-size: 10px; color: #555;
}
.timeline-labels span {
    display: flex; flex-direction: column; align-items: center; width: 30px;
}
.timeline-labels span::before {
    content: ""; width: 1px; height: 8px; background: #ccc; margin-bottom: 4px;
}
.timeline-labels span.active { color: #7a1d3a; font-weight: bold; }
.timeline-labels span.active::before { background: #7a1d3a; height: 12px; margin-top: -4px; }

.btn-timeline-play {
    background: #7a1d3a; color: white; border: none;
    border-radius: 50%; width: 40px; height: 40px; min-width: 40px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.btn-timeline-play:hover { background: #5a152a; }

#ano-selecionado-label {
    margin-top: 10px; font-weight: bold; color: #7a1d3a; text-align: center;
}

/* =========================================
   8. LOADER
   ========================================= */
#loader {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: 9999; display: none;
}
.spinner {
    border: 5px solid #f3f3f3; border-top: 5px solid #7a1d3a;
    border-radius: 50%; width: 50px; height: 50px;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }