:root {
  --bg: #0b0910;
  --bg-2: #130d1c;
  --pink: #ff2e8a;
  --pink-2: #ff5fa8;
  --pink-deep: #c81e6e;
  --glow: rgba(255, 46, 138, 0.45);
  --card: rgba(255, 255, 255, 0.045);
  --card-2: rgba(255, 255, 255, 0.07);
  --card-border: rgba(255, 255, 255, 0.10);
  --text: #f3f0f7;
  --muted: #968fa8;
  --line: rgba(255, 255, 255, 0.08);
  --green: #2ee6a0;
  --green-bg: rgba(46, 230, 160, 0.14);
  --amber: #ffc24b;
  --amber-bg: rgba(255, 194, 75, 0.14);
  --blue: #5b8cff;
  --blue-bg: rgba(91, 140, 255, 0.14);
  --red: #ff5470;
  --red-bg: rgba(255, 84, 112, 0.14);
  --radius: 20px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --header-h: 74px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", "Segoe UI", system-ui, sans-serif;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

/* خلفية متوهّجة فاخرة */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 500px at 85% -5%, rgba(255, 46, 138, 0.22), transparent 60%),
    radial-gradient(700px 500px at 10% 8%, rgba(120, 40, 200, 0.16), transparent 55%),
    radial-gradient(800px 600px at 50% 110%, rgba(255, 46, 138, 0.10), transparent 60%),
    var(--bg);
}

#app { max-width: 1180px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 10px; }

/* ============ الترويسة ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; position: sticky; top: 0; z-index: 30;
  background: rgba(13, 10, 20, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
  min-height: var(--header-h);
}
.tb-right { display: flex; align-items: center; gap: 12px; }
.tb-logo {
  width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--pink), var(--pink-deep));
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  box-shadow: 0 6px 18px var(--glow);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 800; letter-spacing: -.2px; }
.topbar .sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.tb-logout {
  background: rgba(255,255,255,.06); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 9px 14px; font-size: 13px; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; gap: 6px; transition: .15s;
}
.tb-logout:hover { background: var(--red-bg); border-color: var(--red); color: #fff; }
.tb-menu {
  background: rgba(255,255,255,.06); border: 1px solid var(--line); color: var(--text);
  width: 44px; height: 44px; border-radius: 13px; font-size: 21px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: .15s;
}
.tb-menu:hover { background: rgba(255,255,255,.1); }

/* ============ القائمة الجانبية المنزلقة ============ */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .25s;
}
.drawer-overlay.open { opacity: 1; }
.drawer {
  position: absolute; top: 0; right: 0; height: 100%; width: 82%; max-width: 310px;
  background: rgba(16, 11, 23, 0.97); backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
  border-left: 1px solid var(--card-border); padding: 22px 16px 18px;
  display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.drawer-overlay.open .drawer { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 4px 6px 16px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.drawer-name { font-weight: 800; font-size: 16px; }
.drawer-items { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.drawer-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 14px; border: none;
  background: none; color: var(--text); font-family: inherit; font-size: 15.5px; font-weight: 700;
  border-radius: 14px; cursor: pointer; text-align: right; width: 100%; transition: .15s;
}
.drawer-item .ico { font-size: 20px; width: 24px; text-align: center; }
.drawer-item:hover { background: rgba(255,255,255,.05); }
.drawer-item.active { background: linear-gradient(135deg, rgba(255,46,138,.30), rgba(255,46,138,.12)); color: #fff; }

.view { padding: 18px; flex: 1; animation: fadeUp .35s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ============ البطاقات ============ */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 20px; margin-bottom: 14px;
}

/* ============ الأزرار ============ */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: none; border-radius: 14px; font-family: inherit;
  padding: 15px; font-size: 16px; font-weight: 800; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--pink-deep));
  box-shadow: 0 10px 26px var(--glow); transition: transform .06s, filter .15s, box-shadow .2s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
.btn.secondary { background: var(--card-2); color: var(--pink-2); box-shadow: none; border: 1px solid var(--card-border); }
.btn.ghost { background: rgba(255,255,255,.05); color: var(--text); box-shadow: none; border: 1px solid var(--line); }
.btn.ghost:hover { background: rgba(255,255,255,.09); }
.btn.danger { background: linear-gradient(135deg, #ff5470, #c8203f); box-shadow: 0 10px 26px rgba(255,84,112,.35); }
.btn.green { background: linear-gradient(135deg, #2ee6a0, #16a972); box-shadow: 0 10px 26px rgba(46,230,160,.3); }
.btn.small { padding: 10px 14px; font-size: 13px; width: auto; border-radius: 11px; }

/* ============ بلاطات المندوب ============ */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 26px 14px; text-align: center;
  cursor: pointer; box-shadow: var(--shadow); transition: transform .12s, border-color .2s;
}
.tile::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--accent, var(--pink));
}
.tile:hover { transform: translateY(-4px); border-color: var(--accent, var(--pink)); }
.tile:active { transform: scale(.97); }
.tile .emoji {
  font-size: 30px; display: inline-flex; width: 60px; height: 60px; margin-bottom: 10px;
  align-items: center; justify-content: center; border-radius: 50%;
  background: var(--accent-bg, rgba(255,46,138,.14));
}
.tile .label { font-weight: 800; font-size: 16px; }
.tile.order { --accent: var(--pink); --accent-bg: rgba(255,46,138,.16); }
.tile.exchange { --accent: var(--blue); --accent-bg: var(--blue-bg); }
.tile.return { --accent: var(--amber); --accent-bg: var(--amber-bg); }
.tile.transfer { --accent: var(--green); --accent-bg: var(--green-bg); }
.tile.full { grid-column: 1 / -1; }

/* ============ الحقول ============ */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 14px; border: 1.5px solid var(--line);
  border-radius: 13px; font-size: 16px; font-family: inherit;
  background: rgba(255,255,255,.05); color: var(--text); transition: .15s;
}
input::placeholder { color: #6f6982; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pink); box-shadow: 0 0 0 4px rgba(255,46,138,.16); }
select option { background: var(--bg-2); color: var(--text); }

/* ============ الماسح ============ */
#reader { width: 100%; border-radius: 16px; overflow: hidden; background: #000; border: 1px solid var(--card-border); }
#reader video { border-radius: 16px; }
.scan-hint { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 10px; }

.result-badge {
  background: var(--green-bg); color: var(--green); border: 1px solid rgba(46,230,160,.3);
  border-radius: 14px; padding: 16px; text-align: center; font-size: 22px; font-weight: 900; letter-spacing: 1px;
}

/* ============ الشارات ============ */
.chip { display: inline-block; padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 700; border: 1px solid transparent; }
.chip.order { background: rgba(255,46,138,.16); color: var(--pink-2); border-color: rgba(255,46,138,.3); }
.chip.exchange { background: var(--blue-bg); color: var(--blue); border-color: rgba(91,140,255,.3); }
.chip.return { background: var(--amber-bg); color: var(--amber); border-color: rgba(255,194,75,.3); }
.chip.transfer { background: var(--green-bg); color: var(--green); border-color: rgba(46,230,160,.3); }
.chip.picked_up { background: var(--amber-bg); color: var(--amber); border-color: rgba(255,194,75,.3); }
.chip.delivered { background: var(--green-bg); color: var(--green); border-color: rgba(46,230,160,.3); }

/* ============ القوائم ============ */
.list-item { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.list-item .num { font-weight: 800; font-size: 16px; }
.list-item a { color: var(--pink-2); text-decoration: none; }

/* ============ الإحصائيات ============ */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 4px; }
.stat {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 18px;
  padding: 18px 10px; text-align: center; box-shadow: var(--shadow);
}
.stat .stat-ico { font-size: 22px; opacity: .9; }
.stat .n {
  font-size: 34px; font-weight: 900; line-height: 1.1; margin-top: 4px;
  background: linear-gradient(135deg, var(--pink-2), var(--pink-deep));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.stat .t { font-size: 12.5px; color: var(--muted); margin-top: 4px; font-weight: 600; }

.bar-row { display: flex; align-items: center; gap: 12px; margin: 11px 0; font-size: 14px; }
.bar-row .name { width: 100px; flex-shrink: 0; font-weight: 600; }
.bar-track { flex: 1; background: rgba(255,255,255,.07); border-radius: 10px; height: 12px; overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 6px; border-radius: 10px; background: linear-gradient(90deg, var(--pink-2), var(--pink)); box-shadow: 0 0 12px var(--glow); transition: width .6s ease; }
.bar-row .val { width: 34px; text-align: left; font-weight: 800; }

/* ============ شريط التنقّل ============ */
.tabbar {
  display: flex; gap: 4px; z-index: 30;
  position: sticky; bottom: 14px; margin: 8px 14px 14px;
  background: rgba(18, 13, 26, 0.82);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border); border-radius: 20px;
  padding: 8px 6px; box-shadow: var(--shadow);
}
.tabbar button {
  flex: 1; background: none; border: none; padding: 8px 2px; cursor: pointer; font-family: inherit;
  font-size: 10.5px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px;
  border-radius: 14px; transition: .15s;
}
.tabbar button .ico { font-size: 19px; transition: transform .15s; }
.tabbar button.active { color: #fff; background: linear-gradient(135deg, rgba(255,46,138,.28), rgba(255,46,138,.12)); font-weight: 700; }
.tabbar button.active .ico { transform: translateY(-2px) scale(1.08); }

/* ============ متفرقات ============ */
.section-title { font-size: 16px; font-weight: 800; margin: 6px 0 12px; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.spacer { height: 10px; }
.error-msg { background: var(--red-bg); color: #ff9bac; padding: 11px 13px; border-radius: 12px; font-size: 13px; margin: 8px 0; border: 1px solid rgba(255,84,112,.3); }
.success-msg { background: var(--green-bg); color: var(--green); padding: 11px 13px; border-radius: 12px; font-size: 13px; margin: 8px 0; border: 1px solid rgba(46,230,160,.3); }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 24px 0 26px; }
.logo .circle {
  width: 76px; height: 76px; border-radius: 24px;
  background: linear-gradient(135deg, var(--pink), var(--pink-deep));
  display: flex; align-items: center; justify-content: center; font-size: 36px;
  box-shadow: 0 14px 40px var(--glow);
}
.logo .section-title { font-size: 24px; font-weight: 900; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); cursor: pointer; transition: transform .12s, border-color .15s; }
.thumb:hover { transform: scale(1.05); border-color: var(--pink); }
.thumbs { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }

/* عارض الصورة بالحجم الكامل */
.lightbox {
  position: fixed; inset: 0; z-index: 100; padding: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(0, 0, 0, 0.92); backdrop-filter: blur(8px); animation: fadeUp .2s ease;
}
.lightbox img { max-width: 100%; max-height: 78vh; border-radius: 16px; box-shadow: var(--shadow); }
.lb-cap { color: #fff; font-weight: 700; font-size: 16px; }
.lb-close { color: #fff; background: rgba(255,255,255,.14); padding: 11px 20px; border-radius: 12px; cursor: pointer; font-weight: 700; }
.photo-slot {
  border: 2px dashed var(--line); border-radius: 14px; padding: 20px; text-align: center;
  color: var(--muted); cursor: pointer; font-size: 14px; transition: .15s; background: rgba(255,255,255,.02);
}
.photo-slot:hover { border-color: var(--pink); color: var(--text); }
.photo-slot.done { border-style: solid; border-color: var(--green); color: var(--green); background: var(--green-bg); }
.hidden { display: none !important; }
.loading { text-align: center; padding: 60px 20px; color: var(--muted); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--pink); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* صفحات الدخول/الإعداد تتوسّط في الشاشة */
#app:not(:has(.topbar)) .view { max-width: 440px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; justify-content: center; }

/* شاشات المندوب (ترويسة بدون سايد-بار) تتوسّط بعرض مريح على الكمبيوتر */
@media (min-width: 900px) {
  #app:has(.topbar):not(:has(.tabbar)) .view { max-width: 620px; margin: 0 auto; width: 100%; }
}

/* ============ تجاوب سطح المكتب ============ */
@media (min-width: 900px) {
  #app:has(.tabbar) {
    display: grid;
    grid-template-columns: 264px 1fr;
    grid-template-areas: "top top" "nav main";
    align-content: start; column-gap: 22px;
  }
  #app:has(.tabbar) .topbar { grid-area: top; border-radius: 0; }
  #app:has(.tabbar) .view { grid-area: main; padding: 26px 26px 26px 0; }

  /* السايد-بار */
  #app:has(.tabbar) .tabbar {
    grid-area: nav; position: sticky; top: calc(var(--header-h) + 18px);
    align-self: start; flex-direction: column; gap: 6px; margin: 26px 22px 0 0;
    padding: 14px 12px; border-radius: 22px; max-height: calc(100vh - var(--header-h) - 44px); overflow: auto;
  }
  #app:has(.tabbar) .tabbar button {
    flex-direction: row; justify-content: flex-start; gap: 13px; padding: 13px 15px;
    font-size: 15px; font-weight: 700; border-radius: 14px;
  }
  #app:has(.tabbar) .tabbar button .ico { font-size: 21px; }
  #app:has(.tabbar) .tabbar button:hover { background: rgba(255,255,255,.05); color: var(--text); }

  /* لوحة المدير: شبكة أنيقة على الشاشات الكبيرة */
  .dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .dash-grid .stat-grid,
  .dash-grid .full-col { grid-column: 1 / -1; }

  .tiles { grid-template-columns: repeat(4, 1fr); }
  .tile.full { grid-column: auto; }
}

@media (min-width: 1200px) {
  #app:has(.tabbar) .dash-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* على الموبايل: القائمة الجانبية بديلة للبار السفلي */
@media (max-width: 899px) {
  .tabbar { display: none; }
}

/* على الكمبيوتر: السايد-بار ظاهر فلا حاجة لزر القائمة */
@media (min-width: 900px) {
  .tb-menu { display: none; }
}
