:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --indigo: #4338ca;
}

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

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.hidden { display: none !important; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ===== أزرار ===== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: .92rem;
  cursor: pointer;
  font-family: inherit;
  transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-warn { background: var(--warn); color: #fff; }
.btn-warn:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 11px; font-size: .8rem; border-radius: 6px; }
.btn-block { width: 100%; }

/* ===== شاشة الدخول ===== */
#loginView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  padding: 16px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
  text-align: center;
}
.login-logo {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 800;
  font-size: 1.6rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.login-card h1 { font-size: 1.3rem; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: .85rem; margin-bottom: 22px; }
#loginForm label {
  display: block;
  text-align: right;
  font-size: .83rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 12px;
}
#loginForm input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: .95rem;
}
#loginForm .btn { margin-top: 6px; }
.login-error { color: var(--danger); font-size: .85rem; margin-top: 12px; }

/* ===== التخطيط ===== */
#appView { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  padding: 20px 18px;
  font-size: 1.1rem;
  font-weight: 800;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: #fff;
}
.company-switch {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.company-switch-label {
  display: block;
  font-size: .7rem;
  color: #94a3b8;
  margin-bottom: 6px;
}
.company-switch select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.15);
  background: #1e293b;
  color: #fff;
  font-family: inherit;
  font-size: .88rem;
}
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link {
  background: transparent;
  border: none;
  color: #cbd5e1;
  text-align: right;
  padding: 11px 14px;
  border-radius: 8px;
  font-size: .95rem;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-footer { padding: 12px; }
.sidebar-footer .btn { color: #cbd5e1; border-color: rgba(255,255,255,.15); }
.sidebar-footer .btn:hover { background: rgba(255,255,255,.07); }

.content { flex: 1; padding: 24px; max-width: 1200px; min-width: 0; }
.content h2 { margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: .88rem; margin-bottom: 18px; }

/* ===== البطاقات ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 10px rgba(0,0,0,.08);
  border-top: 3px solid var(--primary);
}
.card .value { display: block; font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.card .value.green { color: var(--success); }
.card .value.orange { color: var(--warn); }
.card .value.red { color: var(--danger); }
.card .label { color: var(--muted); font-size: .82rem; }
.card.accent { border-right: 4px solid var(--primary); }
.card.accent-green { border-right: 4px solid var(--success); }
.card.accent-orange { border-right: 4px solid var(--warn); }
.card.accent-red { border-right: 4px solid var(--danger); }

/* ===== الجداول ===== */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  overflow: hidden;
}
.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.panel-head h3 { font-size: 1rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 700px; }
th, td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--border); font-size: .88rem; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
td.actions { white-space: nowrap; }
td.num { white-space: nowrap; }

/* ===== شارات الحالة ===== */
.badge { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-pending { background: #fef3c7; color: var(--warn); }
.badge-delivered { background: #dcfce7; color: var(--success); }
.badge-returned { background: #fee2e2; color: var(--danger); }
.badge-transferred { background: #dbeafe; color: var(--primary); }

/* ===== شريط الأدوات ===== */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: .92rem;
  background: #fff;
}
#parcelSearch { flex: 1; min-width: 200px; }
.toolbar .count { color: var(--muted); font-size: .84rem; margin-inline-start: auto; }

.pagination { display: flex; gap: 8px; justify-content: center; margin: 18px 0 6px; flex-wrap: wrap; }
.pagination button {
  min-width: 36px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer; font-family: inherit;
}
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.empty { text-align: center; padding: 40px; color: var(--muted); }

/* ===== النافذة المنبثقة ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 50;
}
.modal-box {
  background: #fff; border-radius: 14px;
  padding: 24px; width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-box h3 { margin-bottom: 16px; font-size: 1.15rem; }
.modal-box label {
  display: block; margin-bottom: 12px;
  font-size: .83rem; color: var(--muted); font-weight: 600;
}
.modal-box input, .modal-box select, .modal-box textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-family: inherit; font-size: .95rem; color: var(--text);
}
.modal-box textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid label { min-width: 0; }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal-actions .btn + .btn { margin-inline-start: 0; }
.summary-box {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; margin-bottom: 14px;
  font-size: .92rem;
}
.summary-box .row { display: flex; justify-content: space-between; padding: 4px 0; }
.summary-box .row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-weight: 800; font-size: 1.05rem; color: var(--primary); }

/* ===== الإشعار ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: .9rem; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== صفحات ===== */
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.dues-table .net { font-weight: 700; color: var(--primary); }
.hint { color: var(--muted); font-size: .82rem; }

.company-chip {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 600;
}

/* ===== معاينة اللابل ===== */
.label-preview {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #f8fafc;
  margin-bottom: 14px;
  text-align: center;
  overflow-x: auto;
}
.label {
  margin: 0 auto;
  padding: 3mm;
  text-align: center;
  font-family: "Segoe UI", Arial, sans-serif;
  direction: rtl;
  color: #000;
  background: #fff;
  border: 1px solid var(--border);
}
.label-80 { width: 78mm; }
.label-58 { width: 56mm; }
.label-30x50 { width: 50mm; }
.label-25x50 { width: 50mm; }
.label .l-head { font-weight: 800; font-size: 14px; border-bottom: 2px solid #000; padding-bottom: 2mm; margin-bottom: 1.5mm; }
.label .l-barcode img { max-width: 100%; max-height: 18mm; width: auto; height: auto; }
.label .l-tracking { font-size: 17px; font-weight: 800; letter-spacing: 1px; margin: 1mm 0; word-break: break-all; }
.label .l-row { display: flex; justify-content: space-between; font-size: 12px; padding: .5mm 0; }
.label .l-row span { color: #555; }
.label .l-foot { margin-top: 1mm; border-top: 1px dashed #999; padding-top: 1mm; font-size: 11px; color: #333; }
.label-30x50 .l-head, .label-25x50 .l-head { font-size: 10px; border-bottom: none; padding-bottom: 0; margin-bottom: .3mm; }
.label-30x50 .l-barcode img, .label-25x50 .l-barcode img { max-height: 7mm; }
.label-30x50 .l-tracking, .label-25x50 .l-tracking { font-size: 11px; letter-spacing: 0; margin: .3mm 0; }
.label-30x50 .l-meta, .label-25x50 .l-meta { display: flex; justify-content: space-between; gap: 2mm; font-size: 8.5px; padding: .3mm 0; }
.label-preview .label { transform: scale(.72); transform-origin: top center; }
.label-preview .label-58 { transform: scale(.72); transform-origin: top center; }
.label-preview .label-30x50 { transform: scale(1.15); transform-origin: top center; }
.label-preview .label-25x50 { transform: scale(1.15); transform-origin: top center; }
.label-options { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; flex-wrap: wrap; }
.print-hint {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: .78rem;
  margin-bottom: 12px;
  line-height: 1.7;
}

@media print {
  @page { size: 80mm auto; margin: 0; }
  body { margin: 0; }
}

/* ===== التقارير ===== */
.report-filters .toolbar { margin-bottom: 0; }
.report-filters input[type="date"] { direction: ltr; }
#reportResult .cards { margin-top: 0; }

/* نماذج داخل اللوحات */
.panel form label {
  display: block; margin-bottom: 12px;
  font-size: .83rem; color: var(--muted); font-weight: 600;
}
.panel form input {
  display: block; width: 100%; margin-top: 4px;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-family: inherit; font-size: .95rem; color: var(--text);
}

@media (max-width: 720px) {
  #appView { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { display: none; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}
