/* CSS Custom Properties */
:root {
    --primary-color: #1e293b;
    --secondary-color: #3b82f6;
    --accent-color: #10b981;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #ffffff;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --sidebar-width: 320px;
    --header-height: 60px;
    --footer-height: 50px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Layout Principal */
body {
    display: grid;
    grid-template-areas: 
        "header header"
        "sidebar main"
        "footer footer";
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr var(--footer-height);
    min-height: 100vh;
}

/* Header */
.header {
    grid-area: header;
    background: linear-gradient(135deg, var(--primary-color) 0%, #334155 100%);
    color: var(--text-light);
    box-shadow: var(--shadow-md);
    z-index: 1000;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 1.5rem;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
    z-index: 1017;	
    transition: var(--transition-fast);
}

.sidebar-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.header-title {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-title i {
    color: var(--accent-color);
}

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

.header-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.425rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: var(--transition-fast);
}

.header-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    background-color: var(--primary-color);
    color: var(--text-light);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 999;
    transition: transform var(--transition-normal);
}

.sidebar-content {
    padding: 1.5rem 0;
}

/* Seções do Sidebar */
.sidebar-section {
    margin-bottom: 1.5rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background-color: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: var(--transition-fast);
}

.section-header:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.section-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-toggle {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.section-toggle.rotated {
    transform: rotate(180deg);
}

.section-content {
    padding: 0.5rem 0;
    max-height: 500px;
    overflow: hidden;
    transition: max-height var(--transition-normal);
}

.section-content.collapsed {
    max-height: 0;
    padding: 0;
}

/* Itens de Camada */
.layer-item {
    padding: 0.5rem 1.5rem;
    transition: var(--transition-fast);
}

.layer-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.layer-item input[type="radio"] {
    display: none;
}

.layer-item label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: var(--transition-fast);
}

.layer-item input[type="radio"]:checked + label {
    background-color: var(--secondary-color);
    color: var(--text-light);
}

/* Overlays */
.overlay-item {
    margin-bottom: 0.75rem;
}

.overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
    transition: var(--transition-fast);
}

.overlay-header:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.overlay-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.overlay-control input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent-color);
}

.overlay-control label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.overlay-actions {
    display: flex;
    gap: 0.25rem;
}

.download-btn, .opacity-btn {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: var(--transition-fast);
    opacity: 0.7;
}

.download-btn:hover, .opacity-btn:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Controle de Opacidade */
.opacity-control {
    padding: 0.5rem 1.5rem;
    background-color: rgba(255, 255, 255, 0.05);
    display: none;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.75rem;
}

.opacity-control.active {
    display: flex;
}

.opacity-slider {
    flex: 1;
    height: 0.25rem;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 0.125rem;
    outline: none;
    cursor: pointer;
}

.opacity-slider::-webkit-slider-thumb {
    appearance: none;
    width: 1rem;
    height: 1rem;
    background-color: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
}

.opacity-value {
    min-width: 2.5rem;
    text-align: right;
    font-weight: 500;
}


.layer-item input[type="radio"]:checked + label {
    background-color: var(--secondary-color);
    color: var(--text-light);
}

/* Ferramentas */
.tool-item {
    padding: 0.25rem 1.5rem;
}

.tool-btn {
    width: 100%;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0);
    color: var(--text-light);
    padding: 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: var(--transition-fast);
}

.tool-btn:hover {
    background-color: var(--secondary-color);
    border-color: #6b7280;
}

.tool-btn.active {
    background-color: var(--secondary-color);
}

/* Área Principal */
.main-content {
    grid-area: main;
    position: relative;
    overflow: hidden;
}

/* Mapa */
#map {
    width: 100%;
    height: calc(100vh - var(--header-height) - var(--footer-height));
    background-color: var(--surface-color);
}

/* Status Bar */
.status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: var(--text-light);
    padding: 0.5rem 1rem;
    display: flex;
    gap: 2rem;
    font-size: 0.75rem;
    z-index: 1000;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-item i {
    color: var(--accent-color);
}

/* Footer */
.footer {
    grid-area: footer;
    background-color: var(--primary-color);
    color: var(--text-light);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
}

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

.footer-info {
    display: flex;
    gap: 1rem;
}

.footer-tech {
    color: var(--accent-color);
    font-weight: 500;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-light);
}

.loading-spinner i {
    font-size: 2rem;
    color: var(--accent-color);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background-color: var(--surface-color);
    color: var(--text-primary);
    padding: 1rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--accent-color);
    min-width: 300px;
    animation: slideInRight var(--transition-normal);
}

.toast.error {
    border-left-color: #ef4444;
}

.toast.warning {
    border-left-color: #f59e0b;
}

.toast.success {
    border-left-color: var(--accent-color);
}

/* Animações */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

/* Customização do Leaflet */
.leaflet-control-container {
    display: none;
}

.leaflet-popup-content-wrapper {
    background-color: var(--surface-color);
    color: var(--text-primary);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-tip {
    background-color: var(--surface-color);
}

/* Responsividade */
/* Responsividade para telas até 1080px */
@media (max-width: 1080px) {
    body {
        grid-template-areas: 
            "header header"
            "sidebar main"
            "footer footer";
        grid-template-columns: var(--sidebar-width) 1fr;
        grid-template-rows: var(--header-height) 1fr var(--footer-height);
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar {
        position: relative;
        transform: translateX(0);
        z-index: 1001;
    }

    .header-title {
        font-size: 1.5rem;
    }

    .footer-content {
        flex-direction: row;
        gap: 0.5rem;
        text-align: left;
    }

    .status-bar {
        flex-direction: row;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
    }

    .toast {
        min-width: 80vw;
    }
}

@media (max-width: 768px) {
    body {
        grid-template-areas: 
            "header"
            "main"
            "footer";
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-height) 1fr var(--footer-height);
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: var(--footer-height);
        width: var(--sidebar-width);
        transform: translateX(-100%);
        z-index: 1001;
    }

    .sidebar.open {
        transform: translateX(0);
    }

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

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

    .status-bar {
        flex-direction: flex;
        gap: 0.25rem;
        padding: 0.25rem 0.5rem;
    }

    .toast {
        min-width: calc(100vw - 2rem);
    }
}

/* CORREÇÃO PRINCIPAL PARA DISPOSITIVOS MÓVEIS */
@media (max-width: 480px) {
    :root {
        --sidebar-width: 280px;
        --status-bar-height: 35px;
    }

    body {
        min-height: 100dvh;
        overflow-x: hidden;
    }

    /* Correção do container principal */
    .main-content {
        padding-bottom: calc(var(--footer-height) + var(--status-bar-height));
    }

    /* Ajuste da altura do mapa */
    #map {
        height: calc(100dvh - var(--header-height) - var(--footer-height) - var(--status-bar-height));
    }

    /* Posicionamento correto do MiniMap do Leaflet */
    .leaflet-control-minimap {
        position: absolute !important;
        bottom: calc(var(--footer-height) + var(--status-bar-height) - 90px) !important;
        right: 10px !important;
        z-index: 1002 !important;
        transform: scale(0.85) !important;
        transform-origin: bottom right !important;
        width: 140px !important;
        height: 140px !important;
    }

    /* Posicionamento correto da Escala do Leaflet */
    .leaflet-control-scale {
        position: absolute !important;
        bottom: calc(var(--footer-height) + var(--status-bar-height) - 85px) !important;
        left: 10px !important;
        z-index: 1002 !important;
        background-color: rgba(255, 255, 255, 0.95) !important;
        padding: 4px 6px !important;
        border-radius: 4px !important;
        font-size: 10px !important;
        box-shadow: var(--shadow-md) !important;
        border: 1px solid rgba(0, 0, 0, 0.1) !important;
    }

    /* Garantir que os controles Leaflet sejam visíveis */
    .leaflet-control-container {
        display: block !important;
    }

    /* Ajustes do header para mobile */
    .header-content {
        padding: 0 1rem;
    }

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

    .header-actions {
        gap: 0.25rem;
    }

    .header-btn {
        font-size: 1rem;
        padding: 0.25rem 0.4rem;
    }

    .header-btn i {
        font-size: 1rem;
    }

    /* Ocultar botões de zoom no mobile (usar gestos) */
    #zoomInBtn,
    #zoomOutBtn {
        display: none;
    }

    /* Sidebar mobile */
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: var(--footer-height);
        width: var(--sidebar-width);
        transform: translateX(-100%);
        z-index: 1001;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Footer mobile */
    .footer {
        grid-area: footer;
        height: var(--footer-height);
        background: var(--primary-color);
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 0.75rem;
        padding: 0.5rem;
        position: relative;
    }

    /* Status bar mobile */
    .status-bar {
        height: var(--status-bar-height);
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
        gap: 1rem;
    }
}

/* Responsividade para telas até 320px */
@media (max-width: 320px) {
    body {
        grid-template-areas: 
            "header"
            "main"
            "footer";
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-height) 1fr var(--footer-height);
        font-size: 0.85rem;
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: var(--footer-height);
        width: 100vw; /* ocupa a largura toda */
        transform: translateX(-100%);
        z-index: 1001;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .header-title {
        font-size: 1rem;
        text-align: center;
    }

    .footer-content,
    .status-bar {
        flex-direction: column;
        gap: 0.25rem;
        text-align: center;
    }

    .toast {
        min-width: 100%;
        font-size: 0.75rem;
        padding: 0.5rem;
    }

    img,
    video,
    iframe {
        max-width: 100%;
        height: auto;
    }

    button,
    input,
    select {
        font-size: 0.85rem;
        width: 100%;
    }

    /* Ajustes específicos para telas muito pequenas */
    .leaflet-control-minimap {
        width: 120px !important;
        height: 120px !important;
        transform: scale(0.75) !important;
    }

    .leaflet-control-scale {
        font-size: 9px !important;
        padding: 3px 5px !important;
    }
}


/* Estados de Hover e Focus */
button:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

input:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Scrollbar Customizada */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Minimapa e Escala */
.leaflet-control-minimap {
  overflow: hidden !important;
  border-radius: 50% !important;
  width: 160px !important;
  height: 160px !important;
  bottom: 30px;
  border: 3px solid var(--secondary-color);
  box-shadow: var(--shadow);
}

.leaflet-control-minimap .leaflet-container {
  border-radius: 50%;
  width: 100% !important;
  height: 100% !important;
}

.leaflet-control-scale {
  background-color: rgba(255, 255, 255, 0.9);
  padding: 1px 3px;
  border-radius: 5%;
  bottom: 30px;
  font-size: 11px;
  box-shadow: var(--shadow);
  border: none;
}

/* Ativar controles Leaflet */
.leaflet-control-container {
    display: block !important;
}

/* Legendas */

.map-legend {
    position: absolute;
    bottom: 90px; /* acima da escala e do status */
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid #ccc;
    border-radius: 5%;
    padding: 8px;
    z-index: 1002;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    max-width: 200px;
}

.map-legend img {
    max-width: 100%;
    height: auto;
}



