/* ─────────────────────────────────────────────────────────────
   Starboard · Overlays v2 CSS
   Dialog, AlertDialog, Sheet, Drawer, Menu core (Dropdown /
   Context / Menubar), Tooltip v2, Popover v2, HoverCard v2.

   Scrim color is derived from --admiral-navy-black, never pure
   black. Enters use --motion-overlay-enter / --motion-panel-slide;
   exits replay the same keyframe in reverse over the FASTER
   --motion-overlay-exit. No new keyframes are defined here.
   ───────────────────────────────────────────────────────────── */
@import url('../../colors_and_type.css');

/* ═══ Dialog ═══ */
.ad-dlg-scrim {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  padding: var(--space-md);
  background: color-mix(in srgb, var(--admiral-navy-black) 40%, transparent);
  animation: ad-fade-in var(--motion-overlay-enter) both;
}
.ad-dlg-scrim.is-closing { animation: ad-fade-in var(--motion-overlay-exit) reverse both; }

.ad-dlg {
  width: 100%; max-width: 560px;
  max-height: calc(100vh - var(--space-2xl));
  display: flex; flex-direction: column; gap: var(--space-sm);
  padding: var(--space-lg);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  animation: ad-scale-in var(--motion-overlay-enter) both;
}
.ad-dlg.is-closing { animation: ad-scale-in var(--motion-overlay-exit) reverse both; }
.ad-dlg--sm { max-width: 430px; }
.ad-dlg--md { max-width: 560px; }
.ad-dlg--lg { max-width: 720px; }

.ad-dlg__head { display: flex; align-items: flex-start; gap: var(--space-xs); }
.ad-dlg__badge {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: var(--radius-pill);
  display: grid; place-items: center;
  background: var(--primary-50); color: var(--primary-600);
}
.ad-dlg__badge--danger { background: var(--error-100); color: var(--error-500); }
.ad-dlg__heading { flex: 1; min-width: 0; }
.ad-dlg__title {
  margin: 0;
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 700; font-size: var(--text-lg-size); line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--fg-strong);
}
.ad-dlg__desc { margin: 2px 0 0; font-size: 13px; line-height: 1.55; color: var(--fg-muted); }
.ad-dlg__close {
  flex: 0 0 auto;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--fg-muted); cursor: pointer;
  transition: background var(--duration-4) var(--ease-out), color var(--duration-4) var(--ease-out);
}
.ad-dlg__close:hover { background: var(--neutral-100); color: var(--fg-strong); }
.ad-dlg__close:focus-visible { outline: none; box-shadow: var(--shadow-focus-ring); }

.ad-dlg__body {
  font-size: var(--text-sm-size); line-height: 1.6; color: var(--fg-default);
  min-height: 0;
}
.ad-dlg__foot {
  display: flex; justify-content: flex-end; gap: var(--space-2xs);
  margin-top: var(--space-2xs);
}

/* AlertDialog destructive confirm — 80ms press tint + 0.97 scale */
.ad-dlg__foot .ad-btn--danger {
  transition: transform var(--duration-2) var(--ease-out), background var(--duration-2) var(--ease-out);
}
.ad-dlg__foot .ad-btn--danger:active { transform: scale(0.97); background: var(--error-700); }
.ad-dlg .ad-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus-ring); }

/* ═══ Sheet ═══ */
.ad-sheet-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: color-mix(in srgb, var(--admiral-navy-black) 40%, transparent);
  animation: ad-fade-in var(--motion-overlay-enter) both;
}
.ad-sheet-scrim.is-closing { animation: ad-fade-in var(--motion-overlay-exit) reverse both; }

.ad-sheet {
  position: fixed; z-index: 91;
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-xl);
}
.ad-sheet--right  { top: 0; right: 0;  bottom: 0; width: 400px; max-width: 90vw; animation: ad-slide-in-right var(--motion-panel-slide) both; }
.ad-sheet--left   { top: 0; left: 0;   bottom: 0; width: 400px; max-width: 90vw; animation: ad-slide-in-left  var(--motion-panel-slide) both; }
.ad-sheet--bottom {
  left: 0; right: 0; bottom: 0;
  max-height: 90vh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  animation: ad-slide-in-up var(--motion-panel-slide) both;
}
.ad-sheet--right.is-closing  { animation: ad-slide-in-right var(--motion-overlay-exit) reverse both; }
.ad-sheet--left.is-closing   { animation: ad-slide-in-left  var(--motion-overlay-exit) reverse both; }
.ad-sheet--bottom.is-closing { animation: ad-slide-in-up    var(--motion-overlay-exit) reverse both; }

.ad-sheet__head {
  display: flex; align-items: center; gap: var(--space-2xs);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--neutral-100);
}
.ad-sheet__title {
  flex: 1; min-width: 0; margin: 0;
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 700; font-size: var(--text-md-size);
  letter-spacing: -0.01em; color: var(--fg-strong);
}
.ad-sheet__close {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--fg-muted); cursor: pointer;
  transition: background var(--duration-4) var(--ease-out), color var(--duration-4) var(--ease-out);
}
.ad-sheet__close:hover { background: var(--neutral-100); color: var(--fg-strong); }
.ad-sheet__close:focus-visible { outline: none; box-shadow: var(--shadow-focus-ring); }
.ad-sheet__body {
  flex: 1; min-height: 0;
  padding: var(--space-md);
  overflow: auto;
  font-size: var(--text-sm-size); line-height: 1.6; color: var(--fg-default);
}
.ad-sheet__foot {
  display: flex; justify-content: flex-end; gap: var(--space-2xs);
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--neutral-100);
}

/* ═══ Drawer — Sheet side="left" with app-nav styling ═══ */
.ad-drawer.ad-sheet--left { width: 280px; }
.ad-drawer .ad-sheet__body { padding: var(--space-2xs); }
.ad-drawer__group + .ad-drawer__group { margin-top: var(--space-2xs); padding-top: var(--space-2xs); border-top: 1px solid var(--neutral-100); }
.ad-drawer__group-label {
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 600; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--neutral-500);
  padding: var(--space-2xs) var(--space-xs) var(--space-3xs);
}
.ad-drawer__row {
  display: flex; align-items: center; gap: var(--space-2xs);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  color: var(--fg-default);
  cursor: pointer;
  transition: background var(--duration-4) var(--ease-out), color var(--duration-4) var(--ease-out);
}
.ad-drawer__row:hover { background: var(--neutral-100); color: var(--fg-strong); }
.ad-drawer__row.is-active { background: var(--primary-50); color: var(--primary-700); }
.ad-drawer__row:focus-visible { outline: none; box-shadow: var(--shadow-focus-ring); }
.ad-drawer__icon { flex: 0 0 auto; width: 16px; height: 16px; color: var(--neutral-500); }
.ad-drawer__row.is-active .ad-drawer__icon { color: var(--primary-600); }
.ad-drawer__label { flex: 1; min-width: 0; }
.ad-drawer__count {
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  color: var(--fg-muted); background: var(--neutral-100);
  padding: 1px 6px; border-radius: var(--radius-pill);
}
.ad-drawer__row.is-active .ad-drawer__count { background: var(--primary-100); color: var(--primary-700); }

/* ═══ Menu core (Dropdown / Context / Menubar / submenu) ═══ */
.ad-menu2 {
  min-width: 220px;
  padding: var(--space-3xs);
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  outline: none;
  animation: ad-scale-in var(--duration-4) var(--ease-out) both;
  transform-origin: top left;
}
[data-placement^="top"] > .ad-menu2,
[data-placement^="top"].ad-menu2 { transform-origin: bottom left; }
[data-placement$="end"] > .ad-menu2 { transform-origin: top right; }

.ad-menu2__item {
  position: relative;
  display: flex; align-items: center; gap: var(--space-2xs);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px; line-height: 1.4;
  color: var(--fg-default);
  cursor: pointer;
  transition: background var(--duration-3) var(--ease-out), color var(--duration-3) var(--ease-out);
}
.ad-menu2__item.is-highlighted { background: var(--primary-50); color: var(--primary-700); }
.ad-menu2__item[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.ad-menu2__item--danger { color: var(--error-700); }
.ad-menu2__item--danger.is-highlighted { background: var(--error-100); color: var(--error-700); }

.ad-menu2__icon { flex: 0 0 auto; width: 16px; height: 16px; color: var(--neutral-500); display: grid; place-items: center; }
.ad-menu2__item.is-highlighted .ad-menu2__icon { color: var(--primary-600); }
.ad-menu2__item--danger .ad-menu2__icon,
.ad-menu2__item--danger.is-highlighted .ad-menu2__icon { color: var(--error-500); }
.ad-menu2__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ad-menu2__desc { font-size: 12px; line-height: 1.45; color: var(--fg-muted); margin-top: 1px; }
.ad-menu2__item--danger .ad-menu2__desc { color: var(--error-700); opacity: 0.75; }
.ad-menu2__shortcut {
  margin-inline-start: auto; flex: 0 0 auto;
  font-family: var(--font-mono); font-size: 10px; color: var(--neutral-500);
  white-space: nowrap;
}
.ad-menu2__caret { flex: 0 0 auto; width: 14px; height: 14px; color: var(--neutral-500); margin-inline-start: auto; }
.ad-menu2__sep { height: 1px; background: var(--neutral-100); margin: var(--space-3xs) calc(-1 * var(--space-3xs)); }
.ad-menu2__group-label {
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 600; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--neutral-500);
  padding: 8px 10px 4px;
}

/* Submenu panel — nests off the parent item */
.ad-menu2__sub {
  position: absolute;
  inset-inline-start: calc(100% - var(--space-3xs));
  top: calc(-1 * var(--space-3xs) - 1px);
  z-index: 1;
}
.ad-menu2__sub > .ad-menu2 { transform-origin: top left; }

/* Menubar */
.ad-menubar {
  display: flex; align-items: center; gap: 2px;
  padding: var(--space-3xs);
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  width: fit-content;
}
.ad-menubar__wrap { position: relative; }
.ad-menubar__trigger {
  padding: 6px 12px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent;
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 600; font-size: 13px;
  color: var(--fg-default); cursor: pointer;
  transition: background var(--duration-4) var(--ease-out), color var(--duration-4) var(--ease-out);
}
.ad-menubar__trigger:hover { background: var(--neutral-100); color: var(--fg-strong); }
.ad-menubar__trigger.is-open { background: var(--primary-50); color: var(--primary-700); }
.ad-menubar__trigger:focus-visible { outline: none; box-shadow: var(--shadow-focus-ring); }
.ad-menubar__panel { position: absolute; top: calc(100% + var(--space-3xs)); inset-inline-start: 0; z-index: 60; }

/* ═══ Tooltip v2 ═══
   Enter: fade + 2px rise via transition (no new keyframes). */
.ad-tip2 {
  background: var(--neutral-900); color: var(--fg-on-dark);
  font-size: 12px; font-weight: 500; line-height: 1.4;
  padding: 6px 10px; border-radius: 6px;
  box-shadow: var(--shadow-md);
  max-width: 240px; width: max-content;
  pointer-events: none;
  opacity: 0; transform: translateY(2px);
  transition: opacity var(--duration-4) var(--ease-out), transform var(--duration-4) var(--ease-out);
}
.ad-tip2.is-shown { opacity: 1; transform: translateY(0); }
.ad-tip2__shortcut {
  margin-inline-start: 6px; padding-inline-start: 6px;
  border-inline-start: 1px solid color-mix(in srgb, var(--fg-on-dark) 20%, transparent);
  font-family: var(--font-mono); font-size: 10px;
  color: color-mix(in srgb, var(--fg-on-dark) 60%, transparent);
}
.ad-tip2__arrow {
  position: absolute;
  width: 6px; height: 6px;
  background: var(--neutral-900);
  transform: rotate(45deg);
}
.ad-tip2[data-side="top"]    .ad-tip2__arrow { bottom: -3px; }
.ad-tip2[data-side="bottom"] .ad-tip2__arrow { top: -3px; }
.ad-tip2[data-side="left"]   .ad-tip2__arrow { right: -3px; }
.ad-tip2[data-side="right"]  .ad-tip2__arrow { left: -3px; }

/* ═══ Popover v2 ═══ */
.ad-pop2 {
  max-width: 300px;
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: ad-scale-in var(--duration-4) var(--ease-out) both;
  transform-origin: top center;
}
.ad-pop2[data-side="top"] { transform-origin: bottom center; }
.ad-pop2__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2xs);
  padding: var(--space-xs) 14px 6px;
}
.ad-pop2__title {
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 600; font-size: 14px; color: var(--fg-strong);
}
.ad-pop2__sub { font-size: 12px; color: var(--fg-muted); margin-top: 2px; }
.ad-pop2__close {
  width: 20px; height: 20px; border-radius: var(--radius-xs);
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--fg-muted); cursor: pointer;
}
.ad-pop2__close:hover { background: var(--neutral-100); color: var(--fg-strong); }
.ad-pop2__close:focus-visible { outline: none; box-shadow: var(--shadow-focus-ring); }
.ad-pop2__body { padding: var(--space-3xs) 14px var(--space-xs); font-size: 13px; line-height: 1.55; color: var(--fg-default); }
.ad-pop2__foot {
  display: flex; gap: var(--space-2xs); justify-content: flex-end;
  padding: var(--space-2xs) 14px;
  border-top: 1px solid var(--neutral-100);
}
.ad-pop2__arrow {
  position: absolute;
  width: 10px; height: 10px;
  background: var(--bg-elevated);
  transform: rotate(45deg);
}
.ad-pop2[data-side="bottom"] .ad-pop2__arrow { top: -6px;  border-left: 1px solid var(--neutral-200); border-top: 1px solid var(--neutral-200); }
.ad-pop2[data-side="top"]    .ad-pop2__arrow { bottom: -6px; border-right: 1px solid var(--neutral-200); border-bottom: 1px solid var(--neutral-200); }
.ad-pop2[data-side="right"]  .ad-pop2__arrow { left: -6px; border-left: 1px solid var(--neutral-200); border-bottom: 1px solid var(--neutral-200); }
.ad-pop2[data-side="left"]   .ad-pop2__arrow { right: -6px; border-right: 1px solid var(--neutral-200); border-top: 1px solid var(--neutral-200); }

/* ═══ HoverCard v2 ═══ */
.ad-hcard2 {
  width: 280px;
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: ad-scale-in var(--duration-4) var(--ease-out) both;
  transform-origin: top center;
}
.ad-hcard2__head { display: flex; align-items: flex-start; gap: var(--space-2xs); padding: var(--space-xs) 14px 6px; }
.ad-hcard2__meta { flex: 1; min-width: 0; }
.ad-hcard2__name {
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 600; font-size: 13px; color: var(--fg-strong);
}
.ad-hcard2__sub { font-size: 11px; color: var(--fg-muted); margin-top: 1px; }
.ad-hcard2__kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 6px 14px; }
.ad-hcard2__kpi { padding: 6px 8px; background: var(--neutral-50); border-radius: 6px; }
.ad-hcard2__kpi-label { font-size: 10px; color: var(--fg-muted); }
.ad-hcard2__kpi-val { font-family: var(--font-mono); font-weight: 500; font-size: 14px; color: var(--fg-strong); }
.ad-hcard2__foot { padding: var(--space-2xs) 14px; border-top: 1px solid var(--neutral-100); }
.ad-hcard2__link {
  font-family: 'Plus Jakarta Sans', var(--font-display);
  font-weight: 600; font-size: 12px;
  color: var(--primary-600); cursor: pointer;
}

/* ═══ RTL ═══════════════════════════════════════════════════
   The submenu caret points "forward" toward the nested panel,
   so it mirrors under RTL. JS-anchored panel placement
   (position.js page x/y, data-side arrows) stays physical —
   it is computed from rects and flips automatically. */
[dir="rtl"] .ad-menu2__caret { transform: scaleX(-1); }
