/**
 * Royal Atelier — backdrop-filter + تحسين GPU
 *
 * تقنيات التسريع:
 * - translate3d / translateZ → طبقة تركيب مستقلة
 * - contain: paint → تقليل منطقة إعادة الرسم
 * - isolation: isolate → سياق تكديس منفصل
 * - will-change فقط أثناء الفتح (عبر .ra-gpu-live)
 * - لا تحريك لـ backdrop-filter نفسه أبداً
 */

/* ===== متغيرات خفيفة ===== */
html[data-royal-shape="glass"] {
  --ra-bd-panel: blur(10px) saturate(145%);
  --ra-bd-modal: blur(14px) saturate(155%);
  --ra-bd-overlay: blur(6px) brightness(0.9);
  --ra-bd-bar: blur(10px) saturate(145%);
}
html[data-royal-shape="futuristic"] {
  --ra-bd-panel: blur(6px);
  --ra-bd-modal: blur(10px);
  --ra-bd-overlay: blur(5px) brightness(0.7);
  --ra-bd-bar: blur(8px);
}

/* ===== ترقية GPU مشتركة (أسطح كبيرة فقط) ===== */
.ra-gpu,
html[data-royal-shape="glass"] .panel,
html[data-royal-shape="glass"] .modal-box,
html[data-royal-shape="glass"] .custom-alert-box,
html[data-royal-shape="glass"] .print-options-box,
html[data-royal-shape="glass"] .security-modal-box,
html[data-royal-shape="glass"] #royal-top-menu,
html[data-royal-shape="glass"] .top-navbar,
html[data-royal-shape="glass"] nav.top-navbar,
html[data-royal-shape="glass"] #sidebar,
html[data-royal-shape="glass"] .sidebar,
html[data-royal-shape="futuristic"] .modal-box,
html[data-royal-shape="futuristic"] .custom-alert-box,
html[data-royal-shape="futuristic"] #royal-top-menu,
html[data-royal-shape="futuristic"] .top-navbar,
html[data-royal-shape="futuristic"] .panel {
  /* طبقة GPU مستقلة */
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  perspective: 1000px;
  /* عزل الرسم */
  isolation: isolate;
  contain: layout style paint;
  /* لا تحرّك backdrop-filter */
  transition: background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease !important;
}

/* will-change فقط عند الحاجة (يُضاف بالـ JS أو .active) */
.ra-gpu-live,
.modal-overlay.active .modal-box,
.modal-overlay.show .modal-box,
.custom-alert-overlay.active .custom-alert-box,
#royal-top-menu.rtm-open,
#royal-top-menu:not([hidden]) {
  will-change: transform, opacity;
}

/* بعد الإغلاق أزل will-change ضمنياً عبر عدم المُحدد */

/* ===== زجاجي ===== */
html[data-royal-shape="glass"] .panel,
html[data-royal-shape="glass"] .settings-card,
html[data-royal-shape="glass"] .alerts-panel {
  background: rgba(255, 255, 255, 0.52) !important;
  -webkit-backdrop-filter: var(--ra-bd-panel) !important;
  backdrop-filter: var(--ra-bd-panel) !important;
}

/* بطاقات صغيرة: بدون backdrop */
html[data-royal-shape="glass"] .card,
html[data-royal-shape="glass"] .r67-card,
html[data-royal-shape="glass"] .st-card,
html[data-royal-shape="glass"] .dashboard-cards .card {
  background: rgba(255, 255, 255, 0.64) !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  transform: none;
  contain: none;
  isolation: auto;
}

html[data-royal-shape="glass"] .modal-box,
html[data-royal-shape="glass"] .custom-alert-box,
html[data-royal-shape="glass"] .print-options-box,
html[data-royal-shape="glass"] .security-modal-box,
html[data-royal-shape="glass"] .profit-password-box,
html[data-royal-shape="glass"] #universal-modal .modal-box,
html[data-royal-shape="glass"] #quick-action-modal .modal-box,
html[data-royal-shape="glass"] #invoice-modal .modal-box,
html[data-royal-shape="glass"] #royal80-data-modal .royal80-box,
html[data-royal-shape="glass"] #login-screen .login-box {
  background: rgba(255, 255, 255, 0.58) !important;
  -webkit-backdrop-filter: var(--ra-bd-modal) !important;
  backdrop-filter: var(--ra-bd-modal) !important;
}

/* Overlay: طبقة GPU واحدة بكامل الشاشة */
html[data-royal-shape="glass"] .modal-overlay.active,
html[data-royal-shape="glass"] .modal-overlay.show,
html[data-royal-shape="glass"] .custom-alert-overlay.active,
html[data-royal-shape="glass"] #security-modal-overlay.active,
html[data-royal-shape="glass"] #print-options-overlay.active,
html[data-royal-shape="glass"] #profit-password-overlay.active,
html[data-royal-shape="glass"] #royal80-data-modal.active {
  background: rgba(40, 50, 90, 0.28) !important;
  -webkit-backdrop-filter: var(--ra-bd-overlay) !important;
  backdrop-filter: var(--ra-bd-overlay) !important;
  transform: translate3d(0, 0, 0);
  isolation: isolate;
  contain: strict;
  will-change: opacity;
}

html[data-royal-shape="glass"] .top-navbar,
html[data-royal-shape="glass"] nav.top-navbar,
html[data-royal-shape="glass"] #sidebar,
html[data-royal-shape="glass"] .sidebar,
html[data-royal-shape="glass"] #app-sidebar {
  background: rgba(255, 255, 255, 0.48) !important;
  -webkit-backdrop-filter: var(--ra-bd-bar) !important;
  backdrop-filter: var(--ra-bd-bar) !important;
}

html[data-royal-shape="glass"] #royal-top-menu {
  background: rgba(255, 255, 255, 0.52) !important;
  -webkit-backdrop-filter: var(--ra-bd-modal) !important;
  backdrop-filter: var(--ra-bd-modal) !important;
}
html[data-royal-shape="glass"] #royal-top-menu .rtm-group {
  background: rgba(255, 255, 255, 0.5) !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  transform: none;
  contain: none;
}

html[data-royal-shape="glass"] .dropdown-content,
html[data-royal-shape="glass"] .dropdown-menu,
html[data-royal-shape="glass"] .actions-menu,
html[data-royal-shape="glass"] #royal-actions-portal > * {
  background: rgba(255, 255, 255, 0.68) !important;
  -webkit-backdrop-filter: blur(8px) saturate(145%) !important;
  backdrop-filter: blur(8px) saturate(145%) !important;
  transform: translate3d(0, 0, 0);
  isolation: isolate;
}

/* عناصر صغيرة: ممنوع GPU backdrop */
html[data-royal-shape="glass"] .btn-neon,
html[data-royal-shape="glass"] .quick-actions button,
html[data-royal-shape="glass"] button.btn,
html[data-royal-shape="glass"] .btn-outline,
html[data-royal-shape="glass"] .rnav-item,
html[data-royal-shape="glass"] input,
html[data-royal-shape="glass"] select,
html[data-royal-shape="glass"] textarea,
html[data-royal-shape="glass"] #current-user-display,
html[data-royal-shape="glass"] .royal-user-chip {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  will-change: auto !important;
  contain: none !important;
  isolation: auto !important;
}
html[data-royal-shape="glass"] .btn-neon,
html[data-royal-shape="glass"] .quick-actions button,
html[data-royal-shape="glass"] button.btn {
  background: rgba(255, 255, 255, 0.55) !important;
}

html[data-royal-shape="glass"] body.dark .panel,
html[data-royal-shape="glass"] body[data-theme="dark"] .panel,
html[data-royal-shape="glass"] body.dark .modal-box,
html[data-royal-shape="glass"] body[data-theme="dark"] .modal-box {
  background: rgba(20, 24, 45, 0.62) !important;
  -webkit-backdrop-filter: var(--ra-bd-panel) !important;
  backdrop-filter: var(--ra-bd-panel) !important;
}

/* ===== مستقبلي ===== */
html[data-royal-shape="futuristic"] .panel,
html[data-royal-shape="futuristic"] .settings-card {
  background: rgba(8, 20, 40, 0.8) !important;
  -webkit-backdrop-filter: var(--ra-bd-panel) !important;
  backdrop-filter: var(--ra-bd-panel) !important;
}
html[data-royal-shape="futuristic"] .card,
html[data-royal-shape="futuristic"] .r67-card,
html[data-royal-shape="futuristic"] .st-card {
  background: rgba(8, 20, 40, 0.88) !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  transform: none;
  contain: none;
}
html[data-royal-shape="futuristic"] .modal-box,
html[data-royal-shape="futuristic"] .custom-alert-box,
html[data-royal-shape="futuristic"] .print-options-box,
html[data-royal-shape="futuristic"] .security-modal-box,
html[data-royal-shape="futuristic"] #quick-action-modal .modal-box,
html[data-royal-shape="futuristic"] #invoice-modal .modal-box {
  background: rgba(6, 16, 32, 0.9) !important;
  -webkit-backdrop-filter: var(--ra-bd-modal) !important;
  backdrop-filter: var(--ra-bd-modal) !important;
}
html[data-royal-shape="futuristic"] .modal-overlay.active,
html[data-royal-shape="futuristic"] .custom-alert-overlay.active,
html[data-royal-shape="futuristic"] #security-modal-overlay.active {
  background: rgba(0, 10, 30, 0.48) !important;
  -webkit-backdrop-filter: var(--ra-bd-overlay) !important;
  backdrop-filter: var(--ra-bd-overlay) !important;
  transform: translate3d(0, 0, 0);
  isolation: isolate;
  contain: strict;
}
html[data-royal-shape="futuristic"] #royal-top-menu,
html[data-royal-shape="futuristic"] .top-navbar,
html[data-royal-shape="futuristic"] nav.top-navbar {
  background: rgba(6, 14, 28, 0.85) !important;
  -webkit-backdrop-filter: var(--ra-bd-bar) !important;
  backdrop-filter: var(--ra-bd-bar) !important;
}
html[data-royal-shape="futuristic"] #royal-top-menu .rtm-group,
html[data-royal-shape="futuristic"] .btn-neon,
html[data-royal-shape="futuristic"] .quick-actions button,
html[data-royal-shape="futuristic"] .dropdown-content {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

html[data-royal-shape="classic"] .modal-overlay.active {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* ===== إيقاف على الأجهزة الضعيفة ===== */
@media (prefers-reduced-motion: reduce) {
  html[data-royal-shape="glass"] [class],
  html[data-royal-shape="futuristic"] [class] {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    will-change: auto !important;
  }
}

@media (max-width: 768px) {
  html[data-royal-shape="glass"] .panel,
  html[data-royal-shape="glass"] #sidebar {
    -webkit-backdrop-filter: blur(6px) !important;
    backdrop-filter: blur(6px) !important;
  }
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  html[data-royal-shape="glass"] .panel,
  html[data-royal-shape="glass"] .modal-box,
  html[data-royal-shape="glass"] #royal-top-menu {
    background: rgba(255, 255, 255, 0.94) !important;
  }
  html[data-royal-shape="futuristic"] .panel,
  html[data-royal-shape="futuristic"] .modal-box {
    background: rgba(8, 20, 40, 0.96) !important;
  }
}
