/* ============================================
   نظام أورجا O.G - الهوية البصرية النهائية
   الألوان: أزرق داكن / برتقالي ذهبي / بيج
   الخط: Noto Sans Arabic (رسمي واحترافي)
   ============================================ */

/* ---------- استيراد الخط الرسمي ---------- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@300;400;600;700&display=swap');

:root {
  --orga-navy: #0A2342;
  --orga-navy-dark: #071831;
  --orga-navy-light: #12335C;
  --orga-orange: #F4A300;
  --orga-orange-dark: #D98A00;
  --orga-gold: #FFC94D;
  --orga-beige: #F8F4EC;
  --orga-white: #FFFFFF;
  --orga-text: #2B3A4A;
  --orga-danger: #E74C3C;
  --orga-success: #27AE60;
  --orga-warning: #F1C40F;
}

/* ---------- الإعدادات العامة ---------- */
* {
  box-sizing: border-box;
}

body {
  background-color: var(--orga-beige);
  color: var(--orga-text);
  font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
  /* تم حذف direction: ltr; ليستجيب لخاصية dir في HTML */
}

/* ضبط الخط للعربية (نفس الخط مع دعم إضافي) */
html[dir="rtl"] body {
  font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, 'Arial', sans-serif;
}

/* ---------- الشريط الجانبي (Sidebar) ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--orga-navy) 0%, var(--orga-navy-dark) 100%);
  min-height: 100vh;
  color: var(--orga-white);
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: all 0.3s ease;
}
html[dir="ltr"] .sidebar {
  border-right: 3px solid var(--orga-gold);
}
html[dir="rtl"] .sidebar {
  border-left: 3px solid var(--orga-gold);
}

.sidebar .brand {
  background: var(--orga-navy-dark);
  padding: 1.2rem 1rem;
  text-align: center;
  border-bottom: 2px solid var(--orga-orange);
}

.sidebar .brand img {
  max-height: 120px;
  margin-bottom: 0.5rem;
}

.sidebar .brand .brand-title {
  color: var(--orga-white);
  font-weight: 700;
  font-size: 1.3rem;
  margin: 0;
}

.sidebar .brand .brand-sub {
  color: var(--orga-gold);
  font-size: 0.8rem;
  font-weight: 300;
}

.sidebar .nav-section {
  color: var(--orga-gold);
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 1rem 1.2rem 0.3rem;
  letter-spacing: 1px;
  font-weight: 600;
}

.sidebar .nav-link {
  color: rgba(255, 255, 255, 0.8);
  padding: 0.65rem 1.2rem;
  border-radius: 0;
  border-left: 3px solid transparent;
  transition: all 0.2s;
  font-weight: 400;
  white-space: nowrap;
}
html[dir="ltr"] .sidebar .nav-link {
  border-left: 3px solid transparent;
  border-right: none;
}
html[dir="rtl"] .sidebar .nav-link {
  border-right: 3px solid transparent;
  border-left: none;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  color: var(--orga-white);
  background: rgba(244, 163, 0, 0.15);
}
html[dir="ltr"] .sidebar .nav-link:hover,
html[dir="ltr"] .sidebar .nav-link.active {
  border-left-color: var(--orga-orange);
}
html[dir="rtl"] .sidebar .nav-link:hover,
html[dir="rtl"] .sidebar .nav-link.active {
  border-right-color: var(--orga-orange);
}

.sidebar .nav-link i {
  margin-inline-end: 0.5rem;
  color: var(--orga-gold);
  width: 1.2rem;
  text-align: center;
}

.sidebar .sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
}

/* ---------- الهيدر العلوي (Topbar) ---------- */
.topbar {
  background: var(--orga-navy);
  color: var(--orga-white);
  padding: 0.8rem 1.5rem;
  box-shadow: 0 2px 8px rgba(7, 24, 49, 0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar .page-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

.topbar .user-name {
  color: var(--orga-gold);
  font-weight: 600;
}

/* ---------- المحتوى الرئيسي ---------- */
.main-content {
  padding-top: 1.5rem;
}

/* ---------- البطاقات (Cards) ---------- */
.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(10, 35, 66, 0.08);
  margin-bottom: 1.2rem;
  background: var(--orga-white);
}

.card-header {
  background: var(--orga-white);
  border-bottom: 2px solid var(--orga-orange);
  border-radius: 12px 12px 0 0 !important;
  font-weight: 700;
  color: var(--orga-navy);
}

/* ---------- بطاقات الإحصائيات (Dashboard) ---------- */
.stat-card {
  border-top: 4px solid var(--orga-orange);
  padding: 1.2rem;
  text-align: center;
  transition: transform 0.2s;
  height: 100%;
}

.stat-card:hover {
  transform: translateY(-3px);
}

.stat-card .stat-icon {
  font-size: 2rem;
  color: var(--orga-orange);
}

.stat-card .stat-number {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--orga-navy);
}

.stat-card .stat-label {
  color: #7A8A99;
  font-size: 0.85rem;
  font-weight: 400;
}

/* ---------- الأزرار ---------- */
.btn-orga {
  background: var(--orga-orange);
  color: var(--orga-white);
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1.2rem;
  transition: all 0.2s;
}

.btn-orga:hover {
  background: var(--orga-orange-dark);
  color: var(--orga-white);
}

.btn-outline-orga {
  border: 2px solid var(--orga-orange);
  color: var(--orga-orange-dark);
  font-weight: 600;
  background: transparent;
}

.btn-outline-orga:hover {
  background: var(--orga-orange);
  color: var(--orga-white);
}

.btn-navy {
  background: var(--orga-navy);
  color: var(--orga-white);
  border: none;
}

.btn-navy:hover {
  background: var(--orga-navy-light);
  color: var(--orga-white);
}

/* ---------- الجداول (مع تحسين الاستجابة) ---------- */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

.table {
  background: var(--orga-white);
  vertical-align: middle;
  width: 100%;
  min-width: 600px;
}

.table thead th {
  background: var(--orga-navy);
  color: var(--orga-white);
  font-size: 0.85rem;
  border: none;
  white-space: nowrap;
  font-weight: 600;
}

.table-hover tbody tr:hover {
  background-color: rgba(244, 163, 0, 0.06);
}

/* ---------- حالات الصلاحية (الألوان) ---------- */
.expiry-success {
  background-color: #E8F8EF !important;
  color: #1E8449 !important;
}

.expiry-warning {
  background-color: #FEF9E7 !important;
  color: #B7950B !important;
}

.expiry-danger {
  background-color: #FDEDEC !important;
  color: #C0392B !important;
}

/* ---------- مخصصات الجرد ---------- */
.diff-positive {
  color: var(--orga-success);
  font-weight: 700;
}

.diff-negative {
  color: var(--orga-danger);
  font-weight: 700;
}

/* ---------- ختم الحالات (Badges) ---------- */
.badge-order-new { background: #3498DB; }
.badge-order-pending_approval { background: #E67E22; }
.badge-order-approved { background: #27AE60; }
.badge-order-rejected { background: #C0392B; }
.badge-order-preparing { background: var(--orga-orange); }
.badge-order-ready { background: #8E44AD; }
.badge-order-shipped { background: #16A085; }
.badge-order-received { background: var(--orga-success); }

/* ---------- نموذج السلة (Cart) ---------- */
.cart-summary {
  background: var(--orga-navy);
  color: var(--orga-white);
  border-radius: 12px;
  padding: 1rem;
  position: sticky;
  top: 80px;
}

.cart-item {
  background: var(--orga-beige);
  color: var(--orga-text);
  border-radius: 8px;
  padding: 0.6rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.cart-total {
  border-top: 2px solid var(--orga-gold);
  padding-top: 0.8rem;
  margin-top: 0.8rem;
}

/* ---------- البحث الذكي ---------- */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-results {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  z-index: 1000;
  background: var(--orga-white);
  border: 1px solid var(--orga-navy-light);
  border-radius: 0 0 8px 8px;
  max-height: 300px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(7, 24, 49, 0.2);
  display: none;
}

.autocomplete-results .autocomplete-item {
  padding: 0.6rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--orga-beige);
  display: flex;
  justify-content: space-between;
}

.autocomplete-results .autocomplete-item:hover {
  background: rgba(244, 163, 0, 0.15);
}

/* ---------- التنبيهات (Flash) ---------- */
.alert {
  border-radius: 8px;
  border: none;
  font-weight: 500;
}

/* ---------- الطباعة ---------- */
@media print {
  .sidebar, .topbar, .no-print, .topbar-actions {
    display: none !important;
  }
  .main-content {
    padding: 0 !important;
  }
  .card {
    box-shadow: none;
  }
  .table-container {
    overflow: visible !important;
  }
  .table {
    min-width: 100% !important;
  }
}

/* ---------- أدوات عامة ---------- */
.text-gold { color: var(--orga-gold) !important; }
.text-navy { color: var(--orga-navy) !important; }
.bg-orga { background-color: var(--orga-orange) !important; }
.bg-navy { background-color: var(--orga-navy) !important; }
.cursor-pointer { cursor: pointer; }
.fw-600 { font-weight: 600; }

/* ---------- شريط التمرير المخصص ---------- */
.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-track {
  background: var(--orga-navy-dark);
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--orga-orange);
  border-radius: 3px;
}

/* ===========================================================
   تحسينات الاستجابة (للشاشات الصغيرة والمتوسطة)
   =========================================================== */

@media (max-width: 991.98px) {
  .sidebar {
    min-height: auto;
    height: auto;
    position: relative;
  }
  .main-content {
    padding-top: 1rem;
  }
}

@media (max-width: 767.98px) {
  body {
    font-size: 14px;
  }

  .topbar .d-flex {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .topbar .d-flex .ms-auto {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-start;
  }
  
  .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
  }
  .toolbar-actions .btn,
  .toolbar-actions a {
    flex: 1 0 auto;
    min-width: 100px;
    text-align: center;
  }

  .stat-card .stat-number {
    font-size: 1.4rem;
  }
  .stat-card .stat-icon {
    font-size: 1.6rem;
  }

  .table-container {
    overflow-x: auto;
    display: block;
    width: 100%;
  }
  .table {
    min-width: 650px;
    font-size: 0.8rem;
  }
  .table thead th {
    white-space: nowrap;
    font-size: 0.75rem;
  }

  .cart-summary {
    position: relative;
    top: 0;
    margin-top: 1rem;
  }

  .form-control,
  .form-select {
    font-size: 14px;
  }
}

@media (max-width: 479.98px) {
  .sidebar .brand .brand-title {
    font-size: 1rem;
  }
  .topbar .page-title {
    font-size: 1rem;
  }
  .table {
    min-width: 500px;
  }
}
/* ---------- جدول طلب التجهيز (إدخال جدولي مباشر) ---------- */
.table-navy {
  background-color: var(--orga-navy);
  color: var(--orga-white);
}
.table-navy th {
  color: var(--orga-white);
  font-weight: 600;
  border-bottom: none;
}
.category-row td {
  background-color: var(--orga-beige);
  color: var(--orga-navy);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid rgba(243, 157, 32, 0.4);
}
.category-row i.bi-bookmark-fill { color: var(--orga-orange); }
.badge.bg-light.text-dark.border {
  background-color: #f1f3f5 !important;
  font-weight: 500;
  font-size: 0.7rem;
}
.qty-input:focus {
  border-color: var(--orga-orange);
  box-shadow: 0 0 0 0.2rem rgba(243, 157, 32, 0.25);
}
.invalid-input {
  border-color: #dc3545;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.2);
}
/* ---------- إيصال الشحن المطبوع ---------- */
.print-receipt {
  display: none;
  background: #fff;
  color: #000;
  padding: 16px;
  font-family: 'Segoe UI', Tahoma, sans-serif;
}
.receipt-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--orga-navy);
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.receipt-head h3 { color: var(--orga-navy); margin: 0; }
.receipt-head h5 { margin: 0; }
.receipt-rows { margin-bottom: 12px; }
.r-row {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 3px 0;
}
.r-label { font-weight: 700; color: #333; }
.receipt-items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}
.receipt-items th,
.receipt-items td {
  border: 1px solid #999;
  padding: 6px 8px;
  text-align: right;
}
.receipt-items th { background: var(--orga-beige); }
.receipt-sign {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
}
.sign-col { text-align: center; width: 45%; }
.sign-line {
  border-bottom: 1px solid #000;
  height: 40px;
  margin-bottom: 4px;
}

/* ---------- الطباعة: إخفاء الواجهة وإظهار الإيصال ---------- */
@media print {
  body {
    background: #fff !important;
    font-size: 12px;
  }
  .sidebar,
  .topbar,
  .offcanvas,
  .no-print,
  header,
  footer {
    display: none !important;
  }
  .main-content {
    padding: 0 !important;
    margin: 0 !important;
  }
  .col {
    width: 100% !important;
    max-width: 100% !important;
  }
  .print-receipt {
    display: block !important;
  }
}
/* ---------- لوحة أصناف طلب التجهيز في أمر النقل ---------- */
.text-orga { color: var(--orga-orange) !important; }
.order-items-panel {
  border: 1px solid rgba(10, 35, 66, 0.15);
  border-radius: 8px;
  padding: 12px;
  background: var(--orga-beige);
}
.order-items-panel .table {
  background: var(--orga-white);
  border-radius: 6px;
  overflow: hidden;
}
.order-items-panel .requested-qty {
  font-weight: 600;
  color: var(--orga-navy);
}
.transfer-qty:focus {
  border-color: var(--orga-orange);
  box-shadow: 0 0 0 0.2rem rgba(243, 157, 32, 0.25);
}
/* ---------- جداول الإدخال الجدولي المباشر (مبيعات/مرتجعات/نقل) ---------- */
.price-input:focus,
.qty-input:focus {
  border-color: var(--orga-orange);
  box-shadow: 0 0 0 0.2rem rgba(243, 157, 32, 0.25);
}
.balance-cell {
  color: var(--orga-navy);
}
.line-total {
  color: var(--orga-navy);
}