/* الطبقات المنبثقة: قوائم، منتقيات، نوافذ، لوحات جانبية، إشعارات، لوحة الأوامر */

/* ── قائمة/منتقي منبثق (Popover) ── */
.popover {
  position: fixed; z-index: var(--z-modal);
  min-width: 220px; max-width: min(420px, calc(100vw - 24px));
  background: var(--bg-overlay); border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
  padding: 6px; animation: pop-in var(--duration-fast) var(--ease-spring);
  display: flex; flex-direction: column; max-height: min(460px, 70vh);
}
.popover .pop-search { padding: 4px 4px 8px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 4px; }
.popover .pop-search .input { min-height: 36px; border-radius: var(--radius-md); }
.popover .pop-list { overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.popover .pop-group { padding: 8px 10px 4px; font-size: var(--text-2xs); font-weight: 700; color: var(--text-tertiary); }
.popover .pop-foot { border-top: 1px solid var(--border-subtle); margin-top: 4px; padding: 6px 4px 2px; display: flex; gap: 6px; flex-wrap: wrap; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 38px; padding: 6px 10px; border-radius: var(--radius-md);
  border: 0; background: transparent; color: var(--text-primary);
  font-size: var(--text-sm); text-align: start; cursor: pointer;
}
.menu-item .ic { color: var(--text-tertiary); }
.menu-item:hover, .menu-item.active { background: var(--bg-muted); }
.menu-item:hover .ic { color: var(--text-primary); }
.menu-item[aria-selected="true"] { background: var(--accent-subtle); color: var(--accent-text); }
.menu-item[aria-selected="true"] .ic { color: var(--accent-text); }
.menu-item.danger { color: var(--err-text); }
.menu-item.danger .ic { color: var(--err-text); }
.menu-item.danger:hover { background: var(--err-subtle); }
.menu-item .desc { display: block; font-size: var(--text-xs); color: var(--text-tertiary); }
.menu-item .end { margin-inline-start: auto; }
.menu-sep { height: 1px; background: var(--border-subtle); margin: 4px 6px; }
.menu-empty { padding: 18px; text-align: center; color: var(--text-tertiary); font-size: var(--text-sm); }

/* زر المنتقي (يبدو كحقل) */
.picker-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 44px; padding: 6px 12px;
  background: var(--bg-input); color: var(--text-primary);
  border: 1px solid var(--border-default); border-radius: var(--radius-lg);
  cursor: pointer; text-align: start; font-size: var(--text-sm);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.picker-btn:hover { border-color: var(--border-strong); }
.picker-btn[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.picker-btn .placeholder { color: var(--text-tertiary); }
.picker-btn > .chev { margin-inline-start: auto; color: var(--text-tertiary); transition: transform var(--duration-fast); }
.picker-btn[aria-expanded="true"] > .chev { transform: rotate(180deg); }
.picker-btn.compact { min-height: 38px; width: auto; border-radius: var(--radius-full); padding: 4px 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 4px 0 10px;
  border-radius: var(--radius-full); background: var(--bg-muted); font-size: var(--text-xs); font-weight: 600;
}
.chip button { border: 0; background: transparent; color: var(--text-tertiary); cursor: pointer; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; }
.chip button:hover { background: var(--bg-subtle); color: var(--err-text); }

/* ── النوافذ والستارة ── */
.scrim {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: var(--scrim); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 16px;
  animation: fade-up var(--duration-fast) ease both;
}
.dialog {
  width: min(560px, 100%); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--bg-surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-2xl); box-shadow: var(--shadow-xl);
  animation: pop-in var(--duration-normal) var(--ease-spring);
}
.dialog.wide { width: min(880px, 100%); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border-subtle); }
.dialog-head h2 { font-size: var(--text-md); flex: 1; }
.dialog-icon { width: 40px; height: 40px; border-radius: var(--radius-lg); display: grid; place-items: center; background: var(--accent-subtle); color: var(--accent-text); flex-shrink: 0; }
.dialog-icon.danger { background: var(--err-subtle); color: var(--err-text); }
.dialog-body { padding: 20px; overflow-y: auto; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border-subtle); background: var(--bg-subtle); border-radius: 0 0 var(--radius-2xl) var(--radius-2xl); }

/* ── اللوحة الجانبية (Drawer) ── */
.scrim.drawer-scrim { place-items: stretch; justify-items: end; padding: 0; }
.drawer {
  width: min(560px, 100vw); height: 100vh; display: flex; flex-direction: column;
  background: var(--bg-surface); border-inline-start: 1px solid var(--border-strong);
  box-shadow: var(--shadow-xl); animation: drawer-in var(--duration-normal) var(--ease-spring);
}
.drawer.wide { width: min(880px, 100vw); }
@keyframes drawer-in { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer .dialog-foot { border-radius: 0; }

/* ── الإشعارات ── */
.toasts { position: fixed; bottom: 20px; inset-inline-start: 20px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 40px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  background: var(--bg-overlay); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); font-size: var(--text-sm); animation: pop-in var(--duration-normal) var(--ease-spring);
}
.toast .ic { margin-top: 2px; color: var(--accent-text); }
.toast.ok .ic { color: var(--ok-text); }
.toast.err .ic { color: var(--err-text); }
.toast.warn .ic { color: var(--warn-text); }
.toast .grow { line-height: 1.5; }
.toast button { border: 0; background: none; color: var(--text-tertiary); cursor: pointer; padding: 0; }
.toast .toast-action { color: var(--accent-text); font-weight: 700; margin-top: 4px; display: inline-block; }

/* ── لوحة الأوامر ── */
.palette-scrim { place-items: start center; padding-top: 12vh; z-index: var(--z-palette); }
.palette { width: min(620px, 100%); padding: 0; }
.palette .pop-search { padding: 12px; }
.palette .pop-search .input { min-height: 46px; font-size: var(--text-base); }
.palette .pop-list { max-height: 50vh; padding: 6px; }
.palette .pop-foot { justify-content: space-between; color: var(--text-tertiary); font-size: var(--text-xs); padding: 8px 12px; }

/* تلميح */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--bg-canvas); padding: 4px 8px; border-radius: 6px;
  font-size: var(--text-2xs); font-weight: 600; white-space: nowrap; pointer-events: none; z-index: 50;
}

@media (max-width: 720px) {
  .scrim:not(.drawer-scrim):not(.palette-scrim) { place-items: end stretch; padding: 0; }
  .scrim:not(.drawer-scrim):not(.palette-scrim) .dialog { width: 100%; border-radius: var(--radius-2xl) var(--radius-2xl) 0 0; max-height: 92vh; }
  .popover.sheet { inset: auto 0 0 0 !important; max-width: none; border-radius: var(--radius-2xl) var(--radius-2xl) 0 0; max-height: 75vh; }
  .toasts { inset-inline: 12px; bottom: 84px; width: auto; }
}
