html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
    background: #0b1220;
}

body.modal-open {
    overflow: hidden;
}

body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-shell {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

#map {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.topbar {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 24px;
    color: #fff;
    background: linear-gradient(135deg, rgba(6, 14, 33, 0.96), rgba(27, 46, 86, 0.95));
    box-shadow: 0 12px 30px rgba(0,0,0,0.26);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.brand-badge {
    min-width: 54px;
    text-align: center;
    padding: 10px 0;
    border-radius: 18px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.6px;
    background: rgba(79, 124, 255, 0.14);
    border: 1px solid rgba(121, 156, 255, 0.40);
}

.brand-copy h1 {
    margin: 0 0 3px;
    font-size: 18px;
    line-height: 1.1;
}

.brand-copy p {
    margin: 0;
    font-size: 12px;
    color: rgba(226, 232, 240, 0.82);
}

.menu-toggle {
    display: none;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
}

.top-menu {
    display: flex;
    align-items: center;
    gap: 10px;
}

.top-btn,
.top-btn:visited {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #fff;
    white-space: nowrap;
    padding: 12px 16px;
    border-radius: 18px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.legend-box {
    position: absolute;
    top: 100px;
    right: 12px;
    z-index: 1100;
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 18px;
    color: #fff;
    background: rgba(8, 19, 45, 0.92);
    box-shadow: 0 10px 24px rgba(0,0,0,0.22);
    font-size: 12px;
    font-weight: 700;
}

.legend-box span {
    display: inline-flex;
    align-items: center;
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    margin-right: 8px;
}

.dot-inst { background: #4f7cff; }
.dot-user { background: #10b981; }

.toast-status {
    position: absolute;
    left: 16px;
    bottom: 20px;
    z-index: 1100;
    max-width: min(420px, calc(100vw - 32px));
    padding: 14px 18px;
    border-radius: 20px;
    color: #fff;
    background: rgba(8, 19, 45, 0.92);
    box-shadow: 0 10px 24px rgba(0,0,0,0.22);
    font-size: 14px;
    font-weight: 700;
}

.toast-status.error {
    background: rgba(127, 29, 29, 0.94);
}

.search-modal {
    position: absolute;
    inset: 0;
    z-index: 1400;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 86px 16px 16px;
    background: rgba(2, 6, 23, 0.45);
    backdrop-filter: blur(4px);
}

.search-modal.hidden {
    display: none;
}

.search-panel {
    width: min(520px, 100%);
    max-height: calc(100vh - 120px);
    overflow: auto;
    border-radius: 26px;
    padding: 22px;
    background: linear-gradient(180deg, #07142f, #10244b);
    color: #fff;
    box-shadow: 0 18px 50px rgba(0,0,0,0.35);
}

.search-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.eyebrow {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.6px;
    margin-bottom: 14px;
    background: rgba(79, 124, 255, 0.16);
    border: 1px solid rgba(79, 124, 255, 0.42);
}

.search-panel h2 {
    margin: 0;
    font-size: 22px;
}

.close-btn {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 12px;
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
}

.field {
    margin-top: 16px;
}

.field label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 700;
}

.field input,
.field select {
    width: 100%;
    box-sizing: border-box;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-size: 15px;
    outline: none;
}

.actions-row {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.btn-primary,
.btn-secondary {
    border: 0;
    border-radius: 16px;
    padding: 14px 18px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.btn-primary {
    background: #5b7cff;
    color: #fff;
}

.btn-secondary {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.results-meta {
    margin-top: 18px;
    font-size: 14px;
    font-weight: 700;
}

.results-list {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}

.result-item {
    width: 100%;
    text-align: left;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.10);
    background: rgba(255,255,255,0.06);
    color: #fff;
    cursor: pointer;
}

.result-item strong {
    display: block;
    margin-bottom: 6px;
    font-size: 15px;
}

.result-item span {
    color: rgba(226, 232, 240, 0.85);
    font-size: 13px;
}

.custom-div-icon {
    background: transparent;
    border: 0;
}

.map-pin {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: #4f7cff;
    border: 3px solid #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}

.user-pin {
    background: #10b981;
}

.popup-card {
    min-width: 220px;
    max-width: 250px;
}

.popup-title {
    margin-bottom: 8px;
    color: #0f172a;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
}

.popup-line {
    margin-bottom: 6px;
    color: #334155;
    font-size: 13px;
    line-height: 1.45;
}

.popup-line strong {
    color: #0f172a;
}

.popup-line.subtle {
    color: #475569;
}

.popup-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.mini-btn {
    flex: 1;
    padding: 10px 12px;
    border-radius: 12px;
    text-align: center;
    text-decoration: none;
    color: #0f172a;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    font-size: 13px;
    font-weight: 700;
}

.leaflet-popup-content-wrapper {
    border-radius: 18px;
}

.leaflet-popup-content {
    margin: 14px;
}

.leaflet-right {
    right: 16px;
}

.leaflet-top.leaflet-right {
    top: 50%;
    transform: translateY(-50%);
}

.leaflet-control-zoom {
    border: 0 !important;
    box-shadow: 0 10px 24px rgba(0,0,0,0.22) !important;
    border-radius: 16px !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    width: 42px !important;
    height: 42px !important;
    line-height: 42px !important;
    font-size: 22px !important;
}

@media (max-width: 900px) {
    .topbar {
        padding: 10px 12px;
    }

    .brand-copy h1 {
        font-size: 16px;
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .top-menu {
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        left: 0;
        display: none;
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
        border-radius: 20px;
        background: linear-gradient(135deg, rgba(6, 14, 33, 0.98), rgba(27, 46, 86, 0.98));
        box-shadow: 0 12px 30px rgba(0,0,0,0.26);
    }

    .top-menu.open {
        display: flex;
    }

    .top-btn {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
    }

    .legend-box {
        top: auto;
        left: 12px;
        right: 12px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 72px);
        justify-content: center;
        padding: 9px 12px;
        gap: 10px;
        border-radius: 16px;
        font-size: 11px;
        max-width: calc(100vw - 24px);
        box-sizing: border-box;
    }

    .search-modal {
        padding-top: 74px;
    }

    .leaflet-top.leaflet-right {
        top: auto;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 132px);
        transform: none;
    }

    .leaflet-right {
        right: 12px;
    }
}

@media (max-width: 560px) {
    .brand-badge {
        min-width: 46px;
        padding: 8px 0;
        font-size: 11px;
    }

    .brand-copy p {
        display: none;
    }

    .legend-box {
        top: auto;
        left: 10px;
        right: 10px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);
        padding: 8px 10px;
        gap: 8px;
        font-size: 10px;
        max-width: calc(100vw - 20px);
        overflow: hidden;
    }

    .legend-box span {
        min-width: 0;
        white-space: nowrap;
    }

    .dot {
        width: 8px;
        height: 8px;
        margin-right: 6px;
        flex: 0 0 auto;
    }

    .toast-status {
        font-size: 13px;
        padding: 12px 14px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    }

    .leaflet-control-zoom a {
        width: 40px !important;
        height: 40px !important;
        line-height: 40px !important;
    }
}


/* Ajuste extra para garantir legenda visível no mobile */
@media (max-width: 900px) {
    .legend-box {
        position: absolute !important;
        display: inline-flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        z-index: 1300 !important;
        top: auto !important;
        left: 12px !important;
        right: 12px !important;
        bottom: 104px !important;
        width: auto !important;
        max-width: calc(100vw - 24px) !important;
        box-sizing: border-box !important;
        justify-content: center !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        overflow: hidden !important;
        white-space: nowrap !important;
        padding: 10px 12px !important;
        border-radius: 16px !important;
        gap: 12px !important;
        font-size: 11px !important;
    }

    .legend-box span {
        display: inline-flex !important;
        align-items: center !important;
        min-width: 0 !important;
        flex: 0 1 auto !important;
    }

    .toast-status {
        bottom: 16px !important;
        max-width: calc(100vw - 32px) !important;
        z-index: 1250 !important;
    }

    .leaflet-top.leaflet-right {
        top: auto !important;
        bottom: 166px !important;
        transform: none !important;
    }
}

@media (max-width: 560px) {
    .legend-box {
        left: 10px !important;
        right: 10px !important;
        bottom: 108px !important;
        max-width: calc(100vw - 20px) !important;
        padding: 9px 10px !important;
        gap: 10px !important;
        font-size: 10px !important;
    }

    .legend-box span {
        max-width: 48% !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .toast-status {
        bottom: 14px !important;
    }

    .leaflet-top.leaflet-right {
        bottom: 168px !important;
    }
}

/* iPhone com barra inferior maior */
@supports (padding: max(0px)) {
    @media (max-width: 900px) {
        .legend-box {
            bottom: max(104px, calc(env(safe-area-inset-bottom, 0px) + 76px)) !important;
        }

        .toast-status {
            bottom: max(14px, env(safe-area-inset-bottom, 0px)) !important;
        }

        .leaflet-top.leaflet-right {
            bottom: max(166px, calc(env(safe-area-inset-bottom, 0px) + 138px)) !important;
        }
    }

    @media (max-width: 560px) {
        .legend-box {
            bottom: max(108px, calc(env(safe-area-inset-bottom, 0px) + 80px)) !important;
        }

        .leaflet-top.leaflet-right {
            bottom: max(168px, calc(env(safe-area-inset-bottom, 0px) + 140px)) !important;
        }
    }
}
