/* تخصيص الواجهة — ملف مستقل (لا يعدّل app.css). يُحمَّل بعد app.css و ui-kit.css */
/* القائمة الجانبية تتبع لون الثيم (القيم الاحتياطية = الأزرق الأصلي) */
body.with-side #side {
  background: linear-gradient(180deg, var(--sd1, #14306f), var(--sd2, #0f2557));
}
.sd-i.on {
  color: var(--sd1, #14306f);
}

/* ===================== تخصيص الواجهة (m-customize.js) ===================== */
body {
  --bb: 0px;
  --sb: 0px;
  padding-bottom: calc(var(--bb) + var(--sb) + env(safe-area-inset-bottom, 0));
}
body.pf-status {
  --sb: 28px;
}
body.pf-bottom {
  --bb: 64px;
}
/* شريط علوي مخفي */
body.pf-nohdr header {
  display: none;
}
/* كثافة مدمجة */
body.pf-compact .card {
  padding: 11px 13px;
  margin-bottom: 10px;
}
body.pf-compact .tile {
  min-height: 92px;
  padding: 11px 10px;
  gap: 6px;
}
body.pf-compact .it {
  padding: 8px 11px;
  margin-bottom: 7px;
}
body.pf-compact main {
  margin-top: 10px;
}
body.pf-compact input,
body.pf-compact select,
body.pf-compact textarea {
  padding: 8px 10px;
}
body.pf-compact .sd-i {
  padding: 6px 10px;
}
/* حجم الخط: يُكبَّر/يُصغَّر محتوى الصفحة (الشريط العلوي والنوافذ المنبثقة كما هي) */
body.pf-t-s main,
body.pf-t-s footer {
  zoom: 0.92;
}
body.pf-t-l main,
body.pf-t-l footer {
  zoom: 1.12;
}
/* عرض المحتوى الكامل */
body.pf-wide main,
body.pf-wide nav.bar,
body.pf-wide .hd,
body.pf-wide #screen {
  max-width: none;
}
/* القائمة على الطرف الآخر (يسار في العربي) — الجوال: الدرج ينزلق من نفس الطرف */
@media (max-width: 959px) {
  body.pf-end.with-side #side {
    inset-inline-start: auto;
    inset-inline-end: 0;
    transform: translateX(105%);
  }
  [dir='rtl'] body.pf-end.with-side #side {
    transform: translateX(-105%);
  }
  body.pf-end.with-side.side-open #side,
  [dir='rtl'] body.pf-end.with-side.side-open #side {
    transform: none;
  }
}
@media (min-width: 960px) {
  body.pf-end.with-side #side {
    inset-inline-start: auto;
    inset-inline-end: 0;
    box-shadow: -2px 0 14px rgba(8, 20, 60, 0.18);
  }
  [dir='rtl'] body.pf-end.with-side #side {
    box-shadow: 2px 0 14px rgba(8, 20, 60, 0.18);
  }
  body.pf-end.with-side:not(.pf-drawer) header .hd,
  body.pf-end.with-side:not(.pf-drawer) nav.bar,
  body.pf-end.with-side:not(.pf-drawer) main,
  body.pf-end.with-side:not(.pf-drawer) footer {
    margin-inline-start: 0;
    margin-inline-end: 250px;
  }
  body.pf-end.with-side:not(.pf-drawer) header .hd {
    padding-inline-start: 16px;
    padding-inline-end: 20px;
  }
  /* قائمة أيقونات فقط */
  body.pf-rail.with-side:not(.pf-drawer) #side {
    width: 68px;
    padding-inline: 8px;
  }
  body.pf-rail.with-side:not(.pf-end) header .hd,
  body.pf-rail.with-side:not(.pf-end) nav.bar,
  body.pf-rail.with-side:not(.pf-end) main,
  body.pf-rail.with-side:not(.pf-end) footer {
    margin-inline-start: 68px;
  }
  body.pf-rail.pf-end.with-side header .hd,
  body.pf-rail.pf-end.with-side nav.bar,
  body.pf-rail.pf-end.with-side main,
  body.pf-rail.pf-end.with-side footer {
    margin-inline-end: 68px;
  }
  body.pf-rail .sd-i {
    justify-content: center;
    padding: 6px 0;
  }
  body.pf-rail .sd-i .tx,
  body.pf-rail .sd-h span,
  body.pf-rail .sd-ar,
  body.pf-rail .sd-cnt {
    display: none;
  }
  body.pf-rail .sd-h {
    height: 1px;
    padding: 0;
    margin: 8px 6px;
    background: rgba(255, 255, 255, 0.14);
    overflow: hidden;
    pointer-events: none;
  }
  body.pf-rail .sd-g.shut .sd-bx {
    display: block;
  }
  body.pf-rail .sd-bd {
    position: absolute;
    top: -2px;
    inset-inline-end: 2px;
    min-width: 16px;
    height: 16px;
    font-size: 10px;
    padding: 0 4px;
  }
  /* قائمة منزلقة (مخفية أو شريط سفلي) على الشاشات الكبيرة */
  body.pf-drawer .menu-btn {
    display: grid;
  }
  body.pf-drawer.with-side #side {
    top: 0;
    width: 272px;
    transform: translateX(105%);
    transition: transform 0.22s;
    z-index: 50;
    padding-top: calc(14px + env(safe-area-inset-top, 0));
  }
  [dir='ltr'] body.pf-drawer.with-side #side {
    transform: translateX(-105%);
  }
  body.pf-drawer.pf-end.with-side #side {
    transform: translateX(-105%);
  }
  [dir='ltr'] body.pf-drawer.pf-end.with-side #side {
    transform: translateX(105%);
  }
  body.pf-drawer.with-side.side-open #side,
  [dir='ltr'] body.pf-drawer.with-side.side-open #side,
  body.pf-drawer.pf-end.with-side.side-open #side,
  [dir='ltr'] body.pf-drawer.pf-end.with-side.side-open #side {
    transform: none;
  }
  body.pf-drawer.with-side.side-open #scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 12, 35, 0.55);
    z-index: 45;
  }
  body.pf-drawer.with-side header .hd {
    max-width: 900px;
    margin: auto;
    padding: 8px 16px;
  }
  body.pf-drawer.with-side nav.bar {
    max-width: 900px;
    margin: 10px auto 0;
    padding: 0 16px;
  }
  body.pf-drawer.with-side main {
    max-width: 900px;
    margin: 16px auto;
    padding: 0 16px 40px;
  }
  body.pf-drawer.with-side footer {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  body.pf-drawer.with-side #screen {
    max-width: none;
  }
  body.pf-drawer.pf-wide.with-side main,
  body.pf-drawer.pf-wide.with-side .hd,
  body.pf-drawer.pf-wide.with-side nav.bar {
    max-width: none;
  }
}
body.pf-status.with-side #side {
  bottom: var(--sb);
}
/* شريط التنقل السفلي */
#botnav {
  display: none;
}
body.pf-bottom #botnav:not([hidden]) {
  display: flex;
  position: fixed;
  inset-inline: 0;
  bottom: var(--sb);
  z-index: 35;
  gap: 4px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0));
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}
.bn-i {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 4px 2px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--mut);
  text-decoration: none;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}
.bn-i .ic {
  font-size: 20px;
  line-height: 1;
}
.bn-i .l {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bn-i.on {
  background: var(--soft);
  color: var(--g);
}
/* شريط الحالة */
#statusbar:not([hidden]) {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  height: 28px;
  z-index: 36;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: var(--card);
  border-top: 1px solid var(--line);
  color: var(--mut);
  font-size: 12.5px;
  font-weight: 600;
}
#statusbar .sb-c {
  display: flex;
  align-items: center;
  gap: 6px;
}
#statusbar .sb-c i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}
#statusbar .sb-c.bad i {
  background: var(--err);
}
#statusbar .sb-u {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#statusbar .sb-t {
  font-variant-numeric: tabular-nums;
}
/* زر عائم لما الشريط العلوي يكون مخفي (يضمن إن المستخدم يقدر يرجّع التخطيط دائمًا) */
#uiFab {
  display: none;
}
body.pf-nohdr #uiFab {
  display: flex;
  gap: 6px;
  position: fixed;
  z-index: 60;
  top: calc(8px + env(safe-area-inset-top, 0));
  inset-inline-end: 10px;
}
#uiFab button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--g);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  display: grid;
  place-items: center;
  padding: 0;
}
#uiFab button[hidden] {
  display: none;
}
body.pf-panel #uiFab {
  display: none !important;
}
/* لوحة التخصيص */
.pf-p {
  position: fixed;
  z-index: 9000;
  top: 0;
  bottom: 0;
  inset-inline-end: 0;
  width: min(380px, 100vw);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: var(--card);
  color: var(--ink);
  border-inline-start: 1px solid var(--line);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
  animation: pfIn 0.2s ease-out;
}
.pf-p.pf-p-s {
  inset-inline-end: auto;
  inset-inline-start: 0;
  border-inline-start: 0;
  border-inline-end: 1px solid var(--line);
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
}
@keyframes pfIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.pf-ph {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.pf-ph h3 {
  margin: 0;
  font-size: 17px;
}
.pf-ph small {
  color: var(--mut);
  font-size: 12.5px;
}
.pf-x {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 0;
  background: var(--chip);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
}
.pf-pb {
  flex: 1;
  overflow: auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.pf-s {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pf-s > b {
  font-size: 14px;
}
.pf-s > .pf-seg + b {
  margin-top: 10px;
}
.pf-seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}
.pf-seg button {
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  min-height: 44px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  cursor: pointer;
  padding: 0 6px;
}
.pf-seg button[aria-pressed='true'] {
  border-color: var(--g);
  background: var(--soft);
  color: var(--g);
}
.pf-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
.pf-sw {
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 99px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  padding: 2px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  cursor: pointer;
}
.pf-sw i {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--mut);
  display: block;
}
.pf-sw[aria-checked='true'] {
  background: var(--g);
  border-color: var(--g);
  justify-content: flex-end;
}
.pf-sw[aria-checked='true'] i {
  background: #fff;
}
.pf-ths {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.pf-th {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 10px;
  margin: 0;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  text-align: start;
}
.pf-th[aria-pressed='true'] {
  border-color: var(--g);
  background: var(--soft);
}
.pf-th i {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.pf-th input[type='color'] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  flex: none;
}
.pf-adm {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
@media (max-width: 700px) {
  .pf-p,
  .pf-p.pf-p-s {
    top: auto;
    inset-inline: 0;
    width: auto;
    max-height: 72vh;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25);
  }
}
@media (max-width: 480px) {
  .hdr {
    gap: 4px;
  }
  .hdr .pill {
    padding: 5px 9px;
    min-width: 36px;
  }
}
@media print {
  #botnav,
  #statusbar,
  #uiFab,
  .pf-p {
    display: none !important;
  }
}
