/* ============================================
   نظام سلسة التوريد الداخلي - CSS
   ============================================ */

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    direction: rtl;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   Header
   ============================================ */
.app-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow-lg);
}

/* Header ثابت في الصفحة الرئيسية فقط */
body.main-page .app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    width: 100%;
}

/* Header عادي في الصفحات الأخرى */
body:not(.main-page):not(.pos-page) .app-header {
    position: relative;
}

.header-content h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* ============================================
   Navigation - تصميم احترافي مع قوائم منسدلة
   ============================================ */
.main-nav {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-bottom: 2px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(10px);
}

/* Nav ثابت في الصفحة الرئيسية فقط */
body.main-page .main-nav {
    position: fixed;
    top: var(--header-height, 100px);
    left: 0;
    right: 0;
    z-index: 1000;
    width: 100%;
}

/* Nav عادي في الصفحات الأخرى */
body:not(.main-page):not(.pos-page) .main-nav {
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-menu {
    list-style: none;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 0;
    margin: 0;
    gap: 0.25rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.nav-item {
    position: relative;
    margin: 0;
}

/* روابط التنقل العادية */
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
}

.nav-link:hover {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    color: var(--primary-color);
    border-color: #bae6fd;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.1);
}

.nav-link.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-link.active:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, #1e3a8a 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

.nav-icon {
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.nav-text {
    display: inline-block;
}

/* القوائم المنسدلة */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    width: 100%;
    text-align: right;
    justify-content: space-between;
}

.nav-dropdown-toggle .dropdown-arrow {
    font-size: 0.7rem;
    transition: transform 0.3s ease;
    margin-right: auto;
    margin-left: 0.5rem;
    color: var(--text-secondary);
}

.nav-dropdown.active .nav-dropdown-toggle .dropdown-arrow,
.nav-dropdown-menu.show ~ .nav-dropdown-toggle .dropdown-arrow {
    transform: rotate(180deg);
}

.nav-dropdown.active .nav-link {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    color: var(--primary-color);
    border-color: #bae6fd;
}

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    list-style: none;
    padding: 0.5rem;
    margin: 0.5rem 0 0 0;
    min-width: 280px;
    max-width: 320px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1002; /* أعلى من Header (1001) و Nav (1000) */
    max-height: 0;
    overflow: hidden;
}

.nav-dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    max-height: 600px;
}

.nav-dropdown-item {
    margin: 0;
    padding: 0;
}

.nav-dropdown-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.nav-dropdown-link:hover {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    color: var(--primary-color);
    border-color: #bae6fd;
    transform: translateX(-3px);
    padding-right: 1.25rem;
}

.nav-dropdown-link.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
    font-weight: 600;
}

.nav-dropdown-link.active:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, #1e3a8a 100%);
    color: white;
}

/* تحسينات للشاشات الصغيرة */
@media (max-width: 768px) {
    .nav-menu {
        flex-direction: column;
        align-items: stretch;
        padding: 0.5rem;
        gap: 0.25rem;
    }
    
    .nav-link {
        width: 100%;
        justify-content: space-between;
        padding: 1rem;
    }
    
    .nav-dropdown-menu {
        position: static;
        width: 100%;
        max-width: 100%;
        margin: 0.25rem 0 0 0;
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
    }
    
    .nav-dropdown-link {
        padding-right: 1.5rem;
    }
}

/* تأثيرات بصرية إضافية */
.nav-item::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: 50%;
    width: 0;
    height: 3px;
    background: var(--primary-color);
    transition: all 0.3s ease;
    transform: translateX(50%);
    border-radius: 2px 2px 0 0;
}

.nav-link.active::before,
.nav-dropdown.active::before {
    width: 80%;
}

/* تحسينات للوصولية */
.nav-link:focus,
.nav-dropdown-toggle:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* تأثيرات انتقالية سلسة */
.nav-dropdown-menu {
    will-change: transform, opacity;
}

.nav-link,
.nav-dropdown-link {
    will-change: transform, background-color;
}

/* ============================================
   Modals - المودالات (نظام موحد)
   ============================================ */

/* Overlay - الخلفية الشفافة */
.modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 10000 !important;
    display: none !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 1rem !important;
    box-sizing: border-box !important;
    animation: fadeIn 0.2s ease-out;
}

/* إظهار المودال */
.modal-overlay.active,
.modal-overlay:not(.hidden) {
    display: flex !important;
}

/* إخفاء المودال */
.modal-overlay.hidden {
    display: none !important;
}

/* محتوى المودال */
.modal-content,
.modal,
.form-container[id*="Modal"]:not([id*="Overlay"]) {
    position: relative !important;
    z-index: 10001 !important;
    background: white !important;
    border-radius: 12px !important;
    padding: 1.5rem !important;
    max-width: 800px !important;
    width: 95% !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    animation: scaleIn 0.2s ease-out;
    box-sizing: border-box !important;
}

/* رأس المودال */
.modal-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 1.5rem !important;
    padding-bottom: 1rem !important;
    border-bottom: 2px solid #e5e7eb !important;
}

.modal-header h3,
.modal-title {
    margin: 0 !important;
    font-size: 1.25rem !important;
    font-weight: 600 !important;
    color: #1f2937 !important;
}

/* جسم المودال */
.modal-body {
    padding: 0 !important;
    margin-bottom: 1.5rem !important;
}

/* أقدام المودال */
.modal-footer,
.modal-actions {
    display: flex !important;
    gap: 0.75rem !important;
    justify-content: flex-end !important;
    margin-top: 1.5rem !important;
    padding-top: 1rem !important;
    border-top: 2px solid #e5e7eb !important;
}

/* زر الإغلاق */
.modal-close,
.close-modal {
    background: none !important;
    border: none !important;
    font-size: 1.5rem !important;
    cursor: pointer !important;
    color: #6b7280 !important;
    padding: 0.5rem !important;
    min-width: auto !important;
    line-height: 1 !important;
    transition: color 0.2s !important;
}

.modal-close:hover,
.close-modal:hover {
    color: #ef4444 !important;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* إغلاق المودال عند النقر على الخلفية */
.modal-overlay[onclick*="close"],
.modal-overlay[onclick*="remove"] {
    cursor: pointer;
}

.modal-overlay[onclick*="close"] > *,
.modal-overlay[onclick*="remove"] > * {
    cursor: default;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    margin-top: 0; /* سيتم تعديله ديناميكياً حسب ارتفاع الناف بار */
}

/* تعديل padding-top للمحتوى في الصفحة الرئيسية ليكون أسفل Header + Nav الثابت */
body.main-page .main-content {
    padding-top: calc(var(--header-height, 100px) + var(--nav-height, 60px) + 2rem);
}

/* استثناء صفحة نقطة البيع من offset الناف بار */
body.pos-page .main-content,
body.pos-page .app-header,
body.pos-page .main-nav {
    position: static;
}

/* حساب الارتفاع ديناميكياً */
:root {
    --header-height: 100px;
    --nav-height: 60px;
}

/* ============================================
   Dashboard
   ============================================ */
.dashboard h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    font-size: 2.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    border-radius: 8px;
}

.stat-info h3 {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.stat-info p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.quick-actions {
    margin-top: 2rem;
}

.quick-actions h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.3s ease;
    font-weight: 500;
}

.action-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.action-icon {
    font-size: 1.5rem;
}

/* ============================================
   Page Header
   ============================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.page-header h2 {
    color: var(--text-primary);
    font-size: 1.75rem;
}

/* ============================================
   Forms
   ============================================ */
.form-container {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--text-secondary);
    color: white;
}

.btn-secondary:hover {
    background-color: var(--text-primary);
}

.btn-success {
    background-color: var(--secondary-color);
    color: white;
}

.btn-success:hover {
    opacity: 0.9;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-warning {
    background-color: var(--warning-color);
    color: white;
}

.btn-warning:hover {
    opacity: 0.9;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* ============================================
   Tables
   ============================================ */
.table-container {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background-color: var(--bg-color);
}

th {
    padding: 1rem;
    text-align: right;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: var(--bg-color);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================
   Status Badges
   ============================================ */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-info {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-secondary {
    background-color: #e2e8f0;
    color: #475569;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================
   Alerts & Messages
   ============================================ */
.alert {
    padding: 1rem 1.5rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ============================================
   Material Limits Table
   ============================================ */
.limits-table {
    margin-top: 1.5rem;
}

.limits-table th,
.limits-table td {
    text-align: center;
}

.limits-table input[type="number"] {
    width: 120px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* ============================================
   Order Split Cards
   ============================================ */
.split-orders-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.split-order-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.split-order-card h4 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.split-order-items {
    list-style: none;
    margin-top: 1rem;
}

.split-order-items li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
}

.split-order-items li:last-child {
    border-bottom: none;
}

/* ============================================
   Order Items
   ============================================ */
.order-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 0.75rem;
}

.order-item-info {
    flex: 1;
}

.order-item-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.order-item-details {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.order-item-actions {
    display: flex;
    gap: 0.5rem;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }

    .nav-menu {
        padding: 0 1rem;
        flex-direction: column;
    }

    .nav-link {
        padding: 0.75rem 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .actions-grid {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    table {
        font-size: 0.875rem;
    }

    th, td {
        padding: 0.75rem 0.5rem;
    }
}

/* ============================================
   Utilities
   ============================================ */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.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; }

.hidden {
    display: none !important;
}

