:root {
    --primary-blue: #002c4d;
    --active-blue: #004070;
    --accent-blue: #6db9ff;
    --bg-light: #f8f9fa;
    --border-color: #ddd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body, html { height: 100%; width: 100%; font-family: 'Segoe UI', sans-serif; overflow: hidden; }

.main-container { display: flex; height: 100vh; width: 100vw; }

/* Sidebar */
.sidebar {
    width: 320px; 
    background: var(--bg-light); 
    border-right: 1px solid var(--border-color);
    display: flex; 
    flex-direction: column; 
    transition: 0.3s; 
    position: relative; 
    z-index: 2000;
}
.sidebar.collapsed { margin-left: -320px; }

/* Add scrolling to sidebar-content instead */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Map Area */
#map-wrapper { flex-grow: 1; position: relative; height: 100vh; }
#map { height: 100%; width: 100%; z-index: 1; }

/* Positioning native Leaflet controls below the Coordinate Display + Docked Registry */
.leaflet-top.leaflet-right {
    left: 10px !important;   /* sidebar (320px) + spacing */
    right: auto !important;
    top: 130px !important;
    margin: 0 !important;
    align-items: flex-start;
    display: flex;
    flex-direction: column;
}

/* 2. Target the flyout menus (standard Leaflet & common plugins) */
.leaflet-right .leaflet-control-toolbar .leaflet-toolbar-actions,
.leaflet-right .leaflet-draw-actions,
.leaflet-right .leaflet-menu-container {
    left: 100% !important;  /* Push to the right of the button */
    right: auto !important; /* Reset the default 'right' positioning */
    margin-left: 5px;       /* Add a tiny gap between button and menu */
}

/* 3. If there are 'triangles' or pointers on the menus, flip them */
.leaflet-right .leaflet-toolbar-actions::before {
    left: -14px !important;
    right: auto !important;
    border-right-color: rgba(0,0,0,0.4); /* Arrow points left now */
    border-left-color: transparent !important;
}

.leaflet-bar {
    border: none !important;
    
    box-shadow: none !important;
}

/* Docked Feature Registry Panel */
#h2f-docked-registry {
    position: absolute;
    top: 150px;
    right: 10px;
    z-index: 1000;
    pointer-events: auto;
    width: 380px;
}
#h2f-selection-ext {
    position: absolute;
    top: 158px;          /* same as registry — JS will push it below dynamically */
    right: 10px;
    z-index: 999;        /* just below registry */
    pointer-events: auto;
    width: 380px;
    display: none;       /* hidden until a selection exists */
}

/* Coordinate Display Box */
.coordinate-display {
    position: absolute; 
    top: 10px; 
    right: 10px; 
    z-index: 1000;
    background: white; 
    padding: 12px; 
    border-radius: 4px; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    min-width: 220px; 
    pointer-events: auto;
}
.coordinate-display h3 { font-size: 14px; margin-bottom: 8px; border-bottom: 1px solid #eee; }
.coord-row { font-size: 12px; margin: 4px 0; color: #444; }

/* Bookmark Panel */
.bookmarks-panel {
    position: absolute;
    top: 180px;
    right: 80px;
    width: 250px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1001;
}

.bookmark-item {
    padding: 8px; 
    margin-bottom: 5px; 
    background: #f1f3f5;
    border-radius: 4px; 
    cursor: pointer; 
    font-size: 12px;
}
.input-group { display: flex; gap: 5px; margin-top: 10px; }
.input-group input { flex: 1; padding: 5px; border: 1px solid #ddd; }
.bookmark-add-btn { 
    padding: 5px 10px; 
    background: var(--primary-blue); 
    color: white; 
    border: none; 
    cursor: pointer; 
}

/* Sidebar Elements */
.tab-row { display: flex; background: var(--primary-blue); }
.tab-btn { 
    flex: 1; 
    padding: 12px; 
    border: none; 
    background: none; 
    color: white; 
    cursor: pointer; 
    font-size: 12px; 
}
.tab-btn.active { 
    background: var(--active-blue); 
    border-bottom: 3px solid var(--accent-blue); 
}

.sidebar-toggle {
    position: absolute; 
    right: -20px; 
    top: 70%; 
    transform: translateY(-50%);
    width: 20px; 
    height: 50px; 
    background: white; 
    border: 1px solid var(--border-color);
    border-left: none; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    cursor: pointer; 
    border-radius: 0 4px 4px 0; 
    font-size: 12px; 
    z-index: 2001;
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 10px;
}

.tab-content.active {
    display: block;
}

/* Tree View Styling */
.group-header { 
    display: flex; 
    align-items: center; 
    padding: 10px 15px; 
    background: white; 
    border-bottom: 1px solid #eee; 
    cursor: pointer; 
}
.group-items { display: none; }
.group-items.expanded { display: block; }
.tree-item { 
    display: flex; 
    align-items: center; 
    padding: 8px 15px 8px 40px; 
    font-size: 12px; 
}

/* Upload Section */
.upload-section {
    padding: 15px;
    background: white;
    border-bottom: 1px solid #eee;
}

.upload-btn {
    width: 100%;
    padding: 10px;
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.upload-btn:hover {
    background: var(--active-blue);
}

/* Info Content */
.info-content {
    padding: 15px;
    background: white;
}

/* Map Loading Indicator */
.map-loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 20px 30px;
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    font-size: 14px;
    pointer-events: none;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Remove default Leaflet pattern from Canvas renderer */
.leaflet-zoom-animated {
    image-rendering: -webkit-optimize-contrast;
}

/* ═══════════════════════════════════════════════════════════════════════════
   STYLE.CSS — APPEND BLOCK
   Add everything below this comment to the END of assets/css/style.css
   (The cos-controller.js already injects its own overlay styles dynamically,
    but the rules below act as a fallback and cover the legend + tree nodes.)
═══════════════════════════════════════════════════════════════════════════ */

/* ── COS Progress Overlay (fallback / supplement to cos-controller.js injection) ── */
#cos-progress-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9000;
    pointer-events: none;

    background: rgba(0, 12, 28, 0.88);
    border: 1px solid rgba(109, 185, 255, 0.25);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(109, 185, 255, 0.08);

    padding: 24px 32px 22px;
    min-width: 320px;
    max-width: 420px;
    width: 360px;

    display: flex;
    flex-direction: column;
    gap: 14px;

    font-family: 'Segoe UI', sans-serif;
    color: #e8f4ff;
}

/* ── COS Heatmap Legend (cos-legend class added by COSLegend control) ── */
.cos-legend {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
    font-family: 'Segoe UI', sans-serif;
    user-select: none;
    min-width: 80px;
}

.cos-legend-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.cos-legend-title {
    font-size: 11px;
    font-weight: 600;
    color: #002c4d;
    text-align: center;
    line-height: 1.3;
    max-width: 80px;
}

.cos-legend-body {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 5px;
}

.cos-legend-ticks {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.cos-legend-tick {
    position: absolute;
    left: 0;
    transform: translateY(-50%);
    font-size: 10px;
    color: #333;
    white-space: nowrap;
    line-height: 1;
}

/* ── COS Analysis tree group (inherits .tree-group — no new layout needed) ── */
/* The sub-group items for COS Analysis use the same .tree-item / .group-header
   styles as the rest of the sidebar. The rules below provide minor overrides. */

#cos-analysis-group .group-label {
    font-weight: 600;
    color: #002c4d;
}

#cos-analysis-group .tree-item {
    font-size: 11px;
    color: #333;
    cursor: pointer;
    transition: background 0.15s;
}

#cos-analysis-group .tree-item:hover {
    background: rgba(0, 64, 112, 0.06);
    border-radius: 3px;
}

/* Hint text shown when no states are uploaded yet */
#cos-analysis-group .cos-no-data-hint {
    padding: 10px 15px;
    font-size: 11px;
    color: #999;
    font-style: italic;
}

/* ── Geological Layers group (same inheritance pattern) ── */
#geological-layers-group .group-label {
    font-weight: 600;
    color: #002c4d;
}