/**
 * Raya ERP — Window Manager Styles (v2)
 * نظام نوافذ سطح المكتب الداخلي — RTL عربي
 */

/* ── Shell داخل منطقة المحتوى الرئيسية ── */
#main-content.raya-wm-host {
  position: relative;
}

#raya-wm-shell {
  position: absolute;
  inset: 0;
  z-index: 500;
  pointer-events: none;
  overflow: hidden;
}

#raya-wm-workspace {
  position: absolute;
  inset: 0;
  bottom: 42px;
  pointer-events: none;
  direction: rtl;
}

/* النقر يمر عبر المساحة الفارغة إلى الصفحة النشطة؛ النوافذ فقط تلتقط الأحداث */

/* ── النافذة ── */
.raya-win {
  position: absolute;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #dee2e6);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.1), 0 2px 8px rgba(15, 23, 42, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  direction: rtl;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  pointer-events: auto;
  contain: layout style;
  min-width: 0;
}

.raya-win.active {
  border-color: var(--odoo-purple, #714b67);
  box-shadow: 0 16px 40px rgba(113, 75, 103, 0.16), 0 4px 14px rgba(15, 23, 42, 0.08);
}

.raya-win.is-dragging {
  transition: none;
  opacity: 0.97;
  user-select: none;
}

.raya-win.maximized {
  border-radius: 0;
  border: none;
}

.raya-win.minimized {
  display: none !important;
}

/* ── شريط العنوان ── */
.raya-win-header {
  height: 44px;
  background: linear-gradient(180deg, #f8fafc, #f1f5f9);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  padding: 0 10px 0 12px;
  gap: 8px;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  touch-action: none;
}

.raya-win-header:active {
  cursor: grabbing;
}

.raya-win.active .raya-win-header {
  background: linear-gradient(180deg, #f3eef1, #ebe3e8);
}

.raya-win.maximized .raya-win-header {
  cursor: default;
}

.raya-win-icon {
  font-size: 16px;
  flex-shrink: 0;
  line-height: 1;
}

.raya-win-title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #212529);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  text-align: right;
}

/* أزرار التحكم — يسار الشريط (نمط سطح مكتب عربي) */
.raya-win-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  order: -1;
}

.raya-win-btn {
  width: 30px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #475569;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}

.raya-win-btn:hover {
  background: #e2e8f0;
}

.raya-win-btn:focus-visible {
  outline: 2px solid var(--odoo-purple, #714b67);
  outline-offset: 1px;
}

.raya-win-btn.close:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* ── محتوى النافذة ── */
.raya-win-body {
  flex: 1;
  overflow: auto;
  background: var(--surface, #fff);
  position: relative;
  contain: content;
  min-height: 0;
}

.raya-win-body > .page,
.raya-win-body > .page.raya-wm-embedded-page {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  padding: 14px 16px;
  min-height: 100%;
  height: auto !important;
  contain: none;
  animation: none !important;
  transform: none !important;
}

.raya-win-error {
  padding: 40px 24px;
  text-align: center;
  color: #94a3b8;
  line-height: 1.8;
}

.raya-win-error strong {
  display: block;
  color: #64748b;
  margin-bottom: 8px;
}

/* ── نماذج (modals) مضمّنة داخل النافذة ── */
.raya-win-body > .modal-overlay.raya-win-modal-embedded {
  position: static !important;
  display: flex !important;
  flex-direction: column !important;
  inset: auto !important;
  background: transparent !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  z-index: auto !important;
  padding: 0 !important;
  animation: none !important;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.raya-win-body > .modal-overlay.raya-win-modal-embedded .modal {
  margin: 0 auto;
  max-width: 100% !important;
  width: 100% !important;
  height: 100% !important;
  max-height: 100% !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-shadow: none;
  border: none;
  border-radius: 0;
}

.raya-win-body > .modal-overlay.raya-win-modal-embedded .modal-body {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: visible !important;
}

.raya-win-body > .modal-overlay.raya-win-modal-embedded .modal-footer {
  flex-shrink: 0 !important;
  position: sticky;
  bottom: 0;
  z-index: 30;
  background: var(--surface2, #f8fafc);
  box-shadow: 0 -6px 16px rgba(15, 23, 42, .08);
}

.raya-win-body > .modal-overlay.raya-win-modal-embedded .modal-header {
  display: none;
}

/* ── مقابض تغيير الحجم ── */
.raya-win-rs {
  position: absolute;
  z-index: 2;
}

.raya-win-rs.n { top: 0; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.raya-win-rs.s { bottom: 0; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.raya-win-rs.e { right: 0; top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
.raya-win-rs.w { left: 0; top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
.raya-win-rs.ne { top: 0; right: 0; width: 14px; height: 14px; cursor: nesw-resize; }
.raya-win-rs.nw { top: 0; left: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.raya-win-rs.se { bottom: 0; right: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.raya-win-rs.sw { bottom: 0; left: 0; width: 14px; height: 14px; cursor: nesw-resize; }

.raya-win.maximized .raya-win-rs {
  display: none;
}

/* ── شريط المهام ── */
#raya-wm-taskbar {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  height: 42px;
  background: var(--surface, #fff);
  border-top: 1px solid var(--border, #dee2e6);
  display: flex;
  align-items: center;
  padding: 4px 10px;
  gap: 6px;
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
  direction: rtl;
  overflow-x: auto;
  overflow-y: hidden;
  pointer-events: auto;
  flex-shrink: 0;
}

#raya-wm-taskbar.hidden {
  display: none;
}

#raya-wm-taskbar .tb-label {
  font-size: 11px;
  color: var(--text-s, #adb5bd);
  padding: 0 8px;
  flex-shrink: 0;
  white-space: nowrap;
}

#raya-wm-tb-items {
  display: flex;
  gap: 5px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

#raya-wm-tb-items:empty::after {
  content: 'لا توجد نوافذ مفتوحة';
  font-size: 11px;
  color: var(--text-s, #adb5bd);
  padding: 6px 10px;
}

.raya-tb-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--surface2, #fafafa);
  border: 1px solid var(--border, #dee2e6);
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-m, #6c757d);
  max-width: 220px;
  flex-shrink: 0;
  transition: all 0.12s ease;
}

.raya-tb-item:hover {
  background: #f1f5f9;
}

.raya-tb-item.active {
  background: var(--odoo-purple, #714b67);
  color: #fff;
  border-color: var(--odoo-purple, #714b67);
}

.raya-tb-item.minimized {
  opacity: 0.62;
}

.raya-tb-item .tb-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.raya-tb-item .tb-close {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0 3px;
  opacity: 0.55;
  font-size: 11px;
  line-height: 1;
}

.raya-tb-item .tb-close:hover {
  opacity: 1;
}

/* ── حوار التغييرات غير المحفوظة ── */
.raya-wm-confirm {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  direction: rtl;
}

.raya-wm-confirm-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.raya-wm-confirm-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text, #212529);
  margin-bottom: 8px;
}

.raya-wm-confirm-msg {
  font-size: 13px;
  color: var(--text-m, #6c757d);
  margin-bottom: 18px;
  line-height: 1.7;
}

.raya-wm-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.raya-wm-confirm-actions button {
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
}

.raya-wm-btn-cancel { background: #f1f5f9; color: #475569; }
.raya-wm-btn-discard { background: #fee2e2; color: #991b1b; }
.raya-wm-btn-save { background: var(--odoo-purple, #714b67); color: #fff; }

/* نماذج تقليدية على body تظهر فوق نوافذ WM عند العمل المتوازي */
body:has(#raya-wm-shell) > .modal-overlay.open {
  z-index: 5500;
}

/* ── استجابة الشاشات الصغيرة ── */
@media (max-width: 768px) {
  .raya-win:not(.maximized) {
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border-radius: 0;
  }

  .raya-win-btn {
    width: 36px;
    height: 32px;
  }

  .raya-tb-item {
    padding: 6px 10px;
  }

  .raya-tb-item .tb-title {
    max-width: 90px;
  }
}
