:root {
    --primary-color: #667eea;
    --primary-dark: #764ba2;
    --secondary-color: #51cf66;
    --danger-color: #ff6b6b;
    --warning-color: #ffd43b;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    /* Modal & Switch */
    --modal-bg: rgba(0, 0, 0, 0.5);
    --switch-bg: #ccc;
    --sidebar-bg: linear-gradient(180deg, var(--primary-color), var(--primary-dark));
}

body.dark-mode {
    --bg-color: #1a1a2e;
    --card-bg: #16213e;
    /* Highlight color */
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --border-color: #2a2a40;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.7);
    --modal-bg: rgba(0, 0, 0, 0.8);
    --sidebar-bg: #16213e;
}

/* Ensure font size scales with root */
html {
    font-size: 16px;
    /* Base 100% */
}

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

body {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    direction: rtl;
    min-height: 100vh;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    line-height: 1.3;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Dashboard Layout */
.dashboard {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    color: white;
    padding: 20px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    position: fixed;
    height: 100vh;
    right: 0;
    top: 0;
    overflow-y: auto;
}

.sidebar-logo {
    text-align: center;
    padding: 20px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 30px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-toggle-sidebar {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 10px;
    transition: 0.3s;
    z-index: 10;
}

.btn-toggle-sidebar:hover {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

.sidebar-logo img {
    max-width: 100px;
    height: auto;
    filter: brightness(0) invert(1);
}

.sidebar-nav {
    list-style: none;
}

.sidebar-nav li {
    margin-bottom: 10px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.3s;
    font-size: 16px;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: translateX(-5px);
}

.sidebar-nav .icon {
    font-size: 20px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-right: 280px;
    padding: 0;
    transition: margin-right 0.3s ease;
}

/* Sidebar Collapsed State */
body.sidebar-collapsed .sidebar {
    width: 80px;
    /* Minimized width */
    padding: 20px 10px;
}

body.sidebar-collapsed .main-content {
    margin-right: 80px;
    /* Adjust content margin */
}

body.sidebar-collapsed .sidebar-nav a span:last-child {
    display: none;
    /* Hide text label only (assuming icon is first) */
}

body.sidebar-collapsed .sidebar-logo img {
    display: none;
    /* Hide large logo */
}

body.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
    /* Center icons */
    padding: 15px 0;
    /* Remove horizontal padding to center perfectly */
}

body.sidebar-collapsed .sidebar-nav .icon {
    margin: 0;
    /* Remove any margin from icon */
    font-size: 1.5rem;
    /* Ensure icon is large enough */
    display: block;
}

body.sidebar-collapsed .btn-toggle-sidebar {
    right: 50%;
    transform: translate(50%, -50%);
    /* Center the toggle button */
}

/* Header */
.header {
    background: var(--card-bg);
    padding: 20px 40px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo img {
    max-width: 120px;
    height: auto;
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

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

.btn-danger:hover {
    background: #ee5a6f;
}

/* Content Area */
.content {
    padding: 40px;
}

/* Stats Cards - Unified Segmented Bar Design */
.stats-grid {
    display: flex;
    flex-direction: row-reverse;
    margin-bottom: 40px;
    background: linear-gradient(145deg, #1e2a4a 0%, #16213e 100%);
    border-radius: 16px;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

/* Light mode adjustments */
body:not(.dark-mode) .stats-grid {
    background: linear-gradient(145deg, #ffffff 0%, #f1f5f9 100%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.stat-card {
    flex: 1;
    padding: 20px 24px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    gap: 16px;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* Dividers between cards */
.stat-card:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background: linear-gradient(180deg,
            transparent 0%,
            rgba(255, 255, 255, 0.15) 50%,
            transparent 100%);
}

body:not(.dark-mode) .stat-card:not(:last-child)::before {
    background: linear-gradient(180deg,
            transparent 0%,
            rgba(0, 0, 0, 0.1) 50%,
            transparent 100%);
}

/* Hover effect */
.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg,
            rgba(102, 126, 234, 0.15) 0%,
            rgba(118, 75, 162, 0.1) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 0;
}

.stat-card:hover::after {
    opacity: 1;
}

.stat-card:hover {
    background: rgba(102, 126, 234, 0.08);
}

body:not(.dark-mode) .stat-card:hover {
    background: rgba(102, 126, 234, 0.05);
}

.stat-card:active {
    background: rgba(102, 126, 234, 0.15);
}

.stat-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    position: relative;
    z-index: 1;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
    transition: all 0.3s ease;
}

.stat-card:hover .stat-icon {
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.45);
}

.stat-content {
    flex: 1;
    text-align: right;
    position: relative;
    z-index: 1;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Responsive - Stack vertically on mobile */
@media (max-width: 900px) {
    .stats-grid {
        flex-direction: column;
    }

    .stat-card:not(:last-child)::before {
        left: 20%;
        top: auto;
        bottom: 0;
        height: 1px;
        width: 60%;
        background: linear-gradient(90deg,
                transparent 0%,
                rgba(255, 255, 255, 0.15) 50%,
                transparent 100%);
    }

    body:not(.dark-mode) .stat-card:not(:last-child)::before {
        background: linear-gradient(90deg,
                transparent 0%,
                rgba(0, 0, 0, 0.1) 50%,
                transparent 100%);
    }
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
}

.action-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: all 0.3s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.action-card:hover {
    transform: translateY(-10px);
    box-shadow: var(--shadow-lg);
}

.action-icon {
    font-size: 3.75rem;
    margin-bottom: 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.action-title {
    font-size: 1.375rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.action-desc {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Footer */
.footer {
    background: var(--card-bg);
    padding: 30px 40px;
    margin-top: 60px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.footer-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.footer-logo img {
    max-width: 150px;
}

.footer-logo span {
    color: var(--text-secondary);
    font-size: 14px;
}

.footer p {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

/* Loading Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 50px auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* =============================================
   MOBILE RESPONSIVE STYLES
   ============================================= */

/* Tablet (max-width: 992px) */
@media (max-width: 992px) {
    .header {
        padding: 15px 20px;
    }

    .content {
        padding: 25px;
    }

    .action-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {

    /* Hide sidebar completely on mobile */
    .sidebar {
        position: fixed;
        right: -280px;
        width: 280px;
        transition: right 0.3s ease;
        z-index: 1000;
    }

    .sidebar.open {
        right: 0;
    }

    /* Mobile overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.show {
        display: block;
    }

    /* Main content full width */
    .main-content {
        margin-right: 0;
        width: 100%;
    }

    /* Header mobile */
    .header {
        padding: 12px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .header-logo img {
        max-width: 80px;
        height: auto;
    }

    .header-actions {
        gap: 10px;
    }

    .user-info {
        display: none;
        /* Hide on very small screens, show on larger mobile */
    }

    .btn-danger {
        padding: 8px 15px;
        font-size: 12px;
    }

    /* Mobile menu button */
    .btn-mobile-menu {
        display: flex !important;
        background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
        color: white;
        border: none;
        padding: 10px 12px;
        border-radius: 10px;
        font-size: 18px;
        cursor: pointer;
        order: -1;
    }

    /* Content area */
    .content {
        padding: 15px;
    }

    .content h1 {
        font-size: 1.3rem;
        margin-bottom: 20px !important;
        text-align: center;
    }

    .content h2 {
        font-size: 1.1rem;
        text-align: center;
    }

    /* Stats Grid - vertical on mobile */
    .stats-grid {
        flex-direction: column;
        border-radius: 12px;
        margin-bottom: 25px;
    }

    .stat-card {
        padding: 15px 20px;
        flex-direction: row-reverse;
        justify-content: flex-start;
    }

    .stat-icon {
        width: 45px;
        height: 45px;
        min-width: 45px;
        font-size: 1.2rem;
    }

    .stat-content {
        flex: 1;
    }

    .stat-value {
        font-size: 1.3rem;
    }

    .stat-label {
        font-size: 11px;
        white-space: nowrap;
    }

    /* Action buttons - single column on mobile */
    .action-buttons {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .action-card {
        padding: 25px 20px;
        border-radius: 15px;
    }

    .action-icon {
        font-size: 2.5rem;
        margin-bottom: 15px;
    }

    .action-title {
        font-size: 1.1rem;
    }

    .action-desc {
        font-size: 12px;
    }

    /* Footer mobile */
    .footer {
        padding: 20px 15px;
        margin-top: 30px;
    }

    .footer-logo img {
        max-width: 100px;
    }

    .footer p {
        font-size: 11px;
    }
}

/* Small Mobile (max-width: 480px) */
@media (max-width: 480px) {
    .header {
        padding: 10px 12px;
    }

    .header-logo img {
        max-width: 60px;
    }

    .btn-danger {
        padding: 6px 12px;
        font-size: 11px;
    }

    .content {
        padding: 12px;
    }

    .content h1 {
        font-size: 1.15rem;
    }

    .stat-card {
        padding: 12px 15px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 1.1rem;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .stat-label {
        font-size: 10px;
    }

    .action-card {
        padding: 20px 15px;
    }

    .action-icon {
        font-size: 2rem;
    }

    .action-title {
        font-size: 1rem;
    }

    /* Settings modal on mobile */
    .settings-content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .settings-header {
        padding: 15px 20px;
    }

    .settings-body {
        padding: 20px;
    }
}

/* Settings Modal Styles */
.settings-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: var(--modal-bg);
    animation: fadeIn 0.3s;
    align-items: center;
    justify-content: center;
}

.settings-modal.show {
    display: flex;
}

.settings-content {
    background-color: var(--card-bg);
    margin: auto;
    padding: 0;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s;
    overflow: hidden;
}

.settings-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h3 {
    margin: 0;
    font-size: 1.25rem;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.3s;
}

.close-btn:hover {
    transform: rotate(90deg);
}

.settings-body {
    padding: 30px;
}

.setting-item {
    margin-bottom: 25px;
}

.setting-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.setting-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.settings-footer {
    padding: 20px 30px;
    border-top: 1px solid var(--border-color);
    text-align: left;
    display: flex;
    align-items: center;
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--switch-bg);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

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

/* Range Slider */
.range-slider {
    width: 100%;
    height: 10px;
    border-radius: 5px;
    background: #d3d3d3;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
}

.range-slider:hover {
    opacity: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0
    }

    to {
        transform: translateY(0);
        opacity: 1
    }
}