/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary-color: #4F46E5;
    --primary-dark: #4338CA;
    --primary-light: #818CF8;
    --secondary-color: #10B981;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --info-color: #3B82F6;
    
    /* Neutrals */
    --bg-primary: #F9FAFB;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F3F4F6;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-tertiary: #9CA3AF;
    --border-color: #E5E7EB;
    
    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --sidebar-bg: #1F2937;
    --sidebar-text: #D1D5DB;
    --sidebar-active: var(--primary-color);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition: all 0.3s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ============================================
   PAGE VISIBILITY CONTROL
   ============================================ */
#loginPage {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;  /* Center horizontally */
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    padding: 20px;
    width: 100%;  /* Full width */
}

#loginPage:not(.active) {
    display: none;
}

#dashboardContainer {
    display: none;
    width: 100%;
}

#dashboardContainer.active {
    display: block;
}

/* ============================================
   AUTHENTICATION PAGE
   ============================================ */
.auth-container {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;  /* Center the container */
}

.auth-card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    font-size: 48px;
    color: var(--primary-color);
    margin-bottom: 16px;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-primary);
}

.auth-form label i {
    margin-right: 6px;
    color: var(--text-secondary);
}

.auth-form input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: var(--transition);
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* ============================================
   DASHBOARD LAYOUT
   ============================================ */
.dashboard-page {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    transition: var(--transition);
    z-index: 1000;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header i {
    font-size: 24px;
    color: var(--primary-light);
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
    color: #FFFFFF;
}

.sidebar-toggle {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 18px;
    display: none;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: var(--transition);
    cursor: pointer;
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #FFFFFF;
}

.nav-item.active {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary-light);
    border-left: 3px solid var(--primary-light);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-profile i {
    font-size: 32px;
    color: var(--primary-light);
}

.user-info {
    flex: 1;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: #FFFFFF;
    margin-bottom: 2px;
}

.user-role {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.top-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-primary);
}

.header-title h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--bg-tertiary);
}

.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.user-menu-btn:hover {
    background: var(--bg-tertiary);
}

.user-menu-btn i:first-child {
    font-size: 20px;
    color: var(--primary-color);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    display: none;
    z-index: 1000;
}

.user-menu-dropdown.active {
    display: block;
}

.user-menu-dropdown a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--transition);
}

.user-menu-dropdown a:hover {
    background: var(--bg-tertiary);
}

.user-menu-dropdown hr {
    margin: 8px 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* Content Area */
.content-area {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.page-content {
    display: none;
}

.page-content.active {
    display: block;
}

/* ============================================
   COMPONENTS
   ============================================ */

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: #FFFFFF;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-success {
    background: var(--secondary-color);
    color: #FFFFFF;
}

.btn-danger {
    background: var(--danger-color);
    color: #FFFFFF;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.blue {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary-color);
}

.stat-icon.green {
    background: rgba(16, 185, 129, 0.1);
    color: var(--secondary-color);
}

.stat-icon.purple {
    background: rgba(139, 92, 246, 0.1);
    color: #8B5CF6;
}

.stat-icon.orange {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.stat-details h3 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-details p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
}

.chart-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h3 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Search Box */
.search-box {
    position: relative;
    width: 300px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Table */
.table-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--bg-tertiary);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--text-primary);
}

.data-table tbody tr:hover {
    background: var(--bg-tertiary);
}

/* Status Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--secondary-color);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.badge-info {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info-color);
}

/* Action Buttons */
.action-btns {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 14px;
}

.action-btn.view {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info-color);
}

.action-btn.edit {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.action-btn.delete {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.action-btn:hover {
    transform: scale(1.1);
}

/* Limits Grid */
.limits-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.limit-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
}

.limit-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 16px;
}

.limit-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.limit-progress {
    margin-bottom: 12px;
}

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: var(--transition);
}

.progress-text {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Error Message */
.error-message {
    color: var(--danger-color);
    font-size: 14px;
    margin-top: 12px;
    display: none;
}

.error-message.show {
    display: block;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Form Group */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    display: flex;
    align-items: start;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-icon {
    font-size: 20px;
}

.toast-success .toast-icon {
    color: var(--secondary-color);
}

.toast-error .toast-icon {
    color: var(--danger-color);
}

.toast-warning .toast-icon {
    color: var(--warning-color);
}

.toast-info .toast-icon {
    color: var(--info-color);
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.toast-message {
    font-size: 14px;
    color: var(--text-secondary);
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
}

/* Section Title */
.section-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Profile Sections */
.profile-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

.profile-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
}

.profile-card h4 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

/* Filters Card */
.filters-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

/* Mini Stats Grid */
.stats-mini-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-mini-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.stat-mini-card strong {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.stat-mini-card span {
    color: var(--text-secondary);
    font-size: 13px;
}

/* Stats Section */
.stats-section {
    margin-bottom: 32px;
}

.stats-section h4 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.stat-details small {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .profile-sections {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .mobile-toggle {
        display: block;
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-box {
        width: 100%;
    }
    
    .table-container {
        overflow-x: auto;
    }
    
    .data-table {
        min-width: 600px;
    }
    
    .modal-content {
        max-width: 100%;
    }
    
    .filters-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .content-area {
        padding: 16px;
    }
    
    .auth-card {
        padding: 24px;
    }
    
    .toast-container {
        left: 10px;
        right: 10px;
    }
    
    .toast {
        min-width: auto;
    }
}

/* ============================================
   CHARTS SECTION
   ============================================ */

.charts-section {
    margin-top: 32px;
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    margin-top: 20px;
}

.chart-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.chart-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.chart-wide {
    grid-column: span 2;
}

.chart-header {
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.chart-header h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-header h4 i {
    color: var(--primary-color);
    font-size: 18px;
}

.chart-container {
    position: relative;
    width: 100%;
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-container canvas {
    max-height: 350px;
}

/* Responsive Charts */
@media (max-width: 1400px) {
    .chart-wide {
        grid-column: span 2;
    }
}

@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .chart-wide {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .chart-wide {
        grid-column: span 1;
    }
    
    .chart-card {
        padding: 16px;
    }
    
    .chart-container {
        min-height: 200px;
    }
}

@media (max-width: 480px) {
    .chart-container {
        min-height: 180px;
    }
    
    .chart-header h4 {
        font-size: 14px;
    }
}
