:root {
    --map-primary: #007bff;
    --map-primary-dark: #0056b3;
    --map-secondary: #6c757d;
    --map-success: #28a745;
    --map-danger: #dc3545;
    --map-light: #f8f9fa;
    --map-dark: #343a40;
    --map-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* UI Overlays */
.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Search Bar */
.search-container {
    pointer-events: auto;
    margin: 10px;
    max-width: 400px;
    background: white;
    border-radius: 8px;
    box-shadow: var(--map-shadow);
    display: flex;
    padding: 5px;
    align-items: center;
}

.search-input {
    flex: 1;
    border: none;
    padding: 10px;
    font-family: inherit;
    font-size: 16px;
    outline: none;
}

.search-btn {
    background: none;
    border: none;
    padding: 10px;
    cursor: pointer;
    color: var(--map-secondary);
}

/* Bottom Controls */
.controls-container {
    pointer-events: auto;
    margin: 10px 10px 20px 10px;
    display: flex;
    justify-content: flex-end;
}

.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--map-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
}

.fab:active {
    transform: scale(0.95);
}

.fab.cancel {
    background-color: var(--map-danger);
    display: none;
}

/* Add Form Modal - Flexbox Layout */
.modal {
    display: none;
    pointer-events: auto;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: 80vh;
    /* Reduced height to ensure header visibility */
    background: white;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
    z-index: 9999;
    /* Max Z-Index */

    /* Flex Setup for Fixed Header/Footer */
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

/* GLOBAL RESET FOR MODAL CONTENT */
.modal * {
    box-sizing: border-box;
}

.modal.active {
    display: flex;
}

.modal-header-sticky {
    position: relative;
    flex-shrink: 0;
    background: white;
    padding: 15px 25px;
    /* More padding */
    border-bottom: 1px solid #eee;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.modal-header-sticky h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #333;
}

#closeModalBtn {
    background: #f8f9fa;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #666;
    cursor: pointer;
    transition: background 0.2s;
}

#closeModalBtn:active {
    background: #e2e6ea;
}

#addForm {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on iOS */
}

.modal-footer-sticky {
    position: sticky;
    /* Sticky to bottom of form content */
    bottom: 0;
    background: white;
    padding: 15px 0;
    margin-top: auto;
    /* Push to bottom if content is short */
    z-index: 5;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 15px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--map-dark);
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    font-size: 16px;
}

/* Photo Upload Style */
.photo-upload-label {
    display: block;
    background-color: #f0f2f5;
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    margin-bottom: 5px;
    color: var(--map-secondary);
}

.photo-preview {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 8px;
    display: none;
    margin-top: 10px;
}

.photo-preview.active {
    display: block;
}

.popup-img {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 5px;
}

/* Import Panel */
.import-panel {
    display: none;
    pointer-events: auto;
    margin: 0 10px;
    background: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: var(--map-shadow);
}

.import-panel.active {
    display: block;
}

/* User Location Pulse */
.user-location-marker {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.pulse {
    width: 12px;
    height: 12px;
    background: #007bff;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 0 rgba(0, 123, 255, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(0, 123, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0);
    }
}

.btn-block {
    width: 100%;
    padding: 12px;
    background-color: var(--map-success);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
}

.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 500;
    pointer-events: none;
    display: none;
}

.crosshair.active {
    display: block;
}

/* --- Premium Popup Style v3 (Mobile Friendly) --- */
.premium-popup-container {
    min-width: 400px;
    padding: 5px;
    font-family: 'Battambang', sans-serif !important;
}

.popup-flex-layout {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
}

/* Left Column */
.popup-left-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Fix flex text overflow */
}

.popup-header {
    margin-bottom: 8px;
}

.p-name {
    color: #007bff;
    font-size: 20px;
    /* Requested 20px */
    font-weight: 700;
    margin: 0 0 4px 0;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.p-id {
    color: #333;
    font-size: 20px;
    /* Requested 20px */
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
}

.popup-details {
    margin-bottom: 20px;
}

.p-detail-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    color: #444;
    font-size: 14px;
    line-height: 1.4;
}

.p-icon {
    width: 18px;
    text-align: center;
    color: #555;
    font-size: 16px;
}

/* Button */
.p-nav-btn {
    background-color: #007bff;
    color: white !important;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700;
    font-size: 16px;
    transition: all 0.2s ease;
    align-self: flex-start;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.p-nav-btn:hover {
    background-color: #0069d9;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
}

/* Right Column (QR) */
.popup-right-col {
    flex-shrink: 0;
    padding-top: 2px;
}

.p-qr-wrapper {
    background: #fff;
    padding: 6px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.p-qr-code {
    width: 120px;
    height: 120px;
}

.p-qr-code img {
    width: 100% !important;
    height: auto !important;
    margin: 0;
}


/* Leaflet Overrides */
.premium-leaflet-popup .leaflet-popup-content-wrapper {
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
}

.premium-leaflet-popup .leaflet-popup-content {
    margin: 8px 10px !important;
    width: auto !important;
}

.premium-leaflet-popup .leaflet-popup-close-button {
    padding: 8px 8px 0 0 !important;
    color: #bbb !important;
    font-size: 22px !important;
    top: 5px;
    right: 5px;
}

/* === Mobile Responsive === */
@media (max-width: 576px) {
    .premium-popup-container {
        min-width: 280px;
        max-width: 340px;
        /* Prevent wide overflow on small screens */
    }

    .p-name {
        font-size: 18px;
        /* Slightly smaller on very small screens to fit */
        white-space: normal;
        /* Allow wrapping on mobile */
    }

    .p-id {
        font-size: 18px;
    }

    .p-qr-code {
        width: 100px;
        height: 100px;
    }

    .popup-flex-layout {
        gap: 10px;
    }

    .p-nav-btn {
        width: 100%;
        /* Full width button on mobile feels better */
        padding: 10px;
        font-size: 15px;
    }

    .leafet-popup-content-wrapper {
        padding: 10px;
    }
}

/* --- New Premium Popup Style --- */
.custom-infowindow {
    min-width: 380px;
    padding: 10px 5px;
}

.iw-top-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 30px;
    margin-bottom: 20px;
}

.iw-info-col {
    flex: 1;
}

.iw-customer-name {
    color: #007bff;
    font-size: 26px;
    font-weight: 700;
    margin: 0 0 10px 0;
    line-height: 1.2;
    font-family: 'Battambang', cursive, sans-serif !important;
}

.iw-customer-id {
    font-size: 24px;
    font-weight: 700;
    color: #222;
    margin: 0 0 25px 0;
    line-height: 1.2;
    font-family: 'Battambang', cursive, sans-serif !important;
}

.iw-contact-info {
    margin-bottom: 0;
}

.iw-item {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 12px;
    color: #444;
    font-size: 16px;
    line-height: 1.5;
}

.iw-item i {
    margin-top: 5px;
    width: 20px;
    text-align: center;
    color: #555;
    font-size: 18px;
}

.iw-qr-col {
    flex-shrink: 0;
}

.iw-qr-container {
    background: #fff;
    padding: 12px;
    border: 1px solid #eee;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}

.iw-qr-code {
    width: 120px;
    height: 120px;
}

.iw-bottom-row {
    margin-top: 20px;
}

.iw-nav-btn {
    background-color: #007bff;
    color: white !important;
    padding: 14px 28px;
    border-radius: 12px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 20px;
    transition: all 0.2s ease;
}

.iw-nav-btn:hover {
    background-color: #0069d9;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 123, 255, 0.4);
}

/* Leaflet Popup Overrides */
.leaflet-popup-content-wrapper {
    border-radius: 25px;
    padding: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.leaflet-popup-content {
    margin: 20px 30px !important;
    width: auto !important;
    font-family: 'Battambang', 'Kantumruy Pro', sans-serif !important;
}

.leaflet-popup-close-button {
    padding: 20px 25px 0 0 !important;
    color: #bbb !important;
    font-size: 28px !important;
}

.leaflet-popup-close-button:hover {
    color: #888 !important;
    background: transparent !important;
}

.leaflet-popup-tip-container {
    margin-top: -3px;
}

.leaflet-popup-content i {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands" !important;
}