:root {
    --primary-blue: #2563eb;
    --primary-blue-dark: #1e40af;
    --success-green: #10b981;
    --danger-red: #ef4444;
    --warning-yellow: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

body.theme-light {
    --bg-page: var(--gray-50);
    --bg-card: #ffffff;
    --bg-header: var(--gray-900);
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-700);
    --border-color: var(--gray-200);
    --input-bg: #ffffff;
    --hover-bg: var(--gray-100);
}

body.theme-dark {
    --bg-page: #0a0f1e;
    --bg-card: #1a2332;
    --bg-header: #0d1424;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --border-color: #374151;
    --input-bg: #0f1729;
    --hover-bg: #243142;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    direction: rtl;
    text-align: right;
}

.header {
    background: var(--bg-header);
    color: white;
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.user-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.95rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.btn-logout {
    text-decoration: none;

    padding: 0.5rem 1.25rem;
    background: var(--danger-red);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 0;
    box-shadow: var(--shadow-sm);
}

.nav-content {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 2rem;
    overflow-x: auto;
}

.nav-link {
    padding: 0.625rem 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
    position: relative;
}

.nav-link:hover {
    background: var(--hover-bg);
    color: var(--primary-blue);
}

.nav-link.active {
    background: var(--primary-blue);
    color: white;
}

.container {
    max-width: 100%;
    margin: 2rem auto;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.page-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.form-control {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.btn {
    text-decoration: none;

    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

.btn:hover,
.btn:visited,
.btn:link {
    text-decoration: none;
}


.btn-primary {
    background: var(--primary-blue);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-blue-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-success {
    background: var(--success-green);
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-danger {
    background: var(--danger-red);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-secondary {
    background: var(--gray-300);
    color: var(--gray-800);
}

.btn-secondary:hover {
    background: var(--gray-700);
    color: white;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.alert {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.95rem;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.table-responsive {
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

thead {
    background: var(--gray-100);
}

body.theme-dark thead {
    background: var(--bg-header);
}

th {
    padding: 1rem;
    text-align: right;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-primary);
}

td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

tr:hover {
    background: var(--hover-bg);
}

.badge {
    display: inline-block;
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: all 0.3s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
}

.stat-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--primary-blue);
}

.stat-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .nav-content {
        padding: 0.5rem 1rem;
    }

    .container {
        padding: 0 1rem;
        margin: 1rem auto;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
/* Asset image responsive sizing */
.asset-image-wrapper {
    width: 100%;
    max-width: 320px;
    margin: 10px auto;
    display: flex;
    justify-content: center;
}

.asset-image {
    display: block;
    max-width: 100%;
    max-height: 240px;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

@media (min-width: 992px) {
    .asset-image-wrapper {
        max-width: 360px;
    }
    .asset-image {
        max-height: 280px;
    }
}

/* Force size for asset images */
.asset-image {
    display: block !important;
    max-width: 320px !important;
    width: 100% !important;
    max-height: 240px !important;
    height: auto !important;
    object-fit: contain !important;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    margin: 0 auto;
}

/* Theme system helpers */
.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    height: 36px;
    width: auto;
}

.theme-switcher {
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
    font-size: 1rem;
}

.theme-link:hover {
    background: var(--hover-bg);
}

/* Layout with right sidebar */
.layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-page);
}

/* Sidebar on the right for RTL */
.sidebar {
    width: 260px;
    background: var(--bg-header);
    color: #f9fafb;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    box-shadow: var(--shadow-md);
    z-index: 20;
}

.content-area {
    flex: 1;
    padding: 24px;
    margin-right: 260px; /* match sidebar width on RTL */
}

/* Ensure main-content containers still look good */
.main-content,
.container {
    max-width: 100%;
    margin: 0 auto;
}

/* Sidebar inner elements */
.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.3);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-user-icon {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.sidebar-user-role {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* Sidebar nav */
.sidebar-nav {
    padding: 12px 0 16px;
    overflow-y: auto;
    flex: 1;
}

.sidebar-section-title {
    padding: 8px 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.7;
    margin-top: 12px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 10px 20px;
    font-size: 0.9rem;
    color: inherit;
    text-decoration: none;
    border-radius: 999px 0 0 999px;
    margin: 2px 8px 2px 0;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.sidebar-link-icon {
    font-size: 1.1rem;
}

.sidebar-link:hover {
    background: rgba(148, 163, 184, 0.2);
    transform: translateX(-2px);
}

.sidebar-link.active {
    background: #2563eb;
    color: #f9fafb;
}

.sidebar-link-danger {
    color: #fecaca;
}

.sidebar-link-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Remove underline from nav-link if still used anywhere */
.nav-link {
    text-decoration: none;
    border-bottom: none;
}
.nav-link:hover {
    text-decoration: none;
}

/* Responsive: stack sidebar on small screens */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        width: 220px;
    }
    .content-area {
        margin-right: 0;
        padding: 16px;
    }
}

/* Sidebar toggle button - visible on tablets/mobiles */
.sidebar-toggle {
    display: none;
    margin-right: 0.75rem;
    border: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.8);
    color: #f9fafb;
    border-radius: 999px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

/* Backdrop behind sidebar on small screens */
.sidebar-backdrop {
    display: none;
}

/* Default desktop: sidebar fixed on the right, content shifted */
.layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-page);
}

.sidebar {
    width: 260px;
    background: var(--bg-header);
    color: #f9fafb;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    box-shadow: var(--shadow-md);
    z-index: 20;
    transition: transform 0.2s ease-out;
}

.content-area {
    flex: 1;
    padding: 24px;
    margin-right: 260px;
}

/* Small screens (tablets/phones): sidebar slides over content */
@media (max-width: 1024px) {
    .sidebar-toggle {
        display: inline-flex;
    }

    .sidebar {
        transform: translateX(100%);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        z-index: 19;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .content-area {
        margin-right: 0;
        padding: 16px;
    }
}

/* تحسين الهيدر على التابلت والموبايل */
@media (max-width: 1024px) {
    .header {
        padding: 0.75rem 1rem;
    }
    .header h1 {
        font-size: 1.35rem;
    }
    .header-left {
        gap: 0.5rem;
    }
    .page-header {
        margin-top: 1.25rem;
    }
}

/* جعل جداول الأصول أكثر مرونة على الشاشات الصغيرة */
@media (max-width: 1024px) {
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
    table {
        font-size: 0.85rem;
    }
    table th,
    table td {
        padding: 6px 8px;
        white-space: nowrap;
    }
}

/* تحسين جدول الأصول على التابلت والموبايل المتوسطة */
@media (max-width: 1024px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

  .table-responsive table {
    width: 100%;
    font-size: 0.85rem;
    table-layout: auto; /* يخلي الأعمدة تتصرف بمرونة */
}

@media (max-width: 1024px) {
    table th,
    table td {
        white-space: normal; /* يخلي النص يكسر سطر */
        word-break: break-word;
    }
}


    .table-responsive th,
    .table-responsive td {
        padding: 6px 8px;
        white-space: nowrap;
    }

    .table-responsive .btn {
        padding: 4px 8px;
        font-size: 0.78rem;
    }
}


/* === Custom fixes: prevent horizontal scroll and make gallery responsive === */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

.asset-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.asset-gallery-item {
    padding: 4px;
}

.asset-image-thumb {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

/* Ensure asset forms fit nicely on mobile/tablet */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}
pagination-wrapper {
    width: 100%;
    overflow-x: auto;
    display: flex;
    justify-content: center;
}

.pagination-nav {
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
}

/* لضبط العناصر داخل الـ pagination */
.pagination li {
    display: inline-block;
}
