:root {
    --primary: #4361ee;
    --primary-dark: #3a0ca3;
    --secondary: #4cc9f0;
    --success: #06d6a0;
    --warning: #f72585;
    --danger: #ef233c;
    --text-main: #2b2d42;
    --text-muted: #8d99ae;
    --bg-body: #f8f9fa;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    --radius: 12px;
    --radius-sm: 8px;

    --font-main: 'Cairo', sans-serif;
}

* {
    box-sizing: border-box;
    outline: none;
}

body {
    margin: 0;
    font-family: var(--font-main);
    background: var(--bg-body);
    color: var(--text-main);
    direction: rtl;
    text-align: right;
    overflow-x: hidden;
}

/* --- Layout --- */
.app-container {
    display: flex;
    height: 100vh;
    transition: filter 0.3s;
}

.app-container.blur {
    filter: blur(5px);
    pointer-events: none;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: var(--bg-sidebar);
    border-left: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.sidebar .logo {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--primary);
}

.sidebar .logo i {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.sidebar .logo h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
}

.sidebar nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar nav li {
    padding: 12px 24px;
    margin: 4px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar nav li:hover {
    background: rgba(67, 97, 238, 0.05);
    color: var(--primary);
}

.sidebar nav li.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(67, 97, 238, 0.3);
}

.sidebar-footer {
    padding: 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f0f2f5;
}

.top-bar {
    background: var(--bg-card);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.top-bar h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--primary-dark);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-profile span {
    font-weight: 600;
    color: var(--text-main);
}

.logout-btn {
    background: #ffe3e3;
    color: var(--danger);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: var(--danger);
    color: white;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* --- Components --- */

/* Dashboard Grid */
/* Dashboard Grid */
.dashboard-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    max-width: 900px;
    margin: 1.5rem auto;
    padding: 20px;
    width: 100%;
}

.dashboard-grid>div {
    flex: 0 0 130px;
    height: 110px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.dashboard-grid>div:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

/* Cards (Stats) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.stat-card .icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(67, 97, 238, 0.1);
    color: var(--primary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.stat-card.danger .icon {
    background: rgba(239, 35, 60, 0.1);
    color: var(--danger);
}

.stat-card.warning .icon {
    background: rgba(247, 37, 133, 0.1);
    color: var(--warning);
}

.stat-card .info h3 {
    margin: 0 0 5px 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.stat-card .info p {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-card .info p span {
    font-size: 0.9rem;
    opacity: 0.7;
    font-weight: normal;
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem 1.5rem;
    text-align: right;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

th {
    background: rgba(0, 0, 0, 0.02);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background: rgba(0, 0, 0, 0.01);
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge.success {
    background: rgba(6, 214, 160, 0.15);
    color: var(--success);
}

.badge.warning {
    background: rgba(247, 37, 133, 0.15);
    color: var(--warning);
}

.badge.danger {
    background: rgba(239, 35, 60, 0.15);
    color: var(--danger);
}

.badge.info {
    background: rgba(76, 201, 240, 0.15);
    color: var(--secondary);
}

/* Buttons & Forms */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 10px rgba(67, 97, 238, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(67, 97, 238, 0.4);
}

.btn-secondary {
    background: #e9ecef;
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #dee2e6;
}

.btn-icon {
    min-width: 32px;
    height: 32px;
    padding: 0.4rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    background: transparent;
    color: var(--text-muted);
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--primary);
}

.btn-icon.danger:hover {
    background: rgba(239, 35, 60, 0.1);
    color: var(--danger);
}

.header-action {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 1rem;
}

.modal {
    background: var(--bg-card);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

/* Login Overlay */
#login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s;
    padding: 1rem;
}

#login-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.login-card {
    background: white;
    padding: 3rem 2rem;
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.login-card i {
    color: var(--primary);
    margin-bottom: 1rem;
}

.login-card h2 {
    margin-bottom: 2rem;
    font-size: 1.8rem;
}

/* ===== MOBILE RESPONSIVE ===== */

@media (max-width: 768px) {

    /* Hide sidebar by default on mobile */
    .sidebar {
        position: fixed;
        right: -250px;
        top: 0;
        height: 100vh;
        transition: right 0.3s ease;
        z-index: 100;
    }

    .sidebar.active {
        right: 0;
    }

    /* Mobile menu overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        backdrop-filter: blur(3px);
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Top bar adjustments */
    .top-bar {
        padding: 1rem;
    }

    #mobile-menu-btn {
        display: inline-flex !important;
    }

    .top-bar h2 {
        font-size: 1.2rem;
    }

    /* Content area */
    .content-area {
        padding: 1rem;
    }

    /* Stats grid */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-card .icon {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    .stat-card .info p {
        font-size: 1.5rem;
    }

    /* Tables - convert to cards on mobile */
    .table-container {
        overflow-x: visible;
    }

    table thead {
        display: none;
    }

    table,
    table tbody,
    table tr,
    table td {
        display: block;
        width: 100%;
    }

    table tr {
        margin-bottom: 1rem;
        border-radius: var(--radius-sm);
        box-shadow: var(--shadow-sm);
        padding: 1rem;
        background: white;
    }

    table td {
        text-align: right;
        padding: 0.5rem 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    table td:last-child {
        border-bottom: none;
    }

    /* Dashboard Grid Adjustments */
    .dashboard-grid {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        padding: 5px;
        gap: 10px;
        margin: 0.5rem auto;
    }

    .dashboard-grid>div {
        flex: 0 0 calc(50% - 10px) !important;
        width: auto !important;
        height: auto !important;
        aspect-ratio: 1/0.95;
        margin: 0 !important;
    }

    /* Table labels for mobile */
    table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--primary);
        font-size: 0.8rem;
        opacity: 0.8;
    }

    /* Buttons */
    .btn {
        padding: 0.8rem 1.2rem;
        font-size: 0.95rem;
    }

    .header-action {
        justify-content: center;
    }

    /* Modal */
    .modal {
        width: 95%;
    }

    .modal-body {
        padding: 1rem;
    }

    /* Login card */
    .login-card {
        padding: 2rem 1.5rem;
    }

    .login-card h2 {
        font-size: 1.5rem;
    }

    /* User profile in top bar */
    .user-profile {
        gap: 0.5rem;
    }

    .user-profile span {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {

    /* Extra small screens */
    .dashboard-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .dashboard-grid>div {
        width: 100% !important;
    }

    .stat-card {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }

    .stat-card .info p {
        font-size: 1.3rem;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
}