/* ===========================================================
   نظام إدارة الأسعار وأرقام التجار
   لوحة تشغيل — عربية RTL، تعمل على الموبايل والكمبيوتر
   =========================================================== */

:root {
  --ink:        #16212E;
  --ink-2:      #3D4C5C;
  --ink-3:      #6B7A8B;
  --canvas:     #F1F4F7;
  --surface:    #FFFFFF;
  --surface-2:  #F8FAFC;
  --line:       #DDE4EC;
  --line-2:     #EEF2F6;

  --brand:      #12586E;   /* أزرق بحري عميق — الإجراءات الأساسية */
  --brand-dk:   #0D4354;
  --brand-lt:   #E3F0F4;

  --solar:      #E09A2B;   /* كهرماني — طاقة، للتمييز فقط */
  --solar-lt:   #FDF3E2;

  --ok:         #14795E;
  --ok-lt:      #E4F3EE;
  --warn:       #A96A05;
  --warn-lt:    #FBF0DC;
  --bad:        #AE2731;
  --bad-lt:     #FBE9EA;

  --r-sm: 6px;
  --r:    10px;
  --r-lg: 16px;

  --sh-1: 0 1px 2px rgba(22,33,46,.06), 0 1px 3px rgba(22,33,46,.04);
  --sh-2: 0 4px 16px rgba(22,33,46,.09);
  --sh-3: 0 12px 40px rgba(22,33,46,.18);

  --nav-w: 232px;
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

/* أرقام لاتينية بعرض ثابت لسهولة قراءة الأسعار */
.num, input[type="number"], .price-val, td.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  direction: ltr;
  unicode-bidi: plaintext;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
p { margin: 0 0 .6em; }
a { color: var(--brand); }

button, input, select, textarea { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ===================== شاشة الدخول ===================== */
#loginScreen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 88% -8%, #1B5E74 0%, transparent 62%),
    linear-gradient(168deg, #16212E 0%, #101A24 100%);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 34px 30px 30px;
  box-shadow: var(--sh-3);
}
.login-mark {
  display: flex; align-items: center; gap: 11px; margin-bottom: 26px;
}
.login-mark .glyph {
  width: 46px; height: 46px; flex: none;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--solar), #C97F14);
  display: grid; place-items: center;
  color: #fff; font-size: 23px;
  box-shadow: 0 4px 14px rgba(224,154,43,.35);
}
.login-mark h1 { font-size: 19px; }
.login-mark span { font-size: 12.5px; color: var(--ink-3); }

/* ===================== الهيكل العام ===================== */
#app { display: none; min-height: 100dvh; }
#app.ready { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: 58px;
  background: var(--ink);
  color: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  box-shadow: var(--sh-2);
}
.topbar .brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15.5px; }
.topbar .brand .glyph {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, var(--solar), #C97F14);
  display: grid; place-items: center; font-size: 15px;
}
.topbar .spacer { flex: 1; }
.topbar .who {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: #C3D0DB;
}
.role-chip {
  font-size: 11px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px;
  background: rgba(224,154,43,.2); color: #F0C173;
}
.role-chip.rep { background: rgba(255,255,255,.13); color: #D5E0E9; }
.icon-btn {
  background: rgba(255,255,255,.1); border: 0; color: #fff;
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  display: grid; place-items: center; font-size: 16px;
}
.icon-btn:hover { background: rgba(255,255,255,.2); }

.shell { display: flex; align-items: stretch; }

.sidenav {
  width: var(--nav-w); flex: none;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  padding: 14px 10px;
  position: sticky; top: 58px;
  height: calc(100dvh - 58px);
  overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; margin-bottom: 3px;
  border: 0; background: none; cursor: pointer;
  border-radius: var(--r);
  color: var(--ink-2); font-size: 14.5px; text-align: start;
  transition: background .13s, color .13s;
}
.nav-item .ic { font-size: 17px; width: 20px; text-align: center; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.on { background: var(--brand-lt); color: var(--brand-dk); font-weight: 600; }
.nav-sep { height: 1px; background: var(--line-2); margin: 10px 6px; }
.nav-tag {
  margin-inline-start: auto; font-size: 11px; font-weight: 600;
  background: var(--line-2); color: var(--ink-3);
  padding: 1px 7px; border-radius: 20px;
}
.nav-item.on .nav-tag { background: #fff; color: var(--brand); }

main { flex: 1; min-width: 0; padding: 20px; max-width: 1500px; }

.page-head {
  display: flex; align-items: flex-start; gap: 14px;
  flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h2 { font-size: 21px; }
.page-head .sub { font-size: 13.5px; color: var(--ink-3); margin-top: 2px; }
.page-head .acts { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ===================== عناصر أساسية ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-pad { padding: 16px 18px; }
.card-head {
  padding: 13px 18px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-head h3 { font-size: 15.5px; }
.card-head .acts { margin-inline-start: auto; display: flex; gap: 7px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .13s, border-color .13s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #C8D3DE; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dk); border-color: var(--brand-dk); }
.btn-solar { background: var(--solar); border-color: var(--solar); color: #291B03; font-weight: 600; }
.btn-solar:hover { background: #CE8A1E; border-color: #CE8A1E; }
.btn-ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--bad); border-color: #EBC7CA; background: #fff; }
.btn-danger:hover { background: var(--bad-lt); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-wa { background: #1EA855; border-color: #1EA855; color: #fff; }
.btn-wa:hover { background: #178943; border-color: #178943; }

.field { margin-bottom: 14px; }
.field > label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--ink-2); margin-bottom: 5px;
}
.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); color: var(--ink);
  transition: border-color .13s, box-shadow .13s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(18,88,110,.12);
}
.input[readonly] { background: var(--surface-2); color: var(--ink-3); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.7; }
.select { appearance: none; padding-inline-end: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5L6 8.5L10 4.5' stroke='%236B7A8B' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 12px;
  background-position: left 11px center;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 170px; min-width: 0; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; flex: none; }

/* ===================== شارات ===================== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px;
  background: var(--line-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-lt); color: var(--ok); }
.badge.warn { background: var(--warn-lt); color: var(--warn); }
.badge.bad { background: var(--bad-lt); color: var(--bad); }
.badge.brand { background: var(--brand-lt); color: var(--brand-dk); }
.badge.solar { background: var(--solar-lt); color: #94620C; }

/* ===================== بطاقات الإحصاء ===================== */
.stat-grid {
  display: grid; gap: 12px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px 16px;
  position: relative; overflow: hidden;
}
.stat::before {
  content: ''; position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 3px; background: var(--line);
}
.stat.s-brand::before { background: var(--brand); }
.stat.s-ok::before { background: var(--ok); }
.stat.s-warn::before { background: var(--solar); }
.stat.s-bad::before { background: var(--bad); }
.stat .k { font-size: 12.5px; color: var(--ink-3); margin-bottom: 3px; }
.stat .v { font-size: 25px; font-weight: 600; letter-spacing: -.02em; }
.stat .n { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }

/* ===================== جداول ===================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: start; font-weight: 600; font-size: 12.5px;
  color: var(--ink-3); padding: 10px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
tbody td { padding: 11px 13px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.sel { background: var(--brand-lt); }
.t-name { font-weight: 500; }
.t-sub { font-size: 12px; color: var(--ink-3); }
.t-actions { display: flex; gap: 5px; justify-content: flex-end; }

/* ===== السمة المميزة: مكدّس الأسعار الثلاثي ===== */
.price-stack { display: flex; align-items: stretch; gap: 0; }
.price-cell {
  padding: 3px 11px; min-width: 96px;
  border-inline-end: 1px solid var(--line-2);
}
.price-cell:last-child { border-inline-end: 0; }
.price-cell .lb {
  font-size: 10.5px; color: var(--ink-3);
  display: flex; align-items: center; gap: 4px; margin-bottom: 1px;
}
.price-val { font-size: 14.5px; font-weight: 600; }
.price-cell.office .price-val { color: var(--ink); }
.price-cell.rep { background: var(--solar-lt); border-radius: var(--r-sm); }
.price-cell.rep .price-val { color: #8A5B08; }
.price-cell.retail .price-val { color: var(--brand-dk); }
.price-cell.special { background: var(--brand-lt); border-radius: var(--r-sm); }
.price-cell.special .price-val { color: var(--brand-dk); }
.link-chip {
  font-size: 9.5px; font-weight: 700; padding: 0 4px;
  border-radius: 4px; background: var(--solar); color: #291B03;
}
.price-none { color: var(--ink-3); font-size: 13px; }

/* ===================== النوافذ المنبثقة ===================== */
.modal-bg {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16,26,36,.55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); width: 100%; max-width: 640px;
  max-height: 92dvh; display: flex; flex-direction: column;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--sh-3);
  animation: rise .2s cubic-bezier(.2,.8,.3,1);
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
.modal.wide { max-width: 940px; }
.modal-head {
  padding: 15px 20px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 10px; flex: none;
}
.modal-head h3 { font-size: 16.5px; }
.modal-head .x {
  margin-inline-start: auto; background: none; border: 0;
  font-size: 21px; color: var(--ink-3); cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; line-height: 1;
}
.modal-head .x:hover { background: var(--surface-2); color: var(--ink); }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 13px 20px; border-top: 1px solid var(--line-2);
  display: flex; gap: 9px; justify-content: flex-end; flex: none;
  flex-wrap: wrap; background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

@media (min-width: 720px) {
  .modal-bg { align-items: center; padding: 24px; }
  .modal { border-radius: var(--r-lg); }
}

/* ===================== التنبيهات ===================== */
#toasts {
  position: fixed; z-index: 200; bottom: 18px;
  inset-inline-start: 18px;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(420px, calc(100vw - 36px));
}
.toast {
  background: var(--ink); color: #fff;
  padding: 11px 16px; border-radius: var(--r);
  box-shadow: var(--sh-2); font-size: 14px;
  display: flex; align-items: flex-start; gap: 9px;
  animation: rise .2s ease;
}
.toast.ok { background: #14634E; }
.toast.bad { background: #94222B; }
.toast .ic { flex: none; }

.note {
  padding: 11px 14px; border-radius: var(--r);
  font-size: 13.5px; display: flex; gap: 9px; align-items: flex-start;
  margin-bottom: 14px;
}
.note.info { background: var(--brand-lt); color: var(--brand-dk); }
.note.warn { background: var(--warn-lt); color: var(--warn); }
.note.bad  { background: var(--bad-lt); color: var(--bad); }
.note.ok   { background: var(--ok-lt); color: var(--ok); }
.note .ic { flex: none; font-size: 15px; margin-top: 1px; }

/* ===================== حالات فارغة وتحميل ===================== */
.empty { text-align: center; padding: 44px 20px; color: var(--ink-3); }
.empty .ic { font-size: 34px; opacity: .35; display: block; margin-bottom: 10px; }
.empty h4 { font-size: 15.5px; color: var(--ink-2); margin-bottom: 5px; }
.empty p { font-size: 13.5px; max-width: 380px; margin-inline: auto; }

.spinner {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite; display: inline-block;
}
.spinner.dark { border-color: var(--line); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 46px; }

/* ===================== أدوات الفلترة ===================== */
.filters {
  display: flex; gap: 9px; flex-wrap: wrap;
  padding: 13px 16px; border-bottom: 1px solid var(--line-2);
  align-items: center;
}
.filters .input, .filters .select { width: auto; min-width: 132px; flex: 0 1 auto; }
.filters .grow { flex: 1 1 190px; min-width: 150px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 20px; padding: 5px 13px; font-size: 13px;
  cursor: pointer; color: var(--ink-2); white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 500; }

.pager {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px; border-top: 1px solid var(--line-2); font-size: 13.5px;
  color: var(--ink-3); flex-wrap: wrap;
}

/* ===================== تفاصيل التاجر ===================== */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 14px; }
.kv dt { color: var(--ink-3); font-size: 13px; }
.kv dd { margin: 0; }

.timeline { position: relative; padding-inline-start: 20px; }
.timeline::before {
  content: ''; position: absolute; inset-block: 6px 6px;
  inset-inline-start: 5px; width: 2px; background: var(--line);
}
.tl-item { position: relative; padding-bottom: 16px; }
.tl-item::before {
  content: ''; position: absolute; inset-inline-start: -19px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ink-3); border: 2px solid var(--surface);
}
.tl-item.sold::before { background: var(--ok); }
.tl-item.lost::before { background: var(--bad); }
.tl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.tl-date { font-size: 12px; color: var(--ink-3); }
.tl-body { font-size: 13.5px; color: var(--ink-2); }

/* ===================== الاستيراد ===================== */
.drop {
  border: 2px dashed var(--line); border-radius: var(--r-lg);
  padding: 32px 20px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-lt); }
.drop .ic { font-size: 32px; color: var(--ink-3); display: block; margin-bottom: 9px; }

.row-new { background: #F4FBF7; }
.row-fuzzy { background: #FEFAF0; }
.row-skip { opacity: .45; }

/* ===================== الحملات ===================== */
.wa-list { display: flex; flex-direction: column; gap: 8px; }
.wa-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--surface);
}
.wa-item.done { background: var(--ok-lt); border-color: #C6E4DA; }
.wa-item .who { flex: 1; min-width: 0; }
.wa-item .who .nm { font-weight: 500; font-size: 14px; }
.wa-item .who .ph { font-size: 12.5px; color: var(--ink-3); }
.progress { height: 7px; background: var(--line-2); border-radius: 20px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 20px; transition: width .3s; }

.msg-preview {
  background: #E7F4EC; border: 1px solid #C9E4D5;
  border-radius: var(--r); padding: 12px 14px;
  font-size: 14px; white-space: pre-wrap; line-height: 1.75;
}

.var-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.var-btn {
  font-size: 12px; padding: 3px 9px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; color: var(--ink-2); font-family: var(--font);
}
.var-btn:hover { background: var(--brand-lt); border-color: var(--brand); color: var(--brand-dk); }

/* ===================== شريط الموبايل ===================== */
.tabbar { display: none; }

@media (max-width: 900px) {
  main { padding: 14px 12px 84px; }
  .sidenav { display: none; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 14px rgba(22,33,46,.08);
  }
  .tabbar button {
    flex: 1; background: none; border: 0; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 5px 2px; color: var(--ink-3); font-size: 10.5px; border-radius: 9px;
  }
  .tabbar button .ic { font-size: 19px; }
  .tabbar button.on { color: var(--brand); font-weight: 600; }
  .page-head h2 { font-size: 18.5px; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(142px, 1fr)); gap: 9px; }
  .stat .v { font-size: 21px; }
  .topbar .who .nm { display: none; }
  .price-stack { flex-wrap: wrap; gap: 4px; }
  .price-cell { min-width: 84px; border-inline-end: 0; }
}

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .filters { padding: 11px 12px; }
  .filters .input, .filters .select { min-width: 0; flex: 1 1 46%; }
  .card-pad { padding: 13px 14px; }
  .modal-body { padding: 15px 16px; }
  .modal-foot { padding: 11px 16px; }
  .modal-foot .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .topbar, .sidenav, .tabbar, .btn, .filters { display: none !important; }
  main { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
