/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&family=Roboto:wght@400;500;700&display=swap');

:root {
    --bg-color: #0f172a;
    --header-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --header-border: rgba(59, 130, 246, 0.4);
    --text-main: #ffffff;
    --text-muted: #94a3b8;
    --panel-bg: rgba(15, 23, 42, 0.95);
    --panel-border: rgba(255, 255, 255, 0.15);
    --nav-item-bg: rgba(255, 255, 255, 0.05);
    --nav-item-border: rgba(255, 255, 255, 0.15);
    --action-icon-bg: rgba(255, 255, 255, 0.05);
    --action-icon-border: rgba(255, 255, 255, 0.2);
    --action-icon-color: #cbd5e1;
    --shadow-main: 0 4px 12px rgba(0, 0, 0, 0.6);
    --shadow-panel: 0 10px 30px rgba(0, 0, 0, 0.6);
    --accent-blue: #3b82f6;
    --accent-light: #60a5fa;
}

.light-mode {
    --bg-color: #f8fafc;
    --header-bg: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
    --header-border: rgba(51, 65, 85, 0.25);
    --text-main: #1e293b;
    --text-muted: #475569;
    --panel-bg: rgba(255, 255, 255, 0.96);
    --panel-border: rgba(0, 0, 0, 0.12);
    --nav-item-bg: rgba(0, 0, 0, 0.03);
    --nav-item-border: rgba(0, 0, 0, 0.15);
    --action-icon-bg: rgba(0, 0, 0, 0.03);
    --action-icon-border: rgba(0, 0, 0, 0.2);
    --action-icon-color: #334155;
    --shadow-main: 0 2px 10px rgba(0, 0, 0, 0.15);
    --shadow-panel: 0 10px 35px rgba(0, 0, 0, 0.2);
    --accent-blue: #1e40af;
    --accent-light: #1d4ed8;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#map {
    width: 100%;
    height: calc(100% - 70px);
    margin-top: 70px;
    position: relative;
    background-color: var(--bg-color);
}

/* Header Banner */
#header-banner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background: var(--header-bg);
    z-index: 10001;
    display: flex;
    align-items: center;
    padding: 0 15px;
    box-shadow: var(--shadow-main);
    border-bottom: 2px solid var(--header-border);
    box-sizing: border-box;
    transition: background 0.3s ease, border-color 0.3s ease;
}

#header-banner .logo {
    width: 65px;
    height: 65px;
    margin-right: 12px;
    border-radius: 50%;
    background: white;
    padding: 4px;
    flex-shrink: 0;
}

#header-banner .header-top {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#header-banner .title-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#header-banner .main-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin: 0;
    line-height: 1.5;
}

#header-banner .subtitle {
    font-size: 8px;
    font-weight: 400;
    color: var(--text-muted);
    margin: 0;
    letter-spacing: 0.3px;
}

#header-banner .header-nav {
    display: flex;
    gap: 10px;
    flex: 1;
    justify-content: center;
}

.nav-item {
    color: var(--text-main);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    text-decoration: none;
    cursor: pointer;
    padding: 8px 18px;
    border-radius: 4px;
    transition: all 0.2s ease;
    background: var(--nav-item-bg);
    border: 1.5px solid var(--nav-item-border);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.light-mode .nav-item {
    color: var(--accent-blue);
}

.nav-item:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
    color: #60a5fa;
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.3);
    border-color: #60a5fa;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

.light-mode .nav-item.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Header Actions */
.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.action-icon {
    width: 32px;
    height: 32px;
    background: var(--nav-item-bg);
    border: 1.5px solid var(--nav-item-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: var(--action-icon-color);
}

.action-icon:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
    color: #ffffff;
}

.action-icon-text {
    width: auto;
    padding: 0 12px;
    gap: 6px;
}

.action-icon-label {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.light-mode .action-icon-text {
    color: var(--accent-blue);
}

/* Custom Layer Control */
#custom-layer-control {
    position: fixed;
    top: 85px;
    left: 15px;
    z-index: 1000;
    box-sizing: border-box;
    background: var(--panel-bg);
    border-radius: 10px;
    color: var(--text-main);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-panel);
    font-size: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
    width: 40px;
    height: 40px;
    overflow: hidden;
}

#custom-layer-control.expanded {
    width: 210px;
    height: auto;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
}

.layer-control-header {
    display: flex;
    align-items: center;
    height: 36px;
    cursor: pointer;
    flex-shrink: 0;
}

.layer-control-toggle {
    width: 36px;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    color: #60a5fa;
    transition: all 0.3s;
}

#custom-layer-control.expanded .layer-control-toggle {
    border-radius: 8px 0 0 0;
    background: rgba(59, 130, 246, 0.2);
}

.layer-control-title {
    padding-left: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}

#custom-layer-control.expanded .layer-control-title {
    opacity: 1;
}

.layer-control-content {
    padding: 0 8px 8px 8px;
    overflow-y: auto;
    width: 100%;
    box-sizing: border-box;
}

.layer-control-content::-webkit-scrollbar {
    width: 4px;
}

.layer-control-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.layer-control-content h4 {
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 800;
    font-size: 10px;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 2px;
    margin-top: 8px;
    margin-bottom: 4px;
}

.layer-control-content h4:first-child {
    margin-top: 2px;
}

.layer-option {
    display: flex;
    align-items: center;
    margin-bottom: 2px;
    cursor: pointer;
    padding: 3px 4px;
    border-radius: 5px;
    transition: background 0.2s;
}

.layer-option:hover {
    background: var(--nav-item-bg);
}

.layer-option input {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    border: 1.5px solid var(--action-icon-border);
    border-radius: 3px;
    margin-right: 10px;
    cursor: pointer;
    position: relative;
    background: transparent;
}

.layer-option input:checked {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.2);
}

.layer-option input:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: #3b82f6;
    border-radius: 1px;
}

.layer-option input[type="radio"] {
    border-radius: 50%;
}

.layer-option input[type="radio"]:checked::after {
    border-radius: 50%;
}

.lgd-icon {
    display: inline-block;
    flex-shrink: 0;
    margin-right: 8px;
    box-sizing: border-box;
    opacity: 0.95;
}

.lgd-polygon {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1.5px solid;
}

.lgd-line {
    width: 16px;
    height: 3px;
    border-radius: 1.5px;
    margin-top: 2px;
}

.lgd-point {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid #fff;
    margin-left: 2px;
    margin-right: 10px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.layer-option span {
    font-size: 11px;
    color: var(--text-main);
    font-weight: 500;
    line-height: 1.3;
    white-space: normal;
    flex: 1;
}

/* ===========================
   IN-PANEL LEGEND GROUP
   =========================== */
.legend-group-title {
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #60a5fa;
    font-weight: 800;
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    padding-bottom: 4px;
    margin-top: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.legend-group-arrow {
    font-size: 10px;
    transition: transform 0.2s;
    color: var(--text-muted);
}

.inpanel-legend-section {
    margin-bottom: 4px;
}

.inpanel-legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 6px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-main);
    background: var(--nav-item-bg);
    transition: background 0.2s;
    margin-bottom: 2px;
}

.inpanel-legend-header:hover {
    background: rgba(255, 255, 255, 0.09);
}

.inpanel-arrow {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.inpanel-legend-content {
    padding: 4px 4px 6px 4px;
    overflow-y: auto;
    max-height: 250px;
}

.inpanel-legend-content::-webkit-scrollbar {
    width: 3px;
}

.inpanel-legend-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

/* shared legend-item and legend-line used inside panel */
.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-line {
    width: 22px;
    height: 3px;
    margin-right: 9px;
    border-radius: 1px;
    flex-shrink: 0;
}

.legend-item span {
    font-size: 11px;
    color: var(--text-main);
    font-weight: 600;
}

/* Phụ kiểu table inside panel */
.phukieu-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10.5px;
    table-layout: fixed;
    word-wrap: break-word;
    border: 1px solid var(--panel-border);
}

.phukieu-table th,
.phukieu-table td {
    padding: 4px 6px;
    border: 1px solid var(--panel-border);
    color: var(--text-main);
}

.phukieu-table th {
    font-weight: 700;
    color: var(--accent-light);
    background: var(--nav-item-bg);
    text-align: left;
}

.phukieu-table th:first-child {
    width: 28px;
}

.phukieu-table .phukieu-header td {
    font-weight: 700;
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
}

.phukieu-table td:first-child {
    font-weight: 600;
    white-space: nowrap;
}

/* ===========================
   FLOATING LEGEND PANELS
   =========================== */
#legend-toanquoc,
#legend-quangnam,
#legend-hoian {
    position: fixed;
    bottom: 35px;
    left: 15px;
    z-index: 900;
    background: var(--panel-bg);
    border-radius: 10px;
    color: var(--text-main);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-panel);
    padding: 10px 12px;
    width: 210px;
    box-sizing: border-box;
    font-size: 11px;
    /* Slightly smaller text */
}

.legend-main-title {
    text-align: center;
    font-size: 11px;
    font-weight: 900;
    margin-bottom: 8px;
    /* Reduced */
    padding-bottom: 5px;
    /* Reduced */
    border-bottom: 1.5px solid var(--header-border);
    color: var(--accent-light);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.legend-group-title {
    font-size: 9px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent-light);
    padding-bottom: 3px;
    border-bottom: 1px solid var(--header-border);
    margin-bottom: 6px;
    /* Reduced */
    margin-top: 0px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 3px;
    font-size: 11px;
    color: var(--text-main);
}

.legend-item span {
    white-space: normal;
    line-height: 1.5;
    /* Set to specifically match request */
    flex: 1;
    word-break: break-word;
}

.legend-icon-wrap {
    width: 24px;
    height: 18px;
    /* Reduced from 24px to allow tighter spacing */
    display: flex;
    justify-content: flex-start;
    /* Consistent left alignment */
    align-items: center;
    flex-shrink: 0;
}

.legend-line {
    width: 14px;
    height: 3px;
    border-radius: 1.5px;
    margin-left: 5px;
    /* Visual alignment with SVG pin */
    flex-shrink: 0;
}

.legend-item-with-btn {
    justify-content: space-between;
}

.legend-item-with-btn>span {
    flex: 1;
}



.legend-phukieu-btn {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 4px;
    color: #60a5fa;
    cursor: pointer;
    padding: 3px 5px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.legend-phukieu-btn:hover {
    background: rgba(59, 130, 246, 0.3);
    color: #fff;
}

#floating-phukieu-legend {
    position: fixed;
    bottom: 35px;
    right: 15px;
    z-index: 901;
    background: var(--panel-bg);
    border-radius: 8px;
    color: var(--text-main);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-panel);
    width: 240px;
    max-width: calc(100vw - 80px);
    max-height: 35vh;
    overflow-y: auto;
    font-size: 11px;
    padding: 0 14px 6px 14px;
    /* Padding top moved to title */
}

.close-phukieu-btn {
    position: sticky;
    float: right;
    top: 6px;
    right: 0px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 6px;
    transition: all 0.2s;
    z-index: 20;
    margin-right: -4px;
    margin-top: 6px;
}

.close-phukieu-btn:hover {
    color: var(--text-main);
    transform: scale(1.1);
}

#floating-phukieu-legend::-webkit-scrollbar {
    width: 4px;
}

#floating-phukieu-legend::-webkit-scrollbar-thumb {
    background: var(--panel-border);
    border-radius: 10px;
}

.floating-legend-title {
    position: sticky;
    top: 0;
    background: var(--panel-bg);
    z-index: 15;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent-light);
    margin-bottom: 8px;
    padding: 12px 0 6px 0;
    /* Padding included here for sticky background */
    border-bottom: 1px solid var(--header-border);
}



/* Footer */
#project-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--panel-bg);
    color: var(--text-muted);
    padding: 6px 0;
    text-align: center;
    font-size: 11px;
    z-index: 10001;
    backdrop-filter: blur(5px);
    border-top: 1px solid var(--panel-border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* ===========================
   MOBILE QUICK LINKS
   =========================== */
/* Ẩn trên desktop */
#mobile-links-wrap {
    display: none;
}

/* Panel nổi chứa 2 link */
#mobile-links-panel {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--panel-bg);
    border: 1px solid var(--header-border);
    border-radius: 8px;
    padding: 6px;
    min-width: 160px;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-panel);
    flex-direction: column;
    gap: 4px;
    z-index: 1001;
}

#mobile-links-panel.open {
    display: flex;
}

.mobile-link-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-main);
    font-size: 12px;
    font-weight: 600;
    background: var(--nav-item-bg);
    border: 1px solid var(--nav-item-border);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.mobile-link-item:hover,
.mobile-link-item:active {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.4);
    color: #60a5fa;
}

#mobile-links-btn.active {
    background: rgba(59, 130, 246, 0.4);
    border-color: rgba(59, 130, 246, 0.7);
    color: #ffffff;
}

/* Trên mobile, hiển thị wrap */
@media (max-width: 768px) {
    #mobile-links-wrap {
        display: block;
        position: absolute;
        right: 6px;
        bottom: 2px;
        z-index: 1001;
    }
}

/* ===========================
   MAP TOOLS PANEL (Stable Vertical Style)
   =========================== */
#map-tools {
    position: absolute;
    right: 15px;
    top: 90px;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 900;
    box-shadow: var(--shadow-main);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.map-tool-btn {
    width: 40px;
    height: 40px;
    background: var(--nav-item-bg);
    border: 1px solid var(--nav-item-border);
    border-radius: 6px;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}

.map-tool-btn:hover {
    background: rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.5);
    transform: scale(1.05);
}

.map-tool-btn.active {
    background: rgba(59, 130, 246, 0.5);
    border-color: rgba(59, 130, 246, 0.8);
}

.tool-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 4px 0;
}

/* ===========================
   MODAL DIALOGS
   =========================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-panel);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-title {
    color: #60a5fa;
    margin: 0 0 8px 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.modal-subtitle {
    color: var(--text-muted);
    margin: 0 0 16px 0;
    font-size: 0.9rem;
}

.modal-message {
    color: var(--text-main);
    margin: 16px 0 24px 0;
    line-height: 1.5;
}

.search-input {
    width: 100%;
    background: var(--nav-item-bg);
    border: 2px solid var(--header-border);
    border-radius: 8px;
    padding: 12px;
    color: var(--text-main);
    margin-bottom: 24px;
    outline: none;
    transition: all 0.2s;
    box-sizing: border-box;
}

.search-input:focus {
    border-color: var(--accent-blue);
    background: var(--nav-item-bg);
}

/* Suggestions dropdown */
.search-suggestions {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--panel-bg);
    border: 1.5px solid var(--accent-blue);
    border-top: none;
    border-radius: 0 0 8px 8px;
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 220px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: var(--shadow-panel);
}

.search-suggestions.open {
    display: block;
}

.search-suggestions li {
    padding: 10px 14px;
    color: var(--text-main);
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid var(--panel-border);
    line-height: 1.4;
    transition: background 0.15s;
}

.search-suggestions li:last-child {
    border-bottom: none;
}

.search-suggestions li:hover,
.search-suggestions li.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-light);
}

.search-suggestions li .suggest-name {
    font-weight: 600;
    display: block;
}

.search-suggestions li .suggest-detail {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-btn {
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.modal-btn-primary {
    background: #10b981;
    color: white;
}

.modal-btn-primary:hover {
    background: #059669;
}

.modal-btn-secondary {
    background: var(--nav-item-bg);
    border: 1px solid var(--nav-item-border);
    color: var(--text-main);
}

.modal-btn-secondary:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent-blue);
}

/* ===========================
   OPENLAYERS CLEANUP & OVERRIDES
   =========================== */
.ol-viewport-msg {
    display: none !important;
}

/* Re-enable overlays but style them cleanly */
.ol-overlay-container {
    display: block !important;
}

.ol-control {
    background-color: rgba(15, 23, 42, 0.8) !important;
    border-radius: 4px !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 2px !important;
}

.ol-control button {
    background-color: transparent !important;
    color: #fff !important;
    cursor: pointer;
}

.ol-control button:hover {
    background-color: rgba(59, 130, 246, 0.3) !important;
}

/* Zoom Control Position (Upper-Right) */
.ol-zoom {
    top: 90px;
    right: 15px;
    background-color: transparent !important;
    border: none !important;
}

.ol-attribution {
    bottom: 35px !important;
    background: transparent !important;
    color: #64748b;
    font-size: 10px;
}

/* Logo Nhóm - góc dưới phải */
#logo-nhom {
    position: fixed;
    bottom: 35px;
    right: 15px;
    z-index: 900;
    transition: opacity 0.3s ease;
}

#logo-nhom img {
    display: block;
    max-height: 80px;
    max-width: 200px;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}

/* ===========================
   RESPONSIVE - MOBILE (≤768px)
   =========================== */
@media (max-width: 768px) {

    /* === HEADER: CSS Grid trên mobile ===
       Col 1: Logo (span 2 rows)
       Col 2 Row 1: Title + subtitle
       Col 2 Row 2: Nav tabs
    */
    #header-banner {
        display: grid;
        grid-template-columns: 45px 1fr;
        /* Logo | Title */
        grid-template-rows: auto auto;
        height: auto;
        padding: 6px 10px;
        gap: 4px 8px;
        border-bottom: 1px solid var(--header-border);
        box-shadow: var(--shadow-main);
        align-items: center;
    }

    /* Logo: cột 1, span 2 hàng, căn giữa */
    #header-banner .logo {
        grid-column: 1;
        grid-row: 1;
        /* Only row 1 now */
        width: 40px;
        height: 40px;
        margin-right: 0;
        align-self: center;
        justify-self: center;
        object-fit: contain;
    }

    /* header-top (title+subtitle): cột 2, hàng 1 */
    #header-banner .header-top {
        grid-column: 2;
        grid-row: 1;
        flex: unset;
        justify-content: flex-start;
    }

    #header-banner .title-container {
        gap: 1px;
    }

    #header-banner .main-title {
        font-size: 10.5px;
        letter-spacing: 0;
        white-space: normal;
        line-height: 1.4;
    }

    #header-banner .subtitle {
        display: block;
        font-size: 6.5px;
    }

    /* Tabs: cột 2, hàng 2 — tự căn với tiêu đề */
    #header-banner .header-nav {
        grid-column: 1 / 3;
        /* Span full width */
        grid-row: 2;
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        justify-content: flex-start;
        align-items: center;
        padding: 4px 0;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        width: 100%;
        border-top: 1px solid rgba(255, 255, 255, 0.05);
    }

    #header-banner .header-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        font-size: 9px;
        padding: 4px 6px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Header actions & actions hidden */
    .header-actions {
        display: flex;
        gap: 4px;
        align-items: center;
        margin-left: auto;
        flex-shrink: 0;
    }

    .header-actions .action-icon {
        width: auto;
        height: auto;
        padding: 4px 8px;
        box-sizing: border-box;
    }

    .header-actions .action-icon-text {
        width: auto;
        padding: 4px 8px;
        height: auto;
        font-size: 9px;
        gap: 4px;
    }

    .header-actions .action-icon-label {
        font-size: 9px;
    }

    .header-actions .action-icon svg,
    .header-actions .action-icon-text svg {
        width: 12px;
        height: 12px;
    }

    #map {
        height: calc(100% - 95px);
        /* Adjusted for new header height */
        margin-top: 95px;
    }

    /* --- Layer Control Panel --- */
    #custom-layer-control {
        top: 100px;
        left: 8px;
    }

    #custom-layer-control.expanded {
        width: 170px;
        max-height: 50vh;
    }

    .layer-control-content h4 {
        font-size: 9px;
    }

    .layer-option span {
        font-size: 10px;
    }

    /* --- Map Tools --- */
    #map-tools {
        right: 8px;
        top: 100px;
        padding: 4px;
        gap: 3px;
    }

    .map-tool-btn {
        width: 32px;
        height: 32px;
    }

    #mobile-links-btn {
        width: 25px;
        height: 25px;
        padding: 4px;
    }

    /* --- Floating Legends --- */
    #legend-toanquoc,
    #legend-quangnam,
    #legend-hoian {
        bottom: 30px;
        left: 8px;
        padding: 6px 8px;
        min-width: 120px;
        max-width: 140px;
        font-size: 9px;
    }

    .legend-main-title {
        font-size: 9px;
        margin-bottom: 5px;
        padding-bottom: 3px;
    }

    .legend-group-title {
        font-size: 8px;
        margin-bottom: 4px;
        margin-top: 6px;
    }

    .legend-item {
        font-size: 9px;
        gap: 6px;
        margin-bottom: 2px;
    }

    .legend-icon-wrap {
        width: 18px;
        height: 14px;
    }

    .legend-line {
        width: 12px;
        height: 2px;
    }

    .legend-icon-wrap svg {
        width: 10px;
        height: 10px;
        margin-left: 1px !important;
    }

    .legend-phukieu-btn {
        padding: 2px 4px;
    }

    .legend-phukieu-btn svg {
        width: 10px;
        height: 10px;
    }

    #floating-kieubor-legend {
        bottom: 30px;
        left: 8px;
        font-size: 9px;
        padding: 6px 8px;
        min-width: unset;
        max-width: 140px;
    }

    #floating-phukieu-legend {
        bottom: 30px;
        right: 8px;
        width: 50vw;
        max-width: 50vw;
        max-height: 40vh;
        font-size: 9px;
        padding: 0 8px 4px 8px;
    }

    .floating-legend-title {
        font-size: 9px;
        padding: 8px 0 4px 0;
        margin-bottom: 4px;
    }

    .close-phukieu-btn {
        margin-top: 2px;
        margin-right: -2px;
        padding: 4px;
        font-size: 16px;
    }

    /* --- Logo Nhóm mobile --- */
    #logo-nhom img {
        max-height: 50px;
        max-width: 120px;
    }

    /* --- Footer --- */
    #project-footer {
        font-size: 8px;
        padding: 3px 8px;
        line-height: 1.3;
    }

    /* --- Modals --- */
    .modal-content {
        padding: 14px;
        width: 90%;
    }

    .modal-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .modal-btn {
        width: 100%;
        padding: 11px;
    }
}

/* ===========================
   RESPONSIVE - SMALL MOBILE (≤480px)
   =========================== */
@media (max-width: 480px) {

    /* Grid column nhỏ hơn cho màn hình nhỏ */
    #header-banner {
        grid-template-columns: 40px 1fr auto;
        padding: 4px 8px;
    }

    #header-banner .logo {
        width: 34px;
        height: 34px;
    }

    #header-banner .main-title {
        font-size: 9px;
    }

    #header-banner .subtitle {
        font-size: 6px;
    }

    .nav-item {
        font-size: 8px;
        padding: 3px 7px;
    }

    .header-actions .action-icon {
        width: auto;
        height: auto;
        padding: 3px 7px;
        box-sizing: border-box;
    }

    .header-actions .action-icon-text {
        width: auto;
        height: auto;
        font-size: 8px;
        padding: 3px 7px;
        gap: 3px;
    }

    .header-actions .action-icon-label {
        font-size: 8px;
        white-space: nowrap;
    }

    .header-actions .action-icon svg,
    .header-actions .action-icon-text svg {
        width: 11px;
        height: 11px;
    }

    #floating-kieubor-legend {
        max-width: 130px;
    }

    #floating-phukieu-legend {
        width: 50vw;
        max-width: 50vw;
        max-height: 35vh;
    }
}

/* ===========================
   GOOGLE FORM SPREADSHEET POPUP
   =========================== */
.ol-popup {
    position: absolute;
    background-color: white;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #cccccc;
    bottom: 12px;
    left: -50px;
    min-width: 250px;
    z-index: 9999;
    color: #333;
    /* Text color for light theme */
}

.ol-popup:after,
.ol-popup:before {
    top: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
}

.ol-popup:after {
    border-top-color: white;
    border-width: 10px;
    left: 48px;
    margin-left: -10px;
}

.ol-popup:before {
    border-top-color: #cccccc;
    border-width: 11px;
    left: 48px;
    margin-left: -11px;
}

.ol-popup-closer {
    text-decoration: none;
    position: absolute;
    top: 2px;
    right: 8px;
    font-weight: bold;
    color: gray;
}

.ol-popup-closer:after {
    content: "✖";
}

/* ===== Thông tin thêm Modal ===== */

#info-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 20000;
    align-items: center;
    justify-content: center;
}

#info-modal-overlay.open {
    display: flex;
}

#info-modal {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: var(--shadow-panel);
    width: 320px;
    max-width: calc(100vw - 32px);
    overflow: hidden;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.info-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.info-modal-title {
    flex: 1;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-light);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

#info-modal-close {
    background: var(--nav-item-bg);
    border: 1px solid var(--nav-item-border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

#info-modal-close:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

.info-menu-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
}

.info-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--nav-item-bg);
    border: 1.5px solid var(--nav-item-border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 500;
    padding: 12px 16px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.info-menu-item:hover {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.3);
    color: #fff;
    transform: translateX(3px);
}

.info-menu-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

/* ===== Rescue Panel ===== */
#rescue-panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(5px);
    z-index: 21000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#rescue-panel-overlay.open {
    display: flex;
}

#rescue-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: var(--shadow-panel);
    width: 660px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.3) transparent;
    animation: modalIn 0.25s ease;
}

.rescue-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.2) 0%, rgba(59, 130, 246, 0.15) 100%);
    border-bottom: 1px solid rgba(239, 68, 68, 0.2);
    padding: 16px 18px;
}

.rescue-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.rescue-shield {
    font-size: 32px;
    flex-shrink: 0;
}

.rescue-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.rescue-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
}

#rescue-panel-close {
    background: var(--nav-item-bg);
    border: 1px solid var(--nav-item-border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

#rescue-panel-close:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

.rescue-number-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 16px 16px 0;
}

.rescue-number-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 14px 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.rescue-number-icon {
    font-size: 24px;
    line-height: 1;
}

.sos-icon {
    font-size: 13px;
    font-weight: 900;
    color: #f472b6;
    background: rgba(244, 114, 182, 0.2);
    border: 1.5px solid #f472b6;
    border-radius: 4px;
    padding: 2px 6px;
}

.rescue-number-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    line-height: 1.4;
}

.rescue-number-big {
    font-size: 32px;
    font-weight: 900;
    letter-spacing: -1px;
    line-height: 1;
}

.rescue-number-note {
    font-size: 9px;
    color: var(--text-muted);
}

.rescue-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    padding: 14px 16px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: 14px;
}

.rescue-count {
    color: #60a5fa;
    font-size: 11px;
    font-weight: 500;
}

.rescue-commune-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 0 16px 14px;
}

.rescue-commune-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 7px;
    padding: 8px 12px;
}

.rescue-commune-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
}

.rescue-commune-phone {
    font-size: 12px;
    font-weight: 600;
    color: #60a5fa;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s;
}

.rescue-commune-phone:hover {
    color: #93c5fd;
}

.rescue-disclaimer {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    padding: 10px 16px 16px;
    border-top: 1px solid var(--panel-border);
}

/* --- Rescue Panel Mobile Responsive --- */
@media (max-width: 768px) {
    .rescue-number-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 12px 12px 0;
    }

    .rescue-number-card {
        padding: 10px 8px;
    }

    .rescue-number-icon {
        font-size: 20px;
    }

    .rescue-number-big {
        font-size: 26px;
    }

    .rescue-number-label {
        font-size: 8px;
    }

    .rescue-number-note {
        font-size: 8px;
    }

    .rescue-commune-grid {
        gap: 6px;
        padding: 0 12px 12px;
    }

    .rescue-commune-item {
        padding: 6px 8px;
        gap: 4px;
    }

    .rescue-commune-name {
        font-size: 11px;
    }

    .rescue-commune-phone {
        font-size: 11px;
    }

    .rescue-section-title {
        font-size: 11px;
        padding: 12px 12px 8px;
    }

    .mobile-break {
        display: block;
    }

    /* Legend Collapse on Mobile */
    .legend-main-title {
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
    }
    
    .legend-toggle-btn {
        display: flex;
        background: none;
        border: none;
        color: inherit;
        padding: 4px;
        cursor: pointer;
        position: absolute;
        right: 0;
    }
    
    .legend-toggle-btn svg {
        width: 14px;
        height: 14px;
        transition: transform 0.3s ease;
    }

    #legend-toanquoc.collapsed > *:not(.legend-main-title),
    #legend-quangnam.collapsed > *:not(.legend-main-title),
    #legend-hoian.collapsed > *:not(.legend-main-title) {
        display: none !important;
    }

    #legend-toanquoc.collapsed .legend-toggle-btn svg,
    #legend-quangnam.collapsed .legend-toggle-btn svg,
    #legend-hoian.collapsed .legend-toggle-btn svg {
        transform: rotate(180deg);
    }
}

/* Hide legend toggle button on desktop (outside the media query) */
@media (min-width: 769px) {
    .legend-toggle-btn {
        display: none;
    }
}