/* Thêm đoạn này vào thẻ <style> của bạn */
.leaflet-interactive:focus {
    outline: none !important;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    overflow: hidden;
}

#map {
    height: 100vh;
    width: 100vw;
    z-index: 1;
    background-color: #f9fafb;
}

/* --- Thanh tìm kiếm ở trên --- */
#top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
    align-items: center;
    padding: 0.5rem 0.75rem;
    pointer-events: none;
}

#logo-container {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.hcmedu-logo {
    height: 82px;
    display: block;
}

@media (max-width: 640px) {
    #top-bar {
        padding: 0.5rem;
    }

    .hcmedu-logo {
        height: 80px;
    }
}

#search-container {
    width: 100%;
    max-width: 800px;
    position: relative;
    pointer-events: auto;
}

@media (max-width: 640px) {
    #search-container {
        max-width: 85%;
    }

    #search-box {
        padding: 0.4rem 0.4rem;
        font-size: 0.7rem;
    }

    #wardSearchInput {
        font-size: 0.7rem;
    }

    #logo-container {
        margin-right: 0.5rem;
    }
}

#search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 0.5rem 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

#wardSearchInput {
    width: 100%;
    background: transparent;
    font-size: 0.75rem;
    font-weight: 500;
    color: #1f2937;
    outline: none;
    border: none;
}

#search-results {
    display: none;
    position: absolute;
    top: 110%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
}

#search-results button.focused-search-result {
    background-color: #e0e7ff;
    outline: 2px solid #4f46e5;
    outline-offset: -1px;
}

/* --- Thanh điều khiển ở dưới --- */
#bottom-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 799; /* Below Leaflet controls (z-index: 800) but above map panes */
    padding: 1rem;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    border-top: 1px solid #e5e7eb;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    transition: all 0.3s ease;
}

#heatmap-controls {
    display: flex;
    gap: 0.5rem;
}

#heatmap-controls button {
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #d1d5db;
    background-color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: #4b5563;
}

#heatmap-controls button:hover {
    background-color: #f3f4f6;
}

#heatmap-controls button.active {
    background-color: #334155;
    color: white;
    border-color: #1e293b;
}

#legend-container {
    flex-grow: 1;
    max-width: 300px;
    font-size: 12px;
    visibility: hidden;
}

#legend-container .title {
    font-weight: bold;
    margin-bottom: 5px;
    color: #1f2937;
}

#legend-bar-wrapper {
    position: relative;
    padding: 10px 0;
}

#legend-container .gradient {
    width: 100%;
    height: 10px;
    border-radius: 5px;
    border: 1px solid #ccc;
}

#legend-container .labels {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    font-size: 11px;
}

#legend-indicator {
    display: none;
    position: absolute;
    top: 5px;
    height: 18px;
    width: 2px;
    background-color: #ef4444;
    transform: translateX(-1px);
    z-index: 10;
}

#legend-hover-value {
    display: none;
    position: absolute;
    top: -13px;
    transform: translateX(-50%);
    background-color: #ef4444;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
}

/* --- Responsive cho di động --- */
@media (max-width: 768px) {
    #bottom-bar {
        flex-direction: column;
        flex-direction: column-reverse;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    #legend-container {
        width: 100%;
        max-width: none;
        order: -1;
    }

    #top-bar {
        padding: 0.75rem;
    }

    .info-popup .leaflet-popup-content {
        margin: 0;
        font-size: 13px;
        max-width: 60vw; /* Tối đa 60% chiều rộng màn hình lớn */
        min-width: 200px;
        padding-left: 1vw; /* Tạo khoảng cách hai bên ~20% tổng */
        padding-right: 1vw;
        box-sizing: border-box;
    }

    @media (max-width: 768px) {
        .info-popup .leaflet-popup-content {
            max-width: 90vw;
            padding-left: 1vw;
            padding-right: 1vw;
        }
    }
}

#legend-container .labels {
    font-size: 10px;
}

/* --- Các style khác --- */
.spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border: 5px solid rgba(0, 0, 0, 0.1);
    border-left-color: #4f46e5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2000;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.ward-label {
    background-color: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 14px;
    font-weight: bold;
    padding: 5px 10px;
    box-shadow: none;
    white-space: nowrap;
}

.ward-label::before {
    border: none !important;
}

.info-popup .leaflet-popup-content-wrapper {
    border-radius: 0.5rem; /* Smaller border radius */
    padding: 0;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.info-popup .leaflet-popup-content {
    margin: 0;
    font-size: 13px; /* Smaller base font size */
}

.info-popup-header {
    background-color: #f9fafb;
    padding: 0.6rem 1rem; /* Reduced padding */
    border-bottom: 1px solid #e5e7eb;
}

.info-popup-title {
    font-size: 1rem; /* Smaller title font size (16px) */
    font-weight: 700;
    color: #111827;
}

.info-popup-body {
    padding: 0.75rem 1rem; /* Reduced padding */
    display: flex;
    flex-direction: column;
    gap: 0.6rem; /* Reduced gap between items */
}

.info-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.info-label {
    display: flex;
    align-items: center;
    gap: 0.4rem; /* Reduced gap for icon and label */
    font-weight: 500;
    color: #4b5563;
}

.info-label i {
    color: #6b7280;
}

.info-value {
    font-weight: 600;
    color: #1f2937;
}

.info-section {
    border-top: 1px solid #f3f4f6;
    padding-top: 0.6rem; /* Reduced top padding */
    color: #4b5563;
    line-height: 1.4; /* Tighter line height */
}

.info-popup-footer {
    padding: 0.6rem; /* Reduced padding */
    background-color: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.navigate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    background-color: #4f46e5;
    color: #ffffff !important;
    font-weight: 500; /* Lighter font weight */
    padding: 0.5rem; /* Reduced padding */
    border-radius: 0.5rem;
    text-decoration: none;
    transition: background-color 0.2s;
    font-size: 0.9em; /* Smaller font size for button text */
}

.navigate-btn:hover {
    background-color: #4338ca;
    color: #ffffff !important
}

/* --- NEW CSS TO REMOVE POPUP OVERLAY --- */
.leaflet-popup-overlay {
    background: rgba(0, 0, 0, 0); /* Fully transparent */
    pointer-events: none; /* Allows clicks to go through to the map */
}

/* --- Logo Control --- */
.leaflet-logo-control {
    position: relative; /* Ensure z-index applies */
    z-index: 1000; /* Place it above other UI elements */
    background-color: rgba(255, 255, 255, 0);
    padding: 0.3rem;
    border-radius: 5px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
}

.leaflet-logo-control img {
    height: 22px;
    width: auto;
    display: block;
}

.medium-insert-embeds {
    max-width: 800px;
    margin: 20px auto; /* 20px adds space above/below, auto centers it left-to-right */
}

.video {
    position: relative;
    overflow: hidden;
    width: 100%;
    padding-top: 75%; /* 4:3 Aspect Ratio - good for this map */
}

.video iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.info-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem 0.6rem;
    margin-bottom: 0.5rem;
    margin-top: 0.2rem;
}

.metric-cell {
    background: #f1f5f9;
    border-radius: 8px;
    padding: 0.25rem 0.35rem 0.3rem 0.35rem;
    text-align: center;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.metric-label {
    font-size: 0.74em;
    color: #64748b;
    font-weight: 500;
    letter-spacing: 0.01em;
    margin-bottom: 0;
    white-space: nowrap;
    text-align: center;
}

.metric-rank {
    font-size: 1.02em;
    color: #4338ca;
    font-weight: 700;
    letter-spacing: 0.01em;
    margin-bottom: 0;
    line-height: 1.1;
}

.metric-value {
    font-size: 0.7em;
    font-weight: 400;
    color: #111827;
    margin-top: 0;
    text-align: center;
    line-height: 1.18;
    word-break: break-word;
}

@media (max-width: 600px) {
    .info-metrics-grid {
        gap: 0.33rem 0.33rem;
    }

    .metric-cell {
        padding: 0.18rem 0.1rem 0.22rem 0.1rem;
        font-size: 0.91em;
    }

    .metric-label, .metric-rank, .metric-value {
        font-size: 0.98em;
    }

    .info-popup-header {
        padding: 0.35rem 0.6rem !important;
    }

    .info-popup-body {
        padding: 0.4rem 0.6rem !important;
        gap: 0.4rem !important;
    }

    .info-popup-footer {
        padding: 0.4rem !important;
    }

    .navigate-btn {
        padding: 0.35rem !important;
        font-size: 0.8rem !important;
    }

    .info-line {
        gap: 0.25rem !important;
        font-size: 0.8rem !important;
    }

    /* Make Leaflet popup X button bigger and more visible */
    .leaflet-popup-close-button {
        font-size: 2.1rem !important; /* Bigger X */
        line-height: 2.0rem !important;
        width: 2.2rem !important;
        height: 2.2rem !important;
        right: 0.5rem !important;
        top: 0.2rem !important;
        opacity: 0.88 !important;
        color: #333 !important;
        background: none !important;
    }

    .leaflet-popup-close-button:hover {
        color: #ef4444 !important;
        opacity: 1 !important;
    }
}
