/**
 * AKM Manager — تطبيق الجوال (PWA): شريط التثبيت، تنبيه الاتصال، وتحسينات اللمس والشاشات الصغيرة.
 * يُحمَّل بعد akm-theme.css وعلى صفحات AKM فقط؛ كل القواعد مقيَّدة بـ body.osh-page أو بعناصر الوحدة نفسها.
 */

/* ---------- شريط التثبيت (ثابت أسفل الشاشة، يحترم الحافة الآمنة في آيفون) ---------- */
.akm-pwa-banner {
  position: fixed; z-index: var(--akm-z-modal, 100000);
  inset-inline: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 12px;
  max-width: 520px; margin-inline: auto;
  padding: 12px 14px; box-sizing: border-box;
  background: var(--osh-surface, #fff); color: var(--osh-text, #101c26);
  border: 1px solid var(--osh-border, #e3e6ea); border-radius: 16px;
  box-shadow: 0 10px 30px rgba(16, 28, 38, .18);
  font-family: var(--osh-font, system-ui, sans-serif);
}
.akm-pwa-ic {
  flex: none; width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--osh-primary, #0e7a68); color: #fff; font: 700 13px/1 system-ui, sans-serif; letter-spacing: .3px;
}
.akm-pwa-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.akm-pwa-tx strong { font-size: 14px; line-height: 1.4; }
.akm-pwa-tx span { font-size: 12.5px; line-height: 1.5; color: var(--osh-muted, #5b6773); }
.akm-pwa-act { flex: none; display: flex; flex-direction: column; gap: 6px; }
.akm-pwa-act .button { margin: 0; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
@media (min-width: 783px) { .akm-pwa-banner { inset-inline-end: 20px; inset-inline-start: auto; margin-inline: 0; } }

/* ---------- تنبيه انقطاع الاتصال ---------- */
.akm-pwa-toast {
  position: fixed; z-index: var(--akm-z-toast, 100010); inset-inline: 0; margin-inline: auto; width: max-content; max-width: calc(100% - 24px);
  top: calc(10px + env(safe-area-inset-top, 0px));
  padding: 10px 16px; border-radius: 999px; box-sizing: border-box;
  background: #7a2e12; color: #fff; font: 600 13.5px/1.4 var(--osh-font, system-ui, sans-serif);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}

/* ---------- تحسينات الجوال (على صفحات AKM) ---------- */
@media (max-width: 782px) {
  /* يمنع تكبير آيفون التلقائي عند التركيز على حقل (يحدث إذا كان الخط أقل من 16px) */
  body.osh-page :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea) { font-size: 16px; }
  /* أهداف لمس مريحة (44px) للأزرار والحقول */
  body.osh-page #wpbody-content :is(.button, button.button-link-delete, select, input[type="text"], input[type="search"], input[type="number"], input[type="tel"], input[type="email"], input[type="date"], input[type="password"]) { min-height: 44px; }
  /* لا تمدد أفقيًا للصفحة بسبب عنصر عريض */
  body.osh-page { overflow-x: hidden; -webkit-text-size-adjust: 100%; }
  body.osh-page #wpbody-content { max-width: 100vw; }
  body.osh-page #wpbody-content img, body.osh-page #wpbody-content video { max-width: 100%; height: auto; }
  body.osh-page #wpbody-content pre { overflow-x: auto; max-width: 100%; }
  /* نص طويل (روابط، أرقام تتبع) لا يكسر البطاقة */
  /* 2.22.0: break-word بدل anywhere — anywhere يجعل الحد الأدنى لعرض كل خلية حرفاً واحداً فتنهار أعمدة الجداول إلى حرف تحت حرف */
  body.osh-page #wpbody-content .wrap { overflow-wrap: break-word; }
  /* لا يبقى مؤشر تمرير أفقي وراء شريط الجوال */
  body.osh-page .osh-bar { max-width: 100%; box-sizing: border-box; }
}

/* ---------- وضع التطبيق المثبّت (بدون شريط المتصفح) ---------- */
html.akm-standalone body { -webkit-tap-highlight-color: transparent; }
html.akm-standalone body.osh-page { padding-bottom: env(safe-area-inset-bottom, 0px); }
html.akm-standalone body.osh-page #wpbody-content { padding-bottom: 24px; }
html.akm-standalone .akm-pwa-banner { display: none; }
@media (display-mode: standalone) { .akm-pwa-banner { display: none; } }
@media print { .akm-pwa-banner, .akm-pwa-toast { display: none !important; } }

/* ---------- 2.20.2 — واجهة التطبيق: AKM Manager + AKM Finance فقط (تُخفى واجهة ووردبريس في التطبيق المثبّت) ---------- */
.akm-appnav { display: none; }
html.akm-standalone { --akm-nav-h: calc(60px + env(safe-area-inset-bottom, 0px)); }

html.akm-standalone body.osh-page #wpadminbar,
html.akm-standalone body.osh-page #adminmenumain,
html.akm-standalone body.osh-page #adminmenuback,
html.akm-standalone body.osh-page #adminmenuwrap,
html.akm-standalone body.osh-page #wpfooter { display: none !important; }
html.akm-standalone.wp-toolbar { padding-top: 0 !important; }
html.akm-standalone body.osh-page #wpcontent { margin-inline: 0 !important; padding-inline: 0 !important; }
html.akm-standalone body.osh-page #wpbody { padding-top: env(safe-area-inset-top, 0px) !important; }

/* مساحة للشريط السفلي، وإزاحة العناصر اللاصقة التي كانت تحسب ارتفاع شريط ووردبريس العلوي */
html.akm-standalone body.osh-page { padding-bottom: env(safe-area-inset-bottom, 0px); }
html.akm-standalone body.osh-page.akm-hasnav { padding-bottom: var(--akm-nav-h) !important; }
html.akm-standalone body.osh-page #wpbody-content { padding-bottom: 24px; }
html.akm-standalone body.osh-page .osh-savetop { top: env(safe-area-inset-top, 0px); }
html.akm-standalone body.osh-page .akm-jump { top: env(safe-area-inset-top, 0px); }
html.akm-standalone body.osh-page.akm-hasnav :is(.wrap form > p.submit, .bordoro form > p.submit, .vwfm.vwfm-planner form > p:last-child) { bottom: var(--akm-nav-h); }

html.akm-standalone .akm-appnav {
  display: flex; position: fixed; z-index: var(--akm-z-nav, 99990); inset-inline: 0; bottom: 0;
  height: var(--akm-nav-h); padding-bottom: env(safe-area-inset-bottom, 0px); box-sizing: border-box;
  background: var(--osh-surface, #fff); border-top: 1px solid var(--osh-border, #e3e6ea);
  box-shadow: 0 -4px 16px rgba(16, 28, 38, .08); font-family: var(--osh-font, system-ui, sans-serif);
}
html.akm-standalone .akm-appnav-i {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--osh-muted, #5b6773); text-decoration: none; font-size: 11.5px; line-height: 1.2; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
html.akm-standalone .akm-appnav-i .dashicons { width: 24px; height: 24px; font-size: 24px; }
html.akm-standalone .akm-appnav-i:hover, html.akm-standalone .akm-appnav-i:focus { color: var(--osh-primary, #0e7a68); box-shadow: none; outline: none; }
html.akm-standalone .akm-appnav-i.is-active { color: var(--osh-primary, #0e7a68); }
html.akm-standalone .akm-appnav-i.is-active .dashicons { background: color-mix(in srgb, var(--osh-primary, #0e7a68) 14%, transparent); border-radius: 999px; width: 44px; height: 26px; font-size: 22px; line-height: 26px; }
html.akm-standalone .akm-pwa-toast { top: calc(10px + env(safe-area-inset-top, 0px)); }

/* ---------- 2.23.4 — زر التحديث والمزامنة العائم (الهاتف + التطبيق المثبّت) ---------- */
.akm-sync { display: none; }
@media (max-width: 782px), (display-mode: standalone) {
  .akm-sync {
    display: flex; align-items: center; justify-content: center;
    position: fixed; z-index: calc(var(--akm-z-nav, 99990) + 5); inset-inline-start: 14px; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 48px; height: 48px; padding: 0; border: 0; border-radius: 50%; box-sizing: border-box; cursor: pointer;
    background: var(--osh-primary, #0e7a68); color: #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
    -webkit-tap-highlight-color: transparent;
  }
  .akm-sync .dashicons { width: 26px; height: 26px; font-size: 26px; line-height: 26px; }
  .akm-sync:active { transform: scale(.94); }
  .akm-sync.is-busy .dashicons { animation: akm-sync-spin .8s linear infinite; }
  html.akm-standalone body.akm-hasnav .akm-sync { bottom: calc(var(--akm-nav-h) + 14px); }
}
@keyframes akm-sync-spin { to { transform: rotate(360deg); } }

/* ---------- 2.23.6 — أزرار Manager / المالية / ووردبريس أسفل القائمة الجانبية (دائمة الظهور) ---------- */
.akm-appsw { flex: none; margin-top: auto; display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--osh-border, #e3e6ea); background: var(--osh-surface, #fff); font-family: var(--osh-font, system-ui, sans-serif); }
.akm-appsw-i { flex: 1 1 0; min-width: 0; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 2px; border-radius: 10px; color: var(--osh-muted, #5b6773); text-decoration: none; font-size: 11.5px; line-height: 1.2; font-weight: 600; text-align: center; box-shadow: none; }
.akm-appsw-i .dashicons { width: 22px; height: 22px; font-size: 22px; }
.akm-appsw-i:hover, .akm-appsw-i:focus { color: var(--osh-primary, #0e7a68); background: var(--osh-surface-2, #f3f4f6); outline: none; box-shadow: none; }
.akm-appsw-i.is-active { color: var(--osh-primary, #0e7a68); background: var(--osh-primary-soft, rgba(14, 122, 104, .12)); }
body.akm-sb-collapsed .akm-appsw { flex-direction: column; }
body.akm-sb-collapsed .akm-appsw-i span:not(.dashicons) { display: none; }
@media (max-width: 960px) { body.akm-sb-collapsed .akm-appsw { flex-direction: row; } body.akm-sb-collapsed .akm-appsw-i span:not(.dashicons) { display: revert; } }
@media print { .akm-appsw { display: none !important; } }
@media print { .akm-appnav, .akm-backpill, .akm-sync { display: none !important; } }

/* ---------- 2.23.11 — شكل موحّد للأزرار الثلاثة (AKM Manager / AKM Finance / ووردبريس) في كل صفحات الهاتف ----------
   الأصل: الشريط أسفل القائمة الجانبية (أيقونة فوق النص، الزر النشط بخلفية خضراء فاتحة). نفس الشكل الآن في:
   (1) القائمة الجانبية لـ Manager والمالية، (2) الشريط السفلي في التطبيق المثبّت، (3) شريط ثابت أسفل بقية صفحات ووردبريس على الهاتف.
   الأصناف مُقوّاة بـ body حتى لا تغيّرها أنماط ووردبريس/المالية. */
body .akm-appsw, body .akm-appnav, body .akm-appsw--dock { font-family: var(--osh-font, system-ui, sans-serif); }
body .akm-appsw .akm-appsw-i, body .akm-appnav .akm-appnav-i, body .akm-appsw--dock .akm-appsw-i {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  flex: 1 1 0; min-width: 0; min-height: 52px; padding: 4px 2px; margin: 0; border: 0; border-radius: 10px;
  background: transparent; color: var(--osh-muted, #5b6773); text-decoration: none; text-align: center;
  font-size: 11.5px; line-height: 1.2; font-weight: 600; box-shadow: none; -webkit-tap-highlight-color: transparent;
}
body .akm-appsw .akm-appsw-i .dashicons, body .akm-appnav .akm-appnav-i .dashicons {
  width: 22px; height: 22px; font-size: 22px; line-height: 22px; background: none; border-radius: 0; color: inherit;
}
body .akm-appsw .akm-appsw-i:hover, body .akm-appsw .akm-appsw-i:focus,
body .akm-appnav .akm-appnav-i:hover, body .akm-appnav .akm-appnav-i:focus { color: var(--osh-primary, #0e7a68); background: var(--osh-surface-2, #f3f4f6); outline: none; box-shadow: none; }
body .akm-appsw .akm-appsw-i.is-active, body .akm-appnav .akm-appnav-i.is-active { color: var(--osh-primary, #0e7a68); background: var(--osh-primary-soft, rgba(14, 122, 104, .12)); }

/* الشريط السفلي للتطبيق المثبّت: نفس الشكل (يُلغي حبة الأيقونة القديمة) */
html.akm-standalone body .akm-appnav { gap: 6px; padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px)); align-items: stretch; }
html.akm-standalone body .akm-appnav .akm-appnav-i.is-active .dashicons { background: none; width: 22px; height: 22px; font-size: 22px; line-height: 22px; }

/* بقية صفحات ووردبريس على الهاتف: شريط ثابت بالأزرار الثلاثة */
.akm-appsw--dock { display: none; }
@media (max-width: 782px) {
  body.akm-hasdock .akm-appsw--dock {
    display: flex; position: fixed; z-index: var(--akm-z-nav, 99990); inset-inline: 0; bottom: 0; margin: 0; gap: 6px;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px)); box-sizing: border-box;
    background: var(--osh-surface, #fff); border-top: 1px solid var(--osh-border, #e3e6ea); box-shadow: 0 -4px 16px rgba(16, 28, 38, .08);
  }
  body.akm-hasdock { padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
  html.akm-standalone body.akm-hasdock .akm-backpill { display: none; } /* الشريط يغني عن زر «AKM» العائم */
}
html.akm-embed .akm-appsw--dock { display: none !important; }

/* لا يغطي زر التحديث العائم أزرار القائمة الجانبية (كان يحجب «AKM Manager» في الدرج) */
body.akm-drawer-open .akm-sync { display: none !important; }
@media (max-width: 782px) { body.akm-hasdock .akm-sync { bottom: calc(82px + env(safe-area-inset-bottom, 0px)); } }
@media print { .akm-appsw--dock { display: none !important; } }
