/* ==========================================================
   تحسينات الجوال (المتجر + لوحة التحكم) — يُحمَّل آخر ملف
   ========================================================== */

/* لا تمرير أفقي للصفحة أبدًا (clip لا يكسر العناصر الثابتة sticky) */
html, body { max-width: 100%; overflow-x: clip; }
img, video, canvas, iframe { max-width: 100%; }

/* ───── الشريط السفلي للوحة التحكم ───── */
.adm-bar { display: grid; }
.adm-bar a { min-width: 0; padding: 0 2px; }
.adm-bar a span:not(.badge-count) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-bar a .badge-count { position: absolute; top: 6px; inset-inline-start: calc(50% + 4px); inset-inline-end: auto; }
@media (min-width: 992px) { .adm-bar { display: none !important; } }

@media (max-width: 991.98px) {
  /* مساحة للمحتوى فوق الشريط السفلي */
  body.admin .content { padding-bottom: calc(var(--nav-h, 64px) + var(--safe-b, 0px) + 24px); }
  body.admin .content { padding-inline: 14px; }

  /* الشريط العلوي: عنوان في سطر واحد */
  body.admin .topbar { gap: 8px; padding: 0 10px; }
  body.admin .topbar h1 { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

  /* رؤوس الصفحات والأزرار */
  body.admin .head-row { flex-wrap: wrap; gap: 10px; }
  body.admin .head-row h2 { font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
  body.admin .head-row .actions { flex-wrap: wrap; gap: 6px; width: 100%; }
  body.admin .head-row .actions .select { width: 100% !important; }
  body.admin .row-actions { flex-wrap: wrap; }

  /* الشبكات تصير عمودًا واحدًا */
  body.admin .form-grid, body.admin .grid-2, body.admin .grid-3 { grid-template-columns: 1fr !important; }
  body.admin .form-grid > aside { order: -1; }
  body.admin .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  body.admin .filters > .input[name="q"], body.admin .filters > input[type="search"], body.admin .filters .rep-seg { grid-column: 1 / -1; }
  body.admin .filters .btn { width: 100%; }
  body.admin .filters .check { grid-column: 1 / -1; }

  /* الجداول على شكل بطاقات: التسمية يمين والمحتوى يتدفق بشكل طبيعي */
  .tbl-cards tr { padding: 12px 14px !important; }
  .tbl-cards td { display: block !important; position: relative; padding: 5px 0 5px !important; padding-inline-start: 96px !important; min-height: 28px; text-align: start !important; overflow-wrap: anywhere; }
  .tbl-cards td::before { position: absolute; inset-inline-start: 0; top: 6px; width: 88px; font-size: 12px; line-height: 1.5; white-space: normal; }
  .tbl-cards td:empty, .tbl-cards td[data-l=""] { padding-inline-start: 0 !important; }
  .tbl-cards td[data-l=""]::before { display: none; }
  .tbl-cards td .row-actions, .tbl-cards td .actions { justify-content: flex-start; }
  .tbl-cards td.n { text-align: start !important; }

  /* عناصر الشبكة لا تتمدد أوسع من الشاشة بسبب جدول أو نص طويل بداخلها */
  body.admin .form-grid > *, body.admin .panel, body.admin .content > *, body.admin .ver, body.admin .grid-2 > * { min-width: 0; }
  body.admin .panel { max-width: 100%; }

  /* جداول عادية (غير بطاقات): تمرير أفقي داخل الجدول نفسه */
  body.admin table.tbl:not(.tbl-cards) { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  body.admin table.tbl:not(.tbl-cards) th, body.admin table.tbl:not(.tbl-cards) td { white-space: nowrap; }

  /* سطر الإجمالي في جداول البطاقات */
  .tbl-cards tfoot, .tbl-cards tfoot tr { display: block; }
  .tbl-cards tfoot tr { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 10px 14px; border: 1px solid var(--gold); border-radius: 14px; }
  .tbl-cards tfoot th { border: 0 !important; padding: 0 !important; }
  .tbl-cards tfoot th:empty { display: none; }

  /* الأزرار داخل البطاقات جنب بعض */
  .tbl-cards td form { display: inline-block; vertical-align: middle; margin-inline-end: 4px; }
  .tbl-cards td > .actions, .tbl-cards td > .row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

  /* سجل الطلب والنصوص الطويلة */
  body.admin .timeline li, body.admin .log li, body.admin .sum-row { overflow-wrap: anywhere; min-width: 0; }
  body.admin .sum-row { flex-wrap: wrap; }
  body.admin .btn-block, body.admin .panel > .btn { max-width: 100%; }

  /* بطاقات الأرقام */
  body.admin .stat-grid { gap: 10px; }
  body.admin .stat { padding: 13px; }
  body.admin .stat b { font-size: 18px; overflow-wrap: anywhere; }

  /* القائمة الجانبية المنزلقة فوق الشريط السفلي */
  body.admin.nav-open .side { z-index: 130; }
  body.admin .nav-backdrop { z-index: 125 !important; }

  /* لوحة المهام: نموذج الإرسال تحت القائمة مباشرة */
  body.admin .task-form { position: static; }

  /* التقارير */
  .rep-bar { grid-template-columns: 1fr auto; }
  .rep-filters input[type="date"], .rep-filters input[type="month"], .rep-filters .select { width: 100%; }

  /* التبويبات الأفقية تمرر بدل ما تكسر الصفحة */
  .tabs-nav { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs-nav::-webkit-scrollbar { display: none; }
  .tabs-nav a { flex: none; }

  /* نافذة التنبيه فوق الشريط السفلي */
  .ntf { bottom: calc(var(--nav-h, 64px) + var(--safe-b, 0px) + 12px) !important; }
}

/* شاشات صغيرة جدًا */
@media (max-width: 380px) {
  body.admin .stat-grid { grid-template-columns: 1fr 1fr; }
  body.admin .stat b { font-size: 16px; }
  .tbl-cards td { padding-inline-start: 82px !important; }
  .tbl-cards td::before { width: 76px; }
  .adm-bar a { font-size: 10px; }
}

/* ───── المتجر ───── */
@media (max-width: 760px) {
  .header-row { gap: 8px; }
  .header .brand-name { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .header .brand { min-width: 0; }
  .pd-title { overflow-wrap: anywhere; }
  .cart-line, .sum-row { flex-wrap: wrap; }
  .checkout-grid, .cart-grid, .pd-grid { grid-template-columns: 1fr !important; }
}

/* task attachments */
.task-files { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.task-files img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line-soft); display: block; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 10px; border: 1px solid var(--line-soft); background: var(--card); font-size: 13px; color: var(--text); }
@media (min-width: 992px) { .task-form { position: sticky; top: 80px; } }

/* شريط تفعيل إشعارات الجهاز */
.ntf.ntf-push { bottom: auto !important; top: calc(70px + env(safe-area-inset-top, 0px)); z-index: 9998; }

/* صفحة «إشعاراتي» */
.push-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.push-checks li { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-soft); font-size: 14px; }
.push-checks li span { width: 20px; text-align: center; font-weight: 800; }
.push-checks li.ok span { color: var(--ok); } .push-checks li.bad { border-color: rgba(229, 72, 77, .4); } .push-checks li.bad span { color: var(--bad); }
.push-msg { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.push-msg.ok { background: rgba(46, 160, 67, .12); color: var(--ok); } .push-msg.bad { background: rgba(229, 72, 77, .12); color: var(--bad); }
.push-help { margin: 0; padding-inline-start: 18px; display: grid; gap: 8px; font-size: 14px; color: var(--muted); }

/* ───── القوائم المنسدلة (select): الخيارات كانت بيضاء على أبيض في الوضع الليلي ───── */
:root:not([data-theme="light"]) { color-scheme: dark; }       /* قوائم ومنتقي التاريخ بألوان داكنة من المتصفح نفسه */
:root[data-theme="light"] { color-scheme: light; }
select option, select optgroup { background-color: #17171a; color: #fffaf0; }
select option:checked { background-color: #3a2f12; color: #f7e3a3; }
select option:disabled { color: #8a8274; }
:root[data-theme="light"] select option, :root[data-theme="light"] select optgroup { background-color: #ffffff; color: #1c170e; }
:root[data-theme="light"] select option:checked { background-color: #f3e6c2; color: #5a420a; }
.select, select.input { color: var(--text); }

/* تعديل المهمة */
.task-edit { display: inline-block; }
.task-edit[open] { display: block; flex-basis: 100%; width: 100%; order: 10; }
.task-edit > summary { list-style: none; cursor: pointer; }
.task-edit > summary::-webkit-details-marker { display: none; }
.task-edit[open] > summary { background: var(--gold-soft); }
.task-edit-form { margin-top: 10px; padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: rgba(0, 0, 0, .18); }
