/* Orbit design system: floating surfaces (menu, popover, tooltip, toast). Load after design-system.css;
   it uses only --ds-* tokens. docs/design-system/overlays.md explains every rule and the markup.

   Popovers: the UA stylesheet hides a closed [popover] with display:none, and author rules beat UA rules
   whatever their specificity, so a display value here is only ever set on :popover-open. */

:root {
  /* Where the toast stack sits. A room lifts it above its call bar by redefining this. */
  --ds-toaster-inset-block-end: var(--ds-space-4);
  --ds-tooltip-delay: 500ms;
}

/* Shared surface. Menus, popovers and toasts take .ds-glass in markup for their material. */

.ds-menu,
.ds-popover,
.ds-toast {
  color: var(--ds-ink);
  font: var(--ds-text-md)/1.35 var(--ds-font-sans);
  overflow-wrap: anywhere;
}
.ds-menu,
.ds-popover {
  max-inline-size: min(320px, calc(100vw - var(--ds-space-4)));
  max-block-size: calc(100dvh - var(--ds-space-4));
  overflow: auto;
  overscroll-behavior: contain;
}

/* Over live video: glass blurs every frame behind it, which costs a compositor pass per frame and smears
   faces into the surface. Anything that can sit over a tile uses the call scrim instead. */
.ds-glass.ds-over-video,
.ds-over-video .ds-glass {
  background: var(--ds-call-scrim);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Menu: a [popover] with role="menu", opened by a button with popovertarget. */

.ds-menu {
  min-inline-size: 200px;
  padding: var(--ds-space-1);
  border-radius: var(--ds-radius-lg);
}
.ds-menu:popover-open { display: grid; align-content: start; }

.ds-menu-item {
  display: grid;
  grid-template-columns: [lead] 16px [label] minmax(0, 1fr) [trail] auto;
  align-items: center;
  gap: var(--ds-space-2);
  inline-size: 100%;
  min-block-size: var(--ds-target);
  margin: 0;
  padding-block: var(--ds-space-1);
  padding-inline: var(--ds-space-2) var(--ds-space-3);
  border: 0;
  /* Concentric with the menu: its radius minus the menu's padding. */
  border-radius: calc(var(--ds-radius-lg) - var(--ds-space-1));
  color: inherit;
  background: transparent;
  font: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}
.ds-menu--compact .ds-menu-item { min-block-size: 32px; }
/* A finger needs the full target even in a compact menu. */
@media (pointer: coarse) { .ds-menu--compact .ds-menu-item { min-block-size: var(--ds-target); } }

.ds-menu-item:hover,
.ds-menu-item[aria-expanded=true] { background: var(--ds-fill-hover); }
/* The global ring sits 3px outside, where the menu's overflow would clip it, so the ring is inset here.
   Two classes outrank style.css's `body :is(button, …):focus-visible`. */
.ds-menu .ds-menu-item:focus-visible {
  outline: var(--ds-focus-width) solid var(--ds-focus-color);
  outline-offset: calc(var(--ds-focus-width) * -1);
  background: var(--ds-fill-hover);
}
.ds-menu-item:active:not([aria-disabled=true]) { background: var(--ds-fill-pressed); }
.ds-menu-item:is(:disabled, [aria-disabled=true]) { color: var(--ds-ink-disabled); background: transparent; cursor: not-allowed; }

.ds-menu-label { grid-column: label; }
.ds-menu-label small { display: block; color: var(--ds-ink-muted); font-size: var(--ds-text-sm); }
.ds-menu-icon { grid-column: lead; grid-row: 1; inline-size: 16px; block-size: 16px; }
.ds-menu-shortcut {
  grid-column: trail;
  color: var(--ds-ink-muted);
  font: var(--ds-text-sm)/1 var(--ds-font-sans);
  font-variant-numeric: tabular-nums;
  /* Key names read left to right in every language. */
  direction: ltr;
  unicode-bidi: isolate;
}

/* Check and radio marks are drawn with borders, so forced colors repaint them like any other edge. */
.ds-menu-item:is([role=menuitemcheckbox], [role=menuitemradio])::before {
  content: '';
  grid-column: lead;
  grid-row: 1;
  justify-self: center;
  box-sizing: border-box;
  opacity: 0;
}
.ds-menu-item[role=menuitemcheckbox]::before {
  inline-size: 6px;
  block-size: 11px;
  margin-block-end: 3px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  rotate: 45deg;
}
.ds-menu-item[role=menuitemcheckbox][aria-checked=mixed]::before {
  inline-size: 10px;
  block-size: 0;
  margin: 0;
  border-width: 2px 0 0;
  rotate: none;
  opacity: 1;
}
.ds-menu-item[role=menuitemradio]::before { inline-size: 8px; block-size: 8px; border: 4px solid currentColor; border-radius: 50%; }
.ds-menu-item[aria-checked=true]::before { opacity: 1; }

.ds-menu-item--danger { color: var(--ds-danger-ink); }
.ds-menu-item--danger:is(:hover, :focus-visible):not([aria-disabled=true]),
.ds-menu .ds-menu-item--danger:focus-visible { background: var(--ds-danger); }
.ds-menu-item--danger:active:not([aria-disabled=true]) { background: var(--ds-danger-hover); }

/* A row that opens a nested menu. The chevron points to the inline end and mirrors in right-to-left text. */
.ds-menu-chevron {
  grid-column: trail;
  inline-size: 7px;
  block-size: 7px;
  border: solid currentColor;
  border-width: 1.5px 1.5px 0 0;
  rotate: 45deg;
  color: var(--ds-ink-muted);
}
.ds-menu-chevron:dir(rtl) { rotate: -135deg; }

.ds-menu-separator {
  block-size: 0;
  margin: var(--ds-space-1) var(--ds-space-2);
  border: 0;
  border-block-start: 1px solid var(--ds-hairline);
}
.ds-menu-heading {
  margin: 0;
  padding: var(--ds-space-2) var(--ds-space-2) var(--ds-space-1);
  color: var(--ds-ink-muted);
  font: 600 var(--ds-text-xs)/1.3 var(--ds-font-sans);
}
.ds-menu [role=group] { display: grid; }

/* Popover: non-modal panel for short content, opened by a button with popovertarget. */

.ds-popover {
  inline-size: max-content;
  padding: var(--ds-space-4);
  border-radius: var(--ds-radius-lg);
}
.ds-popover:popover-open { display: grid; gap: var(--ds-space-3); align-content: start; justify-items: start; }
.ds-popover-title { margin: 0; font: 700 var(--ds-text-lg)/1.25 var(--ds-font-sans); text-wrap: balance; }
.ds-popover p { margin: 0; color: var(--ds-ink-muted); text-wrap: pretty; }

/* Anchor positioning. A popover opened through popovertarget is anchored to its invoker, so it opens
   below the button and starts at the button's inline start, flipping when it would leave the viewport.
   Fallback without anchor positioning: the UA rule `inset: 0; margin: auto` stays, so the surface opens
   as a card centered in the viewport. It is fully usable, just not attached to its button. */
@supports (position-area: block-end) {
  .ds-menu,
  .ds-popover {
    inset: auto;
    margin: var(--ds-space-1) 0;
    position-area: block-end span-inline-end;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
    max-block-size: calc(100% - var(--ds-space-2));
  }
}

/* Tooltip: a short, visual-only label for a control that already has an accessible name.
   <span class="ds-tooltip-anchor"><button aria-labelledby="t">…</button><span id="t" role="tooltip" class="ds-tooltip">…</span></span>
   It is a child of the anchor so a pointer can move onto it without it closing (WCAG 1.4.13).
   It is absolutely positioned above its control on purpose. CSS anchor positioning resolves against the
   containing block, and the anchor wrapper (or a glass call bar, whose backdrop-filter makes it the
   containing block) leaves zero room above the control, so position-area would always flip onto it.
   Edge flipping needs popover="hint" in the top layer; see the deferred list in the doc. */

.ds-tooltip-anchor {
  position: relative;
  display: inline-flex;
}

.ds-tooltip {
  position: absolute;
  inset-block-end: calc(100% + var(--ds-space-2));
  inset-inline-start: 50%;
  z-index: 1;
  inline-size: max-content;
  max-inline-size: 240px;
  padding: var(--ds-space-1) var(--ds-space-2);
  border: 1px solid var(--ds-hairline);
  border-radius: var(--ds-radius-sm);
  /* Solid, never glass: it carries text over anything, including video. */
  color: var(--ds-ink);
  background: var(--ds-fill-raised);
  box-shadow: var(--ds-shadow-raise);
  font: 500 var(--ds-text-sm)/1.35 var(--ds-font-sans);
  overflow-wrap: anywhere;
  text-wrap: pretty;
  translate: -50% 0;
  pointer-events: auto;
  visibility: hidden;
  opacity: 0;
  /* Zero-length transitions still honor a delay, so the hover delay holds with reduced motion too. */
  transition-property: visibility, opacity;
  transition-duration: 0s;
}
.ds-tooltip:dir(rtl) { translate: 50% 0; }
/* Bridges the gap to the control, on whichever side it flipped to, so the pointer stays inside the
   anchor on its way to the label. */
.ds-tooltip::after { content: ''; position: absolute; inset: calc(var(--ds-space-2) * -1 - 1px) 0; }
.ds-tooltip kbd { margin-inline-start: var(--ds-space-1); color: var(--ds-ink-muted); font: inherit; direction: ltr; unicode-bidi: isolate; }

/* Hover waits so a pointer crossing the call bar does not flash every label; keyboard focus shows at once. */
.ds-tooltip-anchor:hover > .ds-tooltip { visibility: visible; opacity: 1; transition-delay: var(--ds-tooltip-delay); }
.ds-tooltip-anchor:has(> :focus-visible) > .ds-tooltip { visibility: visible; opacity: 1; transition-delay: 0s; }
/* Escape hides it until the pointer leaves or focus moves (ds-overlays.js sets this). */
.ds-tooltip-anchor[data-ds-dismissed] > .ds-tooltip { visibility: hidden; opacity: 0; }
/* Touch has no hover; a tap must not leave a stuck label. */
@media (hover: none) { .ds-tooltip-anchor:not(:has(> :focus-visible)) > .ds-tooltip { visibility: hidden; } }

/* Toast: brief, non-modal status. ds-overlays.js shows the toaster (a manual popover, so it sits in the
   top layer above room chrome) and owns timing, stacking and announcements. */

.ds-toaster {
  inset: auto 0 var(--ds-toaster-inset-block-end);
  inline-size: min(420px, calc(100vw - var(--ds-space-4)));
  margin: 0 auto;
  padding: 0;
  border: 0;
  overflow: visible;
  background: transparent;
  pointer-events: none;
}
.ds-toaster:popover-open { display: block; }
.ds-toast-stack { display: flex; flex-direction: column; gap: var(--ds-space-2); margin: 0; padding: 0; list-style: none; }

.ds-toast {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  min-block-size: 52px;
  padding-block: var(--ds-space-1);
  padding-inline: var(--ds-space-4) var(--ds-space-1);
  border-radius: var(--ds-radius-lg);
  pointer-events: auto;
}
.ds-toast-message { flex: 1; min-inline-size: 0; margin: 0; padding-block: var(--ds-space-2); }
.ds-toast-action { color: var(--ds-accent); }
.ds-toast-close { flex: none; color: var(--ds-ink-muted); }
/* Tone adds a leading mark; the message text still says what happened. */
.ds-toast[data-tone]::before { content: ''; flex: none; inline-size: 8px; block-size: 8px; border: 4px solid; border-radius: 50%; box-sizing: border-box; }
.ds-toast[data-tone=success]::before { color: var(--ds-success); }
.ds-toast[data-tone=warning]::before { color: var(--ds-warning); }
.ds-toast[data-tone=danger]::before { color: var(--ds-danger-ink); }

/* Motion: whimsy stays behind no-preference. With reduced motion, surfaces appear and leave instantly. */

@media (prefers-reduced-motion: no-preference) {
  .ds-menu,
  .ds-popover {
    transition: opacity var(--ds-duration-fast) var(--ds-ease-out), scale var(--ds-duration-fast) var(--ds-ease-out),
      display var(--ds-duration-fast) allow-discrete, overlay var(--ds-duration-fast) allow-discrete;
  }
  .ds-menu:not(:popover-open),
  .ds-popover:not(:popover-open) { opacity: 0; scale: .98; }
  @starting-style {
    .ds-menu:popover-open,
    .ds-popover:popover-open { opacity: 0; scale: .96; }
  }

  .ds-tooltip { transition-duration: var(--ds-duration-fast); transition-timing-function: var(--ds-ease-standard); }

  .ds-toast {
    transition: opacity var(--ds-duration-base) var(--ds-ease-sheet), translate var(--ds-duration-base) var(--ds-ease-sheet);
  }
  @starting-style { .ds-toast { opacity: 0; translate: 0 12px; } }
  .ds-toast[data-leaving] { opacity: 0; translate: 0 6px; }
}

/* Forced colors: system colors draw every edge and state. */

@media (forced-colors: active) {
  .ds-menu, .ds-popover, .ds-toast, .ds-tooltip { border: 1px solid CanvasText; }
  .ds-menu-item:hover, .ds-menu .ds-menu-item:focus-visible {
    outline: var(--ds-focus-width) solid Highlight;
    outline-offset: calc(-1 * var(--ds-focus-width));
  }
  .ds-menu-item:is(:disabled, [aria-disabled=true]) { color: GrayText; }
  .ds-menu-separator { border-block-start-color: CanvasText; }
}
