/* Custom Properties */
:root {
    --primary-color: #0f172a;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --text-main: #334155;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.03);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    --shadow-float: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 64px;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 24px;
    gap: 16px;
    z-index: 10;
}

.sidebar-item {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-size: 20px;
}

.sidebar-item:hover {
    background: var(--bg-color);
    color: var(--primary-color);
}

.sidebar-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-color);
    border-left: 3px solid var(--accent-color);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    margin-left: -3px;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: scroll;
    overflow-x: hidden;
}

.top-bar {
    height: 72px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 24px;
}

.logo-text {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.5px;
}

.logo-text .accent {
    color: var(--accent-color);
    font-weight: 500;
}

.page-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding-left: 24px;
    border-left: 2px solid var(--border-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

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

.icon-btn.outline {
    border: 1px solid var(--border-color);
}

.icon-btn.small {
    width: 28px;
    height: 28px;
    font-size: 16px;
}

.badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid var(--surface-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 12px 6px 6px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.user-profile:hover {
    background: var(--bg-color);
    border-color: var(--border-color);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.user-name {
    font-weight: 500;
    font-size: 14px;
}

/* Controls */
.controls-section {
    padding: 24px 32px 0 32px;
}

.filters {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 12px;
}

.filters.primary-filters {
    background: var(--surface-color);
    padding: 16px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.filters.primary-filters label {
    color: var(--text-muted);
}

.filters.primary-filters .icon-btn {
    color: var(--text-muted);
    border-color: var(--border-color);
}

.filters.secondary-filters {
    background: var(--surface-color);
    padding: 16px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.modern-select {
    appearance: none;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 32px 8px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-main);
    cursor: pointer;
    min-width: 180px;
}

.modern-select:hover {
    border-color: var(--primary-color);
    outline: none;
}

.select-wrapper i {
    position: absolute;
    right: 12px;
    color: var(--text-muted);
}

.date-range {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text-main);
    cursor: pointer;
    min-width: 220px;
}

.btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--accent-color);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* Tabs */
.tabs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.tabs {
    display: flex;
    gap: 32px;
}

.tab {
    background: none;
    border: none;
    padding: 12px 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
}

.tab.active {
    color: var(--primary-color);
    font-weight: 600;
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--primary-color);
}

/* GridStack / Widgets */
.dashboard-grid-area {
    padding: 0 24px 32px 24px;
}

.grid-stack-item-content {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Draggable handle for GridStack items */
.grid-stack-item-content {
    cursor: move; /* Let the entire widget act as a drag handle or just the header */
}

/* Optional hover styles */
.grid-stack-item:hover .grid-stack-item-content {
    box-shadow: var(--shadow-md);
}

/* When dragged */
.grid-stack-item.ui-draggable-dragging .grid-stack-item-content {
    box-shadow: var(--shadow-float);
    opacity: 0.9;
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    cursor: move; /* specific handle */
}

.widget-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-color);
    pointer-events: none;
}

.widget-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    pointer-events: auto;
}

.metric-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* KPIs */
.kpi .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.kpi-compare {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.trend.positive { color: #16a34a; }
.trend.negative { color: #dc2626; }

.kpi-table {
    display: flex;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    padding: 8px;
    justify-content: space-between;
    text-align: center;
    margin-top: auto;
}

.kpi-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    border-right: 1px solid var(--border-color);
}
.kpi-col:last-child { border: none; }

.kpi-lbl { font-size: 11px; color: var(--text-muted); }
.kpi-col strong { font-size: 13px; color: var(--primary-color); }

/* Charts wrapping */
.chart-container {
    flex: 1;
    position: relative;
    min-height: 0; 
}
.canvas-wrapper {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
}

/* Add Widget Drawer */
.widget-drawer-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(3px);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.widget-drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.widget-drawer {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    height: 100vh;
    background: var(--surface-color);
    box-shadow: -4px 0 15px rgba(0,0,0,0.1);
    z-index: 101;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.widget-drawer.active {
    right: 0;
}

.drawer-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-header h2 {
    font-size: 18px;
    color: var(--primary-color);
}

.drawer-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.drawer-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
    padding: 0 8px;
}

/* GridStack internal styles to make drawer items act as items */
#drag-widgets {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.new-widget-placeholder {
    width: 250px;
    border: 1px dashed var(--primary-color);
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    font-weight: 500;
    color: var(--primary-color);
    cursor: grab;
    transition: var(--transition);
}

.new-widget-placeholder:hover {
    background: rgba(11, 32, 70, 0.05);
}

.new-widget-placeholder i {
    font-size: 32px;
}

/* Footer */
.app-footer {
    margin-top: auto;
    padding: 16px 32px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

/* ANALYSIS PAGE SPECIFICS */
.analysis-layout {
    display: flex;
    height: calc(100vh - 72px - 220px); 
    margin: 0 32px 32px 32px;
    gap: 24px;
}

.analysis-sidebar {
    width: 320px;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.analysis-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.analysis-chart-card {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.analysis-info-card {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

/* Meter List */
.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--primary-color);
    display: flex;
    justify-content: space-between;
}

.meter-list {
    overflow-y: auto;
    flex: 1;
}

.meter-item {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 13px;
}
.meter-item.selected {
    background: rgba(59, 130, 246, 0.08);
    border-left: 3px solid var(--accent-color);
}
.meter-item:hover { background: var(--bg-color); }

.meter-id {
    font-weight: 500;
    flex: 1;
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    font-size: 13px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 6px;
}

.info-label { color: var(--text-muted); }

/* Notifications Dropdown */
.notif-dropdown { position: absolute; top: 48px; right: -8px; width: 320px; background: var(--surface-color); box-shadow: var(--shadow-lg); border: 1px solid var(--border-color); border-radius: var(--radius-lg); display: none; flex-direction: column; z-index: 1000; text-align: left; }
.notif-dropdown.active { display: flex; }
.notif-header { padding: 12px 16px; border-bottom: 1px solid var(--border-color); font-weight: 600; font-size: 14px; color: var(--text-main); }
.notif-item { padding: 12px 16px; display: flex; gap: 12px; border-bottom: 1px solid var(--border-color); font-size: 13px; cursor: pointer; color: var(--text-main); line-height: 1.4; }
.notif-item:hover { background: var(--bg-color); }
.notif-item.unread { background: rgba(59, 130, 246, 0.08); }
.notif-item:last-child { border-bottom: none; }