:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --info-light: #cffafe;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Tahoma', 'Segoe UI', Arial, sans-serif;
  direction: rtl;
  text-align: right;
  font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 12px; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  font-weight: bold;
  font-size: 18px;
  padding: 14px 0;
  color: #fff;
}
.topbar nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.topbar nav a {
  color: #e0e7ff;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: background .15s;
}
.topbar nav a:hover, .topbar nav a.active {
  background: rgba(255,255,255,.16);
  color: #fff;
  text-decoration: none;
}
.topbar .user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #e0e7ff;
  font-size: 13px;
  padding: 10px 0;
}
.topbar .user-box .role-chip {
  background: rgba(255,255,255,.18);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
}
.topbar .user-box a { color: #fff; text-decoration: underline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: filter .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-ghost { background: var(--gray-light); color: var(--text); }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn:hover { filter: brightness(0.93); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.card-header h2, .card-header h3 { margin: 0; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; font-weight: 600; }
.form-group { margin-bottom: 14px; }
input[type=text], input[type=password], input[type=number], input[type=search],
input[type=date], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
textarea { resize: vertical; min-height: 60px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 160px; }

/* ---------- Badges / status chips ---------- */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}
.st-submitted  { background: var(--info-light); color: #0e6a80; }
.st-processing { background: var(--warning-light); color: #92400e; }
.st-sent       { background: var(--success-light); color: #166534; }
.st-cancelled  { background: var(--danger-light); color: #991b1b; }

.ln-pending     { background: var(--gray-light); color: #4b5563; }
.ln-prepared    { background: var(--success-light); color: #166534; }
.ln-unavailable { background: var(--danger-light); color: #991b1b; }
.ln-adjusted    { background: var(--warning-light); color: #92400e; }

.role-admin     { background: #ede9fe; color: #5b21b6; }
.role-warehouse { background: var(--warning-light); color: #92400e; }
.role-employee  { background: var(--info-light); color: #0e6a80; }

/* row tint matching status, applied to <tr> or list rows */
.row-submitted  { background: #f0fbff; }
.row-processing { background: #fffaf0; }
.row-sent       { background: #f3fbf5; }
.row-cancelled  { background: #fdf3f3; }

/* row tint matching line item status inside order_view items table */
.rowline-pending     { background: #fff; }
.rowline-prepared    { background: #f3fbf5; }
.rowline-unavailable { background: #fdf3f3; }
.rowline-adjusted    { background: #fffaf6; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--gray-light); font-size: 13px; color: var(--text-muted); font-weight: 700; }
tbody tr:hover { background: #fafafa; }
.table-wrap { overflow-x: auto; }

/* ---------- Product search ---------- */
.search-box { position: relative; }
.search-results {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.12);
  max-height: 420px;
  overflow-y: auto;
}
.search-result-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.search-result-item:hover { background: var(--primary-light); }
.search-result-item img {
  width: 46px; height: 46px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background:#fff;
}
.search-result-item .info { flex: 1; min-width: 0; }
.search-result-item .name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-item .meta { font-size: 12px; color: var(--text-muted); }
.qty-chip { font-size: 11.5px; background: var(--gray-light); padding: 2px 8px; border-radius: 20px; color: var(--text-muted); }

.cart-item, .line-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: #fff;
}
/* تلوين متبادل بين الأسطر لسهولة تتبع كل صنف بسلة الطلبية */
#cart-list .cart-item:nth-child(even) { background: var(--gray-light); }
#cart-list .cart-item { border-right: 4px solid var(--primary); }
.cart-item img, .line-item img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.cart-item .info, .line-item .info { flex: 1; min-width: 0; }
.cart-item .name, .line-item .name { font-weight: 700; }
.cart-item .opt, .line-item .opt { font-size: 12.5px; color: var(--primary); }
/* specificity must beat the generic input[type=number] rule above (0,1,1) - "input.qty-input" ties it and wins on source order */
input.qty-input { width: 60px; padding: 6px 2px; text-align: center; flex: 0 0 auto; }

/* ---------- Quantity stepper (زر - / حقل رقمي / زر +) ---------- */
.qty-stepper { display: inline-flex; align-items: center; gap: 4px; }
button.qty-btn {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary-dark);
  cursor: pointer;
  font-weight: 800;
  font-size: 17px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
button.qty-btn:hover { background: var(--primary-light); }
button.qty-btn:active { transform: scale(0.94); }

/* ---------- Sticky totals bar (يبقى ظاهرًا أثناء التمرير لأسفل) ---------- */
.sticky-totals {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  background: #fff;
  border-top: 2px solid var(--primary);
  box-shadow: 0 -6px 20px rgba(0,0,0,.1);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  z-index: 120;
}
.sticky-totals .totals-text { font-size: 14.5px; }
.sticky-totals .totals-text b { color: var(--primary-dark); font-size: 16px; }
body.has-sticky-bar .container { padding-bottom: 84px; }

.qty-zero { color: var(--danger); font-weight: 700; }

/* ---------- زر نسخ صغير (لنقل البيانات لبرنامج المحاسبة أثناء المناقلة) ---------- */
button.copy-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  color: var(--text-muted);
  vertical-align: middle;
}
button.copy-btn:hover { color: var(--primary); }

/* ---------- Toast / notifications ---------- */
#toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #1f2937;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 14px;
  min-width: 240px;
  animation: toast-in .2s ease-out;
  border-right: 4px solid var(--info);
}
.toast.toast-success { border-color: var(--success); }
.toast.toast-warning { border-color: var(--warning); }
.toast.toast-danger { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.notif-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--danger);
  margin-inline-start: 4px;
  animation: pulse 1.4s infinite;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220,38,38,.5);} 70% { box-shadow: 0 0 0 8px rgba(220,38,38,0);} 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0);} }

/* ---------- Misc ---------- */
.muted { color: var(--text-muted); }
.text-center { text-align: center; }
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.stat-tile {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-tile .num { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.stat-tile .lbl { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.flash-success { background: var(--success-light); color: #166534; }
.flash-error { background: var(--danger-light); color: #991b1b; }
.flash-info { background: var(--info-light); color: #0e6a80; }

.locked-banner {
  background: var(--warning-light);
  color: #92400e;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-weight: 600;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-box .modal-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.modal-box .modal-head img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.option-group { margin-bottom: 14px; }
.option-group .opt-title { font-weight: 700; font-size: 13.5px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.option-value-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
}
.option-value-row label { margin: 0; font-weight: 500; color: var(--text); flex: 1; }
.select-all-link { font-weight: 600; font-size: 12px; cursor: pointer; color: var(--primary); }

.line-actions { display: flex; gap: 6px; }

.summary-bar {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 16px;
  font-size: 14px;
}
.summary-bar b { color: var(--primary-dark); }

/* ---------- Image lightbox (click any product image to zoom) ---------- */
.zoomable-img { cursor: zoom-in; transition: transform .15s, box-shadow .15s; }
.zoomable-img:hover { transform: scale(1.12); box-shadow: 0 4px 14px rgba(0,0,0,.22); position: relative; z-index: 2; }
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .82);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox-overlay img {
  max-width: min(90vw, 720px);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  background: #fff;
}
.lightbox-overlay .lightbox-close {
  position: absolute;
  top: 18px;
  left: 24px;
  color: #fff;
  font-size: 28px;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 34px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .container { max-width: 100%; padding: 0; }
}

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; padding: 8px 12px; }
  .topbar nav { justify-content: center; }
}
