/* civ-map-three.css */

/* === Core Page Setup === */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f7f9; /* A light, neutral background */
    color: #333;
    overflow: hidden; /* Prevent body scrollbars */
    display: flex;
    flex-direction: column;
    height: 100vh; /* Full viewport height */
}

/* === Top Bar === */
.top-bar {
    background-color: #343a40; /* Darker, more standard header color */
    color: #f8f9fa; /* Light text for contrast */
    padding: 0 15px;
    display: flex;
    align-items: center;
    height: 50px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    z-index: 1100; /* High z-index to stay on top */
    flex-shrink: 0; /* Prevent shrinking */
    transition: margin-left 0.3s ease-in-out; /* For sidebar push effect */
    margin-left: 0; /* Default when sidebar is closed */
}
.top-bar.sidebar-open {
    /* margin-left: 320px; /* Adjust to match sidebar width */
    /* Commented out: Sidebar will be fixed and map wrapper will shift, top-bar can stay full width */
}

#toggle-sidebar-button {
    background: none;
    border: none;
    color: #f8f9fa;
    font-size: 22px; /* Slightly adjusted size */
    cursor: pointer;
    padding: 0 12px 0 0; /* Adjusted padding */
    margin-right: 12px;
    line-height: 50px; /* Vertically center icon */
    transition: color 0.2s ease;
}
#toggle-sidebar-button:hover {
    color: #adb5bd; /* Softer hover color */
}

.top-bar h1 {
    margin: 0;
    font-size: 18px; /* Slightly reduced for a cleaner look */
    font-weight: 500; /* Medium weight */
    white-space: nowrap;
}

/* === Control Sidebar === */
#control-sidebar {
    width: 320px; /* Slightly wider for more content space */
    background-color: #ffffff; /* White sidebar */
    border-right: 1px solid #dee2e6; /* Standard border color */
    box-shadow: 3px 0 8px rgba(0,0,0,0.07); /* Softer shadow */
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease-in-out;
    transform: translateX(-100%); /* Start hidden off-screen to the left */
    z-index: 1000; /* Below top-bar, above map overlays if needed */
    height: calc(100vh - 50px); /* Full available height below top bar */
    position: fixed; /* Fixed position for slide-in effect */
    left: 0;
    top: 50px; /* Positioned below the top bar */
}
#control-sidebar.open {
    transform: translateX(0); /* Slide in */
}
.sidebar-content-wrapper {
    overflow-y: auto; /* Enable vertical scrolling for sidebar content */
    flex-grow: 1;
    padding-bottom: 20px; /* Space at the bottom of scrollable area */
}

/* Sidebar section styles are in the HTML's <style> block for this example,
   but should ideally be moved here. */

/* === Control Item Styling (Checkboxes, Labels within Sidebar) === */
.control-item {
    display: flex;
    align-items: center;
    padding: 10px 0; /* Consistent padding for items */
    gap: 10px; /* Space between checkbox and label */
}
.control-item input[type="checkbox"] {
    margin: 0; /* Remove default margin */
    cursor: pointer;
    accent-color: #007bff; /* Standard primary blue */
    width: 16px; /* Custom size */
    height: 16px;
}
.control-item label {
    font-size: 14px;
    color: #495057; /* Slightly muted text color */
    cursor: pointer;
    flex-grow: 1; /* Allow label to take available space */
    line-height: 1.4;
}

/* === General Button Styling === */
button.control-button, .preset-button {
    padding: 8px 14px; /* Adjusted padding */
    background-color: #007bff; /* Primary blue */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
button.control-button:hover, .preset-button:hover {
    background-color: #0056b3; /* Darker blue on hover */
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
button.control-button:active, .preset-button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
#reset-weights {
    background-color: #6c757d; /* Secondary grey for reset */
}
#reset-weights:hover {
    background-color: #5a6268;
}

/* === Tier Filter Styling === */
.tier-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.tier-filters label {
    padding: 6px 10px; /* Adjusted padding */
    border-radius: 4px;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    cursor: pointer;
    font-size: 13px;
    color: #495057;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
    display: inline-flex; /* Align items well if using icons later */
    align-items: center;
    justify-content: center;
}
.tier-filters input[type="checkbox"] {
    display: none; /* Hide the actual checkbox */
}
/* Style the label when its checkbox is checked */
.tier-filters input[type="checkbox"]:checked + span { /* If structure is <label><input><span>S</span></label> */
    /* This is an example, current HTML is <label><input>S</label> */
}
.tier-filters label:has(input[type="checkbox"]:checked) { /* Modern browser support */
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
}
.tier-filters label:hover:not(:has(input[type="checkbox"]:checked)) {
    background-color: #dde2e6; /* Hover for unchecked items */
    border-color: #adb5bd;
}


/* === Map Container and Wrapper === */
#map-container-wrapper {
    flex-grow: 1; /* Occupy remaining vertical space */
    position: relative; /* Context for absolutely positioned children like map-container */
    background-color: #181a1b; /* Dark background for the map area */
    transition: margin-left 0.3s ease-in-out;
    margin-left: 0; /* Default: no margin when sidebar is closed */
    height: calc(100vh - 50px); /* Full available height below top bar */
    overflow: hidden; /* Prevent map from causing body scroll */
}
#map-container-wrapper.sidebar-open {
    margin-left: 320px; /* Push map wrapper to the right when sidebar is open */
}

#map-container {
    width: 100%;
    height: 100%;
    position: relative; /* For tooltip, loading overlay */
    overflow: hidden; /* Clip canvas if it exceeds bounds */
}
#map-container canvas {
    display: block; /* Remove extra space below canvas */
    width: 100%;
    height: 100%;
}

/* === Loading Overlay === */
#loading-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85); /* Darker overlay */
    display: flex;
    justify-content: center; align-items: center;
    z-index: 1500; /* High z-index */
    color: white;
    text-align: center;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}
#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none; /* Allow clicks through when hidden */
}
/* Progress bar styles from original HTML are generally fine */
#progress-bar-container { background-color: #343a40; }
#progress-bar { background-color: #28a745; } /* Green for progress */
#loading-error { color: #dc3545; } /* Red for errors */


/* === Tooltip === */
.tooltip {
    position: absolute;
    visibility: hidden;
    background-color: rgba(20, 20, 20, 0.95); /* Very dark, almost opaque */
    color: #e0e0e0;
    padding: 10px 14px;
    border-radius: 5px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.3);
    pointer-events: none;
    max-width: 260px;
    z-index: 1600; /* Above map, potentially above some UI elements if map is full screen */
    font-size: 12.5px; /* Slightly larger for readability */
    line-height: 1.5;
    border: 1px solid #333;
}
.tooltip h4 {
    margin: 0 0 7px 0;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
    font-size: 13.5px;
    color: #ffffff;
    font-weight: 600;
}
.tooltip p { margin: 4px 0; }
.tooltip strong { color: #adb5bd; }


/* === Legend === */
.legend {
    position: fixed; /* Fixed position relative to viewport */
    bottom: 15px;
    right: 15px;
    background-color: rgba(255, 255, 255, 0.92); /* Slightly more opaque */
    backdrop-filter: blur(6px); /* Stronger blur */
    padding: 14px;
    border-radius: 6px; /* Slightly smaller radius */
    box-shadow: 0 3px 12px rgba(0,0,0,0.12);
    max-width: 230px;
    /* max-height: calc(100vh - 100px); /* Removed: Overall legend height is controlled by its content */
    /* overflow-y: auto; /* Removed: Overall legend scroll is controlled by .legend-content */
    z-index: 900; /* Below sidebar, above map elements */
    font-size: 12px;
    border: 1px solid #dee2e6;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    transform: translateY(0);
}
.legend.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(15px); /* Animate slightly on hide */
    pointer-events: none;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 7px;
    border-bottom: 1px solid #e0e0e0;
}
.legend h3 { margin: 0; font-size: 15px; color: #343a40; }
.legend-toggle {
    cursor: pointer;
    color: #007bff;
    font-size: 11.5px;
    font-weight: bold;
    padding: 3px 7px;
    border-radius: 3px;
    background-color: #e7f3ff; /* Light blue background */
}
.legend-toggle:hover { background-color: #cfe7ff; }

/* Styles for the content area within the legend */
.legend .legend-content {
    max-height: 0; /* Start collapsed */
    overflow: hidden; /* Clip content during collapse/expand */
    transition: max-height 0.3s ease-in-out; /* Animate max-height */
    /* Ensure there's some padding if not inherited, e.g., padding: 10px 0 0 0; if header has bottom padding */
}

.legend-section { margin-bottom: 10px; }
.legend-section:last-child { margin-bottom: 0; }
.legend-section h4 {
    margin: 0 0 7px 0; font-size: 13px; color: #495057;
    border-bottom: 1px solid #f1f1f1; padding-bottom: 4px; font-weight: 600;
}
.legend-item { display: flex; align-items: center; margin-bottom: 4px; line-height: 1.3; }
.legend-color {
    width: 15px; height: 15px; margin-right: 9px;
    border: 1px solid #ccc; flex-shrink: 0;
}
/* Resource colors (ensure these match JS config if dynamically generated) */
.resource-luxury { background-color: #8e44ad; border-radius: 50%; } /* Purple */
.resource-strategic { background-color: #c0392b; border-radius: 50%; } /* Darker Red */
.resource-bonus { background-color: #27ae60; border-radius: 50%; } /* Darker Green */

.tier-symbol {
    width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
    margin-right: 7px; font-weight: bold; border-radius: 50%; font-size: 10.5px;
    flex-shrink: 0; border: 1px solid rgba(0,0,0,0.15);
    color: white; /* Default text color, override per tier if needed */
}
/* Tier colors (ensure consistency with JS config) */
.tier-S { background-color: #f1c40f; color: #333; } /* Gold, dark text */
.tier-A { background-color: #e67e22; } /* Orange */
.tier-B { background-color: #2ecc71; } /* Green */
.tier-C { background-color: #3498db; } /* Blue */
.tier-D { background-color: #95a5a6; } /* Grey */
.tier-E { background-color: #7f8c8d; } /* Darker Grey */
.tier-F { background-color: #34495e; } /* Dark Blue/Grey */

/* Heatmap Legend */
#heatmap-legend-section { /* Styles applied when shown by JS */ }
.heatmap-gradient {
    height: 16px; width: 100%; border: 1px solid #ccc; border-radius: 3px; margin-bottom: 4px;
    background: linear-gradient(to right, #0000ff, #00ffff, #00ff00, #ffff00, #ff0000); /* Standard heatmap gradient */
}
.heatmap-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: #555; }

/* === Show Legend Button === */
#show-legend-button {
    position: fixed;
    bottom: 15px;
    right: 15px;
    z-index: 901; /* Above legend when it's hidden */
    display: none; /* Hidden by default, JS makes it visible */
    /* Inherits .control-button styles */
}
#show-legend-button.visible { display: block; }


/* === Debug Info Overlay === */
#debug-info {
    position: fixed; top: 60px; right: 10px; background: rgba(25,25,25,0.88);
    color: #2ecc71; /* Green text for debug */
    padding: 12px; border-radius: 5px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 11px; max-width: 360px; max-height: 45vh; overflow-y: auto;
    z-index: 2000; /* Very high z-index */
    border: 1px solid #444;
}
#debug-info h3 { margin: 0 0 6px 0; font-size: 12.5px; border-bottom: 1px solid #444; padding-bottom: 4px; }
#debug-content div { margin-bottom: 3px; word-break: break-all; }


/* === Error Message Styling === */
.error-message {
    position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%);
    background-color: white; padding: 25px 35px; border-radius: 6px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2); text-align: center;
    border: 1px solid #e0e0e0; max-width: 85%; z-index: 2500;
}
.error-message h3 { color: #d9534f; margin: 0 0 12px 0; }
.error-message p { margin: 6px 0; font-size: 14.5px; color: #555; }

/* === Slider Customization (Track and Thumb) === */
/* Styles for weight-slider-group are in HTML's <style> or can be moved here */
input[type="range"].weight-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: #dee2e6; /* Track color */
    outline: none;
    border-radius: 4px;
    cursor: pointer;
}
input[type="range"].weight-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #007bff; /* Thumb color */
    border-radius: 50%;
    border: 2px solid white; /* White border around thumb */
    box-shadow: 0 0 4px rgba(0,0,0,0.2); /* Subtle shadow for thumb */
    cursor: pointer;
}
input[type="range"].weight-slider::-moz-range-thumb {
    width: 16px; /* Firefox thumb size (border adds to total size) */
    height: 16px;
    background: #007bff;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 4px rgba(0,0,0,0.2);
    cursor: pointer;
}
input[type="range"].weight-slider::-moz-range-track {
    background: #dee2e6;
    height: 8px;
    border-radius: 4px;
}
