:root {
    /* Glassmorphism Color Palette */
    --bg-glass-heavy: rgba(255, 255, 255, 0.7);
    --bg-glass-medium: rgba(255, 255, 255, 0.45);
    --bg-glass-light: rgba(255, 255, 255, 0.2);
    --bg-glass-hover: rgba(255, 255, 255, 0.85);

    --text-main: #1e293b;
    --text-muted: #475569;
    
    --border-glass: rgba(255, 255, 255, 0.6);
    --border-glass-light: rgba(255, 255, 255, 0.3);
    
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #ef4444;
    --success: #10b981; 
    
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.08);
    --shadow-glass-intense: 0 12px 40px 0 rgba(31, 38, 135, 0.15);
    
    --radius: 12px;
    --radius-sm: 8px;
}

/* --- Animated Mesh Gradient Body --- */
body { 
    margin: 0; padding: 0; 
    font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; 
    display: flex; flex-direction: column; 
    height: 100vh; 
    color: var(--text-main); 
    overflow: hidden; 
    font-size: 14px; 
    
    /* Simple clean background for glass contrast */
    background-color: #f8fafc;
}

/* --- Glassmorphism Base Utility --- */
.glass-panel {
    background: var(--bg-glass-heavy);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-glass);
}

/* --- Login Overlay --- */
#loginOverlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    z-index: 9999; display: flex; justify-content: center; align-items: center; 
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px) saturate(150%);
}
.login-box { 
    background: var(--bg-glass-heavy);
    backdrop-filter: blur(20px) saturate(200%);
    padding: 48px; border-radius: var(--radius); 
    box-shadow: var(--shadow-glass-intense); 
    text-align: center; width: 400px; 
    border: 1px solid var(--border-glass); 
}
.login-box h3 { margin-top: 0; margin-bottom: 22px; font-size: 20px; font-weight: 700; color: var(--text-main); }
.login-box input { 
    width: 100%; padding: 12px 14px; margin-bottom: 18px; 
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1); 
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-sm); font-size: 14px; box-sizing: border-box; 
    outline: none; transition: all 0.3s ease; 
    color: var(--text-main);
}
.login-box input::placeholder {
    color: #94a3b8;
    font-weight: 500;
}
.login-box input:focus { 
    background: #ffffff;
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); 
}
.error-msg { 
    color: var(--danger); font-size: 12px; margin-bottom: 14px; display: none; text-align: left; 
    background: rgba(239, 68, 68, 0.1); padding: 8px; border-radius: var(--radius-sm); border: 1px solid rgba(239, 68, 68, 0.2);
}
.login-box .btn-primary { width: 100%; justify-content: center; padding: 12px; font-size: 14px; font-weight: 700; }

/* --- Loading Overlay --- */
#loadingOverlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background-color: rgba(255, 255, 255, 0.3); z-index: 9998; display: none; 
    justify-content: center; align-items: center; flex-direction: column; 
    backdrop-filter: blur(12px) saturate(180%); 
}
.spinner { 
    border: 4px solid var(--border-glass-light); border-top: 4px solid var(--primary); 
    border-radius: 50%; width: 44px; height: 44px; animation: spin 1s linear infinite; margin-bottom: 16px; 
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.loading-text { font-size: 15px; font-weight: 600; color: var(--text-main); letter-spacing: 0.5px; }

/* --- Main Layout --- */
#mainDashboard { display: none; height: 100%; width: 100%; position: relative; }

/* --- Three-Row Header --- */
#header { 
    position: absolute; top: 20px; left: 20px; right: 20px;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-glass); 
    border-radius: var(--radius);
    box-shadow: var(--shadow-glass-intense); 
    z-index: 1000; display: flex; flex-direction: column; 
    overflow: hidden;
}

.header-top { 
    padding: 14px 20px; 
    border-bottom: 1px solid var(--border-glass-light); 
    display: flex; justify-content: space-between; align-items: center; 
    flex-wrap: wrap; gap: 12px;
}
.header-title { margin: 0; font-size: 18px; font-weight: 700; color: var(--text-main); letter-spacing: 0.3px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.header-middle { 
    padding: 10px 20px; 
    display: flex; flex-wrap: wrap; 
    align-items: center; gap: 14px; 
}

/* --- Controls & Inputs --- */
.control-group { display: flex; align-items: center; gap: 8px; }
.control-label { font-size: 13px; font-weight: 600; color: var(--text-main); }
.form-control { 
    padding: 6px 12px; font-size: 13px; border-radius: var(--radius-sm); 
    border: 1px solid var(--border-glass); 
    background: rgba(255, 255, 255, 0.6); 
    outline: none; transition: all 0.2s ease; 
    color: var(--text-main);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}
.form-control:focus { background: #ffffff; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }
input[type="text"].form-control { width: 160px; }

/* Sliders & Direct Inputs */
.slider-row { display: flex; align-items: center; gap: 8px; }
input[type="range"] { cursor: pointer; accent-color: var(--primary); width: 80px; height: 5px; }

/* Direct Number Input Styling */
.pcf-input { 
    width: 56px; padding: 5px 8px; border: 1px solid var(--border-glass); 
    border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; 
    color: var(--primary); text-align: center; outline: none; transition: all 0.3s; 
    background: rgba(255, 255, 255, 0.6); 
}
.pcf-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }
.pcf-input::-webkit-inner-spin-button, .pcf-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.divider { width: 1px; height: 20px; background-color: var(--border-glass); margin: 0 6px; }

/* --- Buttons --- */
.btn { 
    display: inline-flex; align-items: center; justify-content: center; 
    padding: 7px 14px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; 
    cursor: pointer; transition: all 0.2s ease; border: 1px solid transparent; 
    background: transparent; gap: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.btn-icon-only { padding: 7px 12px; font-size: 15px; } 

.btn-primary { 
    background: linear-gradient(135deg, var(--primary), var(--primary-hover)); 
    color: white; border: 1px solid rgba(255,255,255,0.2); 
    box-shadow: 0 4px 10px rgba(37,99,235,0.3); 
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(37,99,235,0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-outline { 
    background: rgba(255, 255, 255, 0.5); 
    color: var(--text-main); 
    border: 1px solid var(--border-glass); 
    backdrop-filter: blur(4px);
}
.btn-outline:hover { background: rgba(255, 255, 255, 0.8); border-color: rgba(255,255,255,0.9); }
.btn-outline.active { background: #eff6ff; border-color: var(--primary); color: var(--primary); font-weight: 600; box-shadow: inset 0 0 0 1px var(--primary); }

/* --- Workspace & Views --- */
#workspace { display: flex; position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; }
.view-panel { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; display: flex; flex-direction: column; }
.view-panel.active { opacity: 1; pointer-events: auto; position: absolute; z-index: 10; }

#tableView { padding: 140px 20px 20px 20px; box-sizing: border-box; }

/* The map itself doesn't need to be glass, as it renders tiles. But removing harsh background */
#map { width: 100%; height: 100%; background-color: #f8fafc; }
#map .leaflet-top { margin-top: 170px; } /* Push zoom controls below floating header */

/* --- Summary Overlay on Map --- */
#summaryPanel {
    position: absolute; bottom: 20px; left: 20px; 
    background: var(--bg-glass-heavy);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    padding: 16px; border-radius: var(--radius); border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-glass-intense); z-index: 999; width: 220px;
    transition: width 0.3s ease;
}

.summary-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; border-bottom: 1px solid var(--border-glass-light); padding-bottom: 10px; margin-bottom: 12px; transition: all 0.3s; }
.summary-header.collapsed { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.summary-title { font-weight: 700; font-size: 16px; color: var(--text-main); margin: 0; letter-spacing: 0.3px; } 
.toggle-icon { font-size: 14px; color: var(--text-muted); transition: transform 0.3s; }
.toggle-icon.collapsed { transform: rotate(180deg); }

#summaryContent { overflow: hidden; transition: max-height 0.3s ease; }
#summaryContent.collapsed { display: none; }

.summary-item { margin-bottom: 8px; font-size: 14px; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; }
.summary-val { font-weight: 700; font-size: 16px; color: var(--text-main); }

.chart-container { margin-top: 14px; border-top: 1px dashed var(--border-glass); padding-top: 10px; }
.chart-title { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-align: center; }
.mini-chart { display: flex; align-items: flex-end; justify-content: space-between; height: 40px; gap: 2px; }
.chart-bar { flex: 1; background: linear-gradient(to top, var(--primary), #60a5fa); border-radius: 2px 2px 0 0; min-height: 1px; transition: height 0.2s ease; opacity: 0.9; box-shadow: 0 0 2px rgba(37,99,235,0.3); }
.chart-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* --- Table View --- */
#tableContainer { 
    width: 100%; height: 100%; overflow: auto; 
    background: rgba(255, 255, 255, 0.25); /* More transparent to show body gradient deeply */
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    box-shadow: var(--shadow-glass-intense);
    padding: 0; 
}
table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; font-size: 14px; }
th { 
    background: rgba(255, 255, 255, 0.45); 
    backdrop-filter: blur(12px);
    padding: 14px 20px; font-weight: 700; color: var(--text-main); 
    position: sticky; top: 0; border-bottom: 1px solid var(--border-glass); 
    z-index: 10; text-transform: uppercase; font-size: 12px; letter-spacing: 0.8px; user-select: none; 
}
th.sortable-col { cursor: pointer; transition: background-color 0.2s; }
th.sortable-col:hover { background: rgba(255, 255, 255, 0.7); }
th i.sort-icon { font-size: 10px; margin-left: 6px; color: #94a3b8; }
th.active-sort i.sort-icon { color: var(--primary); }
td { 
    padding: 12px 20px; border-bottom: 1px solid rgba(255, 255, 255, 0.3); 
    color: var(--text-main); font-weight: 500; transition: background-color 0.2s; 
    background: rgba(255, 255, 255, 0.1);
}
tbody tr:hover td { background: rgba(255, 255, 255, 0.55); box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), inset 0 -1px 0 rgba(255,255,255,0.7); }
.val-danger { color: #dc2626; font-weight: 700; background: rgba(239, 68, 68, 0.05); border-radius: 4px; padding: 2px 6px; }

/* --- Map Popups --- */
.leaflet-popup-content-wrapper { 
    background: var(--bg-glass-heavy) !important;
    backdrop-filter: blur(12px) !important;
    border-radius: var(--radius) !important; 
    box-shadow: var(--shadow-glass-intense) !important; 
    border: 1px solid var(--border-glass) !important; 
    padding: 4px !important; 
}
.leaflet-popup-tip { background: var(--bg-glass-heavy) !important; backdrop-filter: blur(12px) !important; border: 1px solid var(--border-glass) !important; border-top: none !important; border-left: none !important; }
.popup-content { font-size: 13px; line-height: 1.6; color: var(--text-main); min-width: 190px; }
.popup-header { border-bottom: 1px solid var(--border-glass); padding-bottom: 8px; margin-bottom: 8px; font-weight: 700; font-size: 14px; color: var(--primary); }
.leaflet-tooltip { 
    background: var(--bg-glass-heavy) !important; border-radius: var(--radius-sm) !important; border: 1px solid var(--border-glass) !important; 
    font-weight: 600 !important; font-size: 11px !important; padding: 3px 6px !important; box-shadow: var(--shadow-glass) !important;
    backdrop-filter: blur(8px) !important; color: var(--text-main) !important;
}

/* --- Mobile Display Mode --- */
@media (max-width: 768px) {
    #header { top: 8px; left: 8px; right: 8px; }
    .header-top, .header-middle { padding: 10px 12px; gap: 10px; }
    .header-title { font-size: 16px; }
    
    /* Make actions fit */
    .header-actions { justify-content: space-between; }
    
    /* Allow summary panel to span bottom cleanly on phone */
    #summaryPanel { width: auto; left: 8px; right: 8px; bottom: 8px; }
    
    /* Fix login box width */
    .login-box { width: 90%; padding: 24px; }
    
    /* Safely clear larger wrapped header */
    #tableView { padding-top: 280px; padding-left: 8px; padding-right: 8px; padding-bottom: 8px; }
    #map .leaflet-top { margin-top: 300px; }
}
