/* ============================================================
   MR.FLEX — أنماط وحدات المنصة في لوحة الإدارة
   تُحمَّل بعد style.css وتستخدم نفس المتغيرات، دون إعادة تعريف
   أي نمط موجود إلا ما يلزم للتجاوب.
   ============================================================ */

/* ---------- الشارات في القائمة الجانبية ---------- */
.nav-link .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-badge {
  flex: 0 0 auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}
.nav-badge[hidden] { display: none; }
.nav-badge.nav-badge-muted { background: rgba(255, 255, 255, 0.16); color: var(--sidebar-text-active, #fff); }

/* ---------- عناصر عامة ---------- */
.inline-error, .inline-info {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}
.inline-error { background: var(--danger-soft); color: var(--danger); }
.inline-info { background: var(--surface-2); color: var(--text-muted); }
.clamp-1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.cell-text-clip { min-width: 0; }
.row-flash { animation: rowFlash 2.2s ease; }
@keyframes rowFlash { 0%, 40% { background: var(--primary-soft); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .row-flash { animation: none; } }

/* الإشعارات القابلة للفتح */
.notif-item.is-actionable { cursor: pointer; }
.notif-item.is-actionable:hover { background: var(--surface-2); }
.notif-item.is-actionable:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

/* ---------- الإعدادات ---------- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 16px;
  align-items: start;
}
.settings-grid .settings-card { max-width: none; min-width: 0; }
.settings-card-head { margin-bottom: 14px; }
.settings-card-head h3 { font-size: 15px; }
.settings-card-head .cell-sub { margin-top: 3px; }
.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.settings-sep { height: 1px; background: var(--border); margin: 20px 0 16px; }
.settings-subhead { font-size: 13.5px; margin-bottom: 12px; }

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  min-width: 0;
}
.switch-row input[type="checkbox"] {
  width: 18px; height: 18px;
  margin-top: 2px;
  flex: 0 0 auto;
  accent-color: var(--primary);
}
.switch-row span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-row strong { font-size: 13px; }
.switch-row small { font-size: 11.5px; color: var(--text-muted); line-height: 1.5; }

/* ---------- نموذج المنتج: صفحة الهبوط ---------- */
.form-section-title { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
.form-section-title h4 { font-size: 14px; }

.template-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
}
.template-option {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: start;
  padding: 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  min-width: 0;
}
.template-option:hover { border-color: var(--border-strong); }
.template-option.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.template-option:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.template-name { font-size: 12.5px; font-weight: 700; }
.template-desc { font-size: 11px; color: var(--text-muted); line-height: 1.45; }

/* مصغّرات توضيحية لكل قالب (تخطيط فقط) */
.template-thumb {
  display: grid;
  gap: 4px;
  height: 58px;
  padding: 6px;
  border-radius: 8px;
  background: var(--surface-2);
}
.template-thumb i { display: block; border-radius: 3px; background: var(--border-strong); }
.tpl-thumb-1 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.tpl-thumb-1 i:nth-child(1) { grid-row: 1 / 3; background: var(--primary-soft); }
.tpl-thumb-2 { grid-template-rows: 12px 1fr; grid-template-columns: 1fr 1fr; background: #1f2140; }
.tpl-thumb-2 i:nth-child(1) { grid-column: 1 / 3; background: rgba(255,255,255,.28); }
.tpl-thumb-2 i:nth-child(2) { background: var(--primary); }
.tpl-thumb-2 i:nth-child(3) { background: rgba(255,255,255,.4); }
.tpl-thumb-3 { grid-template-rows: 2fr 1fr; grid-template-columns: 1fr; }
.tpl-thumb-3 i:nth-child(1) { background: var(--primary-soft); }
.tpl-thumb-3 i:nth-child(3) { display: none; }
.tpl-thumb-4 { grid-template-rows: 1fr 14px 1fr; }
.tpl-thumb-4 i:nth-child(2) { background: var(--mint, #22c55e); }
.tpl-thumb-5 { grid-template-rows: 1fr 6px 6px; background: var(--surface); border: 1px solid var(--border); }
.tpl-thumb-5 i:nth-child(1) { background: var(--surface-2); }

.related-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 2px;
}
.picker-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.picker-item .picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.picker-item.selected { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark, var(--primary)); }
.picker-order {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 10.5px; font-weight: 700;
  display: inline-grid; place-items: center; flex: 0 0 auto;
}

/* ---------- الإعلانات ---------- */
.ad-thumb-icon {
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.ad-media-inputs { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1; }
.ad-media-inputs input[type="url"] { width: 100%; }
#adModalOverlay [data-ad-part][hidden],
#ad-products-wrap[hidden],
#pf-related-picker-wrap[hidden] { display: none; }

/* ---------- السحوبات: طلب التواصل ---------- */
.wd-contact-callout {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12.5px;
  line-height: 1.6;
}
.wd-contact-callout span { color: var(--text); }

/* ============================================================
   جداول الإعلانات وسلة المحذوفات: بطاقات على الموبايل
   (نفس نمط صفحات الطلبات والسحوبات الحالي)
   ============================================================ */
@media (max-width: 760px) {
  #page-ads .toolbar, #page-trash .toolbar { gap: 8px; }
  #page-ads .select-filter, #page-trash .select-filter { flex: 1 1 100%; }

  .table-wrap table.responsive-table { min-width: 0; width: 100%; }
  .table-wrap:has(> table.responsive-table) { overflow: visible; border: none; background: transparent; }
  table.responsive-table thead { display: none; }
  table.responsive-table tbody { display: block; }
  table.responsive-table tbody tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 4px 12px;
    margin-bottom: 10px;
  }
  table.responsive-table tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--border);
    text-align: end;
    min-width: 0;
  }
  table.responsive-table tbody td:last-child { border-bottom: none; }
  table.responsive-table tbody td::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-align: start;
  }
  table.responsive-table tbody td.cell-actions { justify-content: flex-end; padding-top: 6px; }
  table.responsive-table tbody td.cell-actions::before { content: none; }
  table.responsive-table tbody tr.empty-row { border: none; background: transparent; padding: 0; }
  table.responsive-table tbody tr.empty-row td { display: block; text-align: center; padding: 32px 12px; border: none; }
  table.responsive-table tbody tr.empty-row td::before { content: none; }
  table.responsive-table .clamp-1 { max-width: 60vw; }
  table.responsive-table .row-actions { flex-wrap: wrap; }
}

/* ============================================================
   تدقيق التجاوب العام للوحة الإدارة (320px → 768px)
   ============================================================ */
@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .topbar-left { gap: 8px; min-width: 0; flex: 1; }
  .topbar-left > div { min-width: 0; }
  .page-title, .page-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-title { font-size: 15px; }
  .topbar-right { gap: 6px; flex: 0 0 auto; }
  #authUserEmail { display: none !important; }
  #logoutBtn { padding: 7px 9px; font-size: 0; gap: 0; }
  #logoutBtn svg { margin: 0; }

  .modal-overlay { padding: 12px 8px; }
  .modal-head, .modal-body, .modal-foot { padding-inline: 14px; }
  .modal-body { max-height: calc(100vh - 170px); }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }

  .section-head { align-items: stretch; }
  .section-actions { width: 100%; }
  .section-actions .btn { flex: 1 1 auto; justify-content: center; }

  .settings-actions .btn { flex: 1 1 auto; justify-content: center; }
  .image-upload { flex-wrap: wrap; }
  .template-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .field input, .field select, .field textarea, .select-filter, .search-box input { font-size: 16px; }
  .btn { min-height: 40px; }
  .btn.btn-icon { min-width: 40px; min-height: 40px; }
}

.wd-owner-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
@media (max-width: 760px) { .wd-owner-cell { align-items: flex-end; text-align: end; } }

/* ============================================================
   بيانات المتجر العامة + الظهور
   ============================================================ */
.settings-grid .settings-card-wide { grid-column: 1 / -1; }
.store-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 14px;
}
.store-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.store-field-full { grid-column: 1 / -1; }
.store-field label:first-child { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.store-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.store-field input:focus { border-color: var(--primary); outline: none; }
.visibility-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.visibility-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.visibility-toggle:has(input:checked) { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.field .visibility-toggle { margin-top: 6px; }
.page-toggles { display: flex; flex-wrap: wrap; gap: 8px; }

/* ============================================================
   طلبات تعديل بيانات المسوّقين
   ============================================================ */
.request-fields { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-start; }
.compare-wrap { margin-top: 14px; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
.compare-table { width: 100%; min-width: 0; border-collapse: collapse; font-size: 13px; }
.compare-table th, .compare-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: start;
  vertical-align: top;
  overflow-wrap: anywhere;
}
.compare-table thead th { background: var(--surface-2); font-size: 11.5px; color: var(--text-muted); }
.compare-table tbody th { width: 28%; font-weight: 600; color: var(--text-muted); }
.compare-table tbody tr:last-child th, .compare-table tbody tr:last-child td { border-bottom: none; }
.compare-table tr.is-changed td:last-child { background: var(--success-soft); color: var(--text); font-weight: 700; }
@media (max-width: 560px) {
  .compare-table tbody th { width: 34%; }
  .compare-table th, .compare-table td { padding: 8px; }
}
