/* ==========================================================================
   هندسة صفحة المحرر — Zakhraf Studio Editor Shell Architecture
   تنظيم مكاني احترافي لواجهة الصفحة (الشريط العلوي، سكة الأدوات، اللوحة الجانبية،
   ومسرح التصميم) على غرار design.andalusi.app دون المساس بالمحرر نفسه أو ألوانه.
   ========================================================================== */

html, body {
  height: 100dvh;
  overflow: hidden;
  background-color: #eef1f5;
}

/* ---------- خلفية مسرح التصميم (شبكة نقطية هادئة) ---------- */
body main > section {
  background-color: #eef1f5;
  background-image: radial-gradient(rgba(148, 163, 184, 0.42) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* ---------- تعويم أزرار التكبير والشبكة فوق المسرح بأناقة ---------- */
body main > section > button[aria-label="شبكة إرشادية"] {
  top: 12px !important;
  left: 12px !important;
  width: 34px !important;
  height: 34px !important;
  border-radius: 999px !important;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08) !important;
}

body main > section > div[role="toolbar"][aria-label="أزرار تكبير اللوحة وتصغيرها"] {
  top: 12px !important;
  left: 54px !important;
  border-radius: 999px !important;
  padding: 3px 6px !important;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08) !important;
  background: rgba(255, 255, 255, 0.96) !important;
  backdrop-filter: blur(8px);
}

/* ---------- إخفاء شريط التمرير المزعج مع بقاء التمرير سلساً ---------- */
body main > nav {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
body main > nav::-webkit-scrollbar {
  display: none;
}
body main > aside::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
body main > aside::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.45);
  border-radius: 999px;
}

/* ==========================================================================
   هندسة سطح المكتب والشاشات العريضة (>= 1024px)
   1) شريط علوي عائم (Floating Top Bar)
   2) سكة أدوات يمنى عائمة (order: 1)
   3) لوحة خصائص/قوالب مجاورة مباشرة لسكة الأدوات وقابلة للطي (order: 2)
   4) مسرح تصميم رحب يمتد لملء الشاشة تلقائياً (order: 3)
   ========================================================================== */
@media (min-width: 1024px) {
  body div[dir="rtl"].flex-col > header {
    margin: 10px 12px 0;
    border-radius: 18px;
    border: 1px solid rgba(226, 232, 240, 0.95) !important;
    box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
    padding-inline: 16px;
    min-height: 56px;
    z-index: 30;
  }

  body main {
    padding: 10px 12px 12px;
    gap: 10px;
    background: transparent;
  }

  /* 1. سكة الأدوات الجانبية (يمين الصفحة) */
  body main > nav {
    order: 1;
    width: 78px;
    min-width: 78px;
    background: #ffffff !important;
    border: 1px solid rgba(226, 232, 240, 0.95) !important;
    border-radius: 20px;
    box-shadow: 0 8px 26px rgba(15, 23, 42, 0.06);
    padding: 8px 6px !important;
    z-index: 25;
  }

  /* 2. لوحة الأداة النشطة / القوالب — ملاصقة لسكة الأدوات مباشرة */
  body main > aside {
    order: 2;
    width: 356px !important;
    min-width: 356px;
    max-width: 356px;
    background: #ffffff !important;
    border: 1px solid rgba(226, 232, 240, 0.95) !important;
    border-radius: 20px;
    box-shadow: 0 8px 26px rgba(15, 23, 42, 0.06);
    transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                min-width 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                max-width 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.16s ease,
                margin 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
  }

  /* وضع طي اللوحة الجانبية لمنح مساحة كاملة لمسرح التصميم */
  body.zkh-aside-collapsed main > aside {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    border-width: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
    margin-inline-end: -10px !important;
  }

  /* 3. مسرح التصميم واللوحة */
  body main > section {
    order: 3;
    border-radius: 20px;
    border: 1px solid rgba(226, 232, 240, 0.75);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
  }
}

/* ==========================================================================
   هندسة الجوال والأجهزة اللوحية (< 1024px)
   1) شريط علوي مدمج
   2) مسرح التصميم أولاً في الأعلى بأكبر مساحة رؤية (order: 1)
   3) درج سفلي أنيق قابل للطي للأداة النشطة (order: 2)
   4) شريط أدوات سفلي بصفّ واحد منزلق أفقياً دون تكدّس (order: 3)
   ========================================================================== */
@media (max-width: 1023px) {
  body div[dir="rtl"].flex-col > header {
    min-height: 50px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
    z-index: 30;
  }

  body main > section {
    order: 1;
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }

  body main > aside {
    order: 2;
    max-height: 38dvh !important;
    border-top: 1px solid #e2e8f0 !important;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
    transition: max-height 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.16s ease;
    z-index: 22;
  }

  body.zkh-aside-collapsed main > aside {
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    border-top-width: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
  }

  body main > nav {
    order: 3;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    border-bottom: 0 !important;
    border-top: 1px solid #e2e8f0 !important;
    background: #ffffff !important;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)) !important;
    gap: 4px !important;
    z-index: 25;
  }

  body main > nav > button {
    flex: 0 0 auto !important;
  }

  /* رفع زر موشن الصلاة العائم على الجوال لئلا يحجب شريط الأدوات السفلي */
  #pm-prayer-link {
    bottom: 74px !important;
    left: 12px !important;
    width: 40px !important;
    height: 40px !important;
  }
}

/* ==========================================================================
   مقبض طي/فتح لوحة الأدوات الجانبية (خارج شجرة المحرر تماماً)
   ========================================================================== */
#zkh-panel-toggle {
  position: fixed;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #ffffff;
  color: #475569;
  border: 1px solid #cbd5e1;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.10);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  user-select: none;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
#zkh-panel-toggle:hover {
  background: #f8fafc;
  color: #c9a84c;
  border-color: #fde68a;
  box-shadow: 0 6px 18px rgba(201, 168, 76, 0.16);
}
#zkh-panel-toggle.is-desktop {
  width: 22px;
  height: 54px;
  border-radius: 999px;
  padding: 0;
  transform: translate(-50%, -50%);
}
#zkh-panel-toggle.is-mobile {
  height: 26px;
  padding: 0 12px;
  border-radius: 999px;
  transform: translate(-50%, 0);
}

/* تحسين التباين اللوني (WCAG 2.2 AA) لشريط التكبير العائم والاختصارات */
body main > section > div[role="toolbar"][aria-label="أزرار تكبير اللوحة وتصغيرها"] button,
body main > section > div[role="toolbar"][aria-label="أزرار تكبير اللوحة وتصغيرها"] span {
  color: #334155 !important;
  font-weight: 700;
}

button[aria-label="إعادة ضبط التكبير"] { background-color: #fffdf5 !important; color: #a87c20 !important; border: 1px solid #fde68a !important; }

/* zkh-rail-v30: Refined Studio Rail & Panel Polish */
main > nav > button {
  position: relative;
  border: 1px solid transparent;
  transition: transform 0.14s ease, background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease !important;
}
main > nav > button:hover:not(.from-teal-600):not(.bg-teal-600):not(.zkh-custom-rail-on) {
  background-color: #f1f5f9 !important;
  color: #a87c20 !important;
  transform: translateY(-1px);
}
main > nav > button.zkh-custom-rail-on {
  background-color: #c9a84c !important; background-image: none !important;
  color: #ffffff !important;
  box-shadow: 0 6px 16px rgba(201, 168, 76, 0.28) !important;
}
main > nav > button.zkh-custom-rail-on svg {
  stroke: #ffffff !important;
}
body:not(.zkh-smart-active) main > nav > button.zkh-custom-rail-active-peer ~ button.from-teal-600,
body.zkh-has-custom-tab main > nav > button.from-teal-600:not(.zkh-custom-rail-on), body.zkh-has-custom-tab main > nav > button.bg-teal-600:not(.zkh-custom-rail-on) {
  background-image: none !important;
  background-color: transparent !important;
  color: #64748b !important;
  box-shadow: none !important;
}
main > aside {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

/* High-contrast floating canvas HUD shortcut badges over dark & light backdrops */
button[aria-label="تراجع"] kbd,
button[aria-label="إعادة"] kbd {
  color: #18181b !important;
  font-weight: 700;
}


/* v45 Harmonized Andalusi Teal & Slate utility supplements */
.bg-teal-600 { background-color: #c9a84c; }
.bg-teal-700 { background-color: #a87c20; }
.bg-teal-100 { background-color: #fef3c7; }
.text-teal-900 { color: #78350f; }
.border-teal-400 { border-color: #d4b96a; }
.border-teal-500 { border-color: #d4af37; }
.bg-slate-50 { background-color: #f8fafc; }
.text-slate-800 { color: #1e293b; }
.border-slate-300 { border-color: #cbd5e1; }
.hover\:bg-teal-700:hover { background-color: #a87c20; }
.hover\:bg-teal-50:hover { background-color: #fffdf5; }
.hover\:text-teal-700:hover { color: #a87c20; }
.hover\:border-teal-300:hover { border-color: #e8d5a3; }
.hover\:border-teal-400:hover { border-color: #d4b96a; }
