/* Modern Design System - Device Data Analysis */
:root {
    /* Primary Colors */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --primary-bg: #eef2ff;
    
    /* Background */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: rgba(255,255,255,0.08);
    
    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #f1f5f9;
    
    /* Status */
    --success: #10b981;
    --success-bg: #ecfdf5;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --info: #3b82f6;
    --info-bg: #eff6ff;
    
    /* Borders */
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    
    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    
    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    /* Transitions */
    --transition: all 0.2s ease;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-main: #0f172a;
        --bg-card: #1e293b;
        --bg-sidebar: #0f172a;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border: #334155;
        --border-light: #1e293b;
    }
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Navigation */
.top-nav {
    background: var(--bg-sidebar);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 100;
}

.top-nav a {
    color: var(--text-inverse);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 14px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-nav a:hover {
    background: var(--bg-sidebar-hover);
}

.top-nav a.active {
    background: var(--primary);
}

/* Map Container */
#map {
    position: absolute;
    top: 56px;
    left: 300px;
    right: 0;
    bottom: 0;
    background: var(--bg-main);
}

/* Tile Switcher */
.tile-switcher {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: flex;
    gap: 4px;
}

.tile-switcher button {
    background: transparent;
    border: none;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: var(--transition);
    white-space: nowrap;
}

.tile-switcher button:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.tile-switcher button.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

/* Sidebar */
#sidebar {
    position: absolute;
    top: 56px;
    left: 0;
    width: 300px;
    bottom: 0;
    background: var(--bg-sidebar);
    padding: 20px;
    overflow-y: auto;
    user-select: none;
    z-index: 50;
}

.sidebar-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
    transition: var(--transition);
}

.sidebar-resizer:hover,
.sidebar-resizer.active {
    background: var(--primary);
}

/* Sidebar Typography */
#sidebar h3 {
    margin: 20px 0 10px;
    color: var(--text-inverse);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

#sidebar h3:first-child {
    margin-top: 0;
}

/* Form Controls */
#sidebar label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-inverse);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

#sidebar label:hover {
    background: var(--bg-sidebar-hover);
}

#sidebar input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

#sidebar select {
    width: 100%;
    padding: 12px 14px;
    margin: 8px 0;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-md);
    color: var(--text-inverse);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

#sidebar select:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255,255,255,0.12);
}

#sidebar select option {
    background: var(--bg-sidebar);
    color: var(--text-inverse);
}

/* Divider */
#sidebar hr {
    margin: 16px 0;
    border: none;
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* Statistics Panel */
#stats {
    font-size: 13px;
    line-height: 1.8;
    color: var(--text-inverse);
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-md);
}

#stats b {
    color: var(--primary-light);
    font-weight: 600;
}

#stats hr {
    margin: 12px 0;
    border-top-color: rgba(255,255,255,0.1);
}

/* Device Info Panel */
#device-info {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-inverse);
}

#device-info h4 {
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
}

#device-info table {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-md);
    overflow: hidden;
}

#device-info td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 13px;
}

#device-info td:first-child {
    color: var(--text-muted);
}

/* Legend */
.legend {
    margin: 12px 0;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-md);
}

.legend-item {
    display: flex;
    align-items: center;
    padding: 6px 0;
    font-size: 12px;
    color: var(--text-inverse);
}

.legend-color {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 10px;
    border: 2px solid rgba(255,255,255,0.2);
}

/* Report Page */
.report-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.report-container h1 {
    color: var(--text-primary);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.report-time {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.card.total::before { background: var(--danger); }
.card.active::before { background: var(--success); }
.card.components::before { background: var(--info); }
.card.anomalies::before { background: var(--warning); }

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card h3 {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.card .count {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

/* Sections */
.section {
    margin-bottom: 32px;
}

.section h2 {
    color: var(--text-primary);
    margin-bottom: 16px;
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

th, td {
    padding: 14px 16px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
}

th {
    background: var(--bg-main);
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--primary-bg);
}

/* Severity Badges */
.severity-high {
    color: var(--danger);
    font-weight: 600;
}

.severity-medium {
    color: var(--warning);
    font-weight: 600;
}

.severity-low {
    color: var(--success);
}

/* Device Cards */
.device-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    border-left: 4px solid var(--success);
    transition: var(--transition);
}

.device-card.critical {
    border-left-color: var(--danger);
}

.device-card.warning {
    border-left-color: var(--warning);
}

.device-card:hover {
    box-shadow: var(--shadow-md);
}

.device-card h3 {
    color: var(--text-primary);
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 600;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.chart-container {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.chart-container.full-width {
    grid-column: 1 / -1;
}

.chart-container h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

/* Recommendations */
.recommendations {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.recommendation {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    border-top: 4px solid var(--border);
}

.recommendation.emergency {
    border-top-color: var(--danger);
}

.recommendation.short-term {
    border-top-color: var(--warning);
}

.recommendation.long-term {
    border-top-color: var(--success);
}

.recommendation h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

.recommendation ul {
    list-style: none;
    padding: 0;
}

.recommendation li {
    margin: 10px 0;
    line-height: 1.6;
    padding-left: 20px;
    position: relative;
    color: var(--text-secondary);
}

.recommendation li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
}

.recommendation.emergency li::before { background: var(--danger); }
.recommendation.short-term li::before { background: var(--warning); }
.recommendation.long-term li::before { background: var(--success); }

/* Appendix */
.appendix {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.appendix h3 {
    margin: 20px 0 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

.appendix h3:first-child {
    margin-top: 0;
}

.appendix ul {
    list-style: none;
    padding: 0;
}

.appendix li {
    margin: 8px 0;
    line-height: 1.6;
    color: var(--text-secondary);
    padding-left: 16px;
    position: relative;
}

.appendix li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--primary);
}

/* Profile Container */
#profile-container {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.profile-header {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary);
}

.profile-header h4 {
    margin: 0 0 4px 0;
    color: var(--primary-dark);
    font-size: 16px;
    font-weight: 600;
}

.profile-header p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Precipitation Info */
.precip-info {
    display: flex;
    gap: 20px;
    font-size: 13px;
    margin: 12px 0;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--info);
}

.precip-info.light {
    color: #1565c0;
    background: linear-gradient(90deg, #e3f2fd 0%, #bbdefb 100%);
    border-left-color: #42a5f5;
}

.precip-info.moderate {
    color: #e65100;
    background: linear-gradient(90deg, #fff3e0 0%, #ffe0b2 100%);
    border-left-color: #ff9800;
}

.precip-info.heavy {
    color: #b71c1c;
    background: linear-gradient(90deg, #ffebee 0%, #ffcdd2 100%);
    border-left-color: #f44336;
}

/* Profile Chart */
.profile-chart {
    margin: 16px 0;
    height: 240px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 12px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

/* Pipe Segments */
.pipe-segments {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.segment-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    margin: 6px 0;
    background: var(--bg-main);
    border-radius: var(--radius-md);
    font-size: 13px;
    transition: var(--transition);
}

.segment-info:hover {
    background: var(--primary-bg);
}

.segment-info.reverse {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
}

.seg-label {
    font-weight: 600;
    color: var(--text-primary);
}

.seg-detail {
    color: var(--text-secondary);
}

/* Node Details */
.node-details {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.node-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin: 4px 0;
    font-size: 12px;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.node-item:nth-child(odd) {
    background: var(--bg-main);
}

.node-name {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 100px;
}

.device-tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--danger);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    margin-left: 6px;
}

.node-info {
    color: var(--text-secondary);
    flex: 1;
    text-align: center;
}

.node-fullness {
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    min-width: 70px;
    text-align: center;
    font-size: 11px;
}

.node-fullness.normal { background: var(--success-bg); color: #065f46; }
.node-fullness.medium { background: var(--warning-bg); color: #92400e; }
.node-fullness.high { background: #fff7ed; color: #9a3412; }
.node-fullness.critical { background: var(--danger-bg); color: #991b1b; }

/* No Data */
.no-data {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 40px;
    background: var(--bg-main);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border);
}

/* Device Readings Summary in Profile Modal */
.device-readings-summary {
    margin-bottom: 20px;
    padding: 16px;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.device-readings-summary h4 {
    margin: 0 0 12px 0;
    color: var(--primary-dark);
    font-size: 14px;
    font-weight: 600;
}

.readings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.reading-item {
    display: flex;
    flex-direction: column;
    padding: 10px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
}

.reading-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.reading-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Trend Charts Section */
.trend-charts-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 2px solid var(--border);
}

.trend-charts-section h4 {
    margin: 0 0 16px 0;
    color: var(--primary-dark);
    font-size: 14px;
    font-weight: 600;
}

.trend-charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.trend-chart-container {
    background: var(--bg-main);
    border-radius: var(--radius-md);
    padding: 12px;
    height: 180px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.trend-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

@media (max-width: 768px) {
    .readings-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .trend-charts-grid {
        grid-template-columns: 1fr;
    }
}

/* Profile Button */
.profile-btn {
    width: 100%;
    padding: 12px;
    margin-top: 12px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.profile-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-card);
    margin: 3% auto;
    padding: 0;
    width: 92%;
    max-width: 1000px;
    height: 88%;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(20px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, #312e81 100%);
    color: white;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.close-modal {
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
    opacity: 0.8;
}

.close-modal:hover {
    opacity: 1;
    transform: scale(1.1);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

#modal-profile-content {
    min-height: 400px;
}

#modal-profile-content .profile-chart {
    height: 320px;
}

#modal-profile-content .node-item {
    padding: 10px 14px;
    font-size: 13px;
}

#modal-profile-content .segment-info {
    padding: 12px 14px;
    font-size: 13px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        width: 260px;
    }
    
    #map {
        left: 260px;
    }
    
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .recommendations {
        grid-template-columns: 1fr;
    }
}
