* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; overflow: hidden; height: 100%; }
.header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: white;
    padding: 14px 24px;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-left: calc(24px + env(safe-area-inset-left));
    padding-right: calc(24px + env(safe-area-inset-right));
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 1000;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
}
.header-left { display: flex; align-items: center; gap: 14px; }
.logo {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: #e2e8f0;
}
.logo span { color: #4fc3f7; }
.tagline {
    font-size: 13px;
    color: #94a3b8;
    letter-spacing: 0.3px;
}
.header-right { display: flex; align-items: center; gap: 10px; }
.ctrl {
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 14px;
    cursor: pointer;
}
.ctrl option { background: #1a1a2e; color: white; }
.ctrl-check { display: flex; align-items: center; gap: 6px; user-select: none; }
.ctrl-check input { cursor: pointer; }
#drop-pin.active { background: #8e44ad; border-color: #8e44ad; }
#controls { display: flex; align-items: center; gap: 10px; }
#filters-toggle, #controls-done, .legend-toggle { display: none; }
#map {
    position: fixed;
    top: calc(56px + env(safe-area-inset-top));
    bottom: 0;
    left: 0;
    right: 0;
}
.legend {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(8px);
    border-radius: 10px;
    padding: 14px 18px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    z-index: 1001;
    font-size: 13px;
}
.legend-title {
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 8px;
    font-size: 13px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    color: #444;
}
.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.pin-form {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 280px;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(8px);
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.18);
    z-index: 1002;
    font-size: 13px;
}
.pin-form-title { font-weight: 700; color: #1a1a2e; margin-bottom: 8px; }
.pin-form textarea {
    width: 100%;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    padding: 8px;
    font: inherit;
    resize: vertical;
}
.pin-form-actions { display: flex; gap: 8px; margin-top: 10px; }
.pin-form button {
    flex: 1;
    border: none;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: #8e44ad;
    color: white;
}
.pin-form button.secondary { background: #e9ecef; color: #444; }
.bl-pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50% 50% 50% 0;
    background: #8e44ad;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    transform: rotate(-45deg);
}
.bl-trend svg { display: block; width: 100%; height: auto; }
.bl-trend-msg { font-size: 11px; color: #888; }
.pin-popup { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; min-width: 180px; }
.pin-popup .pin-note { font-size: 14px; color: #1a1a2e; white-space: pre-wrap; }
.pin-popup .pin-meta { font-size: 11px; color: #888; margin: 6px 0 8px; }
.pin-popup .pin-del {
    border: none; border-radius: 6px; padding: 6px 10px;
    background: #fdedec; color: #c0392b; font-weight: 600; cursor: pointer;
}
.legend-body { display: block; }

/* -- Accounts (Phase 1) -- */
.account-menu {
    position: fixed;
    top: calc(56px + env(safe-area-inset-top));
    right: 24px;
    background: #fff;
    color: #1a1a2e;
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.18);
    min-width: 220px;
    overflow: hidden;
    z-index: 1100;
    font-size: 14px;
}
.account-menu-email {
    padding: 12px 16px 6px;
    font-size: 12px;
    color: #667;
    border-bottom: 1px solid #eef0f3;
    word-break: break-all;
}
.account-menu button {
    display: block;
    width: 100%;
    border: none;
    background: none;
    text-align: left;
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    color: #1a1a2e;
}
.account-menu button:hover:not(:disabled) { background: #f4f6fa; }
.account-menu button:disabled { color: #aab1bd; cursor: default; }
.account-menu button[data-action="logout"] {
    border-top: 1px solid #eef0f3;
    color: #c0392b;
    font-weight: 600;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}
.modal-card {
    position: relative;
    background: #fff;
    color: #1a1a2e;
    border-radius: 12px;
    padding: 28px 28px 24px;
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal-card h2 { font-size: 20px; margin-bottom: 8px; }
.modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    font-size: 24px;
    line-height: 1;
    color: #94a3b8;
    cursor: pointer;
    border-radius: 6px;
}
.modal-close:hover { background: #f4f6fa; color: #1a1a2e; }
.modal-lede {
    font-size: 14px;
    color: #475569;
    margin: 8px 0 14px;
    line-height: 1.45;
}
.modal-fine { font-size: 12px; color: #888; margin-top: 12px; }
.modal-icon { font-size: 40px; text-align: center; margin: 4px 0 8px; }

.modal-card input[type="email"],
.modal-card input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    margin-bottom: 10px;
}
.modal-card input:focus { outline: 2px solid #1e6fd9; outline-offset: 0; }

.modal-card button:not(.modal-close):not(.secondary):not(.danger) {
    width: 100%;
    padding: 11px 14px;
    background: #1e6fd9;
    color: #fff;
    border: none;
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.modal-card button.secondary {
    width: 100%;
    padding: 10px 14px;
    background: #eef0f3;
    color: #1a1a2e;
    border: none;
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}
.modal-card button.danger {
    padding: 8px 12px;
    background: #fdedec;
    color: #c0392b;
    border: 1px solid #f5c0bb;
    border-radius: 6px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.modal-card button:disabled { opacity: 0.6; cursor: default; }

.claim-list {
    list-style: none;
    padding: 0;
    margin: 4px 0 12px;
    max-height: 180px;
    overflow-y: auto;
}
.claim-list li {
    padding: 6px 0;
    font-size: 14px;
    color: #1a1a2e;
    border-bottom: 1px solid #eef0f3;
}
.claim-list li:last-child { border-bottom: none; }

.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions button { flex: 1; }

.modal-row { margin: 12px 0 4px; }
.modal-label { font-size: 12px; color: #667; margin-bottom: 4px; }
.modal-value { font-size: 14px; color: #1a1a2e; word-break: break-all; }
.modal-danger {
    border-top: 1px solid #eef0f3;
    margin-top: 18px;
    padding-top: 14px;
}

@media (max-width: 700px) {
    .account-menu {
        right: 12px;
        left: 12px;
        min-width: auto;
    }
    .modal-card { padding: 22px 20px 20px; }
}

/* Fluid popups so the card never exceeds a phone screen */
.leaflet-popup-content table { max-width: 100%; }
/* Leaflet's maxHeight scroll container: vertical scroll only, smooth on touch */
.leaflet-popup-scrolled {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
@media (max-width: 700px) {
    .leaflet-popup-content-wrapper { max-width: 90vw; }
    .leaflet-popup-content { width: auto !important; max-width: calc(90vw - 30px); }
}

/* -- Mobile layout -- */
@media (max-width: 700px) {
    .header {
        padding: 10px 14px;
        padding-top: calc(10px + env(safe-area-inset-top));
    }
    .tagline { display: none; }
    .logo { font-size: 20px; }
    #map { top: calc(50px + env(safe-area-inset-top)); }

    #filters-toggle { display: inline-block; }
    #filters-toggle.active { background: #4fc3f7; color: #0b2233; border-color: #4fc3f7; }
    #controls {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        background: rgba(20, 20, 40, 0.98);
        backdrop-filter: blur(8px);
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
        border-radius: 14px 14px 0 0;
        box-shadow: 0 -4px 22px rgba(0,0,0,0.45);
        transform: translateY(115%);
        transition: transform 0.25s ease;
        z-index: 1003;
        max-height: 72vh;
        overflow: auto;
    }
    #controls.open { transform: none; }
    #controls .ctrl {
        width: 100%;
        font-size: 16px;   /* >=16px stops iOS focus zoom */
        padding: 12px 14px;
    }
    #controls .ctrl-check { justify-content: space-between; }
    #controls-done {
        display: block;
        background: #4fc3f7; color: #0b2233; border-color: #4fc3f7;
        font-weight: 700;
    }

    .legend {
        bottom: calc(12px + env(safe-area-inset-bottom));
        left: 12px;
        padding: 8px 10px;
        font-size: 12px;
    }
    .legend-toggle {
        display: block;
        background: none; border: none;
        font-weight: 700; color: #1a1a2e; font-size: 12px;
        cursor: pointer; padding: 2px 2px;
    }
    .legend.collapsed .legend-body { display: none; }

    .pin-form {
        width: min(280px, calc(100vw - 24px));
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
    }
}
