@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Prompt', sans-serif;
    overflow: hidden;
    background-color: #0f172a;
}

.app-container {
    position: relative;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
}

.map-container {
    flex: 1;
    height: 100%;
    width: 100%;
    z-index: 1;
}

/* Glassmorphism Classes (Premium Dark Mode) */
.glass-panel {
    background: rgba(15, 23, 42, 0.85); /* Deep slate/navy for professional look */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
}

/* Splash Screen */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0f172a, #1e293b);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.splash-content {
    text-align: center;
    animation: fadeIn 1s ease-in-out;
}

/* Top Bar (Floating Pill on Desktop, Full on Mobile) */
.top-bar {
    position: absolute;
    top: max(15px, env(safe-area-inset-top));
    left: 15px;
    right: 15px;
    z-index: 1000;
    border-radius: 16px;
    padding: 10px 15px;
}

@media (min-width: 768px) {
    .top-bar {
        left: 20px;
        right: auto;
        width: 380px;
        border-radius: 12px;
    }
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
    transition: all 0.2s;
    border: 1px solid rgba(255,255,255,0.1);
}
.btn-icon:hover, .btn-icon:active {
    background: rgba(255,255,255,0.15);
}

/* Search Overlay */
.search-overlay {
    position: absolute;
    top: max(85px, calc(65px + env(safe-area-inset-top)));
    left: 15px;
    right: 15px;
    z-index: 1000;
    border-radius: 22px;
    padding: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.search-overlay.collapsed {
    right: auto;
    width: 44px; /* Just enough for the icon */
    background: rgba(15, 23, 42, 0.8) !important;
}

.search-overlay.collapsed .search-input-field,
.search-overlay.collapsed .search-action-btn {
    opacity: 0;
    pointer-events: none;
    width: 0;
    padding: 0;
}

.search-input-field {
    transition: opacity 0.3s ease, width 0.3s ease;
}

.input-group-text.cursor-pointer {
    cursor: pointer;
    transition: transform 0.2s;
    width: 40px;
    justify-content: center;
}

.input-group-text.cursor-pointer:hover {
    transform: scale(1.1);
}

@media (min-width: 768px) {
    .search-overlay {
        top: 20px;
        left: 420px; /* Right next to the top bar */
        right: auto;
        width: 350px;
    }
}

.search-overlay input::placeholder {
    color: rgba(255,255,255,0.5) !important;
}

.search-overlay input:focus {
    box-shadow: none;
}

/* Dashboard Widgets */
.dashboard-widgets {
    position: absolute;
    top: 140px;
    right: 15px;
    z-index: 1000;
    border-radius: 16px;
    padding: 15px;
    width: 200px;
}

@media (min-width: 768px) {
    .dashboard-widgets {
        top: 20px;
        right: 20px;
        width: 250px;
        border-radius: 12px;
    }
}

/* Bottom Sheet / Side Panel */
.bottom-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    border-radius: 24px 24px 0 0;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.drag-handle {
    width: 40px;
    height: 5px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    margin: 10px auto 15px auto;
}

@media (min-width: 768px) {
    .bottom-sheet {
        bottom: 20px;
        left: 20px;
        width: 380px;
        border-radius: 12px;
        padding-bottom: 20px;
    }
    .drag-handle {
        display: none;
    }
    .bottom-sheet h5 {
        margin-top: 15px;
    }
}

.layer-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
}

.bottom-sheet.collapsed .layer-grid {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

@media (min-width: 768px) {
    .bottom-sheet.collapsed {
        padding-bottom: 0 !important;
    }
    .bottom-sheet.collapsed .layer-grid {
        margin-bottom: 15px; /* keep some spacing when collapsed */
    }
}

@media (max-width: 380px) {
    .layer-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (min-width: 768px) {
    .layer-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

.layer-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 10px 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: rgba(255,255,255,0.6);
    transition: all 0.2s;
    font-size: 0.75rem;
}

.layer-btn i {
    font-size: 1.25rem;
    filter: grayscale(100%) opacity(0.6);
    transition: all 0.2s;
}

.layer-btn.active {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.3);
    color: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.layer-btn.active i {
    filter: none;
    transform: scale(1.1);
}

/* Custom Leaflet overrides */
.leaflet-control-zoom {
    border: none !important;
    margin-bottom: 250px !important; /* Above bottom sheet */
    box-shadow: 0 4px 12px rgba(0,0,0,0.2) !important;
}
.leaflet-control-zoom a {
    background: rgba(30, 64, 175, 0.8) !important;
    color: white !important;
    backdrop-filter: blur(5px);
    border-color: rgba(255,255,255,0.2) !important;
}
.leaflet-control-zoom a:hover {
    background: rgba(30, 64, 175, 1) !important;
}

/* Popup Mobile Adjustments */
.public-popup .leaflet-popup-content-wrapper {
    background: rgba(15, 23, 42, 0.95);
    color: white;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
}
.public-popup .leaflet-popup-tip {
    background: rgba(15, 23, 42, 0.95);
}
.public-popup .leaflet-popup-close-button {
    color: white !important;
}
.public-popup-title {
    font-weight: bold;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 5px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Road Labels Tooltips (Zoom-dependent) */
.leaflet-tooltip.road-label-tooltip {
    background: rgba(255, 253, 240, 0.95) !important; /* Soft cream/light yellow */
    backdrop-filter: blur(4px);
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    border-radius: 6px !important;
    color: #1e293b !important; /* Dark slate text */
    font-family: 'Prompt', sans-serif !important;
    padding: 4px 8px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
    white-space: nowrap;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.leaflet-tooltip.road-label-tooltip::before {
    display: none !important;
}

#publicMap:not(.show-road-labels) .road-label-tooltip {
    opacity: 0 !important;
    visibility: hidden;
    pointer-events: none;
}

/* Boundary Labels Tooltips */
.leaflet-tooltip.boundary-label-subdistrict {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #fef08a !important;
    font-family: 'Prompt', sans-serif !important;
    font-size: 1.5rem !important;
    font-weight: 700 !important;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8), -1px -1px 2px rgba(0,0,0,0.8);
    text-align: center;
    white-space: nowrap;
}

.leaflet-tooltip.boundary-label-village {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #ffffff !important;
    font-family: 'Prompt', sans-serif !important;
    font-size: 1.25rem !important;
    font-weight: 800 !important;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.9), -1px -1px 3px rgba(0,0,0,0.8), 0px 0px 8px rgba(0,0,0,0.8);
    text-align: center;
    white-space: nowrap;
    transition: opacity 0.3s ease;
}

.leaflet-tooltip.boundary-label-subdistrict::before,
.leaflet-tooltip.boundary-label-village::before {
    display: none !important;
}

#publicMap.hide-village-labels .boundary-label-village {
    opacity: 0 !important;
    visibility: hidden;
    pointer-events: none;
}

/* Map Labels for High Zoom (Performance-friendly, CSS-only toggling) */
#publicMap:not(.zoom-19-up) .marker-label-house {
    display: none !important;
}

#publicMap:not(.zoom-19-up) .marker-label-lighting {
    display: none !important;
}

.marker-label-house, .marker-label-lighting {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff, 0px 0px 4px rgba(255,255,255,0.9);
    font-family: 'Prompt', sans-serif;
    font-weight: 700;
    pointer-events: none;
    z-index: 10;
}

.marker-label-house {
    top: -24px;
    font-size: 0.85rem;
    color: #0f172a; /* dark slate for better readability */
    font-weight: 800;
}

.marker-label-lighting {
    top: -20px;
    font-size: 0.8rem;
    color: #0f172a; /* dark slate */
    font-weight: 800;
}
