* {
    box-sizing: border-box;
}

:root {
    --painel-largura: min(360px, 28vw);
    --map-surface: #0c1713;
    --map-panel: #17271f;
    --map-text: #eef3e9;
    --map-muted: #b0bfb4;
    --map-accent: #b5cd87;
    --map-line: #304238;
    color-scheme: dark;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #050806;
    color: var(--map-text);
    font-family: "Segoe UI", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--map-accent); outline-offset: 3px; }

#map-stage {
    position: relative;
    width: calc(100% - var(--painel-largura) - var(--painel-largura));
    height: 100vh;
    margin: 0 var(--painel-largura);
}

#map-stage:fullscreen {
    width: 100%;
    height: 100%;
    margin: 0;
    background: #000;
}

#map {
    width: 100%;
    height: 100%;
    background-color: #000;
}

#status-mapa[hidden], #repetir-camadas[hidden] { display: none; }
.status-mapa {
    position: absolute;
    bottom: 78px;
    left: 50%;
    z-index: 1000;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: max-content;
    max-width: calc(100% - 32px);
    transform: translateX(-50%);
    padding: 10px 14px;
    border: 1px solid var(--map-line);
    border-radius: 7px;
    background: var(--map-surface);
    color: var(--map-text);
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    box-shadow: 0 4px 18px #0003;
}
.status-mapa.com-erro { border-color: #b89b58; color: #f2d78a; }
#repetir-camadas { border: 0; padding: 3px 8px; border-radius: 4px; background: var(--map-accent); color: #14241b; cursor: pointer; font-size: 12px; }

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    width: var(--painel-largura);
    max-width: calc(100vw - 24px);
    height: 100vh;
    background: var(--map-surface);
    border-right: 1px solid rgba(199, 223, 170, 0.14);
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.18);
    transform: none;
}

.painel-info {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    width: var(--painel-largura);
    max-width: calc(100vw - 24px);
    height: 100vh;
    background: var(--map-surface);
    border-left: 1px solid rgba(199, 223, 170, 0.14);
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.18);
    transform: none;
}

.painel-info.aberto {
    transform: translateX(0);
}

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

.sidebar-header,
.painel-info-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 22px 16px;
    border-bottom: 1px solid rgba(199, 223, 170, 0.12);
}

.painel-info-header {
    padding-bottom: 18px;
}

.sidebar-kicker {
    display: block;
    margin-bottom: 5px;
    color: var(--map-accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
}

.sidebar h1,
.sidebar h2,
.painel-info h2 {
    margin: 0;
    color: var(--map-text);
}

.sidebar h1 {
    font-size: 20px;
    line-height: 1.2;
}

.sidebar h2 {
    margin-bottom: 8px;
    font-size: 15px;
}

.sidebar p,
.painel-info p {
    margin: 0;
    color: var(--map-muted);
    font-size: 13px;
    line-height: 1.6;
}

#btn-sidebar,
#btn-info,
#btn-fechar-sidebar,
#btn-fechar-info {
    border: 1px solid rgba(199, 223, 170, 0.18);
    background: var(--map-surface);
    color: var(--map-text);
    cursor: pointer;
    font-family: inherit;
}

#btn-sidebar,
#btn-info {
    position: fixed;
    top: 15px;
    z-index: 1250;
    width: 42px;
    height: 42px;
    border-radius: 7px;
    font-size: 20px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

#btn-sidebar {
    left: 15px;
    display: none;
}

#btn-info {
    right: 15px;
    display: none;
}

#btn-sidebar.oculto,
#btn-info.oculto {
    display: none;
}

#btn-fechar-sidebar,
#btn-fechar-info {
    display: none;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 6px;
    font-size: 24px;
    line-height: 1;
}

#btn-sidebar:hover,
#btn-info:hover,
#btn-fechar-sidebar:hover,
#btn-fechar-info:hover {
    border-color: rgba(143, 188, 114, 0.46);
    background: rgba(32, 50, 38, 0.98);
}

.sidebar-conteudo,
.painel-info-conteudo {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px 22px;
    scrollbar-width: thin;
    scrollbar-color: #425c4b var(--map-surface);
}

.painel-bloco,
.camada-bloco {
    margin-bottom: 16px;
    padding: 16px;
    background: var(--map-panel);
    border: 1px solid rgba(199, 223, 170, 0.12);
    border-radius: 8px;
}

.camada-bloco { transition: border-color .18s ease, background-color .18s ease; }
.camada-bloco:has(input[type="checkbox"]:checked) { border-color: #526b46; }
.camada-bloco:has(input[type="checkbox"]:checked) .camada-principal label { color: #d9e8bf; }
.camada-linha:has(input:checked) label { color: var(--map-text); }
.camada-linha:hover label { color: var(--map-accent); }
.camada-linha label { cursor: pointer; line-height: 1.5; }

.camada-linha {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 8px;
}

.camada-principal {
    margin-bottom: 10px;
}

.seletor-ano-mapa {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    margin: 4px 0 12px;
}

.seletor-ano-mapa label {
    color: rgba(245, 241, 232, 0.58);
    font-size: 13px;
}

.seletor-ano-mapa select {
    min-width: 92px;
    padding: 7px 10px;
    border: 1px solid rgba(199, 223, 170, 0.16);
    border-radius: 6px;
    background: rgba(8, 16, 12, 0.92);
    color: #e8eadf;
    font-family: inherit;
    font-size: 13px;
}

.seletor-ano-mapa select:focus {
    border-color: var(--map-accent);
}

.camada-linha label {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
    color: rgba(245, 241, 232, 0.78);
    font-size: 13px;
}

.camada-linha input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin: 0;
    cursor: pointer;
    accent-color: var(--map-accent);
}

.camada-bloco input[type="range"] {
    width: 100%;
    height: 20px;
    margin: 5px 0;
    cursor: pointer;
    accent-color: var(--map-accent);
}

.val-opacidade {
    min-width: 34px;
    color: var(--map-muted);
    font-size: 12px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.subclasses-bloco {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(199, 223, 170, 0.1);
}

.camada-linha.sub {
    min-height: 30px;
    margin-bottom: 4px;
}

.camada-linha.sub label {
    color: rgba(245, 241, 232, 0.7);
    font-size: 13px;
}

.legenda-cor {
    display: inline-block;
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 4px;
}

.classe-urbano { background: rgb(255, 0, 0); }
.classe-vegdensa { background: rgb(38, 115, 0); }
.classe-vegesparsa { background: rgb(133, 199, 126); }
.classe-agricultura { background: rgb(255, 255, 0); }
.classe-rochosa { background: rgb(128, 128, 128); }
.classe-soloexposto { background: rgb(139, 69, 19); }
.classe-agua { background: rgb(84, 117, 168); }
.camada-rodovia-federal { background: rgb(255, 90, 50); }
.camada-rodovia-estadual { background: rgb(255, 180, 70); }
.camada-hidrografia { background: rgb(70, 170, 255); }
.camada-app { background: rgb(68, 190, 210); }
.camada-uc-federal { background: rgb(90, 150, 255); }
.camada-uc-estadual { background: rgb(166, 110, 255); }
.camada-uc-municipal { background: rgb(255, 120, 190); }

.produto-complementar { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--map-line); }
.produto-complementar h3 { margin: 0 0 8px; color: var(--map-accent); font-size: 12px; font-weight: 600; }
.sidebar p.camada-nota { margin: 10px 0; font-size: 12px; line-height: 1.55; }
.legenda-cor.legenda-poligono { border: 2px solid var(--cor-camada); background: color-mix(in srgb, var(--cor-camada) 20%, transparent); border-radius: 3px; }
.legenda-ponto { border-radius: 50%; background: var(--cor-camada); }
.camada-vegetacao { --cor-camada: #40966b; }
.camada-geomorfologia { --cor-camada: #bf936b; }
.camada-pedologia { --cor-camada: #d5b477; }
.camada-cofau-apa { --cor-camada: #f2b84b; }
.camada-cofau-entorno { --cor-camada: #ed7850; }
.camada-sibbr { --cor-camada: #c28be0; }
.camada-flora { --cor-camada: #79c65b; }
.camada-uc-federal { --cor-camada: #5a96ff; }
.camada-uc-estadual { --cor-camada: #a66eff; }
.camada-uc-municipal { --cor-camada: #ff78be; }
.camada-app { --cor-camada: #44bed2; }
.camada-app-nascentes { --cor-camada: #6ed6b5; }
.camada-app-declividade { --cor-camada: #68b9a0; }
.camada-rppn { --cor-camada: #c8db56; }
.camada-distritos { --cor-camada: #e1c66f; }
.camada-municipios { --cor-camada: #dfecdf; }
.camada-estrutura { --cor-camada: #f1a97c; }
.camada-quilombo { --cor-camada: #d485ba; }
.camada-zoneamento { --cor-camada: #87b6e8; }
.camada-car { --cor-camada: #e4c169; }
.camada-mineracao { --cor-camada: #db7770; }

#btn-home,
#barra-busca button {
    border: 1px solid rgba(199, 223, 170, 0.18);
    border-radius: 7px;
    background: rgba(199, 223, 170, 0.08);
    color: #dce9ca;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

#acoes-mapa {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 1300;
    display: flex;
    flex-direction: row;
    gap: 10px;
    transform: translateX(-50%);
}

.btn-acao-mapa {
    width: 42px;
    height: 42px;
    border: 1px solid rgba(199, 223, 170, 0.18);
    border-radius: 7px;
    background: var(--map-surface);
    color: var(--map-text);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    font-family: inherit;
    font-size: 21px;
    line-height: 1;
}

.btn-acao-mapa:hover {
    border-color: rgba(143, 188, 114, 0.46);
    background: rgba(32, 50, 38, 0.98);
    color: #fff;
}

#btn-home {
    width: 100%;
    padding: 12px;
}

#btn-home:hover,
#barra-busca button:hover {
    border-color: rgba(143, 188, 114, 0.5);
    background: rgba(143, 188, 114, 0.18);
    color: #fff;
}

.chart-container {
    width: 100%;
    margin: 14px 0 18px;
    padding: 16px;
    background: var(--map-panel);
    border: 1px solid rgba(199, 223, 170, 0.12);
    border-radius: 8px;
}

.painel-info .chart-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--map-text); font-size: 13px; font-weight: 600; }
.chart-heading span { color: var(--map-accent); font-size: 11px; font-weight: 400; }
.chart-visual { position: relative; height: 310px; margin-top: 10px; }
.painel-info .chart-note { padding-top: 12px; margin-top: 8px; border-top: 1px solid var(--map-line); font-size: 12px; color: var(--map-muted); }

.creditos-bloco {
    margin-top: 18px;
}

.stats-resumo {
    margin-top: 10px;
    color: rgba(245, 241, 232, 0.74);
    font-size: 13px;
    line-height: 1.7;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    background: var(--map-panel);
    border: 1px solid rgba(199, 223, 170, 0.12);
    border-radius: 8px;
    font-size: 13px;
}

.stats-table th,
.stats-table td {
    padding: 9px 10px;
    border-bottom: 1px solid rgba(199, 223, 170, 0.08);
    text-align: left;
}

.stats-table th:not(:first-child),
.stats-table td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table tbody tr:hover { background: #b5cd870a; }

.stats-table th {
    color: var(--map-muted);
    font-size: 12px;
    text-transform: uppercase;
}

.stats-table td {
    color: rgba(245, 241, 232, 0.78);
}

.stats-table tr:last-child td {
    border-bottom: 0;
}

.legenda-limite { display: flex; align-items: center; gap: 9px; margin-top: 12px; font-size: 13px; }
.sidebar p.legenda-limite { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--map-line); color: #e2cd98; font-size: 12px; }
.limite-amostra { flex: 0 0 22px; border-top: 2px solid #f2d78a; }

.creditos-corpo {
    padding-top: 12px;
    text-align: center;
}

.creditos-logo-selo {
    box-sizing: border-box;
    display: inline-grid;
    place-items: center;
    width: 76px;
    height: 76px;
    margin: 8px;
    padding: 8px;
    background: #fff;
    border-radius: 50%;
    overflow: hidden;
    vertical-align: middle;
}

.creditos-logo-selo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.creditos-corpo p {
    margin-top: 12px;
}

#barra-busca {
    position: absolute;
    top: 15px;
    left: 50%;
    z-index: 1000;
    display: flex;
    gap: 6px;
    width: min(430px, calc(100vw - var(--painel-largura) - var(--painel-largura) - 60px));
    min-width: 300px;
    padding: 8px;
    transform: translateX(-50%);
    background: var(--map-surface);
    border: 1px solid rgba(199, 223, 170, 0.14);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

#barra-busca input {
    min-width: 0;
    width: 100%;
    padding: 8px 10px;
    background: rgba(8, 16, 12, 0.92);
    border: 1px solid rgba(199, 223, 170, 0.16);
    border-radius: 6px;
    color: #e8eadf;
    font-family: inherit;
    font-size: 13px;
}

#barra-busca input::placeholder {
    color: #99aa9e;
}

#barra-busca input:focus {
    border-color: var(--map-accent);
}

#barra-busca button {
    padding: 8px 14px;
    background: var(--map-accent);
    color: #14241b;
    border-color: var(--map-accent);
}

#barra-busca button:hover { background: #ccdfa9; color: #14241b; }
#barra-busca:focus-within { border-color: #779b63; }

.leaflet-control-scale-line {
    background: var(--map-surface);
    border-color: rgba(199, 223, 170, 0.24);
    color: #dce9ca;
    font-size: 12px;
}

.coordenadas-cursor {
    padding: 8px 10px;
    border: 1px solid var(--map-line);
    border-radius: 6px;
    background: var(--map-surface);
    color: var(--map-text);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
    white-space: nowrap;
    pointer-events: none;
}

.leaflet-control-zoom {
    border: 0 !important;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.32);
}

.leaflet-control-zoom a {
    background: var(--map-surface) !important;
    border-color: rgba(199, 223, 170, 0.18) !important;
    color: var(--map-text) !important;
}

.leaflet-control-zoom a:hover {
    background: rgba(32, 50, 38, 0.98) !important;
    color: #fff !important;
}

.leaflet-control-zoom { border-radius: 7px; overflow: hidden; }
.leaflet-control-zoom a { width: 36px; height: 36px; line-height: 36px; }
.leaflet-bottom.leaflet-right { max-width: calc(100% - 20px); }
.leaflet-control-attribution { max-width: 100%; white-space: normal; background: #0c1713e8 !important; color: var(--map-muted); }
.leaflet-control-attribution a { color: var(--map-accent); }

@media (min-width: 900px) {
    .leaflet-left {
        left: 0;
    }
}

@media (min-width: 900px) and (max-width: 1100px) {
    .stats-table th, .stats-table td { padding: 9px 5px; }
}

#ferramentas-mobile { display: none; }

@media (max-width: 899px) {
    .status-mapa { bottom: 132px; }
    .leaflet-bottom .coordenadas-cursor { margin-bottom: 82px; font-size: 11px; }
    body {
        overflow-y: auto;
    }

    #map-stage {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        margin: 0;
    }

    #btn-sidebar {
        top: 10px;
        left: 10px;
        display: block;
        width: auto;
        min-height: 44px;
        height: auto;
        padding: 10px 14px;
        font-size: 15px;
    }

    #btn-info,
    #btn-info.oculto {
        position: static;
        display: none;
    }

    #acoes-mapa {
        position: static;
        transform: none;
    }

    #map-stage:fullscreen #acoes-mapa {
        position: absolute;
        top: max(10px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
        bottom: auto;
        left: auto;
    }

    #ferramentas-mobile { display: block; }
    #ferramentas-mobile > label { display: block; font-size: 13px; line-height: 1.5; }
    #acoes-mobile { display: grid; gap: 8px; margin-top: 12px; }
    #acoes-mobile #acoes-mapa { display: block; }
    #acoes-mobile #btn-info,
    #acoes-mobile #btn-info.oculto,
    #acoes-mobile .btn-acao-mapa {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 44px;
        height: auto;
        padding: 10px 12px;
        box-shadow: none;
        text-align: left;
    }
    #acoes-mobile #btn-info::after { content: 'Informações e estatísticas'; font-size: 13px; }
    #acoes-mobile #btn-fullscreen::after { content: 'Tela cheia'; font-size: 13px; }

    .sidebar {
        width: min(360px, 92vw);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        height: 100dvh;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

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

    #btn-fechar-sidebar {
        display: block;
        width: 44px;
        height: 44px;
    }

    .painel-info {
        position: static;
        width: 100%;
        max-width: none;
        height: auto;
        min-height: 0;
        border-top: 1px solid rgba(199, 223, 170, 0.14);
        border-left: 0;
        box-shadow: none;
        transform: none;
    }

    .painel-info-header {
        padding: 14px 16px 10px;
    }

    .painel-info-conteudo {
        overflow: visible;
        padding: 12px 14px 18px;
    }

    #btn-fechar-info {
        display: none;
    }

    #barra-busca {
        position: static;
        flex-direction: column;
        width: 100%;
        min-width: 0;
        margin-top: 10px;
        padding: 0;
        border: 0;
        box-shadow: none;
        background: transparent;
        transform: none;
    }

    #barra-busca input { min-height: 44px; font-size: 16px; }
    #barra-busca button { min-height: 44px; }

    .sidebar-conteudo {
        padding-bottom: 28px;
    }

    .chart-visual { height: 300px; }

    .leaflet-top.leaflet-left {
        top: 64px;
    }
}

@media (max-width: 420px) {
    .sidebar-header {
        padding: 18px 16px 14px;
    }

    .sidebar-conteudo {
        padding: 14px;
    }

    #barra-busca {
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
