/* ============================================================
   نظام إدارة الطلبات - التصميم الرئيسي
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800;900&display=swap');

:root {
  --primary: #1e3a5f;
  --primary-light: #2d5a9e;
  --primary-dark: #132742;
  --accent: #f0a500;
  --accent-light: #ffd060;
  --accent-dark: #c07800;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --purple: #8b5cf6;
  --pink: #ec4899;

  --bg: #f0f4f8;
  --sidebar-bg: #1e3a5f;
  --card-bg: #ffffff;
  --text: #1a2332;
  --text-muted: #64748b;
  --border: #e2e8f0;

  --sidebar-width: 260px;
  --header-height: 68px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(30,58,95,0.08);
  --shadow-md: 0 8px 30px rgba(30,58,95,0.14);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { direction: rtl; font-size: 15px; }
body {
  font-family: 'Tajawal', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0; right: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  box-shadow: -4px 0 20px rgba(0,0,0,0.2);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex; align-items: center; gap: 12px;
}

.sidebar-logo-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}

.sidebar-logo-text h1 {
  font-size: 1rem; font-weight: 800;
  color: #fff; line-height: 1.2;
}

.sidebar-logo-text span {
  font-size: 0.72rem; color: rgba(255,255,255,0.5);
}

.sidebar-nav { flex: 1; padding: 16px 0; }

.nav-section-title {
  padding: 8px 20px 4px;
  font-size: 0.68rem; font-weight: 700;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase; letter-spacing: 0.08em;
}

.nav-item { margin: 1px 10px; }

.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px;
  border-radius: 10px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.88rem; font-weight: 500;
  transition: var(--transition);
  position: relative;
}

.nav-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-link.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(240,165,0,0.4);
}

.nav-link .nav-icon {
  width: 20px; text-align: center; font-size: 1rem; flex-shrink: 0;
}

.nav-badge {
  margin-right: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
}

.user-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 800;
  color: #fff; flex-shrink: 0;
}

.user-details .user-name { font-size: 0.82rem; font-weight: 700; color: #fff; }
.user-details .user-role { font-size: 0.7rem; color: rgba(255,255,255,0.5); }

/* ===== SIDEBAR TOGGLE BUTTON ===== */
#menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--primary);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
#menu-toggle:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== SIDEBAR transition fix ===== */
.sidebar { transition: width 0.25s ease, overflow 0.25s ease; }
.main-wrapper { transition: margin-right 0.25s ease; }

/* ===== MAIN LAYOUT ===== */
.main-wrapper {
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: var(--transition);
}

.header {
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky; top: 0; z-index: 900;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.header-title { font-size: 1.1rem; font-weight: 700; color: var(--text); flex: 1; }
.header-subtitle { font-size: 0.75rem; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 10px; }

.btn-icon {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
  color: var(--text);
}

.btn-icon:hover { background: var(--bg); border-color: var(--primary-light); }

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

/* ===== CARDS ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.card-title {
  font-size: 0.95rem; font-weight: 700;
  color: var(--text);
  display: flex; align-items: center; gap: 8px;
}

.card-body { padding: 22px; }

/* ===== STAT CARDS ===== */
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  transition: var(--transition);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; flex-shrink: 0;
}

.stat-icon.blue { background: rgba(59,130,246,0.12); }
.stat-icon.green { background: rgba(16,185,129,0.12); }
.stat-icon.amber { background: rgba(245,158,11,0.12); }
.stat-icon.red { background: rgba(239,68,68,0.12); }
.stat-icon.purple { background: rgba(139,92,246,0.12); }
.stat-icon.pink { background: rgba(236,72,153,0.12); }

.stat-value { font-size: 1.8rem; font-weight: 900; color: var(--text); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.stat-change { font-size: 0.75rem; margin-top: 6px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: 'Tajawal', sans-serif;
  font-size: 0.88rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); color: #fff; }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: var(--accent-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary-light); color: var(--primary-light); background: rgba(45,90,158,0.05); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px;
  border-radius: 30px;
  font-size: 0.75rem; font-weight: 700;
}

.badge-new { background: rgba(59,130,246,0.12); color: #1d4ed8; }
.badge-production { background: rgba(245,158,11,0.12); color: #b45309; }
.badge-ready { background: rgba(16,185,129,0.12); color: #065f46; }
.badge-delivered { background: rgba(30,58,95,0.12); color: var(--primary); }
.badge-cancelled { background: rgba(239,68,68,0.12); color: #b91c1c; }
.badge-postponed { background: rgba(245,158,11,0.15); color: #b45309; border: 1px dashed #f59e0b; }

/* ===== TABLE ===== */
.table-wrapper { overflow-x: auto; }

.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  background: #f8fafc;
  padding: 13px 16px;
  text-align: right;
  font-size: 0.77rem; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: rgba(30,58,95,0.025); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 0.82rem; font-weight: 700;
  color: var(--text);
  margin-bottom: 7px;
}

.form-label .required { color: var(--danger); margin-right: 2px; }

.form-control, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Tajawal', sans-serif;
  font-size: 0.88rem;
  color: var(--text);
  background: #fff;
  transition: var(--transition);
  outline: none;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45,90,158,0.1);
}

textarea.form-control { resize: vertical; min-height: 90px; }

.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 5px; }

/* ===== ALERTS ===== */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
}
.alert-success { background: rgba(16,185,129,0.1); color: #065f46; border: 1px solid rgba(16,185,129,0.2); }
.alert-danger { background: rgba(239,68,68,0.1); color: #b91c1c; border: 1px solid rgba(239,68,68,0.2); }
.alert-warning { background: rgba(245,158,11,0.1); color: #b45309; border: 1px solid rgba(245,158,11,0.2); }
.alert-info { background: rgba(59,130,246,0.1); color: #1d4ed8; border: 1px solid rgba(59,130,246,0.2); }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.65);
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(4px);
}

.modal-overlay.active { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  width: 100%; max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  transform: scale(0.95) translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal { transform: scale(1) translateY(0); }

.modal-lg { max-width: 900px; }

.modal-header {
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.modal-title { font-size: 1rem; font-weight: 800; color: var(--text); }

.modal-close {
  width: 32px; height: 32px;
  border: none; background: var(--bg);
  border-radius: 8px; cursor: pointer;
  font-size: 1rem; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { background: var(--danger); color: #fff; }

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ===== CAPACITY BAR ===== */
.capacity-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}

.capacity-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.capacity-fill.high { background: var(--success); }
.capacity-fill.medium { background: var(--warning); }
.capacity-fill.low { background: var(--danger); }

/* ===== CANVAS EDITOR ===== */
.canvas-editor-wrap {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f8fafc;
  margin-bottom: 12px;
}

.canvas-editor-wrap canvas { display: block; width: 100%; height: auto; }

.canvas-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 0 6px;
}

.canvas-tool-btn {
  padding: 5px 11px;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 6px;
  font-size: 0.78rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; gap: 5px;
}
.canvas-tool-btn.active, .canvas-tool-btn:hover {
  border-color: var(--primary-light);
  background: rgba(45,90,158,0.07);
  color: var(--primary-light);
}

/* ===== UPLOAD ZONE ===== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: #fafbfc;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary-light);
  background: rgba(45,90,158,0.04);
}
.upload-zone-icon { font-size: 2.5rem; margin-bottom: 8px; }
.upload-zone-text { font-size: 0.88rem; color: var(--text-muted); }

/* ===== TOAST ===== */
.toast-container {
  position: fixed; bottom: 24px; left: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  background: var(--primary-dark);
  color: #fff;
  padding: 13px 18px;
  border-radius: 10px;
  font-size: 0.85rem; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  min-width: 260px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  animation: slideUp 0.3s ease;
}
.toast.success { background: #065f46; border-right: 4px solid var(--success); }
.toast.error { background: #7f1d1d; border-right: 4px solid var(--danger); }
.toast.warning { background: #78350f; border-right: 4px solid var(--warning); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== ORDER STEPS ===== */
.order-steps {
  display: flex; align-items: center; gap: 0;
  margin-bottom: 28px;
  overflow-x: auto;
}

.step {
  flex: 1; text-align: center; position: relative;
  padding: 16px 8px;
}

.step::before {
  content: '';
  position: absolute;
  top: 24px; right: 50%;
  width: 100%; height: 2px;
  background: var(--border);
  z-index: 0;
}
.step:last-child::before { display: none; }
.step.done::before, .step.active::before { background: var(--primary-light); }

.step-circle {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 700;
  margin: 0 auto 8px;
  position: relative; z-index: 1;
  transition: var(--transition);
}
.step.done .step-circle { background: var(--primary-light); border-color: var(--primary-light); color: #fff; }
.step.active .step-circle { background: var(--accent); border-color: var(--accent); color: var(--primary-dark); }

.step-label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); }
.step.done .step-label, .step.active .step-label { color: var(--primary); }

/* ===== PRODUCT CARD (in order creation) ===== */
.product-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.product-card:hover { border-color: var(--primary-light); background: rgba(45,90,158,0.03); }
.product-card.selected { border-color: var(--accent); background: rgba(240,165,0,0.04); }
.product-card.out-of-capacity { opacity: 0.5; cursor: not-allowed; }
.product-card-name { font-weight: 700; font-size: 0.9rem; }
.product-card-price { color: var(--primary); font-weight: 800; font-size: 0.95rem; }
.product-card-capacity { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; }

/* ===== FILTER BAR ===== */
.filter-bar {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
}

/* ===== PAGINATION ===== */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 20px; }
.page-btn {
  width: 36px; height: 36px;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: 0.82rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.page-btn:hover, .page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== PRINT ===== */
@media print {
  .sidebar, .header, .no-print { display: none !important; }
  .main-wrapper { margin-right: 0 !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); --sidebar-width: 260px; }
  .main-wrapper { margin-right: 0; }
  .page-content { padding: 16px; }
  .filter-bar { gap: 8px; }
}

/* ===== PROGRESS RING ===== */
.progress-ring-container { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.progress-ring-text { position: absolute; font-size: 0.75rem; font-weight: 800; }

/* Misc */
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.fw-bold { font-weight: 700; }
.fw-black { font-weight: 900; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mb-3 { margin-bottom: 18px; }
.p-0 { padding: 0 !important; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 9998;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
