/* =================================================================
   1. ROOT VARIABLES & GENERAL STYLES
   ================================================================= */
:root {
    --brand: #0b486b;
    --brand-light: #4dd0e1;
    --brand-gradient: linear-gradient(90deg, var(--brand-light), #0077ff);
    --muted: #6b7280;
    --border-color: #e5e7eb;
    --background-light: #f9fafb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1),
        0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
        0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1),
        0 8px 10px -6px rgb(0 0 0 / 0.1);
    --radius-md: 0.5rem; /* 8px */
    --radius-lg: 0.75rem; /* 12px */
    --radius-xl: 1rem; /* 16px */
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial,
        sans-serif;
    background-color: var(--background-light);
    color: #374151;
    overflow: hidden;
}

/* =================================================================
   2. HEADER & NAVIGATION
   ================================================================= */
.header {
    display: flex;
    background-image: url("../../assets/images/banner_web.png");
    background-repeat: no-repeat;
    background-size: inherit;
    background-position: center;
    align-items: center;
    gap: 12px;
    color: white;
    padding: 12px 16px;
    box-shadow: var(--shadow-md);
}

.header {
    padding-top: calc(12px + env(safe-area-inset-top));
}

.logo_header {
    height: 40px;
    width: auto;
}
.title {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
}

/* Bootstrap overrides */
.navbar-collapse {
    flex-grow: 0 !important;
}
#navbarContent {
    max-width: 280px;
}

/* Search component */
#searchWrap {
    position: relative;
    max-width: 420px;
    width: 100%;
    margin-left: auto;
}

#searchInput {
    width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    padding: 10px 12px;
    outline: none;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#searchInput:focus {
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(77, 208, 225, 0.3);
}

#suggest {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    overflow: hidden;
    border: 1px solid var(--border-color);
}
#suggest div {
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}
#suggest div:hover {
    background: var(--background-light);
}

/* =================================================================
   3. MAP & MAP-RELATED COMPONENTS
   ================================================================= */
#map {
    height: calc(100dvh - 64px);
}

/* Filter Box (Collapsible) */
.filter-box {
    position: absolute;
    top: 80px;
    right: 16px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px) saturate(180%);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(229, 231, 235, 0.5);
    z-index: 800;
    overflow: hidden;
}

.filter-box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 12px 16px;
    gap: 10px;
}

.filter-box-title {
    font-weight: 700;
}

.btn-toggle-filter {
    border: none;
    background: transparent;
    width: 20px;
    height: 20px;
    padding: 0;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3e%3cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd' /%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    transition: transform 0.25s ease-in-out;
}

.btn-toggle-filter[aria-expanded="true"] {
    transform: rotate(180deg);
}

#filterCollapse {
    padding: 0 16px 16px;
}
#filterCollapse.collapsing {
    transition: height 0.25s ease;
}

.filter-title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
}

/* Legend Box */
.legend-box {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}
.legend-title {
    font-weight: 600;
    text-align: center;
    margin-bottom: 10px;
    font-size: 0.9rem;
}
.legend-items {
    display: flex;
    flex-direction: column;
}
.legend-group {
    margin-bottom: 12px;
}
.legend-group:last-child {
    margin-bottom: 0;
}
.legend-group-title {
    font-weight: bold;
    font-size: 0.9em;
    margin-bottom: 8px;
    color: var(--brand);
}
.legend-group-items {
    padding-left: 10px; /* Indent the types */
    border-left: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}
.legend-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}
.legend-name {
    font-size: 0.85em;
}

.legend-type-row {
    display: flex;
    gap: 10px;
}


.legend-cluster-explanation {
    margin-bottom: 12px;
}

.legend-cluster-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
}

.legend-cluster-symbol {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    font-weight: bold;
    box-sizing: border-box;
}

.legend-cluster-symbol.small {
    background-color: rgb(110, 204, 57);
    border: 5px solid rgb(181, 226, 140);
}

.legend-cluster-symbol.medium {
    background-color: rgb(240, 194, 12);
    border: 5px solid rgb(241, 211, 87);
}

.legend-cluster-symbol.large {
    background-color: rgb(241, 128, 23);
    border: 5px solid rgb(253, 156, 115);
}

/* Leaflet Customizations */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}

.ward-outline {
    stroke-linejoin: round;
    stroke-linecap: round;
    transition: all 0.2s ease-in-out;
    filter: url(#wardShadowDesktop);
}

.ward-outline:hover {
    filter: drop-shadow(1px 1px 0 rgba(0, 0, 0, 0.35))
        drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.35))
        drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.35))
        drop-shadow(4px 4px 0 rgba(0, 0, 0, 0.35))
        drop-shadow(5px 5px 0 rgba(0, 0, 0, 0.35))
        drop-shadow(6px 6px 0 rgba(0, 0, 0, 0.35))
        drop-shadow(9px 9px 12px rgba(0, 0, 0, 0.4));
}

#map .custom-map-label {
    background-color: transparent;
    border: none;
    box-shadow: none;
    color: #555;
    font-size: 12px;
    font-weight: lighter;
}
#map .custom-map-label__ward {
    background-color: transparent;
    border: none;
    box-shadow: none;
    color: blue;
    font-size: 14px;
    font-weight: bold;
}

/* =================================================================
   4. BOTTOM SHEET
   ================================================================= */
.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.2);
    transform: translateY(
        calc(100% - 120px)
    ); /* Adjust based on visible height */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 900;
}
.bottom-sheet.open {
    transform: translateY(0%);
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: ns-resize;
}
.grabber {
    width: 60px;
    height: 5px;
    background: #d1d5db;
    border-radius: 4px;
    margin: 6px auto;
}
.sheet-title {
    font-weight: 700;
    margin: 0;
}
.toggle-btn {
    border: 1px solid var(--border-color);
    background: #fff;
    border-radius: var(--radius-md);
    padding: 6px 10px;
    box-shadow: var(--shadow-sm);
}

/* =================================================================
   5. CARDS (in Bottom Sheet)
   ================================================================= */
.list-wrap {
    padding: 6px 16px 16px;
    overflow-x: auto;
    white-space: nowrap;
}
.card-item {
    cursor: pointer;
    display: inline-block;
    width: 230px;
    margin-right: 12px;
    vertical-align: top;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}
.card-thumb {
    width: 100%;
    height: 120px;
    object-fit: cover;
}
.card-body {
    padding: 10px 12px;
}
.card-title {
    font-weight: 700;
    font-size: 14px;
    margin: 0 0 6px;
    white-space: normal;
}
.card-meta {
    color: var(--muted);
    font-size: 12px;
    white-space: normal;
}

/* =================================================================
   6. MODALS & DOCX PREVIEW
   ================================================================= */
#detailModal .modal-header {
    position: relative;
    padding: 12px 16px;
}
#detailModal .modal-header .btn-close {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 16px;
}
#detailModalBody {
    min-height: 200px;
    background: #fff;
}

/* DOCX Preview styles */
.docx {
    color: #222;
    line-height: 1.5;
    font-size: 1rem;
}
.docx p {
    margin: 0 0 12px;
}
.docx table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}
.docx td,
.docx th {
    border: 1px solid var(--border-color);
    padding: 8px 10px;
}
.docx img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
}
.docx-wrapper {
    overflow: hidden;
}

.modal-body .docx-preview {
    max-width: 100% !important; /* Force it to not exceed parent width */
    overflow-x: auto; /* Add horizontal scroll if content is still too wide */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.modal-body .docx-preview * {
    max-width: 100% !important;
    box-sizing: border-box; /* Prevent padding/border from adding to width */
}

/* =================================================================
   7. UTILITIES
   ================================================================= */
.brand-gradient {
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    color: transparent;
    letter-spacing: 1px;
    text-shadow: 0 0 12px rgba(0, 136, 255, 0.25);
}

.brand-gradient-map {
    background: linear-gradient(90deg, #b8faff, var(--brand-light));
    -webkit-background-clip: text;
    color: transparent;
    letter-spacing: 1px;
    text-shadow: 0 0 12px rgba(0, 200, 255, 0.25);
}

/* =================================================================
   8. RESPONSIVE STYLES
   ================================================================= */

@media (min-width: 768px) and (max-width: 1023.99px) {
    .header {
        background-size: cover;
    }
    .logo_header {
        height: 5px;
    }
}

@media (max-width: 767.98px) {
    #navbarContent {
        max-width: 100%;
    }

    .filter-box {
        right: 16px;
        max-width: calc(100% - 90px);
        width: auto;
    }

    .bottom-sheet {
        /* On mobile, maybe we want it to take more initial height */
        transform: translateY(calc(100% - 85px));
    }

    .leaflet-tooltip.custom-map-label {
        font-size: 16px !important;
    }

    .leaflet-tooltip.custom-map-label__ward {
        font-size: 18px !important;
    }

    .header {
        background-image: url("../../assets/images/banner_mobile.png");
        background-size: cover;
    }

    /* Responsive styles for the legend */
    .legend-group-items {
        /* Enable vertical scrolling for the legend items */
        max-height: 150px; /* Example max height, can be adjusted */
        overflow-y: auto;
        padding-right: 5px; /* Add some padding for scrollbar */
    }

    .legend-type-row {
        /* Allow multiple types on the same row to wrap on smaller screens */
        flex-wrap: wrap;
        justify-content: flex-start; /* Align items to the start */
        gap: 5px; /* Reduce gap slightly */
    }

    .legend-item {
        /* Reduce size of legend items for mobile */
        gap: 5px;
        margin-bottom: 5px; /* Add some vertical spacing */
    }

    .legend-icon {
        width: 20px; /* Smaller icon size */
        height: 20px;
    }

    .legend-name {
        font-size: 0.8em; /* Smaller font size */
    }
    .ward-outline {
        filter: url(#wardShadowMobile) !important;
    }

    .docx-preview-wrapper, .docx-preview{
        padding: 10px !important;
    }
    /* Make modal-xl take more width on mobile */
    .modal-dialog.modal-xl {
        max-width: 95vw !important; /* Allow modal to take up to 95% of viewport width */
        margin: 0.5rem auto !important; /* Center with a small margin */
    }

    .modal-dialog.modal-xl .modal-content {
        height: calc(100vh - 1rem) !important; /* Make modal content almost full height */
    }

    /* Further adjustments for tables within DOCX preview on small screens */
    .modal-body .docx-preview table {
        display: block !important; /* Make table behave like a block element */
        width: 100% !important; /* Ensure table uses full available width */
        overflow-x: auto !important; /* Allow horizontal scrolling within the table if needed */
        -webkit-overflow-scrolling: touch !important;
        white-space: normal !important; /* Allow text to wrap within cells */
    }

    .modal-body .docx-preview table th,
    .modal-body .docx-preview table td {
        white-space: normal !important; /* Ensure text wraps in table cells */
        word-break: break-word !important; /* Break long words */
    }

    .modal-body .docx-preview img {
        height: auto !important; /* Ensure images scale correctly */
    }

    /* Adjust font sizes within DOCX for better readability on mobile */
    .modal-body .docx-preview {
        font-size: 0.9rem !important; /* Slightly smaller base font size */
    }
    .modal-body .docx-preview p {
        margin-bottom: 0.8rem !important; /* Adjust paragraph spacing */
    }
    .modal-body .docx-preview h1,
    .modal-body .docx-preview h2,
    .modal-body .docx-preview h3,
    .modal-body .docx-preview h4,
    .modal-body .docx-preview h5,
    .modal-body .docx-preview h6 {
        font-size: smaller !important; /* Scale down heading sizes */
    }
}

.filter-box {
    max-height: 70vh;
    overflow-y: auto;
}
