:root {
    --primary-color: #2c3e50;
    --primary-dark: #1a252f;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --text-color: #333;
    --bg-color: #f4f6f9;
    --white: #ffffff;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #c0392b;
    --sidebar-width: 260px;
    --header-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

@import url('https://fonts.googleapis.com/css2?family=Noto+Kufi+Arabic:wght@400;500;700&display=swap');

body {
    font-family: 'Droid Arabic Kufi', 'Noto Kufi Arabic', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    direction: rtl;
    text-align: right;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

/* App Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-color);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    height: auto;
    min-height: var(--header-height);
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-dark);
    font-size: 1rem;
    font-weight: bold;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--white);
    text-decoration: none;
    text-align: center;
}

.sidebar-logo {
    width: 100px;
    height: 100px;
    object-fit: contain;
    margin-bottom: 0.5rem;
    background: white;
    border-radius: 10%;
    padding: 3px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 0.8rem 1.5rem;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s;
    border-right: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--white);
    border-right-color: var(--accent-color);
}

.sidebar-nav a i {
    margin-left: 10px;
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    /* Push content layout */
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Fix flex child overflow */
    transition: margin-right 0.3s ease;
}

/* Top Header */
.top-bar {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 900;
}

.menu-toggle {
    display: none;
    /* Hidden on desktop */
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary-color);
    padding: 0 10px; /* Increase touch target */
}

/* Fix mobile table scrolling */
.card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.page-body {
    padding: 2rem;
    flex: 1;
}

/* Mobile & Responsive */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
        /* Hide off-screen right */
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
    }

    .menu-toggle {
        display: block;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .page-body {
        padding: 1rem;
    }
}

/* Existing Components Refined */
.card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    /* Table scroll container */
}

.card-header {
    margin-bottom: 1rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    /* Wrap on small screens */
    gap: 10px;
}

/* Inputs & Forms */
.form-group {
    margin-bottom: 1rem;
}

label {
    margin-bottom: 0.5rem;
    display: block;
    font-weight: 600;
}

input:not([type="checkbox"]),
select,
textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Tables Responsive */
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

/* Force min-width to ensure scroll appears on mobile instead of squishing */
th,
td {
    padding: 0.8rem;
    text-align: right;
    border-bottom: 1px solid #eee;
}

th {
    background-color: #f8f9fa;
    font-weight: 600;
}

/* Buttons & Utils */
.btn,
button {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    background: var(--accent-color);
    color: white;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
}

.btn-danger {
    background: var(--danger);
}

.btn-success {
    background: var(--success);
}

.status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
}

.status-pending {
    background: #ffeeba;
    color: #856404;
}

.status-completed {
    background: #d4edda;
    color: #155724;
}

.status-cancelled {
    background: #f8d7da;
    color: #721c24;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    color: var(--accent-color);
    font-weight: bold;
}

/* Helpers */
.d-none {
    display: none;
}

.text-danger {
    color: var(--danger);
}

/* Settings Form */
.settings-form img {
    max-width: 150px;
    border: 1px solid #ddd;
    padding: 5px;
    border-radius: 4px;
}

/* Footer */
.main-footer {
    padding: 1rem 2rem;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    color: #6c757d;
    text-align: center;
    font-size: 0.9rem;
    margin-top: auto;
}

.main-footer a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.main-footer a:hover {
    text-decoration: underline;
}