:root {
    /* Color Palette - Premium Dark Theme */
    --bg-main: #0f172a;
    /* Slate 900 */
    --bg-card: #1e293b;
    /* Slate 800 */
    --bg-hover: #334155;
    /* Slate 700 */

    --text-primary: #f8fafc;
    /* Slate 50 */
    --text-secondary: #94a3b8;
    /* Slate 400 */
    --text-muted: #64748b;
    /* Slate 500 */

    --primary: #22c55e;
    /* Green 500 */
    --primary-hover: #4ade80;
    --secondary: #f97316;
    /* Orange 500 */
    --accent: #3b82f6;
    /* Blue 500 */

    --danger: #ef4444;
    --success: #22c55e;
    --warning: #eab308;

    /* Spacing & Layout */
    --header-height: 60px;
    --sidebar-width: 260px;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    /* Transitions */
    --trans-speed: 0.2s;
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Tajawal', 'Outfit', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    user-select: none;
    direction: rtl;
    /* RTL Enforced */
    text-align: right;
}

/* Typography & Visuals */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    color: var(--text-primary);
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    font-family: inherit;
    border: none;
    cursor: pointer;
    background: none;
}

/* Layout Structure */
#app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar */
aside {
    width: var(--sidebar-width);
    background-color: var(--bg-card);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    /* RTL: Left border */
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    flex-shrink: 0;
}

.brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.5rem;
}

.brand i {
    font-size: 1.8rem;
    margin-left: 0.5rem;
    margin-right: 0;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    transition: all var(--trans-speed);
    white-space: nowrap;
}

.nav-item i {
    width: 24px;
    text-align: center;
    font-size: 1.2rem;
    margin-left: 0.5rem;
}

.nav-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background-color: var(--bg-main);
    width: 100%;
}

header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    z-index: 10;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scroll-behavior: smooth;
}

/* Responsive Grid & Utilities */
.grid {
    display: grid;
    gap: 1rem;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.w-100 {
    width: 100%;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

/* Components */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.05);
    height: 100%;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--bg-main);
    border: 1px solid var(--bg-hover);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--trans-speed);
    text-align: right;
    /* RTL Input */
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

textarea.form-control {
    resize: vertical;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.95rem;
    gap: 0.5rem;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

.btn i {
    margin-left: 0.5rem;
    margin-right: 0;
}

/* Fix Icon spacing */
.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-secondary {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.btn-success {
    background-color: var(--success);
    color: white;
}

/* Tables */
.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--bg-hover);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

th,
td {
    padding: 1rem;
    text-align: right;
    /* RTL Table */
    border-bottom: 1px solid var(--bg-hover);
}

th {
    background-color: rgba(0, 0, 0, 0.2);
    font-size: 0.85rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    padding: 1rem;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    width: 500px;
    max-width: 100%;
    border-radius: var(--radius);
    padding: 1.5rem;
    transform: translateY(20px);
    transition: all 0.3s;
    max-height: 90vh;
    overflow-y: auto;
    text-align: right;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-close {
    margin-right: auto;
    margin-left: 0;
}

/* Close button on left */

/* MOBILE RESPONSIVENESS */
.mobile-toggle {
    display: none;
    font-size: 1.5rem;
    color: var(--text-primary);
    padding: 0.5rem;
    margin-left: 0.5rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

@media (max-width: 1024px) {
    #app {
        flex-direction: column;
    }

    /* Sidebar Drawer RTL */
    aside {
        position: fixed;
        top: 0;
        right: 0;
        /* Right side */
        height: 100%;
        left: auto;
        transform: translateX(100%);
        /* Hidden to right */
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    }

    aside.open {
        transform: translateX(0);
    }

    aside.open+.sidebar-overlay {
        display: block;
    }

    .mobile-toggle {
        display: block;
    }

    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .content-area {
        padding: 1rem;
    }
}

@media (max-width: 640px) {

    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    header {
        padding: 0 1rem;
    }

    .page-title {
        font-size: 1.1rem;
    }

    .card {
        padding: 1rem;
    }

    .mobile-col .btn {
        width: 100%;
        justify-content: center;
    }

    .table-container {
        margin: 0 -0.5rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    th,
    td {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.badge-success {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.badge-warning {
    background: rgba(234, 179, 8, 0.2);
    color: var(--warning);
}

/* Icons Fix for RTL */
.ri-arrow-right-s-line::before {
    content: "\ea60";
}

/* arrow-left */

/* LOGIN SCREEN */
#login-screen {
    position: fixed;
    inset: 0;
    background-color: var(--bg-main);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

#login-screen.hidden {
    display: none;
}

.login-card {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: 16px;
    width: 400px;
    max-width: 100%;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.role-toggle-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    background: var(--bg-hover);
    padding: 0.5rem;
    border-radius: 12px;
}

.role-option {
    flex: 1;
    cursor: pointer;
    padding: 0.75rem;
    border-radius: 8px;
    transition: all 0.2s;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.role-option.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.role-option input {
    display: none;
}

.login-avatar-preview {
    width: 100px;
    height: 100px;
    margin: 0 auto 1.5rem;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--primary);
    background: var(--bg-hover);
}

.login-avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* HEADER USER PROFILE */
.user-profile-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.25rem 0.5rem 0.25rem 1rem;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.user-profile-header.hidden {
    display: none;
}

.user-profile-header img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
}

/* SETUP & LOGIN SCREENS - PREMIUM POLISH */
.setup-overlay,
#login-screen {
    position: fixed;
    inset: 0;
    background-color: var(--bg-main);
    z-index: 3000;
    display: none;
    /* Flex when active */
    align-items: center;
    justify-content: center;
    background-image: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    padding: 1rem;
    animation: fadeIn 0.5s ease-out;
}

.setup-overlay.active,
#login-screen:not(.hidden) {
    display: flex;
}

.setup-card,
.login-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 3rem;
    border-radius: 24px;
    width: 450px;
    max-width: 100%;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    transition: transform 0.3s ease;
}

/* Hover effect for cards */
.setup-card:hover,
.login-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.setup-icon {
    width: 90px;
    height: 90px;
    margin: 0 auto 1.5rem;
    border-radius: 50%;
    border: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--primary);
    background: rgba(34, 197, 94, 0.05);
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.15);
}

/* ENHANCED BUTTONS */
.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #16a34a 100%);
    box-shadow: 0 4px 6px -1px rgba(34, 197, 94, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 10px 15px -3px rgba(34, 197, 94, 0.4);
    transform: translateY(-1px);
}

.loader {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.55, 0.055, 0.675, 0.19) infinite;
    margin: 0 auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.small {
    font-size: 0.85rem;
    opacity: 0.8;
}

/* RESPONSIVE TWEAKS */
@media (max-width: 640px) {

    .setup-card,
    .login-card {
        padding: 2rem 1.5rem;
        width: 100%;
    }

    .setup-icon {
        width: 70px;
        height: 70px;
        font-size: 2rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }
}