/* إعادة تعيين الأنماط */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* الخطوط والنصوص */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    direction: rtl;
    text-align: right;
}

/* الحاوي الرئيسي */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* الهيدر */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* الأزرار */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    text-decoration: none;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102,126,234,0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: black;
    border: 2px solid black;
}

.btn-outline:hover {
    background: black;
    color: white;
}

.btn-danger {
    background: #dc3545;
    color: white;
    border: 2px solid #dc3545;
}

.btn-danger:hover {
    background: #c82333;
    border-color: #bd2130;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.3);
}

/* صفحة تسجيل الدخول */
.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-form {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

.logo h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 2rem;
    font-size: 1.5rem;
}

/* المجموعات والحقول */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="text"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

/* تسجيل دخول تلقائي */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* التنبيهات */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

/* بيانات تجريبية */
.demo-info {
    margin-top: 2rem;
    padding: 1rem;
    background: #e9ecef;
    border-radius: 8px;
    font-size: 0.9rem;
}

.demo-info h3 {
    margin-bottom: 0.5rem;
    color: #495057;
}

/* شبكة المنتجات */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.product-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.product-image {
    height: 200px;
    overflow: hidden;
    position: relative;
    background-color: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.3s ease;
    min-width: 100%;
    min-height: 100%;
}

/* للصور الصغيرة - استخدم contain مع خلفية */
.product-image img.small-image {
    object-fit: contain;
    background-color: #fff;
}

.product-image:hover img {
    transform: scale(1.05);
}

.no-image {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-weight: 500;
    border: 2px dashed #dee2e6;
}

.product-info {
    padding: 1.5rem;
}

.product-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
}

.product-description {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.product-unit {
    color: #888;
    font-size: 0.8rem;
    margin-bottom: 1rem;
}

/* أدوات التحكم في الكمية */
.quantity-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0 1.5rem 1.5rem;
}

.btn-quantity {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #667eea;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-quantity:hover {
    background: #5a6fd8;
    transform: scale(1.1);
}

.quantity-input {
    width: 60px;
    text-align: center;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

/* أدوات التحكم في المنتجات الوزنية */
.weight-controls {
    padding: 0 1.5rem 1.5rem;
}

.control-group {
    margin-bottom: 1rem;
}

.control-group label {
    display: block;
    font-weight: bold;
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 0.5rem;
}

.weight-input {
    width: 100%;
    text-align: center;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    transition: border-color 0.3s ease;
}

.weight-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* ملخص السلة */
.cart-summary {
    position: sticky;
    top: 2rem;
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    border-left: 4px solid #667eea;
}

.cart-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

/* النوافذ المنبثقة */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* ملخص الطلب */
.order-summary {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.order-summary h3 {
    margin-bottom: 1rem;
    color: #333;
}

.order-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e9ecef;
}

.order-item:last-child {
    border-bottom: none;
}

.total-items {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 2px solid #667eea;
    text-align: center;
    font-size: 1.1rem;
}

/* الحالة الفارغة */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.empty-state p {
    font-size: 1.1rem;
}

/* تصميم متجاوب */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .header-actions {
        justify-content: center;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
    
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1rem;
    }
    
    .cart-info {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .modal {
        padding: 1rem;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .btn {
        padding: 0.6rem 1.2rem;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .login-form {
        padding: 1.5rem;
    }
    
    .products-grid {
        grid-template-columns: 1fr;
    }
    
    .quantity-controls {
        padding: 0 1rem 1rem;
    }
    
    .btn-quantity {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    .quantity-input {
        width: 50px;
        padding: 0.4rem;
    }
}

/* طباعة */
@media print {
    .header,
    .cart-summary,
    .modal,
    .btn,
    .connection-status,
    .notifications-container {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
        font-size: 12pt;
    }
    
    .container {
        max-width: none;
        padding: 0;
    }
}

/* أنماط نظام العمل أوف لاين والمزامنة */

/* مؤشر حالة الاتصال */
.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.5s ease; /* زيادة مدة الانتقال */
    position: relative;
    min-width: 100px; /* عرض ثابت لتجنب الحركة */
    justify-content: center;
}

.connection-status.online {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    animation: none; /* إزالة أي حركة */
}

.connection-status.offline {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    animation: none; /* إزالة أي حركة */
}

.connection-status i {
    font-size: 1rem;
    transition: none; /* منع انتقال الأيقونة */
}

/* زر المزامنة اليدوية */
.sync-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.manual-sync-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.3s ease;
}

.manual-sync-btn:hover {
    background: #218838;
}

.manual-sync-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* عداد العناصر المؤجلة */
.pending-counter {
    position: relative;
    display: inline-block;
}

.pending-sync-counter {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* حاوي الإشعارات */
.notifications-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 10000;
    width: 350px;
    max-width: 90vw;
    pointer-events: none; /* تجنب التداخل مع التفاعل */
}

/* الإشعار الفردي */
.notification {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideInSlow 0.6s ease-out; /* حركة أبطأ */
    border-left: 4px solid #007bff;
    position: relative;
    pointer-events: auto; /* تمكين التفاعل مع الإشعار نفسه */
    transition: all 0.3s ease;
}

@keyframes slideInSlow {
    from { 
        opacity: 0;
        transform: translateX(-100%);
    }
    to { 
        opacity: 1;
        transform: translateX(0);
    }
}

.notification.success {
    border-left-color: #28a745;
}

.notification.error {
    border-left-color: #dc3545;
}

.notification.warning {
    border-left-color: #ffc107;
}

.notification.info {
    border-left-color: #17a2b8;
}

.notification i {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.notification.success i {
    color: #28a745;
}

.notification.error i {
    color: #dc3545;
}

.notification.warning i {
    color: #ffc107;
}

.notification.info i {
    color: #17a2b8;
}

.notification span {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.4;
}

.notification .close-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #999;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.notification .close-btn:hover {
    background: #f1f1f1;
    color: #333;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* مؤشر وضع أوف لاين */
.offline-indicator {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: #6c757d;
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 25px;
    font-size: 0.9rem;
    display: none;
    align-items: center;
    gap: 0.5rem;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.offline-indicator.show {
    display: flex;
}

/* إضافات لوضع أوف لاين في المنتجات */
.product-card.offline {
    opacity: 0.7;
    border: 2px dashed #dc3545;
}

.product-card.offline::after {
    content: "غير متاح أوف لاين";
    position: absolute;
    top: 10px;
    left: 10px;
    background: #dc3545;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
}

/* تحسينات للطاولات في وضع أوف لاين */
.table-container.offline {
    position: relative;
}

.table-container.offline::before {
    content: "البيانات محفوظة محلياً";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: #fff3cd;
    color: #856404;
    text-align: center;
    padding: 0.5rem;
    border: 1px solid #ffeaa7;
    border-radius: 4px 4px 0 0;
    font-size: 0.85rem;
}

/* تحسينات للأزرار في وضع أوف لاين */
.btn.offline-mode {
    background: #6c757d;
    position: relative;
}

.btn.offline-mode::after {
    content: "سيتم المزامنة لاحقاً";
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.btn.offline-mode:hover::after {
    opacity: 1;
}

/* تحسينات للشاشات الصغيرة */
@media (max-width: 768px) {
    .notifications-container {
        left: 10px;
        right: 10px;
        width: auto;
    }
    
    .connection-status {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    
    .manual-sync-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .offline-indicator {
        left: 10px;
        bottom: 10px;
        font-size: 0.8rem;
        padding: 0.5rem 0.8rem;
    }
}