:root {
    --bg-color: #0d1117;
    --sidebar-bg: rgba(22, 27, 34, 0.7);
    --panel-bg: rgba(33, 38, 45, 0.6);
    --border-color: rgba(255, 255, 255, 0.15); /* Darkened slightly for contrast against 2px width */
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    
    --accent-red: #f85149;
    --accent-green: #3fb950;
    --accent-blue: #58a6ff;
    --accent-purple: #bc8cff;
    --accent-orange: #d29922;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    overflow: hidden;
    height: 100vh;
}

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

/* Sidebar */
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

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

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.badge {
    background: var(--accent-blue);
    color: #fff;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: bold;
}

.sidebar-menu {
    padding: 0 20px 20px 20px;
    flex-grow: 1;
    overflow-y: auto;
}

.menu-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.menu-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.4;
}

/* Toggle Switches */
.toggle-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toggle-switch {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
    position: relative;
    padding-left: 45px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 20px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    transition: .4s;
    border: 2px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-primary);
    border-radius: 50%;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--accent-blue);
    border-color: var(--accent-blue);
}

input:checked + .slider:before {
    transform: translateX(16px);
}

.label-text {
    transition: color 0.3s;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.5px;
}

input:not(:checked) ~ .label-text {
    color: var(--text-secondary);
    text-decoration: line-through;
}

/* Sidebar Accordions */
.sidebar-subtitle {
    font-size: 1.05rem;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.module-accordion {
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    overflow: hidden;
}

.module-accordion summary {
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    user-select: none;
    transition: background 0.3s;
    outline: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.5px;
}

.module-accordion summary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.module-accordion ul {
    list-style: none;
    padding: 8px 12px;
    margin: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.2);
}

.module-accordion li {
    padding: 6px 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: color 0.2s;
    cursor: pointer;
}

.module-accordion li:hover {
    color: var(--accent-blue);
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at top right, rgba(88, 166, 255, 0.1), transparent 400px),
                radial-gradient(circle at bottom left, rgba(188, 140, 255, 0.05), transparent 400px);
}

/* Header */
.header {
    height: auto;
    padding: 15px 30px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(13, 17, 23, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Icons */
.header-right {
    display: flex;
    gap: 15px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
}

.icon-btn:hover {
    color: var(--text-primary);
}

/* Dashboard Grid */
.dashboard-grid {
    flex-grow: 1;
    padding: 30px 40px;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: auto; /* Allow rows to shrink to content, fixing the huge header gaps */
    gap: 24px;
}

/* Glass Panel */
.glass-panel {
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    min-height: 140px; /* Force minimum height on cards instead of grid rows */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.glass-panel:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.15);
}

/* Col Spans */
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: span 4; }
.col-span-6 { grid-column: span 6; }
.col-span-8 { grid-column: span 8; }
.col-span-12 { grid-column: span 12; }

/* Row Spans and Specific Panels */
.row-span-2 { grid-row: span 2; }
.chart-panel {
    grid-row: span 2;
    min-height: 380px; /* Forces grid to allocate vertical track space for the second spanned row */
}

/* Panel Header */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 8px;
}

.panel-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* Scrollable List Container */
.list-container {
    flex-grow: 1;
    overflow-y: auto;
    margin-top: 10px;
    padding-right: 5px;
}

.list-container::-webkit-scrollbar {
    width: 6px;
}
.list-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.data-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.data-list-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-left: 3px solid var(--accent-blue);
    border-radius: 4px;
    font-size: 0.85rem;
}

.border-red { border-left-color: var(--accent-red); }
.border-green { border-left-color: var(--accent-green); }
.border-orange { border-left-color: var(--accent-orange); }
.border-blue { border-left-color: var(--accent-blue); }

.item-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.item-title {
    font-weight: 500;
    color: var(--text-primary);
}

.item-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.item-value {
    font-weight: 600;
    text-align: right;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* KPI Values */
.kpi-value {
    font-size: 1.7rem;
    font-weight: 700;
    margin-bottom: 8px;
    display: flex;
    align-items: baseline;
    gap: 5px;
    flex-wrap: wrap;
}

.kpi-unit {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.kpi-trend {
    font-size: 0.85rem;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    line-height: 1.4;
    word-break: break-word;
}

.trend-up { color: var(--accent-green); }
.trend-down { color: var(--accent-red); }
.trend-neutral { color: var(--text-secondary); }

/* Utilities */
.hidden { display: none !important; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.text-xs { font-size: 0.75rem; }
.text-secondary { color: var(--text-secondary); }

/* Alerts */
.alert-card {
    border-left: 4px solid var(--accent-red);
    background: linear-gradient(90deg, rgba(248, 81, 73, 0.1) 0%, transparent 100%);
}

.alert-value { color: var(--accent-red); }

/* Period Selectors */
.period-selectors { display: flex; gap: 5px; background: rgba(255, 255, 255, 0.05); padding: 4px; border-radius: 6px; }
.filter-btn { background: transparent; color: var(--text-secondary); border: none; padding: 6px 14px; font-size: 0.85rem; border-radius: 4px; cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.filter-btn:hover { color: var(--text-primary); }
.filter-btn.active { background: var(--accent-blue); color: #fff; font-weight: 500; }

/* Module Titles */
.module-header {
    grid-column: span 12;
    margin-top: 24px;
    margin-bottom: 0px; /* Reduced to pull cards closer */
    padding-bottom: 6px;
    border-bottom: 3px solid rgba(255, 255, 255, 0.2);
}
.module-header:first-child {
    margin-top: 0;
}
.module-header h2 {
    font-size: 1.3rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    line-height: 1;
}
.module-header i {
    color: var(--accent-blue);
}

/* Chart Containers */
.chart-container {
    flex-grow: 1;
    position: relative;
    width: 100%;
    margin-top: 10px;
    min-height: 250px; /* Replaces fixed height to avoid layout breaking, lets flex-grow handle remainder */
}

/* Responsive Design */
@media (max-width: 1200px) {
    .glass-panel.col-span-3 {
        grid-column: span 6;
    }
    .glass-panel.col-span-6 {
        grid-column: span 12;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    body {
        overflow: auto;
    }
    
    .hidden-mobile {
        display: none !important;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        display: block;
    }
    
    .sidebar-menu {
        overflow-x: auto;
        display: flex;
        flex-direction: row;
        gap: 20px;
        padding: 10px 20px;
        align-items: center;
    }
    
    .toggle-group {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 15px;
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: none;
    }
    
    .sidebar-subtitle {
        display: none;
    }
    
    .module-accordions {
        display: none;
    }
    
    .dashboard-grid {
        padding: 15px;
        display: flex;
        flex-direction: column;
    }
    
    .glass-panel.col-span-3,
    .glass-panel.col-span-6,
    .chart-panel {
        grid-column: span 12;
        width: 100%;
        margin-bottom: 15px;
    }
    
    .module-header {
        margin-top: 5px;
        margin-bottom: 10px;
    }
    
    .kpi-value {
        font-size: 1.4rem;
    }
}
