/* ==========================================
   1. المتغيرات والألوان الأساسية (Variables)
========================================== */
:root {
    --primary: #1A3D2B;        /* أخضر غابة داكن — لون اللوغو */
    --primary-dark: #0E2A1C;   /* أخضر داكن جداً */
    --primary-light: #ECF3EE;  /* خلفية خضراء فاتحة */
    --accent: #C9A84B;         /* ذهبي اللوغو */
    --accent-soft: #FBF5E6;    /* خلفية الذهبي الفاتحة */
    --bg-color: #F5F6F4;       /* خلفية مخضّرة ناعمة */
    --surface: #FFFFFF;
    --text-main: #1A2B22;      /* أخضر داكن للنصوص */
    --text-muted: #6B7D74;
    --danger: #DC2626;
    --danger-light: #fee2e2;
    --warning: #C9A84B;        /* الذهبي للتحذيرات */
    --success: #16A34A;        /* أخضر للنجاح */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.02);
    --border-radius: 16px;
    --border-color: #e2e8f0;
    --transition: all 0.3s ease;
}

/* ==========================================
   2. الإعدادات العامة (Reset & Base)
========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Tajawal', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden; /* لمنع التمرير العام، التمرير سيكون داخل main */
}

/* ==========================================
   3. تخطيط لوحة التحكم (Dashboard Layout)
========================================== */
.dashboard-wrapper {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* الشريط الجانبي (Sidebar) */
.sidebar {
    width: 280px;
    background-color: var(--surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: var(--transition);
}

.brand-header {
    height: 80px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 15px;
    border-bottom: 1px solid var(--border-color);
}

.brand-icon {
    width: 45px;
    height: 45px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.brand-title h1 {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-main);
    margin: 0;
}

.brand-title span {
    font-size: 12px;
    color: var(--text-muted);
}

.close-sidebar-mobile {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    margin-right: auto;
}

.sidebar-nav {
    flex: 1;
    padding: 24px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 20px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    border-radius: 12px;
    transition: var(--transition);
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item:hover {
    background-color: var(--bg-color);
    color: var(--primary);
    transform: translateX(-5px);
}

.nav-item.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(44, 95, 45, 0.2);
}

.sidebar-footer {
    padding: 24px 16px;
    border-top: 1px solid var(--border-color);
}

/* المحتوى الرئيسي (Main Content) */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    background: var(--bg-color);
    scroll-behavior: smooth;
}

.topbar {
    height: 80px;
    background: var(--surface);
    display: flex;
    align-items: center;
    padding: 0 40px;
    position: sticky;
    top: 0;
    z-index: 99;
    box-shadow: var(--shadow-sm);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-main);
    cursor: pointer;
    margin-left: 20px;
}

.topbar-welcome h2 {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-main);
}

.content-body {
    padding: 40px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.section {
    margin-bottom: 50px;
    animation: fadeInUp 0.6s ease;
}

.section-header {
    margin-bottom: 25px;
}

.section-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-title i {
    color: var(--primary);
}

/* ==========================================
   4. البطاقات والنماذج (Cards & Forms)
========================================== */
.card {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 30px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.premium-card {
    border-top: 4px solid var(--primary);
}

.grid-2-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.form-row {
    display: flex;
    gap: 20px;
}

.half-width {
    flex: 1;
}

.form-group {
    margin-bottom: 24px;
}

label {
    display: block;
    margin-bottom: 10px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text-main);
}

.input-icon-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon-wrapper i {
    position: absolute;
    right: 15px;
    color: var(--text-muted);
    font-size: 18px;
    pointer-events: none;
}

input, select, textarea {
    width: 100%;
    padding: 16px;
    background-color: var(--bg-color);
    border: 1.5px solid transparent;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-main);
    transition: var(--transition);
}

.input-icon-wrapper input, 
.input-icon-wrapper select {
    padding-right: 45px;
}

input:focus, select:focus, textarea:focus {
    background-color: var(--surface);
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-light);
}

/* زر رفع الملفات المخصص */
.file-upload-wrapper {
    position: relative;
    width: 100%;
    height: 120px;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    background: var(--bg-color);
    transition: var(--transition);
}

.file-upload-wrapper:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.file-upload-wrapper input[type="file"] {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-muted);
    z-index: 1;
}

.upload-placeholder i {
    font-size: 30px;
    color: var(--primary);
}

/* ==========================================
   5. الأزرار (Buttons)
========================================== */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 800;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-lg {
    width: 100%;
    padding: 16px;
    font-size: 18px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(44, 95, 45, 0.3);
}

.btn-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-warning {
    background: #fef3c7;
    color: #d97706;
}

.btn-warning:hover {
    background: var(--warning);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    width: 100%;
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

.btn-icon {
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon.danger {
    background: var(--danger-light);
    color: var(--danger);
}

.btn-icon.danger:hover {
    background: var(--danger);
    color: white;
}

/* ==========================================
   6. شبكة المنتجات والفلاتر (Store)
========================================== */
.d-flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.search-container {
    position: relative;
    width: 300px;
}

.search-input {
    border-radius: 30px;
    padding: 12px 40px 12px 15px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.search-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.filters-container {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.filters-container::-webkit-scrollbar {
    height: 4px;
}

.filters-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.filter-btn {
    padding: 8px 24px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.filter-btn:hover {
    background: var(--bg-color);
}

.filter-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 10px rgba(44, 95, 45, 0.2);
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

.product-card {
    background: var(--surface);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

.card-image-wrapper {
    position: relative;
    height: 220px;
    overflow: hidden;
}

.product-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.product-card:hover .product-img {
    transform: scale(1.05);
}

.category-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 800;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}

.status-badge {
    position: absolute;
    top: 15px;
    left: 15px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 800;
    z-index: 2;
}

.danger-badge {
    background: var(--danger);
    color: white;
}

.product-info {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 18px;
    margin-bottom: 8px;
}

.meta-info {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 15px;
    font-weight: 600;
}

.product-price {
    font-size: 24px;
    font-weight: 900;
    color: var(--primary);
    margin-bottom: 20px;
}

.product-price span {
    font-size: 14px;
    color: var(--text-muted);
}

.stock-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background: var(--bg-color);
    border-radius: 10px;
    margin-bottom: 20px;
    margin-top: auto;
}

.stock-label {
    font-size: 14px;
    font-weight: 700;
}

.product-actions {
    display: flex;
    gap: 10px;
}

.product-actions .btn {
    flex: 1;
    padding: 10px;
    font-size: 14px;
}

/* ==========================================
   7. زر التبديل (Toggle Switch)
========================================== */
.stock-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.stock-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.stock-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--danger);
    transition: .4s;
    border-radius: 34px;
}

.stock-slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 4px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .stock-slider {
    background-color: var(--success);
}

input:checked + .stock-slider:before {
    transform: translateX(22px);
}

/* ==========================================
   8. القوائم والإشعارات الداخلية (Lists)
========================================== */
.category-form {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.category-input-group {
    flex: 1;
    margin: 0;
}

.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
}

.category-item:last-child { border-bottom: none; }

.admin-list-container {
    margin-top: 20px;
    max-height: 250px;
    overflow-y: auto;
}

.admin-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--bg-color);
    border-radius: 12px;
    margin-bottom: 10px;
}

.notif-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 14px;
}

.text-primary { color: var(--primary); }

.banners-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.banner-card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.banner-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.banner-card .btn {
    border-radius: 0;
    padding: 10px;
}

.flex-form {
    display: flex;
    gap: 15px;
    align-items: center;
}
.flex-1 { flex: 1; }
.m-0 { margin: 0 !important; }

/* ==========================================
   9. النافذة المنبثقة (Modal)
========================================== */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--surface);
    width: 90%;
    max-width: 600px;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* يمنع خروج المحتوى عن حواف البطاقة المدوّرة */
}

/* إصلاح عام: أي جسم مودال يأتي مباشرة بعد modal-header (فورم أو div قابل
   للتمرير) يجب أن يأخذ المساحة المتبقية فعلياً ويتمرّر داخلياً، وإلا فإن
   محتواه يفيض خارج البطاقة بدل التمرير — وهذا ما كان يكسر شكل الفواتير
   والنوافذ الطويلة في كل صفحات اللوحة (الطلبات، تعديل المنتج، نقطة البيع...) */
.modal-content > .modal-header + * {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 25px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 20px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-modal-btn {
    background: var(--bg-color);
    border: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
    transition: var(--transition);
}

.close-modal-btn:hover {
    background: var(--danger-light);
    color: var(--danger);
}

#editProductForm {
    padding: 30px;
    overflow-y: auto;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 10px;
}

/* ==========================================
   10. نظام الإشعارات الذكي (Toasts)
========================================== */
.toast-container {
    position: fixed;
    bottom: 30px;
    left: 30px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 100000;
}

.toast {
    background: var(--surface);
    color: var(--text-main);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 15px;
    transform: translateX(-120%);
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border-right: 6px solid transparent;
}

.toast.show {
    transform: translateX(0);
}

.toast-success { border-right-color: var(--success); }
.toast-success i { color: var(--success); font-size: 20px; }

.toast-error { border-right-color: var(--danger); }
.toast-error i { color: var(--danger); font-size: 20px; }

/* ==========================================
   11. شاشة التحميل (Loader)
========================================== */
.startup-loader {
    position: fixed;
    inset: 0;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.startup-loader.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loader-icon-container {
    width: 80px; height: 80px;
    background: var(--primary);
    color: white;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 35px;
    animation: pulse 2s infinite;
}

.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--primary-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(44, 95, 45, 0.4); }
    70% { box-shadow: 0 0 0 20px rgba(44, 95, 45, 0); }
    100% { box-shadow: 0 0 0 0 rgba(44, 95, 45, 0); }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================
   12. التصميم المتجاوب (Mobile & Tablets)
========================================== */
@media (max-width: 1024px) {
    .grid-2-columns { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; /* ليدعم اتجاه RTL يكون مخفي على اليمين */
        right: -280px; /* إخفاء من اليمين في RTL */
        height: 100%;
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.active { right: 0; }
    
    .close-sidebar-mobile { display: block; }
    .menu-toggle { display: block; }
    
    .content-body { padding: 20px; }
    .topbar { padding: 0 20px; }
    
    .form-row { flex-direction: column; gap: 0; }
    
    .search-container { width: 100%; }
    
    .flex-form { flex-direction: column; align-items: stretch; }
    .flex-form button { width: 100%; }
    
    .modal-content { width: 95%; }
    .toast-container { left: 50%; transform: translateX(-50%); bottom: 20px; width: 90%; }
    .toast { transform: translateY(150%); border-right: none; border-bottom: 4px solid transparent; justify-content: center;}
    .toast.show { transform: translateY(0); }
    .toast-success { border-bottom-color: var(--success); }
    .toast-error { border-bottom-color: var(--danger); }
}
/* ==========================================
   11. تحسين شريط التمرير (مظهر أكثر احترافية)
========================================== */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #cbd5c9; border-radius: 20px; }
*::-webkit-scrollbar-thumb:hover { background: var(--primary); }
