/* Layout and Panel */
body, html { 
    margin: 0; 
    padding: 0; 
    height: 100%; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    overflow: hidden; /* Prevent page scroll */
}

#map { 
    width: 100%; 
    height: 100%; 
    position: absolute; 
    z-index: 1; 
}

.control-panel { 
    position: absolute; 
    top: 20px; 
    left: 20px; 
    z-index: 1000; 
    background: rgba(255, 255, 255, 0.95); 
    padding: 0; 
    border-radius: 8px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.2); 
    width: 300px; 
    overflow: hidden;
    pointer-events: auto; /* Ensure panel is clickable */
    height: 800px;       /* Required: Fixed height */
    overflow-y: auto;    /* Adds scrollbar only if content overflows */
    overflow-x: hidden
}

.panel-header { 
    background: #004085; 
    color: white; 
    padding: 12px; 
    margin: 0; 
    font-size: 16px; 
}

/* Accordion Sections */
details.layer-section { 
    border-bottom: 1px solid #ddd; 
}

details.layer-section summary { 
    padding: 12px; 
    cursor: pointer; 
    font-weight: 600; 
    color: #333; 
    list-style: none; 
    outline: none; 
    transition: background 0.2s;
}

details.layer-section summary:hover { 
    background: #f8f9fa; 
}

details.layer-section[open] summary { 
    border-bottom: 1px solid #eee; 
    background: #f1f3f5; 
}

.section-content { 
    padding: 12px; 
    background: white; 
}

/* Search Container - Fixed */
.search-container {
    position: relative;
    margin-top: 8px;
}

#mun-search { 
    width: 100%; 
    padding: 10px 35px 10px 10px;
    border: 1px solid #ced4da; 
    border-radius: 4px; 
    box-sizing: border-box; 
    font-size: 14px;
    outline: none;
}

#mun-search:focus {
    border-color: #004085;
    box-shadow: 0 0 5px rgba(0,64,133,0.2);
}

.clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #aaa;
    font-size: 18px;
    display: none;
    z-index: 10;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
}

.clear-btn:hover {
    color: #333;
}

/* Search Results - Fixed Position */
#search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #004085;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.result-item {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    background: white;
    color: #333;
    font-size: 13px;
    transition: background 0.2s;
}

.result-item:hover {
    background: #e8f0fe;
}

.result-item:last-child {
    border-bottom: none;
}

/* Layer Items */
.layer-item { 
    display: flex; 
    align-items: center; 
    margin-bottom: 8px; 
    cursor: pointer; 
    font-size: 14px; 
}

.layer-item input { 
    margin-right: 10px; 
}
.layer-item input[type="checkbox"] {
    -webkit-appearance: checkbox;
    appearance: checkbox;
    accent-color: #004085; /* Matches your header blue */
    width: 16px;
    height: 16px;
    cursor: pointer;
}
/* Analysis Console */
.analysis-buttons {
    padding: 5px 0;
}

.analysis-buttons button {
    width: 100%;
    margin: 5px 0;
    padding: 8px;
    background: #004085;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.analysis-buttons button:hover {
    background: #002752;
}

.analysis-buttons button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

#console-output { 
    background: #1e1e1e; 
    color: #4af626; 
    font-family: 'Consolas', monospace; 
    font-size: 11px; 
    padding: 10px; 
    margin-top: 10px; 
    border-radius: 4px; 
    max-height: 120px; 
    overflow-y: auto; 
    white-space: pre-wrap;
    display: none;
}

/* Popup Styles */
.ol-popup {
    position: fixed; /* Changed from absolute to stay relative to the screen */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Perfectly centers the element */
    
    background-color: white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3); /* Slightly deeper shadow for center modal */
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #ddd;
    
    /* Dimensions increased: 
       Width + ~100px (from 280 to 380) 
       Height + ~100px (from 400 to 500) */
    min-width: 380px; 
    max-width: 500px;
    max-height: 500px;
    
    overflow-y: auto;
    z-index: 3000; /* Increased to ensure it stays above all layers */
    font-size: 13px;
    line-height: 1.5;
}

.ol-popup:after, .ol-popup:before {
    /* top: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none; */
    display: none;
}

.ol-popup:after {
    border-top-color: white;
    border-width: 10px;
    left: 48px;
    margin-left: -10px;
}

.ol-popup-closer {
    position: sticky;
    top: -5px;
    right: -5px;
    float: right;
    cursor: pointer;
    background: #f8f9fa;
    border: 1px solid #eee;
    font-size: 20px;
    padding: 0px 8px;
    border-radius: 50%;
    color: #333;
    z-index: 3001;
    transition: background 0.2s;
}

.ol-popup-closer:after {
    content: "✖";
    color: #666;
    font-size: 14px;
    font-weight: bold;
}

.ol-popup-closer:hover:after {
    color: #000;
    background: #f0f0f0;
}
.ol-layer[zIndex="10000"] {
    z-index: 10000 !important;
}

.ol-popup::-webkit-scrollbar {
    width: 8px;
}

.ol-popup::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.ol-popup::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.ol-popup::-webkit-scrollbar-thumb:hover {
    background: #555;
}


/* Smoother map transitions */
.ol-viewport {
    transition: all 0.3s ease;
}

/* Optional: Add a loading indicator for tiles */
.ol-tile-loading {
    background: rgba(0,0,0,0.1);
}

/* Make zoom animations smoother */
.ol-viewport {
    will-change: transform;
}

/* Prevent any default behavior that might cause refresh */
a, button, .clear-btn, .result-item {
    -webkit-tap-highlight-color: transparent;
}

/* Ensure no default cursor changes */
.clear-btn, .result-item {
    cursor: pointer;
}

/* Make sure no form-like behavior */
/* Force no default button behavior */
button, .result-item {
    -webkit-appearance: none;
    appearance: none;
}

button {
    background: none;
    border: none;
}

.clear-btn {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:active {
    outline: none;
}

/* Prevent any form submission or refresh */
form {
    margin: 0;
    padding: 0;
}

/* Disable any default link behaviors */
a[href="#"] {
    cursor: default;
}

.map-legend {
    position: absolute;
    right: 20px;
    bottom: 30px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
    z-index: 1000;
    font-family: Arial, sans-serif;
    font-size: 12px;
    min-width: 180px;
}

.map-legend h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

.legend-header {
    font-size: 11px;
    font-weight: bold;
    color: #555;
    text-transform: uppercase;
    margin-top: 10px;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
    font-size: 12px;
    color: #333;
}

.legend-color {
    width: 24px;
    height: 12px;
    margin-right: 10px;
    border: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

#legend-panel hr {
    margin: 12px 0;
    border-top: 1px solid #eee;
}

.legend-symbol {
    margin-right: 10px;
}

/* Ensure the scrollbar doesn't look ugly inside the small panel */
#legend-panel .panel-body-content {
    max-height: 450px;
    overflow-y: auto;
    padding-right: 10px;
}

/* Essential styles for the large crop list */
.crop-selection-container {
    margin-top: 10px;
    background: #222;
    border-radius: 4px;
    padding: 8px;
}
.crop-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    max-height: 250px;
    overflow-y: auto;
    padding: 5px;
    background: #1a1a1a;
    border: 1px solid #444;
}
.crop-group-header {
    grid-column: span 2;
    font-size: 11px;
    color: #4CAF50;
    background: #333;
    padding: 2px 5px;
    margin-top: 5px;
    font-weight: bold;
    text-transform: uppercase;
}
.crop-item {
    display: flex;
    align-items: center;
    font-size: 11px;
    color: #ccc;
    cursor: pointer;
}
.crop-item input { margin-right: 5px; }
.crop-actions {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}
.crop-actions button {
    font-size: 10px;
    padding: 2px 8px;
    background: #444;
    color: white;
    border: none;
    cursor: pointer;
}
.crop-actions button:hover { background: #555; }
.crop-item input[type="checkbox"] {
    -webkit-appearance: checkbox; /* Force checkbox appearance back */
    appearance: checkbox;
    margin-right: 8px;
    cursor: pointer;
    accent-color: #4CAF50; /* Makes the "checked" state bright green */
    width: 14px;
    height: 14px;
}

/* Dynamic Analysis Right Panel */
.analysis-panel-right {
    position: absolute;
    top: 20px;
    right: 20px; /* Positioned on the right */
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: -4px 4px 15px rgba(0,0,0,0.2);
    width: 320px;
    max-height: 90vh;
    overflow-y: auto;
    display: block;
}

#dynamic-crop-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 5px;
    max-height: 400px;
    overflow-y: auto;
    background: #f9f9f9;
    padding: 10px;
    border: 1px solid #ddd;
}

.crop-category-label {
    font-weight: bold;
    font-size: 12px;
    color: #004085;
    margin-top: 10px;
    border-bottom: 1px solid #ccc;
    grid-column: 1 / -1;
}

.crop-item-row {
    display: flex;
    align-items: center;
    font-size: 12px;
}

.panel-header {
    background: #2c3e50;
    color: white;
    padding: 10px 15px;
    font-size: 14px;
    font-weight: bold;
    border-radius: 4px 4px 0 0;
}

.visualizer-section {
    padding: 15px;
    border-bottom: 1px solid #f0f0f0;
}

.visualizer-section:last-child {
    border-bottom: none;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
}

.section-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 15px;
    margin-right: 8px;
    border-radius: 2px;
}

.prod-title::before { background-color: #4CAF50; }
.storage-title::before { background-color: #2171b5; }

/* Form Elements */
.storage-inputs {
    padding: 15px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    margin-top: 10px;
}

.storage-inputs label {
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 5px;
}

.input-group-text {
    font-size: 12px;
    background-color: #e9ecef;
}

.form-control-sm {
    border-radius: 4px;
    border: 1px solid #ced4da;
    font-size: 12px;
}

.form-control-sm:focus {
    border-color: #2171b5;
    box-shadow: 0 0 0 0.2rem rgba(33, 113, 181, 0.25);
}

/* Custom button hover effects */
.btn-sm {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    padding: 6px 10px;
}

.btn-info {
    background-color: #2171b5;
    border-color: #2171b5;
}

.btn-info:hover {
    background-color: #08306b;
    border-color: #08306b;
}

#update-storage-map-btn {
    width: 100%;
    font-weight: bold;
    letter-spacing: 0.5px;
    margin-top: 10px;
    transition: all 0.2s ease;
}

#update-storage-map-btn:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

/* Modal Styling */
.list-group-item {
    font-size: 13px;
    border-left: 4px solid #2171b5;
}

/* Vertical Button Container */
.map-controls-vertical {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2500;
}

.map-btn {
    width: 45px;
    height: 45px;
    background: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.map-btn:hover {
    background: #f0f0f0;
    color: #004085;
}

/* Base Panel Styling */
.analysis-panel-right, .map-legend-right {
    position: absolute;
    right: 75px; /* Sits to the left of the buttons */
    width: 320px;
    background: white;
    border-radius: 10px;
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    display: none; /* Controlled by JS */
    z-index: 2400;
    border: 1px solid #ddd;
    max-height: 80vh;
    overflow-y: auto;
}

.analysis-panel-right { top: 20px; }
.map-legend-right { bottom: 20px; }

.panel-header-simple {
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 10px 10px 0 0;
}

.close-panel {
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    color: #999;
}

.close-panel:hover { color: #333; }

.panel-body-content {
    padding: 15px;
}

/* Top Right Positioning */
.map-control-top-right {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 2500;
}

/* Bottom Right Positioning */
.map-control-bottom-right {
    position: absolute;
    bottom: 30px; /* High enough to clear the scale bar/attribution */
    right: 20px;
    z-index: 2500;
}

/* Circular Professional Buttons */
.map-btn-circular {
    width: 50px;
    height: 50px;
    background: #004085; /* Professional Dark Blue */
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease-in-out;
}

.map-btn-circular:hover {
    background: #002752;
    transform: scale(1.1);
}

/* Adjust Panels to align with the new button positions */
.analysis-panel-right {
    position: absolute;
    top: 20px;
    right: 80px;
    width: 320px;
    background: white;
    border-radius: 12px;
    display: none;
    z-index: 2400;
    box-shadow: -5px 5px 15px rgba(0,0,0,0.2);
}

.map-legend-right {
    position: absolute;
    bottom: 30px;
    right: 80px;
    width: 320px;
    background: white;
    border-radius: 12px;
    display: none;
    z-index: 2400;
    box-shadow: -5px -5px 15px rgba(0,0,0,0.2);
}

/* Container positioning */
.map-control-top-right {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 2500;
}

.map-control-bottom-right {
    position: absolute;
    bottom: 25px;
    right: 15px;
    z-index: 2500;
}

/* The Icon Button - No background, just the icon */
.map-icon-btn {
    background: transparent;
    border: none;
    padding: 5px;
    cursor: pointer;
    transition: transform 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
}

/* The Actual Icon Style */
.map-icon-btn i {
    font-size: 28px; /* Adjust size as needed */
    color: #004085;  /* Your theme color */
    /* Add a text-shadow to make it readable over busy map areas */
    text-shadow: 0px 0px 3px white, 0px 0px 8px rgba(255,255,255,0.8);
}

/* Hover effect: Subtle grow and color shift */
.map-icon-btn:hover i {
    color: #002752;
    transform: scale(1.15);
}

/* Active/Clicked state */
.map-icon-btn:active i {
    transform: scale(0.95);
}


/* Container positioning */
.map-control-top-right { position: absolute; top: 20px; right: 20px; z-index: 2500; }
.map-control-bottom-right { position: absolute; bottom: 30px; right: 20px; z-index: 2500; }

.map-control-glass {
    /* Glassmorphism Effect */
    background: rgba(255, 255, 255, 0.85); 
    backdrop-filter: blur(4px); /* Blurs map behind button slightly */
    
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px; /* Square with slight roundness looks more technical */
    width: 40px;
    height: 40px;
    
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.map-control-glass i {
    font-size: 22px;
    color: #004085; /* Deep professional blue */
}

/* Hover state: Button becomes solid and icon pops */
.map-control-glass:hover {
    background: #004085;
    border-color: #004085;
}

.map-control-glass:hover i {
    color: white;
}

.map-control-glass.active {
    background: #004085;
    border-color: #004085;
}
.map-control-glass.active i {
    color: white;
}