/* ============================================================
   PUBLIC MAP — AP Mapping (halaman publik, tanpa login)
   ============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: #070b14;
    color: #e2e8f0;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

#map {
    position: absolute;
    inset: 0;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(14px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) 14px calc(20px + env(safe-area-inset-left));
    background: linear-gradient(180deg, rgba(7, 11, 20, 0.92) 0%, rgba(7, 11, 20, 0) 100%);
    pointer-events: none;
}

.topbar > * {
    pointer-events: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand img {
    height: 34px;
    width: auto;
}

.brand-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: #5a6e8a;
}

.btn-login {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    background: #0d1424;
    border: 1px solid #1c2b45;
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: border-color .2s, background .2s;
}

.btn-login:hover {
    border-color: #06b6d4;
    background: #131d30;
}

.btn-login i {
    color: #a1fd0b;
}

.btn-login {
    touch-action: manipulation;
}

/* ── Stats pill bar ──────────────────────────────────────── */
.stats-bar {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: stretch;
    max-width: calc(100vw - 24px);
    background: rgba(13, 20, 36, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid #1c2b45;
    border-radius: 14px;
    padding: 12px 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 18px;
    min-width: 64px;
}

.stat-item + .stat-item {
    border-left: 1px solid #1c2b45;
}

.stat-val {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 18px;
    line-height: 1;
    white-space: nowrap;
}

.stat-label {
    font-size: 10px;
    color: #5a6e8a;
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}

.stat-val.online {
    color: #a1fd0b;
}

.stat-val.offline {
    color: #ef4444;
}

/* ── Legend ──────────────────────────────────────────────── */
.legend {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 20;
    background: rgba(13, 20, 36, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid #1c2b45;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 12px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.legend-row:last-child {
    margin-bottom: 0;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot.online {
    background: #a1fd0b;
    box-shadow: 0 0 8px #a1fd0b;
}

.dot.offline {
    background: #ef4444;
    box-shadow: 0 0 8px #ef4444;
}

.dot.unknown {
    background: #ff9100;
    box-shadow: 0 0 8px #ff9100;
}

.legend-title {
    font-size: 10px;
    color: #5a6e8a;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 8px;
}

/* ── Legend toggle (mobile only) ─────────────────────────── */
.legend-toggle {
    display: none;
}

/* ── Loading screen ──────────────────────────────────────── */
.loading-screen {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: #070b14;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    transition: opacity .4s ease;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #1c2b45;
    border-top-color: #a1fd0b;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-screen span {
    font-size: 12px;
    color: #5a6e8a;
    font-family: 'JetBrains Mono', monospace;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
    .topbar {
        padding-left: calc(14px + env(safe-area-inset-left));
        padding-right: calc(14px + env(safe-area-inset-right));
    }

    .brand img {
        height: 26px;
    }

    .brand-text {
        display: none;
    }

    /* Login button collapses to an icon-only circle to save space */
    .btn-login {
        gap: 0;
        padding: 11px;
        border-radius: 50%;
    }

    .btn-login-text {
        display: none;
    }

    .stats-bar {
        padding: 10px 4px;
    }

    .stat-item {
        padding: 0 10px;
        min-width: 0;
    }

    .stat-val {
        font-size: 15px;
    }

    .stat-label {
        font-size: 8.5px;
        letter-spacing: .3px;
    }

    /* Legend becomes a toggleable panel so it never permanently
       covers the map on small screens */
    .legend-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: calc(68px + env(safe-area-inset-top));
        right: calc(12px + env(safe-area-inset-right));
        z-index: 21;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(13, 20, 36, 0.92);
        border: 1px solid #1c2b45;
        color: #a1fd0b;
        font-size: 16px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
        touch-action: manipulation;
    }

    .legend-toggle[aria-expanded="true"] {
        border-color: #06b6d4;
    }

    .legend {
        top: auto;
        bottom: auto;
        right: calc(12px + env(safe-area-inset-right));
        left: auto;
        top: calc(114px + env(safe-area-inset-top));
        max-width: min(220px, calc(100vw - 24px));
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
        pointer-events: none;
        transition: opacity .18s ease, transform .18s ease;
    }

    .legend.legend-open {
        opacity: 1;
        transform: translateY(0) scale(1);
        pointer-events: auto;
    }
}

@media (max-width: 380px) {
    .stats-bar {
        padding: 8px 2px;
    }

    .stat-item {
        padding: 0 7px;
    }

    .stat-val {
        font-size: 13px;
    }

    .stat-label {
        font-size: 7.5px;
        letter-spacing: .2px;
    }
}