:root {
    /* Colors */
    --background-primary: #ffffff;
    --background-secondary: #f8f9fa;
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --border-color: #e9ecef;
    --accent-color: #4d6bff;
    --accent-hover: #3a56e0;
    --success-color: #2ecc71;
    --warning-color: #f1c40f;
    --danger-color: #e74c3c;
    
    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 48px;
    
    /* Layout */
    --header-height: 70px;
    --sidebar-width: 220px;
    --widget-min-height: 300px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-speed: 0.3s;
    --transition-timing: ease;
    --color-background: var(--background-primary);
    --color-background-tertiary: var(--background-secondary);
    --color-text-primary: var(--text-primary);
    --color-text-secondary: var(--text-secondary);
    --color-border: var(--border-color);
    --color-primary: var(--accent-color);
    --color-primary-dark: var(--accent-hover);
    --color-success: var(--success-color);
    --color-warning: var(--warning-color);
    --color-error: var(--danger-color);
    --color-info: var(--accent-color);
    --surface-ground: var(--background-secondary);
    --widget-1-color: var(--success-color);
    --widget-2-color: var(--warning-color);
    --widget-3-color: var(--danger-color);
    --widget-4-color: var(--accent-color);
    --brand-primary: var(--accent-color);
    --brand-primary-dark: var(--accent-hover);
    --box-shadow-lg: var(--shadow-lg);
    --border-radius: var(--radius-md);
    --color-surface-hover: var(--background-secondary);
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Layout */
html, body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    background: var(--surface-ground);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--color-text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Header */
.top-header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
    padding: 0;
    flex-shrink: 0;
}

/* Main Layout */
.main-wrapper {
    display: flex;
    flex: 1;
    min-height: 0;
    background: var(--surface-ground);
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    background: var(--color-background);
    border-right: 1px solid var(--color-border);
    flex-shrink: 0;
}

/* Account Switcher */
.account-switcher {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    position: relative;
}

.account-switcher-btn {
    width: 100%;
    background: var(--surface-card, #f9fafb);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.account-switcher-btn:hover {
    background: var(--surface-hover, #f3f4f6);
    border-color: var(--brand-primary, #6366f1);
}

.account-switcher-current {
    display: flex;
    align-items: center;
    gap: 10px;
}

.account-initial {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.account-info {
    flex: 1;
    text-align: left;
    min-width: 0;
}

.account-name {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-location {
    display: block;
    font-size: 11px;
    color: var(--text-secondary, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-chevron {
    color: var(--text-secondary, #6b7280);
    font-size: 12px;
    transition: transform 0.2s ease;
}

.account-dropdown.open ~ .account-switcher-btn .account-chevron,
.account-switcher-btn:focus .account-chevron {
    transform: rotate(180deg);
}

.account-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 12px;
    right: 12px;
    background: white;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    max-height: 400px;
    display: flex;
    flex-direction: column;
}

.account-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.account-dropdown-header {
    padding: 12px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
}

.account-search {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease;
}

.account-search:focus {
    border-color: var(--brand-primary, #6366f1);
}

.account-dropdown-list {
    overflow-y: auto;
    max-height: 300px;
    padding: 8px;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.account-item:hover:not(.current) {
    background: var(--surface-hover, #f3f4f6);
}

.account-item.current {
    background: var(--brand-light, #eef2ff);
    cursor: default;
}

.account-item-initial {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.account-item-info {
    flex: 1;
    min-width: 0;
}

.account-item-name {
    display: block;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-item-location {
    display: block;
    font-size: 11px;
    color: var(--text-secondary, #6b7280);
}

.account-item-check {
    color: var(--brand-primary, #6366f1);
    font-size: 14px;
}

/* ─── Location Switcher ─── */
.location-switcher {
    padding: 4px 12px 8px;
    position: relative;
}

.location-switcher-btn {
    width: 100%;
    background: var(--surface-card, #f9fafb);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.location-switcher-btn:hover {
    background: var(--surface-hover, #f3f4f6);
    border-color: var(--brand-primary, #6366f1);
}

.location-switcher-current {
    display: flex;
    align-items: center;
    gap: 8px;
}

.location-icon {
    color: var(--brand-primary, #6366f1);
    font-size: 14px;
    flex-shrink: 0;
}

.location-name {
    flex: 1;
    font-weight: 500;
    font-size: 12px;
    color: var(--text-primary, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.location-chevron {
    color: var(--text-secondary, #6b7280);
    font-size: 10px;
    transition: transform 0.2s ease;
}

.location-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 12px;
    right: 12px;
    background: white;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    max-height: 350px;
    display: flex;
    flex-direction: column;
}

.location-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.location-dropdown-list {
    overflow-y: auto;
    max-height: 300px;
    padding: 6px;
}

.location-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.location-item:hover:not(.current) {
    background: var(--surface-hover, #f3f4f6);
}

.location-item.current {
    background: var(--brand-light, #eef2ff);
    cursor: default;
}

.location-item-icon {
    color: var(--text-secondary, #6b7280);
    font-size: 13px;
    flex-shrink: 0;
}

.location-item.current .location-item-icon {
    color: var(--brand-primary, #6366f1);
}

.location-item-info {
    flex: 1;
    min-width: 0;
}

.location-item-name {
    display: block;
    font-weight: 500;
    font-size: 12px;
    color: var(--text-primary, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.location-item-detail {
    display: block;
    font-size: 10px;
    color: var(--text-secondary, #6b7280);
}

.location-item-check {
    color: var(--brand-primary, #6366f1);
    font-size: 12px;
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    background: var(--surface-ground);
    padding: var(--space-4);
    overflow-y: auto; /* Allow vertical scrolling */
}

/* Date Range */
.date-range {
    margin-bottom: 24px;
    color: var(--color-text-secondary);
    font-size: 14px;
}

/* Date Range Picker Styles */
.date-range-picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--background-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
}

.date-range-picker i {
    color: var(--text-secondary);
}

.date-range-picker input {
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 14px;
    min-width: 260px;
    padding: 0;
    cursor: pointer;
}

.date-range-picker input:focus {
    outline: none;
}

/* DateRangePicker Plugin Overrides */
.daterangepicker {
    background-color: var(--background-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-lg);
    color: var(--text-primary);
}

.daterangepicker .calendar-table {
    background-color: var(--background-primary);
    border: none;
}

.daterangepicker td.active, 
.daterangepicker td.active:hover {
    background-color: var(--brand-primary);
}

.daterangepicker .ranges li.active {
    background-color: var(--brand-primary);
}

.daterangepicker .ranges li:hover {
    background-color: var(--brand-primary);
    opacity: 0.8;
}

.daterangepicker td.available:hover, 
.daterangepicker th.available:hover {
    background-color: var(--brand-primary);
    opacity: 0.3;
}

/* Dashboard Controls */
.dashboard-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

/* Widget Grid */
.widget-grid {
    display: none;
}

.widget {
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
}

.widget-controls {
    display: flex;
    gap: var(--space-2);
}

.widget-control {
    background: transparent;
    border: none;
    padding: var(--space-2);
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.widget-control:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.widget-content {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.widget i {
    font-size: 24px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.widget-title {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
}

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

.widget-1 { border-left: 4px solid var(--widget-1-color); }
.widget-2 { border-left: 4px solid var(--widget-2-color); }
.widget-3 { border-left: 4px solid var(--widget-3-color); }
.widget-4 { border-left: 4px solid var(--widget-4-color); }

/* Chart Grid */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

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

.chart-actions {
    display: flex;
    gap: 8px;
}

.chart-action {
    background: var(--color-background-tertiary);
    border: none;
    border-radius: var(--border-radius);
    padding: 6px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-speed) var(--transition-timing);
}

.chart-action:hover {
    background: var(--color-background-primary);
    color: var(--color-text-primary);
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: var(--border-radius);
    border: none;
    cursor: pointer;
    transition: all var(--transition-speed) var(--transition-timing);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

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

/* Status Colors */
.status-success { color: var(--color-success); }
.status-warning { color: var(--color-warning); }
.status-error { color: var(--color-error); }
.status-info { color: var(--color-info); }

/* Dark Mode Overrides */
[data-theme="dark"] {
    --background-primary: #14151A;
    --background-secondary: #0B0C0F;
    --text-primary: #E0E7FF;
    --text-secondary: #A0ABC0;
    --border-color: #2A2B33;
    --success-color: #38A169; /* Dark mode green */
    --danger-color: #E53E3E; /* Dark mode red */

    /* Form Controls Dark Mode */
    --input-bg: #2a2a2a;
}
