@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700;900&family=IBM+Plex+Mono:wght@400;600&display=swap');

:root {
  --bg:         #0d0f14;
  --bg2:        #151820;
  --bg3:        #1c2030;
  --border:     #2a2f42;
  --border2:    #3a4058;
  --accent:     #f59e0b;
  --accent2:    #ef4444;
  --accent3:    #10b981;
  --text:       #e8eaf0;
  --text2:      #9aa0b8;
  --text3:      #5a6280;
  --radius:     10px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ===== LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 200;
  transition: transform .3s ease;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.sidebar-logo p { font-size: .75rem; color: var(--text3); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: var(--text2);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 600;
  transition: all .2s;
  border-right: 3px solid transparent;
  position: relative;
}
.sidebar-nav a:hover { color: var(--text); background: var(--bg3); }
.sidebar-nav a.active {
  color: var(--accent);
  background: rgba(245,158,11,.08);
  border-right-color: var(--accent);
}
.sidebar-nav a .nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }
.sidebar-nav .nav-badge {
  margin-right: auto;
  background: var(--accent2);
  color: #fff;
  font-size: .65rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-family: 'IBM Plex Mono', monospace;
}

.main-content {
  flex: 1;
  margin-right: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 150;
}
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.page-content { padding: 28px; flex: 1; }

/* ===== CARDS ===== */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: .95rem; font-weight: 700; color: var(--text); }

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s;
}
.stat-card:hover { border-color: var(--border2); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 4px; height: 100%;
  background: var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.stat-card.green::before  { background: var(--accent3); }
.stat-card.red::before    { background: var(--accent2); }
.stat-card.blue::before   { background: #3b82f6; }
.stat-label { font-size: .8rem; color: var(--text3); margin-bottom: 8px; }
.stat-value { font-size: 1.6rem; font-weight: 900; color: var(--text); line-height: 1; }
.stat-sub   { font-size: .75rem; color: var(--text2); margin-top: 6px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead tr { background: var(--bg3); }
th {
  padding: 10px 14px;
  text-align: right;
  font-weight: 700;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: .8rem;
  letter-spacing: .3px;
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--bg3); }
.mono { font-family: 'IBM Plex Mono', monospace; font-size: .82rem; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: none;
  font-family: 'Cairo', sans-serif;
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent);  color: #000; }
.btn-primary:hover  { background: #d97706; }
.btn-danger   { background: var(--accent2); color: #fff; }
.btn-danger:hover   { background: #dc2626; }
.btn-success  { background: var(--accent3); color: #fff; }
.btn-success:hover  { background: #059669; }
.btn-ghost    { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover    { color: var(--text); border-color: var(--border2); }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-icon { padding: 7px; border-radius: 7px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .82rem; font-weight: 700; color: var(--text2); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 9px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: .875rem;
  transition: border-color .2s;
  outline: none;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text3); }
select.form-control option { background: var(--bg2); }

.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-yellow { background: rgba(245,158,11,.15); color: var(--accent); }
.badge-green  { background: rgba(16,185,129,.15);  color: var(--accent3); }
.badge-red    { background: rgba(239,68,68,.15);   color: var(--accent2); }
.badge-blue   { background: rgba(59,130,246,.15);  color: #60a5fa; }

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 14px;
  width: 280px;
  transition: border-color .2s;
}
.search-bar:focus-within { border-color: var(--accent); }
.search-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: .875rem;
  padding: 9px 0;
}
.search-icon { color: var(--text3); font-size: 1rem; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
.modal-lg { max-width: 760px; }
@keyframes modalIn { from { opacity:0; transform:scale(.95) translateY(10px); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.05rem; font-weight: 800; }
.modal-close { background:none; border:none; color:var(--text3); cursor:pointer; font-size:1.2rem; padding:4px; }
.modal-close:hover { color: var(--text); }
.modal-footer { display:flex; justify-content:flex-end; gap:10px; margin-top:20px; padding-top:16px; border-top:1px solid var(--border); }

/* ===== CONFIRM MODAL ===== */
#confirm-modal { display:none; }
#confirm-modal.show,
#confirm-modal[style*="flex"] { display:flex !important; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 40px;
  font-size: .875rem;
  font-weight: 600;
  z-index: 9999;
  opacity: 0;
  transition: all .3s ease;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { border-color: var(--accent3); color: var(--accent3); }
.toast.error   { border-color: var(--accent2); color: var(--accent2); }
.toast.warning { border-color: var(--accent);  color: var(--accent);  }

/* ===== LOADER ===== */
#loader {
  display: none;
  position: fixed; inset: 0;
  background: rgba(13,15,20,.8);
  backdrop-filter: blur(4px);
  z-index: 9000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== STOCK SPECIFIC ===== */
.location-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 700;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
}
.stock-low  { color: var(--accent2) !important; }
.stock-mid  { color: var(--accent)  !important; }
.stock-ok   { color: var(--accent3) !important; }

/* ===== TABS ===== */
.tabs { display:flex; gap:4px; border-bottom:1px solid var(--border); margin-bottom:20px; }
.tab-btn {
  background: none; border: none; cursor: pointer;
  padding: 10px 18px; color: var(--text2);
  font-family: 'Cairo',sans-serif; font-size:.875rem; font-weight:700;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
  transition: all .2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display:none; }
.tab-panel.active { display:block; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text3);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; opacity:.4; }
.empty-state p { font-size:.9rem; }

/* ===== RESPONSIVE / MOBILE ===== */

/* زر الهامبرغر */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background .2s;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
}
.menu-toggle:hover { background: var(--bg3); }
.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all .3s;
}
/* تحويل الهامبرغر لـ X عند الفتح */
.menu-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Overlay خلف السيدبار */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

@media (max-width: 768px) {
  /* إخفاء السيدبار وإظهار الزر */
  .menu-toggle { display: flex; }
  .sidebar {
    transform: translateX(110%);
    box-shadow: -4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-right: 0; }

  /* شريط علوي */
  .topbar {
    padding: 0 10px;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: 0 2px 12px rgba(0,0,0,.3);
    min-height: 54px;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 6px;
    overflow: visible;
  }
  .topbar-title {
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    flex-shrink: 1;
  }
  .topbar-actions {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: nowrap;
    flex-shrink: 0;
  }
  .topbar-actions .btn {
    padding: 7px 10px;
    font-size: .78rem;
    white-space: nowrap;
    min-height: 36px;
  }
  /* زر الهامبرغر */
  .menu-toggle { flex-shrink: 0; }

  /* محتوى الصفحة */
  .page-content { padding: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .form-row { grid-template-columns: 1fr; }
  .search-bar { width: 100%; }

  /* الجداول: scroll أفقي */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }

  /* البطاقات */
  .card { border-radius: 10px; }
  .modal { margin: 12px; width: calc(100% - 24px); max-width: 100% !important; border-radius: 14px; }

  /* أزرار أكبر للموبايل */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; font-size: .8rem; }

  /* فورم */
  .form-control, select.form-control { min-height: 42px; font-size: .95rem; }

  /* إخفاء نصوص الأزرار الطويلة */
  .topbar-actions .btn-text-hide { display: none; }
}

/* شاشات صغيرة جداً */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 1.1rem; }
  .topbar-title { font-size: .85rem; }
}

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .btn, .topbar-actions { display: none !important; }
  .main-content { margin: 0 !important; }
  body { background: white; color: black; }
  table { font-size: 12px; }
  .card { border: 1px solid #ccc; box-shadow: none; }
}

/* ===== إخفاء URL عند الطباعة ===== */
@media print {
  @page {
    margin: 10mm;
    /* إخفاء رأس وتذييل المتصفح */
  }
  /* Chrome/Edge: إخفاء URL */
  a[href]:after { content: none !important; }
  abbr[title]:after { content: none !important; }
}


/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  /* إخفاء sidebar وإظهار هامبرغر */
  .menu-toggle { display: flex !important; }
  .sidebar {
    transform: translateX(110%) !important;
    box-shadow: -4px 0 24px rgba(0,0,0,.4);
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0) !important; }

  /* المحتوى يأخذ كامل العرض */
  .main-content {
    margin-right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
  }

  /* topbar كامل العرض */
  .topbar {
    padding: 0 10px !important;
    width: 100% !important;
    box-sizing: border-box;
  }
  .topbar-title { font-size: .85rem; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 6px 10px; font-size: .8rem; }

  .page-content { padding: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .search-bar { width: 100%; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .btn, .topbar-actions { display: none !important; }
  .main-content { margin: 0 !important; }
  body { background: white; color: black; }
}

/* ============================================
   MOBILE: كل الصفحات
   ============================================ */
@media (max-width: 768px) {

  /* ===== عام ===== */
  .tabs { display:flex; overflow-x:auto; flex-wrap:nowrap; gap:0; -webkit-overflow-scrolling:touch; scrollbar-width:none; }
  .tabs::-webkit-scrollbar { display:none; }
  .tab-btn { flex-shrink:0; padding:9px 14px; font-size:.82rem; white-space:nowrap; }
  .filter-bar { flex-wrap:wrap; gap:8px; }
  .btn { min-height:36px; }
  .btn-sm { min-height:32px; }
  .form-control, select.form-control { min-height:40px; font-size:.9rem; }
  .form-row { grid-template-columns:1fr !important; }
  .modal-footer { flex-wrap:wrap; gap:8px; }
  .modal-footer .btn { flex:1; min-width:100px; justify-content:center; }

  /* ===== جداول → scroll أفقي ===== */
  .table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
  table { min-width:500px; }

  /* ===== المبيعات ===== */
  .sales-meta { grid-template-columns:1fr 1fr !important; gap:8px !important; }
  .col-headers { display:none !important; }
  .sales-row {
    display:flex !important; flex-wrap:wrap; gap:5px;
    padding:10px 8px !important; border-bottom:1px solid var(--border);
    position:relative;
  }
  .sales-row .row-num { position:absolute; top:8px; right:8px; font-size:.7rem; color:var(--text3); }
  .sales-row .ac-wrap { width:calc(100% - 28px); margin-right:22px; }
  .sales-row .cell-input { width:100% !important; min-height:40px; font-size:.9rem; }
  .sales-row .loc-sel { width:100% !important; min-height:40px; font-size:.85rem; }
  .sales-row .total-cell { width:100%; text-align:center; background:var(--bg3); border-radius:6px; padding:5px; font-size:.9rem; font-weight:800; }
  .sales-row .del-btn { position:absolute; top:8px; left:8px; }
  .total-bar { flex-direction:column !important; align-items:flex-start !important; gap:10px !important; }
  .total-bar > div:last-child { width:100%; display:flex; gap:8px; }
  .total-bar .btn { flex:1; justify-content:center; }

  /* ===== التجهيز ===== */
  .customer-card-hdr { padding:12px 14px !important; }
  .cust-name { font-size:.9rem !important; }
  .prep-item { flex-direction:column !important; }
  .prep-img-col { width:100% !important; min-width:unset !important; height:120px; border-left:none !important; border-bottom:1px solid var(--border); }
  .prep-img-col img, .prep-img-col .no-img { width:100px !important; height:100px !important; }
  .prep-info-col { padding:10px 12px !important; }
  .prep-qty-input { width:100% !important; min-height:44px !important; font-size:1rem !important; }
  .prep-input-row { flex-wrap:wrap !important; gap:8px !important; }
  .loc-hdr { flex-direction:column !important; align-items:flex-start !important; gap:8px !important; padding:10px 12px !important; }
  .loc-hdr .btn { width:100% !important; min-height:42px !important; justify-content:center; }
  .loc-title { font-size:.82rem !important; }

  /* ===== قوائم بعد التجهيز ===== */
  .done-hdr { padding:12px 14px !important; flex-wrap:wrap; gap:6px; }

  /* ===== الزبائن ===== */
  #customers-tbody tr { display:flex !important; flex-wrap:wrap; padding:10px 12px; border-bottom:1px solid var(--border); gap:4px; }
  #customers-tbody td { border:none !important; padding:2px 4px !important; }
  #customers-tbody td:first-child { display:none; }
  #customers-tbody td:nth-child(2) { flex:1; font-size:.9rem; font-weight:800; }
  #customers-tbody td:nth-child(6) { font-size:.88rem; font-weight:800; }

  /* ===== التقارير ===== */
  .report-filters { padding:10px; gap:8px; }
  .report-filters .form-group { min-width:130px !important; }
  .movement-table { min-width:600px; }

  /* ===== فلتر المخازن ===== */
  .location-filter { overflow-x:auto !important; flex-wrap:nowrap !important; padding-bottom:4px; -webkit-overflow-scrolling:touch; scrollbar-width:none; }
  .location-filter::-webkit-scrollbar { display:none; }
  .loc-chip { white-space:nowrap; flex-shrink:0; min-height:32px; }

  /* ===== عرض الصور ===== */
  .gallery-grid { grid-template-columns:repeat(2,1fr) !important; gap:10px !important; padding:10px !important; }
  .gallery-topbar { flex-wrap:wrap; gap:6px; padding:10px; }
  .gallery-search { width:100% !important; order:3; }
  .gallery-name { font-size:.82rem; }
  .gallery-actions .btn { padding:5px 4px !important; font-size:.76rem; }

  /* ===== إحصائيات ===== */
  .stats-grid { grid-template-columns:1fr 1fr !important; gap:8px; }
  .stat-card { padding:12px 10px; }
  .stat-label { font-size:.72rem; }
  .stat-value { font-size:1rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns:1fr 1fr !important; gap:6px; }
  .gallery-grid { grid-template-columns:repeat(2,1fr) !important; }
  .total-bar .btn { font-size:.78rem; padding:7px 6px; }
}
