:root {
    --primary-color: #10b981;
    /* Emerald 500 */
    --primary-dark: #059669;
    /* Emerald 600 */
    --secondary-color: #3b82f6;
    /* Blue 500 */
    --danger-color: #ef4444;
    /* Red 500 */
    --bg-color: #f3f4f6;
    /* Gray 100 */
    --sidebar-bg: #1f2937;
    /* Gray 800 */
    --card-bg: #ffffff;
    --text-primary: #111827;
    /* Gray 900 */
    --text-secondary: #4b5563;
    /* Gray 600 */
    --border-color: #e5e7eb;
    /* Gray 200 */
    --border-radius: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --sidebar-width: 280px;
    --transition: all 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Tajawal', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* === Layout & Containers === */
.container {
    background-color: var(--card-bg);
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 550px;
    margin: 20px auto;
    /* Center conventionally for non-flex bodies */
}

/* For pages that use flex centering (like auth/upload index) */
body:not(.dashboard-body) {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}



body.dashboard-body {
    display: flex;
    min-height: 100vh;
}

/* === Typography === */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    font-weight: 700;
    margin-bottom: 0.5em;
}

h1 {
    font-size: 1.8rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

/* === Forms === */
.form-group {
    margin-bottom: 24px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="email"],
select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-family: 'Tajawal', sans-serif;
    font-size: 1rem;
    transition: var(--transition);
    background-color: #fff;
}

input:focus,
select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}

/* === Buttons === */
.submit-btn,
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: 'Tajawal', sans-serif;
    text-align: center;
}

.submit-btn {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);
}

.submit-btn:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px rgba(16, 185, 129, 0.3);
}

/* === File Upload === */
.file-upload-box {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    background-color: #fafafa;
}

.file-upload-box:hover {
    border-color: var(--primary-color);
    background-color: #f0fdf4;
    /* Light green bg */
}

#preview {
    max-width: 300px;
    max-height: 300px;
    margin: 10px auto;
    border-radius: 8px;
    object-fit: contain;
    display: none;
    /* Initially hidden */
}

/* === Dashboard Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: #e5e7eb;
    padding: 30px 20px;
    position: fixed;
    height: 100vh;
    /* Ensure full height */
    right: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    overflow: hidden;
    /* Container doesn't scroll, children do */
}

.sidebar h2 {
    color: white;
    text-align: center;
    margin-bottom: 30px;
    font-size: 1.6rem;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    /* Keep header static */
}

.sidebar ul {
    list-style: none;
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 0;
    /* Remove bottom margin as switcher has padding */
    scrollbar-width: thin;
    /* Firefox */
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Custom scrollbar for webkit */
.sidebar ul::-webkit-scrollbar {
    width: 6px;
}

.sidebar ul::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar ul::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
}

.sidebar ul li {
    margin-bottom: 8px;
}

.sidebar ul li a {
    color: #9ca3af;
    /* Gray 400 */
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-radius: 12px;
    font-weight: 500;
}

.sidebar ul li a:hover,
.sidebar ul li a.active {
    background-color: var(--primary-color);
    color: white;
    transform: translateX(-5px);
}

/* === Dashboard Content === */
.main-content {
    margin-right: var(--sidebar-width);
    padding: 40px;
    width: calc(100% - var(--sidebar-width));
    transition: margin-right 0.3s ease;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.stat-card h3 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.stat-card p {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
}

/* === Tables === */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

th {
    background-color: #f9fafb;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 16px 24px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #f9fafb;
}

/* Action Buttons in Table */
.action-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    border-radius: 8px;
    margin: 0 4px;
    display: inline-block;
    width: auto;
    box-shadow: none;
}

.edit-btn {
    background-color: #e0f2fe;
    /* Light Blue */
    color: #0284c7;
    /* Dark Blue */
}

.edit-btn:hover {
    background-color: #bae6fd;
    color: #0369a1;
}

.delete-btn {
    background-color: #fee2e2;
    /* Light Red */
    color: #dc2626;
    /* Dark Red */
}

.delete-btn:hover {
    background-color: #fecaca;
    color: #b91c1c;
}

/* === Authentication === */
.auth-container {
    padding: 50px 40px;
    width: 100%;
    max-width: 450px;
}

.auth-container h2 {
    font-size: 2rem;
    margin-bottom: 30px;
}

/* === UI Utility Classes === */
.card-container,
.settings-card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 30px;
}

.card-title {
    margin-bottom: 20px;
    font-size: 1.25rem;
    color: var(--text-primary);
    border-bottom: 2px solid var(--bg-color);
    padding-bottom: 10px;
}

.responsive-form-row {
    display: flex;
    gap: 15px;
    align-items: center;
}

.responsive-form-row .input-group {
    flex: 1;
}

.responsive-form-row input,
.responsive-form-row select {
    width: 100%;
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.user-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.user-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.permission-badges {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.perm-badge {
    background: #f3f4f6;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    display: flex;
    justify-content: center;
    /* Center content */
    align-items: center;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    width: 100%;
    /* Fill grid cell */
}

.perm-badge input {
    margin-left: 8px;
    width: auto !important;
}

.perm-badge:hover {
    background: #e5e7eb;
}

.perm-badge.active-badge {
    background: #ecfdf5;
    border-color: var(--primary-color);
    color: var(--primary-dark);
}

.flex-row-mobile {
    display: flex;
    gap: 10px;
    width: 100%;
}

.flex-row-mobile .input-group {
    flex: 1;
}

.responsive-form-row .flex-row-mobile {
    flex: 2;
    /* Gives date container 2x space vs 1x for order number, balancing the 3 inputs (1:1:1) */
}

/* === Badges === */
.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-block;
}

.badge-admin {
    background-color: #fef3c7;
    color: #d97706;
}

.badge-user {
    background-color: #e0f2fe;
    color: #0284c7;
}

/* === Responsive === */
@media (max-width: 1024px) {


    .menu-toggle {
        display: block;
        position: fixed;
        top: 20px;
        right: 20px;
        z-index: 1001;
        width: auto;
        border: none;
        border-radius: 8px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        text-align: center;
        padding: 12px 16px;
        cursor: pointer;
        background: var(--primary-color);
        color: white;
    }

    .dashboard-body {
        flex-direction: column;
    }

    .main-content {
        margin-right: 0;
        width: 100%;
        padding: 80px 20px 20px 20px;
    }

    .sidebar {
        width: 280px;
        height: 100vh;
        position: fixed;
        top: 0;
        right: -300px;
        display: flex !important;
        flex-direction: column;
        transition: right 0.3s ease-in-out;
        z-index: 10000;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
        padding-top: 80px;
        background-color: var(--sidebar-bg);
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 85px 10px 20px 10px !important;
        /* Top padding keeps header clear */
    }

    .card-container,
    .settings-card,
    .container {
        padding: 15px !important;
        margin: 10px 0 !important;
        width: 100% !important;
    }

    /* Compress table spacing on mobile */
    th,
    td {
        padding: 12px 8px !important;
        font-size: 0.85rem;
    }

    /* Improve headers */
    h1 {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }

    .card-title {
        font-size: 1.1rem;
        margin-bottom: 15px;
    }

    .responsive-form-row {
        flex-direction: column;
        align-items: stretch !important;
    }

    .responsive-form-row .submit-btn {
        width: 100% !important;
        margin-top: 10px;
    }
}

/* ... removed badges ... */

.sidebar.open {
    right: 0;
}

.sidebar h2 {
    display: block;
    text-align: center;
    margin-bottom: 20px;
}

.sidebar ul {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.sidebar ul li {
    width: 100%;
    margin: bottom 5px;
}

.sidebar ul li a {
    justify-content: flex-start;
    padding: 14px 20px;
    border-radius: 0;
}

.container {
    padding: 20px;
    margin: 10px auto;
    width: 95%;
}

.filter-form {
    flex-direction: column;
    align-items: stretch;
}

.menu-close {
    display: block;
    position: absolute;
    top: 20px;
    left: 20px;
    /* Left side for RTL close button */
    background: transparent;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    z-index: 10001;
}

.menu-close:hover {
    color: var(--danger-color);
}

/* Modal Mobile Fix */
.modal-content {
    width: 95%;
    margin-top: 20%;
}
}

/* === Modal Styles === */
/* === Modal Styles === */
.modal {
    display: none;
    position: fixed;
    z-index: 20001;
    /* Higher than sidebar (10000) */
    padding-top: 50px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0, 0, 0);
    background-color: rgba(0, 0, 0, 0.9);
}

.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 900px;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    animation-name: zoom;
    animation-duration: 0.3s;
}

@keyframes zoom {
    from {
        transform: scale(0)
    }

    to {
        transform: scale(1)
    }
}

.close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #f1f1f1;
    font-size: 50px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    z-index: 20002;
    /* Above modal content */
    background: rgba(0, 0, 0, 0.5);
    width: 60px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    border-radius: 50%;
}

.close:hover,
.close:focus {
    color: #fff;
    background: rgba(0, 0, 0, 0.8);
    text-decoration: none;
    cursor: pointer;
}

@media only screen and (max-width: 700px) {
    .modal-content {
        width: 100%;
        margin-top: 30%;
    }

    .close {
        top: 10px;
        right: 10px;
        font-size: 40px;
        width: 50px;
        height: 50px;
        line-height: 50px;
    }
}

/* === LTR Overrides === */
html[dir="ltr"] .sidebar {
    right: auto;
    left: 0;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
}

html[dir="ltr"] .main-content {
    margin-right: 0;
    margin-left: var(--sidebar-width);
}

html[dir="ltr"] .menu-close {
    left: auto;
    right: 20px;
}

html[dir="ltr"] .sidebar ul li a {
    justify-content: flex-start;
    /* Ensure items align start (left) */
}

/* LTR Responsive */
@media (max-width: 1024px) {
    html[dir="ltr"] .menu-toggle {
        right: auto;
        left: 20px;
    }

    html[dir="ltr"] .sidebar {
        right: auto;
        left: -300px;
    }

    html[dir="ltr"] .sidebar.open {
        right: auto;
        left: 0;
    }

    html[dir="ltr"] .main-content {
        margin-left: 0;
        margin-right: 0;
    }
}

/* === Footer Styles === */
footer {
    background: var(--dark);
    color: var(--white);
    padding: 60px 5% 20px;
    margin-top: auto;
    /* Push to bottom in flex column layout */
    width: 100%;
}

.footer-content {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 40px;
    margin-bottom: 40px;
}

.footer-section h3 {
    color: var(--primary);
    margin-bottom: 20px;
}

.footer-section p,
.footer-section a {
    color: #d1d5db;
    margin-bottom: 10px;
    display: block;
}

.social-icons {
    display: flex;
    gap: 15px;
}

.social-icons a {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: 0.3s;
}

.social-icons a:hover {
    background: var(--primary);
}

.copyright {
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 20px;
    color: #9ca3af;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .footer-content {
        flex-direction: column;
    }
}