/* ============================================
   WebGIS REURB ES — estilos especificos do mapa
   Depende de theme.css (tokens da paleta LabCidades)
   ============================================ */

body.sig-body {
    margin: 0;
    padding: 0;
    height: 100dvh;
    font-family: var(--font-body);
    color: var(--black);
    overflow: hidden;
    background: var(--gray-light);
    display: flex;
    flex-direction: column;
}

/* Header SIG: reutiliza .lbc-header do theme.css, sem position fixed */
.sig-header.lbc-header {
    position: relative;
    flex-shrink: 0;
    top: auto;
    left: auto;
    right: auto;
}

body.sig-menu-open {
    overflow: hidden;
}

/* ========== Estrutura ========== */
#wrapper.sig-shell {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    position: relative;
    overflow: hidden;
}

#main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    position: relative;
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ========== Barra de filtros ========== */
#filter-bar {
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--purple-dark) 0%, #4a0470 50%, #3d0360 100%);
    border-bottom: 2px solid var(--magenta);
    padding: 16px 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 1001;
}

.filter-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 100%;
}

.filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-title {
    font-family: var(--font-titles);
    font-size: 1.1em;
    font-weight: 700;
    color: var(--white);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-title i {
    color: var(--orange);
    font-size: 1.2em;
}

.filter-hint {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-hint i {
    color: var(--orange);
    flex-shrink: 0;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 20px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    min-width: 160px;
    flex: 1;
    max-width: 220px;
}

.filter-label {
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: rgba(255, 255, 255, 0.95);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-label .step-badge {
    background: var(--orange);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.7rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    flex-shrink: 0;
}

.filter-select {
    background: var(--white);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--black);
    font-size: 0.92em;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 42px;
}

.filter-select:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.filter-select:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(255, 131, 0, 0.25);
    outline: none;
}

.filter-select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: #f8f9fa;
}

.filter-group.filter-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    min-width: 0;
    max-width: none;
    flex: 0 0 auto;
}

.filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.filter-actions .btn-group {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-actions .btn-group-primary { flex: 0 1 auto; }
.filter-actions .btn-group-secondary { flex-shrink: 0; }

.btn-search {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-sm);
    padding: 12px 24px;
    color: white;
    font-weight: 700;
    font-size: 0.95em;
    letter-spacing: 0.04em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.35);
    transition: all 0.2s ease;
    min-width: 140px;
}

.btn-search:hover {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.45);
    transform: translateY(-1px);
}

.btn-search:active { transform: translateY(0); }

.btn-clear {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    color: white;
    font-weight: 700;
    font-size: 0.95em;
    letter-spacing: 0.04em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.35);
    transition: all 0.2s ease;
    min-width: 120px;
}

.btn-clear:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.45);
    transform: translateY(-1px);
}

.btn-clear:active { transform: translateY(0); }

.btn-reload {
    background: linear-gradient(135deg, var(--magenta) 0%, var(--purple-dark) 100%);
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    color: white;
    font-weight: 700;
    font-size: 0.9em;
    letter-spacing: 0.04em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(93, 5, 140, 0.35);
    transition: all 0.2s ease;
}

.btn-reload:hover {
    background: linear-gradient(135deg, var(--orange) 0%, #d97706 100%);
    box-shadow: 0 4px 14px rgba(255, 131, 0, 0.45);
    transform: translateY(-1px);
}

.btn-reload:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.filter-actions-divider {
    width: 1px;
    min-height: 36px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 1px;
    flex-shrink: 0;
}

.filtros-ativos {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.95);
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--orange);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: fit-content;
}

.filtros-ativos strong { color: var(--orange); }

/* ========== Sidebar redimensionavel ========== */
.sidebar-wrapper {
    display: flex;
    flex-shrink: 0;
    width: 480px;
    min-width: 320px;
    max-width: 70%;
    height: 100%;
}

.resize-handle {
    width: 8px;
    flex-shrink: 0;
    background: var(--gray-medium);
    cursor: col-resize;
    transition: background 0.2s, width 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.resize-handle::before {
    content: '';
    width: 2px;
    height: 40px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

.resize-handle:hover,
.resize-handle.resizing { background: var(--magenta); }

.resize-handle:hover::before,
.resize-handle.resizing::before { background: rgba(255, 255, 255, 0.8); }

#sidebar {
    width: 100%;
    min-width: 0;
    background: linear-gradient(180deg, var(--purple-dark) 0%, #4a0470 50%, #3d0360 100%);
    color: var(--white);
    height: 100%;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    z-index: 1500;
    position: relative;
    border-right: 3px solid var(--magenta);
    padding-bottom: 12px;
}

/* ========== Cards de stats / indicadores ========== */
.stat-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    border-left: 6px solid var(--purple-dark);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
}

.stat-card:hover {
    background: var(--white);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.stat-card .stat-icon {
    font-size: 1.07em;
    color: var(--purple-dark);
    text-align: center;
}

.stat-card .stat-value {
    font-family: var(--font-titles);
    font-size: 1.2em;
    font-weight: 700;
    color: var(--black);
    line-height: 1.2;
    word-break: break-word;
    text-align: center;
    width: 100%;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--black);
    opacity: 0.75;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    line-height: 1.1;
    text-align: center;
    width: 100%;
}

.sidebar-header {
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

.logo-container { text-align: center; margin-bottom: 0; }

.logo-container img {
    max-width: 160px;
    height: auto;
    border-radius: var(--radius-md);
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    display: block;
    margin: 0 auto;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.sidebar-header h4 {
    font-family: var(--font-titles);
    color: var(--white);
    font-weight: 700;
    font-size: 1.25em;
    margin: 12px 0 4px 0;
    letter-spacing: 1px;
}

.sidebar-header small {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85em;
    font-weight: 500;
}

.sidebar-content {
    padding: 16px 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.section-title {
    font-family: var(--font-titles);
    font-size: 1.1em;
    font-weight: 700;
    margin: 0 0 8px 0;
    color: var(--white);
    border-bottom: 2px solid var(--orange);
    padding-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: center;
}

.section-hint {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    margin: 0 0 8px 0;
    line-height: 1.2;
    text-align: center;
}

.layers-section {
    margin-bottom: 6px;
    flex-shrink: 0;
}

.layers-section.stats-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
}

.layers-section.stats-section .stats-cards {
    flex: 1;
    min-height: 0;
}

.cards-indicadores {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 12px;
    flex: 1;
    min-height: 180px;
    align-content: start;
}

.card-indicador {
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    border-left: 6px solid var(--orange);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.card-indicador:hover {
    background: var(--gray-light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.card-indicador.total { border-left-color: var(--purple-dark); }
.card-indicador.regularizados { border-left-color: #22c55e; }
.card-indicador.em-regularizacao { border-left-color: #facc15; }
.card-indicador.em-planejamento { border-left-color: var(--magenta); }
.card-indicador.paralisados { border-left-color: #ef4444; }
.card-indicador.area-risco { border-left-color: var(--orange); }

.card-indicador .card-icon {
    font-size: 1.07em;
    opacity: 0.9;
    text-align: center;
}

.card-indicador.total .card-icon { color: var(--purple-dark); }
.card-indicador.regularizados .card-icon { color: #4ade80; }
.card-indicador.em-regularizacao .card-icon { color: #facc15; }
.card-indicador.em-planejamento .card-icon { color: var(--magenta); }
.card-indicador.paralisados .card-icon { color: #f87171; }
.card-indicador.area-risco .card-icon { color: var(--orange); }

.card-indicador .card-numero {
    font-family: var(--font-titles);
    font-size: 1.2em;
    font-weight: 700;
    color: var(--black);
    line-height: 1.2;
    text-align: center;
    width: 100%;
}

.card-indicador .card-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    text-align: center;
    line-height: 1.1;
    width: 100%;
    color: var(--black);
    opacity: 0.8;
}

.legenda-cores {
    margin-top: 6px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px 10px;
    flex-shrink: 0;
}

.legenda-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.95);
}

.legenda-quadro {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.stat-card-tipologias .stat-tipologias-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    justify-content: center;
    align-items: center;
    font-size: 0.82em;
    line-height: 1.35;
    text-align: center;
}

.stat-card-tipologias .stat-tipologias-list.stat-empty { display: block; }

.stat-card-tipologias .tipologia-item {
    display: inline-block;
    background: rgba(93, 5, 140, 0.08);
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.stat-card-tipologias .tipologia-item strong { color: var(--purple-dark); }

/* ========== Map container ========== */
#map-container {
    flex: 1 1 0;
    min-height: 280px;
    position: relative;
    z-index: 1000;
    border-radius: var(--radius-md);
    margin: 6px 8px 8px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

#map-container .folium-map,
#map-container [id^="map_"],
#leaflet-map,
.sig-leaflet-map {
    flex: 1;
    min-height: 400px;
    width: 100%;
}

.sig-map-loading {
    position: absolute;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(2px);
}

.sig-map-loading__inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    font-weight: 600;
    color: var(--purple-dark, #5d058c);
}

.bairro-label-marker {
    background: transparent !important;
    border: none !important;
}

.leaflet-container {
    height: 100% !important;
    width: 100% !important;
    min-height: 400px;
    border-radius: var(--radius-md);
}

/* ========== Footer SIG ========== */
body.sig-body > .sig-footer {
    flex-shrink: 0;
    height: 32px;
    background: var(--black);
    border-top: 2px solid var(--orange);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1.5rem;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: var(--font-titles);
    letter-spacing: 0.05em;
}

.sig-footer a {
    color: var(--orange);
    text-decoration: none;
    margin-left: 0.4rem;
    font-weight: 600;
    transition: color var(--transition-fast);
}

.sig-footer a:hover { color: var(--magenta); text-decoration: underline; }

/* ========== Loading ========== */
.loading {
    display: none;
    text-align: center;
    padding: 30px;
    color: var(--white);
}

.spinner-border {
    width: 2rem;
    height: 2rem;
    border-width: 3px;
}

/* ========== Sidebar scrollbar ========== */
#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.1); border-radius: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.3); border-radius: 4px; transition: background 0.3s ease; }
#sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.5); }

/* ========== Responsive ========== */
@media (max-width: 1200px) {
    .sidebar-wrapper { width: 420px; min-width: 420px; }
}

@media (max-width: 1100px) {
    .filter-group { min-width: 140px; max-width: none; }
    .sidebar-wrapper { width: 380px; min-width: 380px; }
    .cards-indicadores,
    .stats-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    #main-content { flex-direction: column; }
    .sidebar-wrapper {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        max-height: 45vh;
    }
    .resize-handle { display: none; }
    .right-panel { flex: 1; min-height: 50vh; }
    .filter-group { min-width: 120px; max-width: none; }
    .filter-row { gap: 10px 14px; }
    .filter-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 700px) {
    #filter-bar { padding: 12px 14px; }
    .filter-container { gap: 12px; }
    .filter-row { flex-direction: column; align-items: stretch; gap: 12px; }
    .filter-group { min-width: 0; max-width: none; }
    .filter-group.filter-actions { flex-direction: column; align-items: stretch; }
    .filter-actions { flex-direction: column; gap: 10px; }
    .filter-actions .btn-group { width: 100%; justify-content: stretch; }
    .filter-actions .btn-group-primary,
    .filter-actions .btn-group-secondary { width: 100%; }
    .filter-actions .btn-group-primary .btn,
    .filter-actions .btn-group-secondary .btn { flex: 1; min-width: 0; }
    .filter-actions-divider { display: none; }
    .filter-title { font-size: 1em; }
    .filter-hint span { font-size: 0.8rem; }
    .sidebar-wrapper { max-height: 45vh; }
    #sidebar { overflow-y: auto; }
    .cards-indicadores,
    .stats-cards { grid-template-columns: repeat(2, 1fr); }
}
