/* =========================================================
   style.css - v47 (FINAL: Fixed Header Layout & Text Formats)
   ========================================================= */

/* --- 1. MODAL (Universal) --- */
.modal { display: none; position: fixed; z-index: 10000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); backdrop-filter: blur(2px); align-items: center; justify-content: center; }
.modal-content { background-color: #fefefe; padding: 25px; border: 1px solid #888; border-radius: 8px; width: 80%; max-width: 600px; box-shadow: 0 4px 20px rgba(0,0,0,0.4); position: relative; max-height: 85vh; overflow-y: auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #333; line-height: 1.5; }
.close-button { color: #aaa; position: absolute; top: 10px; right: 20px; font-size: 32px; font-weight: bold; line-height: 1; cursor: pointer; transition: color 0.2s; }
.close-button:hover { color: #000; }
.modal-content h2 { margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 10px; font-size: 22px; }
.modal-content h3 { margin-top: 20px; margin-bottom: 8px; font-size: 16px; color: #007bff; font-weight: 700; }
.modal-content p { margin: 10px 0; }
.modal-content hr { border: 0; border-top: 1px solid #eee; margin: 20px 0; }
.modal-content ul { list-style: none; padding-left: 0; }
.modal-content li { margin-bottom: 8px; padding-left: 1.5em; text-indent: -1.5em; }
.modal-footer { text-align: right; font-size: 13px; color: #666; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.modal-footer input, .modal-footer label { cursor: pointer; }

/* --- 2. CORE LAYOUT --- */
body, html { margin: 0; padding: 0; height: 100%; width: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; overflow: hidden; }
#map { position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: auto !important; z-index: 1; transition: right 0.3s ease-in-out; }
body.sidebar-open #map { right: 450px; }

/* --- 3. CONTROLS --- */
.opacity-control { background: white; padding: 6px 10px; border-radius: 4px; box-shadow: 0 1px 5px rgba(0,0,0,0.4); font-size: 12px; display: flex; flex-direction: row; align-items: center; gap: 8px; }
.opacity-control label { font-weight: 600; font-size: 12px; color: #333; margin: 0; padding: 0; writing-mode: horizontal-tb; transform: none; }
.opacity-control input[type=range] { width: 100px; height: auto; margin: 0; cursor: pointer; writing-mode: horizontal-tb; -webkit-appearance: slider-horizontal; }

.leaflet-control.logo-control { width: 200px !important; height: 100px !important; margin-right: 10px !important; margin-bottom: 10px !important; pointer-events: none; }
.logo-control.leaflet-bar { pointer-events: auto; background: #fff; border: 2px solid #ccc; box-shadow: 0 1px 5px rgba(0,0,0,0.65); padding: 0 !important; width: 125px !important; height: 72px !important; display: flex; align-items: center; justify-content: center; border-radius: 4px; float: right; }
.logo-control.leaflet-bar a { width: 100% !important; height: 100% !important; padding: 0 !important; display: flex; align-items: center; justify-content: center; }
.logo-control img { width: 90% !important; height: 100% !important; object-fit: contain; display: block; opacity: 1; }

.sidebar-toggle { width: 125px !important; height: 30px !important; background-color: white; border-radius: 4px; box-shadow: 0 1px 5px rgba(0,0,0,0.65); cursor: pointer; text-align: center; padding: 0 !important; }
.sidebar-toggle a { display: block !important; width: 100% !important; height: 30px !important; line-height: 30px !important; text-decoration: none !important; color: #333 !important; font-weight: 600; font-size: 13px; background: transparent; }
.sidebar-toggle:hover { background-color: #f4f4f4; }

.leaflet-control.polyline-measure-control, .leaflet-bottom.leaflet-right .leaflet-bar { display: flex !important; flex-direction: row !important; white-space: nowrap !important; width: auto !important; }
.leaflet-control.polyline-measure-control a, .leaflet-bottom.leaflet-right .leaflet-bar a { float: none !important; display: inline-block !important; border-bottom: none !important; border-right: 1px solid #ccc !important; height: 30px !important; line-height: 30px !important; width: 30px !important; }
.leaflet-control.polyline-measure-control a:last-child, .leaflet-bottom.leaflet-right .leaflet-bar a:last-child { border-right: none !important; }

.info.legend { background: rgba(255, 255, 255, 0.95); box-shadow: 0 1px 5px rgba(0,0,0,0.4); border-radius: 5px; padding: 10px; line-height: 20px; color: #333; font-size: 13px; min-width: 100px; }
.info.legend b { display: block; margin-bottom: 5px; font-size: 14px; border-bottom: 1px solid #ccc; padding-bottom: 3px; text-align: center; }
.leaflet-control-home { font-size: 18px; line-height: 30px; text-align: center; display: block; text-decoration: none; color: #333; }
.leaflet-control-home:hover { background-color: #f4f4f4; }

/* --- 4. POPUP STYLING --- */
.wide-popup .leaflet-popup-content-wrapper { border-radius: 8px; box-shadow: 0 3px 14px rgba(0,0,0,0.4); padding: 0; }
.wide-popup .leaflet-popup-content { margin: 15px; padding-bottom: 15px !important; line-height: 1.5; font-size: 13px; color: #333; min-width: 400px !important; }
.wide-popup .leaflet-popup-close-button { top: 16px !important; right: 16px !important; width: 24px !important; height: 24px !important; font: 24px/24px Tahoma, Verdana, sans-serif !important; color: #999 !important; background: transparent !important; }
.wide-popup h4 { margin: 0 0 10px 0; font-size: 16px; color: #007bff; border-bottom: 2px solid #f0f0f0; padding-bottom: 5px; padding-right: 20px; }
.wide-popup h5 { font-size: 13px; font-weight: 700; color: #555; margin-top: 12px; margin-bottom: 4px; text-align: left; }
.wide-popup img { border-radius: 4px; transition: transform 0.2s; cursor: pointer; max-height: 250px; width: auto; object-fit: contain; }
.wide-popup img:hover { transform: scale(1.02); opacity: 0.9; border-color: #007bff !important; }

/* [FIXED] POPUP COMMENTS: Standard font and normal whitespace to fix weird formatting */
.popup-comments { 
    max-height: none; 
    overflow-y: visible; 
    text-align: left; 
    background-color: #f9f9f9; 
    border: 1px solid #ddd; 
    padding: 10px; 
    margin-bottom: 5px; 
    border-radius: 4px; 
    
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    font-size: 13px; 
    line-height: 1.5; 
    color: #444;
    white-space: normal !important; 
    word-wrap: break-word;
}
.scroll-hint { display: none; font-size: 10px; color: #999; text-align: center; font-style: italic; margin-top: -2px; margin-bottom: 10px; }
.marker-id-tooltip { background-color: rgba(255, 255, 255, 0.9); border: 1px solid #333; color: #000; font-weight: bold; font-size: 11px; padding: 0 4px; border-radius: 3px; box-shadow: 1px 1px 3px rgba(0,0,0,0.3); }

/* --- 5. SIDEBAR (FIXED) --- */
#sidebar { position: fixed; top: 0; right: 0; width: 450px; height: 100%; background: white; box-shadow: -2px 0 10px rgba(0,0,0,0.2); z-index: 2000; transform: translateX(100%); transition: transform 0.3s ease-in-out; display: flex; flex-direction: column; }
body.sidebar-open #sidebar { transform: translateX(0); }

/* [FIXED] Sidebar Header: Using Class (.) Selector and Flexbox */
.sidebar-header { 
    position: relative; 
    background: #f8f9fa; 
    padding: 15px 20px; 
    border-bottom: 1px solid #ddd; 
    display: flex; 
    align-items: center; 
    justify-content: space-between; /* Title Left, Controls Right */
    flex-shrink: 0; 
    min-height: 60px; 
    box-sizing: border-box; 
    overflow: hidden; 
}

.sidebar-header h3 { 
    margin: 0; 
    font-size: 1.25rem; 
    white-space: nowrap; 
}

/* Container for Download Buttons + Close Button */
.sidebar-controls { 
    display: flex; 
    align-items: center; 
    gap: 15px; 
}

#download-buttons-container { 
    display: flex; 
    gap: 8px; 
    align-items: center; 
}

/* Close Button: Static position to flow inside flex container */
#sidebar-close-btn, .close-btn { 
    position: static !important; 
    margin: 0 !important; 
    padding: 0 !important; 
    background: transparent !important; 
    border: none !important; 
    font-size: 28px !important; 
    line-height: 1 !important; 
    width: auto !important; 
    height: auto !important; 
    cursor: pointer !important; 
    color: #888; 
}
#sidebar-close-btn:hover, .close-btn:hover { color: #000; background-color: transparent; }

/* Download Button Style */
.btn-download-sidebar { 
    display: inline-block; 
    background-color: #007bff; 
    color: white; 
    text-decoration: none; 
    padding: 8px 15px; 
    border-radius: 4px; 
    font-size: 13px; 
    font-weight: 600; 
    border: none; 
    line-height: 1.2; 
    white-space: nowrap; 
    margin-right: 0 !important; /* Managed by flex gap */
}
.btn-download-sidebar:hover { background-color: #0056b3; color: white; }

.sidebar-content { padding: 20px; flex-grow: 1; overflow-y: auto; position: relative; }
.index-link { cursor: pointer; color: #007bff; text-decoration: none; display: block; }
.index-link:hover { color: #0056b3; text-decoration: underline; }
#reportContent { color: #333; line-height: 1.6; font-size: 14px; }
#reportContent h1 { font-size: 24px; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-top: 0; }
#reportContent h2 { font-size: 20px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
#reportContent h3 { font-size: 16px; margin-top: 20px; }
#reportContent table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 13px; border: 1px solid #ddd; }
#reportContent th, #reportContent td { border: 1px solid #ddd; padding: 10px; text-align: left; }
#reportContent th { background-color: #f2f2f2; font-weight: bold; color: #333; }
#reportContent tr:nth-child(even) { background-color: #f9f9f9; }
#reportContent img { display: block; max-width: 100%; height: auto; margin: 15px 0; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

/* --- 6. MOBILE OVERRIDES (SCREENS < 768px) --- */
@media (max-width: 768px) {
    #sidebar { width: 100%; max-width: 100%; }
    body.sidebar-open #map { right: 0; }
    .info.legend { display: none !important; }

    /* MOBILE POPUP: NARROW & SCROLLABLE */
    .wide-popup .leaflet-popup-content-wrapper { max-width: 280px; }
    .wide-popup .leaflet-popup-content { min-width: 0 !important; max-width: 250px; max-height: 60vh; overflow-y: auto; }
    .wide-popup img { max-height: 160px !important; width: auto !important; max-width: 100%; margin: 0 auto; display: block; }

    /* MOBILE COMMENTS */
    .popup-comments { max-height: 100px; overflow-y: auto; }
    .scroll-hint { display: block; }

    /* MOVE OPACITY SLIDER */
    .opacity-control.leaflet-bar { position: fixed !important; top: 10px !important; left: 10px !important; bottom: auto !important; margin: 0 !important; z-index: 5000; flex-direction: row !important; }

    /* PUSH ZOOM CONTROLS DOWN */
    .leaflet-top.leaflet-left .leaflet-control-zoom { margin-top: 60px !important; }

    /* MOVE LOGO (Smaller & Padded on Mobile) */
    .leaflet-control.logo-control { position: fixed !important; top: auto !important; bottom: 20px !important; left: 10px !important; right: auto !important; margin: 0 !important; z-index: 5000; width: 120px !important; height: auto !important; }
    .logo-control.leaflet-bar { float: none !important; padding: 5px !important; height: auto !important; }
    
    /* MOBILE MODAL FIXES */
    .modal-content { width: 90%; max-height: 70vh; padding: 15px; margin: auto; display: flex; flex-direction: column; }
    #modal-body-content { overflow-y: auto; flex: 1; padding-right: 5px; }
    .modal-content h2 { font-size: 18px; margin-bottom: 10px; }
}

/* FIX: Mobile Landscape Popups ONLY */
@media only screen and (max-height: 500px) and (orientation: landscape) {
    .leaflet-popup-content { max-height: 160px !important; overflow-y: auto !important; width: 250px !important; }
    .leaflet-popup { bottom: 10px !important; }
}