/* ==================================================================================================
   Overlays — r4 «Birge OS» (spec §10). Every floating layer lives in the top layer (Popover API /
   <dialog>), wears the glass recipe (sheen + material + blur + 0.5px edge + rim + shadow) and leaves
   faster than it came.

   Menus & popovers   Alpine x-data="menu" (or "popover") with [data-menu-trigger] + [data-menu-panel].
                      .menu__panel (--wide) · .menu__item (--danger, [aria-checked] check marks,
                      __icon/__text/__kbd/__check, .is-chosen blink) · .menu__label · .menu__sep ·
                      .menu__header · .popover__panel. app.js sets data-side / data-align
                      (transform-origin: the panel grows out of its trigger).
   Context menu lift  .ctx-lift (+ .ctx-lift__clone) — long press on [data-context-menu] (app.js)
   Tooltips           data-tooltip="Text" [data-tooltip-pos="bottom|left|right"] (hover devices)
   Sheet (modal)      components/modal.html → <dialog class="modal modal--sm|md|lg|xl"> — centred on
                      desktop, a bottom sheet < 640px. Alert: .modal--confirm (App.confirm).
   Inspector          components/drawer.html → <dialog class="drawer"> floating right panel; docked
                      (non-modal, .drawer--docked + :root.has-inspector) ≥ 1280px; a sheet < 768px.
   Toasts             #toast-root (.toast-root) with .toast (--success/--info/--warning/--error):
                      top right (top on phones), the deck grows downwards.
   Spotlight          dashboard/palette.html (dialog.palette.spotlight)
   Shortcut sheet     .shortcuts (+ .shortcuts__search) built by app.js
   Lightbox           dialog.lightbox (chat media) — the dark glass frame
   Motion ghost       .motion-ghost (App.motion.zoomFrom)
   ================================================================================================== */

/* -- Menu / popover panels (r4 · 10.2, 10.4) ----------------------------------------------------- */
.menu__panel,
.popover__panel {
  position: fixed;
  inset: auto;
  z-index: var(--z-overlay);
  min-width: 220px;
  max-width: min(320px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  margin: 0;
  padding: 5px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 0.5px solid var(--glass-border);
  border-radius: var(--radius-menu);
  background: var(--glass-sheen), var(--mat-thick);
  -webkit-backdrop-filter: var(--mat-filter-strong);
  backdrop-filter: var(--mat-filter-strong);
  box-shadow: var(--glass-rim), var(--shadow-lg);
  color: var(--text);
  font-size: var(--fs-md);
  opacity: 1;
  transform: none;
  transform-origin: var(--origin, top left);
  transition:
    opacity 140ms var(--ease-in),
    transform 140ms var(--ease-in),
    overlay 140ms allow-discrete,
    display 140ms allow-discrete;
}
.menu__panel:popover-open,
.popover__panel:popover-open {
  transition:
    opacity 160ms var(--ease-out),
    transform 220ms var(--spring-snappy),
    overlay 160ms allow-discrete,
    display 160ms allow-discrete;
}
@starting-style {
  .menu__panel:popover-open,
  .popover__panel:popover-open {
    opacity: 0;
    transform: translateY(-4px) scale(0.97);
  }
}
.menu__panel:not(:popover-open),
.popover__panel:not(:popover-open) {
  opacity: 0;
  transform: scale(0.98);
}
.menu__panel[data-side="bottom"][data-align="start"],
.popover__panel[data-side="bottom"][data-align="start"] { transform-origin: top left; }
.menu__panel[data-side="bottom"][data-align="end"],
.popover__panel[data-side="bottom"][data-align="end"] { transform-origin: top right; }
.menu__panel[data-side="top"][data-align="start"],
.popover__panel[data-side="top"][data-align="start"] { transform-origin: bottom left; }
.menu__panel[data-side="top"][data-align="end"],
.popover__panel[data-side="top"][data-align="end"] { transform-origin: bottom right; }
.menu__panel[data-align="center"],
.popover__panel[data-align="center"] { transform-origin: top center; }
/* Browsers without the Popover API: app.js toggles .is-open */
.menu__panel.is-fallback:not(.is-open),
.popover__panel.is-fallback:not(.is-open) {
  display: none;
}
.menu__panel--wide {
  min-width: 260px;
}
.popover__panel {
  min-width: 240px;
  padding: 12px;
}
.menu__panel::-webkit-scrollbar {
  width: 6px;
}

.menu__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: var(--fw-regular);
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: default;
  outline: none;
  scroll-margin: 6px;
}
.menu__item > .icon:not(.menu__check),
.menu__icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--text-2);
}
.menu__text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu__sub {
  display: block;
  overflow: hidden;
  color: var(--text-2);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
}
.menu__kbd {
  margin-left: auto;
  padding-left: 12px;
  color: var(--text-3);
  font-size: var(--fs-sm);
  letter-spacing: 0.02em;
}
.menu__check {
  flex-shrink: 0;
  margin-left: auto;
  color: var(--accent);
  visibility: hidden;
}
.menu__item[aria-checked="true"] .menu__check,
.menu__item[aria-selected="true"] .menu__check {
  visibility: visible;
}
.menu__item--danger {
  color: var(--danger-ink);
}
.menu__item--danger > .icon {
  color: currentColor;
}
.menu__item:disabled,
.menu__item[aria-disabled="true"] {
  background: none;
  color: var(--text-disabled);
}
.menu__item:disabled > .icon,
.menu__item[aria-disabled="true"] > .icon {
  color: currentColor;
}
.menu__label {
  padding: 6px 10px 2px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.menu__sep {
  height: 0.5px;
  margin: 5px 10px;
  background: var(--line);
}
.menu__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 12px;
}
.menu__header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}
.menu__header-text strong {
  overflow: hidden;
  font-weight: var(--fw-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu__header-text span {
  overflow: hidden;
  color: var(--text-2);
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu__row {
  padding: 4px 6px 6px;
}
.menu__row .segmented {
  width: 100%;
}
.menu__search {
  margin: 2px 2px 6px;
}
.menu__empty {
  padding: 10px;
  color: var(--text-3);
  font-size: var(--fs-sm);
  text-align: center;
}
.menu form {
  display: contents;
}
/* macOS: hover / keyboard focus = accent fill + white text and glyphs. */
@media (pointer: fine) {
  .menu__item:is(:hover, :focus-visible, .is-focused):not(:disabled, [aria-disabled="true"]) {
    outline: none;
    background: var(--selection-bg);
    color: var(--selection-fg);
  }
  .menu__item:is(:hover, :focus-visible, .is-focused):not(:disabled, [aria-disabled="true"]) :is(.icon, .menu__kbd, .menu__check, .menu__sub) {
    color: currentColor;
  }
  .menu__item--danger:is(:hover, :focus-visible, .is-focused):not(:disabled, [aria-disabled="true"]) {
    background: var(--danger-solid);
    color: var(--text-on-accent);
  }
  /* The chosen item blinks twice before the menu goes away (app.js .is-chosen). */
  .menu__item.is-chosen {
    animation: menu-blink 150ms steps(1, end);
  }
}
@keyframes menu-blink {
  0%,
  66% {
    background: var(--selection-bg);
    color: var(--selection-fg);
  }
  33% {
    background: transparent;
    color: var(--text);
  }
}
/* Touch: iOS context menu — 44px rows, 17px text, the glyph on the right, full-width hairlines. */
@media (pointer: coarse) {
  .menu__panel {
    min-width: 250px;
    padding: 0;
  }
  .menu__item {
    min-height: 44px;
    padding: 0 16px;
    border-radius: 0;
    font-size: var(--type-body);
  }
  .menu__item > .icon:not(.menu__check) {
    order: 2;
    width: 20px;
    height: 20px;
    margin-left: auto;
    color: var(--text);
  }
  .menu__item--danger > .icon:not(.menu__check) {
    color: currentColor;
  }
  .menu__item + .menu__item {
    box-shadow: inset 0 0.5px 0 var(--line);
  }
  .menu__item:active:not(:disabled) {
    background: var(--fill-2);
  }
  .menu__sep {
    height: 8px;
    margin: 0;
    background: var(--fill-1);
  }
  .menu__label {
    padding: 10px 16px 6px;
    font-size: var(--type-footnote);
    font-weight: var(--fw-regular);
  }
  .menu__header {
    padding: 14px 16px;
  }
  .menu__row {
    padding: 8px 12px;
  }
}
@media (pointer: coarse) and (prefers-reduced-motion: no-preference) {
  .menu__panel:popover-open {
    transition:
      opacity 160ms var(--ease-out),
      transform var(--dur-bouncy) var(--spring-bouncy),
      overlay 160ms allow-discrete,
      display 160ms allow-discrete;
  }
  @starting-style {
    .menu__panel:popover-open {
      opacity: 0;
      transform: scale(0.6);
    }
  }
}

/* -- Context menu lift (r4 · 10.3) — the one short-lived full-screen blur (exception to 4.4) ----- */
.ctx-lift {
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  pointer-events: none;
  transition:
    background-color var(--dur-2) ease,
    backdrop-filter var(--dur-2) ease;
}
.ctx-lift.is-on {
  pointer-events: auto; /* the tap that closes the menu must not reach the card underneath */
  background: var(--scrim-light);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
/* domain.css loads later — a higher specificity */
.ctx-lift > .ctx-lift__clone.ctx-lift__clone {
  position: fixed;
  margin: 0;
  border-radius: var(--radius-board-card);
  background: var(--surface);
  box-shadow: var(--shadow-lift);
  transform: scale(1);
  transition: transform var(--dur-snappy) var(--spring-snappy);
}
.ctx-lift.is-on > .ctx-lift__clone.ctx-lift__clone {
  transform: scale(1.03);
}
:root[data-transparency="reduced"] .ctx-lift.is-on {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
@media (pointer: coarse) {
  [data-context-menu] {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
}

/* -- Tooltips (r4 · 10.10) — macOS: 12px, 7px radius, 500 ms wait (none while warm), hover only -- */
:where([data-tooltip]) {
  position: relative;
}
@media (hover: hover) {
  [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    z-index: var(--z-tooltip);
    bottom: calc(100% + 8px);
    left: 50%;
    width: max-content;
    max-width: 260px;
    padding: 4px 8px;
    border: 0.5px solid var(--glass-border);
    border-radius: 7px;
    background: var(--tooltip-bg);
    box-shadow: var(--shadow-md);
    color: var(--tooltip-fg);
    font-size: var(--fs-xs);
    font-weight: var(--fw-regular);
    letter-spacing: 0;
    line-height: 1.35;
    text-align: center;
    text-transform: none;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    translate: -50% 0;
  }
  [data-tooltip]:hover::after,
  [data-tooltip]:focus-visible::after {
    opacity: 1;
  }
  [data-tooltip][aria-expanded="true"]::after {
    display: none;
  }
  [data-tooltip-pos="bottom"]::after {
    top: calc(100% + 8px);
    bottom: auto;
  }
  [data-tooltip-pos="right"]::after {
    top: 50%;
    bottom: auto;
    left: calc(100% + 8px);
    translate: 0 -50%;
  }
  [data-tooltip-pos="left"]::after {
    top: 50%;
    right: calc(100% + 8px);
    bottom: auto;
    left: auto;
    translate: 0 -50%;
  }
  [data-tooltip-align="end"]::after {
    right: 0;
    left: auto;
    translate: 0 0;
  }
  [data-tooltip-align="start"]::after {
    right: auto;
    left: 0;
    translate: 0 0;
  }
  /* Only laid out while shown — a hidden tooltip near the edge used to widen the page in narrow
     desktop windows. The entrance is a keyframe animation, so the 500 ms wait (none while warm)
     survives the display switch; app.js end/start-aligns a tooltip that would leave the viewport. */
  [data-tooltip]:not(:hover):not(:focus-visible)::after {
    display: none;
  }
  [data-tooltip]:is(:hover, :focus-visible)::after {
    animation: tooltip-in 120ms ease-out 500ms both;
  }
  [data-tooltip-pos="bottom"]:is(:hover, :focus-visible)::after {
    animation-name: tooltip-in-down;
  }
  :root.tooltips-warm [data-tooltip]:hover::after {
    animation-delay: 0ms;
  }
}
@keyframes tooltip-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
}
@keyframes tooltip-in-down {
  from {
    opacity: 0;
    transform: translateY(-2px);
  }
}

/* -- Sheet (modal) — r4 · 10.5 ------------------------------------------------------------------- */
dialog.modal {
  width: min(var(--modal-w, 560px), calc(100vw - 32px));
  max-width: none;
  max-height: min(86dvh, 900px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sheet); /* inherited by panels that ask for it (vault) */
  background: transparent;
  color: var(--text);
  overflow: visible;
}
dialog.modal--sm { --modal-w: 420px; }
dialog.modal--md { --modal-w: 560px; }
dialog.modal--lg { --modal-w: 760px; }
dialog.modal--xl { --modal-w: 960px; }
dialog.modal::backdrop {
  background: var(--scrim);
}
.modal__panel {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  min-height: 0;
  overflow: hidden;
  border: 0.5px solid var(--glass-border);
  border-radius: var(--radius-sheet);
  background: var(--surface-elevated);
  box-shadow: var(--glass-rim), var(--shadow-xl);
  translate: 0 var(--drag-y, 0px); /* phones: the sheet follows the finger (app.js initSheetDrag) */
  transition: translate var(--dur-snappy) var(--spring-snappy);
}
dialog.is-dragging .modal__panel {
  transition: none;
}
.modal__form {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  min-height: 0;
}
.modal__panel:focus,
.drawer__panel:focus {
  outline: none;
}
.modal__header {
  display: flex;
  flex-shrink: 0;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 18px 6px 20px;
}
.modal__title {
  flex: 1;
  min-width: 0;
  font-size: var(--type-title3);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-snug);
  text-wrap: balance;
}
.modal__subtitle {
  margin-top: 2px;
  color: var(--text-3);
  font-size: var(--type-footnote);
  font-weight: var(--fw-regular);
  letter-spacing: 0;
}
.modal__subtitle:empty {
  display: none;
}
.modal__close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  --btn-h: 28px;
  --btn-bg: var(--fill-1);
  --btn-bg-hover: var(--fill-2);
  --btn-fg: var(--text-2);
  background: var(--fill-1);
  color: var(--text-2);
}
.modal__close .icon {
  width: 16px;
  height: 16px;
}
.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 20px 20px;
  overflow: auto;
  overscroll-behavior: contain;
}
.modal__footer {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 18px;
}
.modal__footer:not(:has(*)) {
  display: none;
}
.modal__footer-start {
  margin-right: auto;
}
/* Animations: the specificity is ordered on purpose. is-instant (content swapped) — no entrance;
   is-closing comes last and wins (an instant sheet still plays its exit). */
@media (prefers-reduced-motion: no-preference) {
  dialog.modal[open] .modal__panel {
    animation: sheet-in var(--dur-sheet) var(--spring-sheet) both;
  }
  dialog.modal[open]::backdrop {
    animation: fade-in var(--dur-3) ease both;
  }
  dialog.modal[open].is-instant .modal__panel,
  dialog.modal[open].is-instant::backdrop {
    animation: none;
  }
  dialog.modal[open].is-closing .modal__panel {
    animation: sheet-out 160ms var(--ease-in) both;
  }
  dialog.modal[open].is-closing::backdrop {
    animation: vt-fade-out 160ms ease both;
  }
}
@media (prefers-reduced-motion: reduce) {
  dialog.modal[open] .modal__panel {
    animation: fade-in 150ms ease both;
  }
  dialog.modal[open].is-instant .modal__panel {
    animation: none;
  }
  dialog.modal[open].is-closing .modal__panel {
    animation: vt-fade-out 120ms ease both;
  }
}
@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.94);
  }
}
@keyframes sheet-out {
  to {
    opacity: 0;
    transform: scale(0.97);
  }
}

/* Grabber handle for sheets (phones) */
.sheet-grabber {
  display: none;
}

/* Phones: a bottom sheet — grabber, centred title, a sticky footer with the primary action on top
   (iOS "Not Now" pattern: DOM order [Cancel, Primary] + column-reverse), grouped fields on --bg. */
@media (max-width: 639px) {
  dialog.modal {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - var(--safe-top) - 12px);
    margin: auto 0 0;
    border-radius: 32px 32px 0 0;
  }
  .modal__panel {
    border-radius: 32px 32px 0 0;
    background: var(--bg);
    padding-bottom: var(--safe-bottom);
  }
  .modal .sheet-grabber,
  .drawer .sheet-grabber {
    position: absolute;
    z-index: 3;
    top: 0;
    left: 50%;
    display: block;
    width: 72px;
    height: 22px;
    translate: -50% 0;
    touch-action: none;
    cursor: grab;
  }
  .sheet-grabber::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 18px;
    width: 36px;
    height: 5px;
    border-radius: 3px;
    background: var(--fill-3);
  }
  .modal__header {
    position: relative;
    justify-content: center;
    padding: 20px 52px 8px;
    text-align: center;
  }
  .modal__close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    --btn-h: 32px;
    background: var(--glass-sheen), var(--mat-regular);
    -webkit-backdrop-filter: var(--mat-filter);
    backdrop-filter: var(--mat-filter);
    box-shadow: var(--glass-rim);
  }
  .modal__body {
    padding: 8px 16px 18px;
  }
  .modal__footer {
    flex-direction: column-reverse;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 4px;
    padding: 10px 16px 14px;
    background: var(--bg);
  }
  .modal__footer-start {
    margin-right: 0;
  }
  .modal__footer .btn {
    width: 100%;
  }
  .modal__footer .btn--primary {
    --btn-h: var(--control-h-lg);
    font-size: var(--type-body);
  }
  .modal__footer .btn:not(.btn--primary, .btn--danger) {
    --btn-bg: transparent;
    --btn-bg-hover: var(--fill-1);
    --btn-border: transparent;
    --btn-shadow: none;
    --btn-fg: var(--accent-ink);
  }
}
@media (max-width: 639px) and (prefers-reduced-motion: no-preference) {
  dialog.modal[open] .modal__panel {
    animation: sheet-up var(--dur-sheet) var(--spring-sheet) both;
  }
  dialog.modal[open].is-instant .modal__panel {
    animation: none;
  }
  dialog.modal[open].is-closing .modal__panel {
    animation: sheet-down 220ms var(--ease-in) both;
  }
}
@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
}
@keyframes sheet-down {
  to {
    transform: translateY(100%);
  }
}
/* vault.js runs its own card ⇄ dialog view transition: no second entrance under it. */
:root.vault-vt dialog.modal .modal__panel {
  animation: none;
}

/* -- Alert (App.confirm) — r4 · 10.6: macOS 26 / iOS 26, a glass card that zooms in -------------- */
dialog.modal--confirm {
  --modal-w: 300px;
}
.modal--confirm .modal__panel {
  background: var(--glass-sheen), var(--mat-thick);
  -webkit-backdrop-filter: var(--mat-filter-strong);
  backdrop-filter: var(--mat-filter-strong);
  text-align: center;
}
.modal--confirm .modal__body {
  padding: 22px 20px 6px !important;
}
.modal--confirm .confirm__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--tone-gradient);
  color: var(--tone-on);
  box-shadow:
    inset 0 0.5px 0 rgb(255 255 255 / 0.35),
    0 2px 6px rgb(0 0 0 / 0.15);
}
.modal--confirm .confirm__icon .icon {
  width: 26px;
  height: 26px;
}
.modal--confirm .modal__title {
  font-size: var(--fs-xl);
}
.modal--confirm .confirm__text {
  color: var(--text-2);
  font-size: var(--type-callout);
}
.modal--confirm .modal__footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 14px 16px 16px;
}
.modal--confirm .modal__footer .btn {
  width: 100%;
  --btn-h: 36px;
  border-radius: var(--radius-full);
}
.modal--confirm .modal__footer .btn--secondary {
  --btn-bg: var(--fill-2);
  --btn-bg-hover: var(--fill-3);
  --btn-border: transparent;
  --btn-shadow: none;
  --btn-fg: var(--text);
}
@media (max-width: 639px) {
  dialog.modal--confirm {
    width: 280px;
    margin: auto;
    border-radius: var(--radius-sheet);
  }
  .modal--confirm .modal__panel {
    border-radius: var(--radius-sheet);
    background: var(--glass-sheen), var(--mat-thick);
    padding-bottom: 0;
  }
  .modal--confirm .sheet-grabber {
    display: none;
  }
  .modal--confirm .modal__footer {
    flex-direction: row;
    background: none;
  }
  .modal--confirm .modal__footer .btn {
    --btn-h: 44px;
  }
  .modal--confirm .modal__footer .btn:not(.btn--primary, .btn--danger) {
    --btn-bg: var(--fill-2);
    --btn-fg: var(--text);
  }
}
@media (prefers-reduced-motion: no-preference) {
  dialog.modal--confirm[open] .modal__panel {
    animation: alert-in 320ms var(--spring-snappy) both;
  }
  dialog.modal--confirm[open].is-closing .modal__panel {
    animation: vt-fade-out 150ms var(--ease-in) both;
  }
}
@keyframes alert-in {
  from {
    opacity: 0;
    transform: scale(1.12);
  }
}

/* Confirm dialog body (base) */
.confirm__icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: var(--tone-soft);
  color: var(--tone-ink);
}
.confirm__text {
  color: var(--text-2);
  font-size: var(--fs-md);
  line-height: 1.5;
}

/* -- Inspector (task panel) — r4 · 10.7 ---------------------------------------------------------
   A floating panel 8px in from the right edge. ≥ 1280px it is docked: non-modal (dialog.show()),
   the board / list stays usable and .app__main makes room for it (Mail's two panes). 768–1279px:
   modal over a light scrim. < 768px: a full-height bottom sheet. */
dialog.drawer {
  position: fixed;
  inset: 8px 8px 8px auto;
  width: var(--inspector-w);
  max-width: calc(100vw - 16px);
  height: auto;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
dialog.drawer::backdrop {
  background: var(--scrim-light);
}
dialog.drawer.drawer--docked {
  z-index: var(--z-inspector);
}
@media (min-width: 1280px) {
  /* Mail's two panes: the content (with its toolbar) gives the inspector its room */
  :root.has-inspector .app__main {
    margin-right: calc(var(--inspector-w) + 16px);
  }
  :root.has-inspector .toast-root,
  :root.has-inspector .toast-root:popover-open {
    right: calc(var(--inspector-w) + 32px);
  }
}
.drawer__panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 0.5px solid var(--glass-border);
  border-radius: var(--radius-panel);
  background: var(--surface-elevated);
  box-shadow: var(--glass-rim), var(--shadow-xl);
  translate: 0 var(--drag-y, 0px);
  transition: translate var(--dur-snappy) var(--spring-snappy);
}
dialog.drawer.is-dragging .drawer__panel {
  transition: none;
}
.drawer__header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 10px 8px 16px;
  background: var(--glass-sheen), var(--mat-chrome);
  -webkit-backdrop-filter: var(--mat-filter);
  backdrop-filter: var(--mat-filter);
  box-shadow: 0 0.5px 0 var(--line-subtle);
}
.drawer__heading {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text-2);
  font-size: var(--fs-md);
}
.drawer__actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}
.drawer__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px 20px 24px;
  overflow: auto;
  overscroll-behavior: contain;
}
.drawer__footer {
  flex-shrink: 0;
  padding: 10px 16px 14px;
  border-top: 0.5px solid var(--line-subtle);
  background: var(--surface-elevated);
}
/* Skeleton drawer (app.js): shown at once while a task panel loads. */
.drawer--skeleton .drawer__body {
  overflow: hidden;
}
.drawer-skeleton {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.drawer-skeleton__title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.drawer-skeleton__title .skeleton--title {
  height: 26px;
}
.drawer-skeleton__props {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 32px;
  padding-bottom: 22px;
  border-bottom: 0.5px solid var(--line);
}
.drawer-skeleton__prop {
  display: flex;
  align-items: center;
  gap: 18px;
}
/* Animations: the specificity is ordered on purpose — closing always wins. A zoom from the card
   (App.motion.zoomFrom, .is-zooming) replaces the slide-in. */
@media (prefers-reduced-motion: no-preference) {
  dialog.drawer[open] .drawer__panel {
    animation: inspector-in var(--dur-smooth) var(--spring-smooth) both;
  }
  dialog.drawer[open]::backdrop {
    animation: fade-in var(--dur-3) ease both;
  }
  dialog.drawer[open]:is(.is-instant, .is-zooming) .drawer__panel,
  dialog.drawer[open].is-instant::backdrop {
    animation: none;
  }
  dialog.drawer[open].is-closing .drawer__panel {
    animation: inspector-out 200ms var(--ease-in) both;
  }
  dialog.drawer[open].is-closing::backdrop {
    animation: vt-fade-out 200ms ease both;
  }
}
@media (prefers-reduced-motion: reduce) {
  dialog.drawer[open] .drawer__panel {
    animation: fade-in 150ms ease both;
  }
  dialog.drawer[open].is-instant .drawer__panel {
    animation: none;
  }
  dialog.drawer[open].is-closing .drawer__panel {
    animation: vt-fade-out 120ms ease both;
  }
}
@keyframes inspector-in {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
}
@keyframes inspector-out {
  to {
    opacity: 0;
    transform: translateX(24px);
  }
}
@media (max-width: 767px) {
  dialog.drawer {
    inset: auto 0 0 0;
    width: 100%;
    max-width: none;
    height: calc(100dvh - var(--safe-top) - 10px);
  }
  dialog.drawer::backdrop {
    background: var(--scrim);
  }
  .drawer__panel {
    border-radius: 32px 32px 0 0;
    padding-bottom: var(--safe-bottom);
  }
  .drawer__header {
    padding-top: 18px;
    padding-left: 16px;
  }
  .drawer__body {
    padding: 16px 16px 28px;
  }
  .drawer-skeleton__props {
    grid-template-columns: minmax(0, 1fr);
  }
}
@media (max-width: 767px) and (prefers-reduced-motion: no-preference) {
  dialog.drawer[open] .drawer__panel {
    animation: sheet-up var(--dur-sheet) var(--spring-sheet) both;
  }
  dialog.drawer[open].is-instant .drawer__panel {
    animation: none;
  }
  dialog.drawer[open].is-closing .drawer__panel {
    animation: sheet-down 220ms var(--ease-in) both;
  }
}

/* -- Toasts — r4 · 10.8: macOS Notification Center banners ---------------------------------------
   Top right under the toolbar (top of the screen on phones, iOS banners). The newest in front,
   older ones peek 10px BELOW it (--i: 0 = front); hover/focus fans the deck out downwards
   (--offset) and pauses every timer (.is-paused); a hairline bar shows the time left. Swipe
   sideways (or up on phones) to dismiss (--swipe-x / --swipe-y from app.js). */
.toast-root {
  position: fixed;
  inset: calc(var(--safe-top) + 64px) max(16px, var(--safe-right)) auto auto;
  z-index: var(--z-overlay);
  width: min(360px, calc(100vw - 32px));
  height: var(--front-h, 0px);
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  background: none;
  color: var(--text);
  pointer-events: none;
}
.toast-root:popover-open {
  inset: calc(var(--safe-top) + 64px) max(16px, var(--safe-right)) auto auto;
  width: min(360px, calc(100vw - 32px));
}
.toast-root:has(> .toast:not(.is-leaving)) {
  pointer-events: auto;
}
.toast-root:is(:hover, :focus-within) {
  height: var(--deck-h, 0px);
}
@media (max-width: 767px) {
  .toast-root,
  .toast-root:popover-open {
    inset: calc(var(--safe-top) + 8px) max(8px, var(--safe-right)) auto max(8px, var(--safe-left));
    width: auto;
  }
}
.toast {
  --deck-y: calc(var(--i, 0) * 10px);
  --deck-scale: calc(1 - var(--i, 0) * 0.045);
  --toast-tone: var(--c-blue);
  position: absolute;
  top: 0;
  right: 0;
  bottom: auto;
  z-index: calc(10 - var(--i, 0));
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: var(--h, auto);
  min-height: 56px;
  padding: 12px 10px 12px 12px;
  overflow: hidden;
  border: 0.5px solid var(--glass-border);
  border-radius: 18px;
  background: var(--glass-sheen), var(--mat-regular);
  -webkit-backdrop-filter: var(--mat-filter-strong);
  backdrop-filter: var(--mat-filter-strong);
  box-shadow: var(--glass-rim), var(--shadow-lg);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  pointer-events: auto;
  touch-action: pan-y;
  user-select: none;
  transform: translate(var(--swipe-x, 0px), calc(var(--deck-y) + var(--swipe-y, 0px))) scale(var(--deck-scale));
  transform-origin: 50% 0;
  transition:
    transform var(--dur-3) var(--ease-out),
    opacity var(--dur-2) ease;
}
.toast > * {
  transition: opacity var(--dur-2) ease;
}
.toast.is-behind {
  box-shadow: var(--glass-rim), var(--shadow-md);
}
.toast-root:not(:hover, :focus-within) .toast.is-behind {
  height: var(--front-h, auto);
}
.toast-root:not(:hover, :focus-within) .toast.is-behind > * {
  opacity: 0;
}
.toast-root.is-measuring .toast {
  height: auto !important;
  transition: none !important;
}
.toast-root:is(:hover, :focus-within) .toast {
  transform: translate(var(--swipe-x, 0px), calc(var(--offset, 0px) + var(--swipe-y, 0px))) scale(1);
}
@media (prefers-reduced-motion: no-preference) {
  @starting-style {
    .toast {
      opacity: 0;
      transform: translateX(calc(100% + 24px));
    }
  }
  .toast {
    transition:
      transform var(--dur-sheet) var(--spring-sheet),
      height var(--dur-3) var(--ease-out),
      opacity var(--dur-2) ease;
  }
}
.toast.is-swiping {
  cursor: grabbing;
  transition: none;
}
/* Leaving: desktop — off to the right; phones — up (the deck is at the top now) */
.toast.is-leaving {
  opacity: 0;
  pointer-events: none;
  transform: translate(calc(var(--swipe-x, 0px) + 24px), calc(var(--deck-y) + var(--swipe-y, 0px))) scale(var(--deck-scale));
  transition:
    transform var(--dur-2) var(--ease-in),
    opacity var(--dur-2) ease;
}
.toast.is-swiped {
  transform: translate(var(--swipe-x, 0px), calc(var(--deck-y) + var(--swipe-y, 0px))) scale(var(--deck-scale));
}
@media (max-width: 767px) {
  .toast {
    border-radius: 22px;
    touch-action: none; /* with pan-y the browser would take the upward swipe */
  }
  .toast.is-leaving {
    transform: translate(var(--swipe-x, 0px), calc(var(--deck-y) - 14px + var(--swipe-y, 0px))) scale(calc(var(--deck-scale) - 0.04));
  }
  .toast.is-swiped {
    transform: translate(var(--swipe-x, 0px), calc(var(--deck-y) + var(--swipe-y, 0px))) scale(var(--deck-scale));
  }
  @media (prefers-reduced-motion: no-preference) {
    @starting-style {
      .toast {
        opacity: 0;
        transform: translateY(calc(-100% - 16px)) scale(0.96);
      }
    }
  }
}
.toast__icon {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(180deg, color-mix(in oklab, var(--toast-tone) 78%, white), var(--toast-tone));
  box-shadow: inset 0 0.5px 0 rgb(255 255 255 / 0.3);
  color: var(--text-on-accent);
}
.toast__icon .icon {
  width: 17px;
  height: 17px;
}
.toast--success { --toast-tone: var(--c-green); }
.toast--info { --toast-tone: var(--c-blue); }
.toast--warning { --toast-tone: var(--c-orange); }
.toast--error { --toast-tone: var(--c-red); }
.toast__message {
  flex: 1;
  min-width: 0;
  padding-block: 2px;
  line-height: 1.35;
  text-wrap: pretty;
}
/* The same message shown again: "×3" next to the text (App.toast counts repeats). */
.toast__count {
  flex-shrink: 0;
  min-width: 26px;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: var(--fill-2);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  text-align: center;
}
@media (prefers-reduced-motion: no-preference) {
  .toast.is-bumped .toast__count {
    animation: toast-count-bump var(--dur-2) var(--ease-spring);
  }
}
@keyframes toast-count-bump {
  from {
    scale: 1.35;
  }
}
/* The action: a small tinted capsule (.btn--sm.btn--tinted look) */
.toast__action {
  flex-shrink: 0;
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition:
    background-color var(--dur-1) ease,
    transform var(--dur-1) var(--ease-out);
}
.toast__action:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.toast__action:active,
.toast__close:active {
  transform: scale(0.94);
}
.toast__close {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  transition:
    background-color var(--dur-1) ease,
    color var(--dur-1) ease,
    opacity var(--dur-1) ease,
    transform var(--dur-1) var(--ease-out);
}
.toast__close:hover {
  background: var(--fill-1);
  color: var(--text);
}
/* macOS: the ✕ shows on hover only, as a small glass disc over the top-left corner. */
@media (hover: hover) and (pointer: fine) {
  .toast__close {
    position: absolute;
    top: 3px;
    left: 3px;
    z-index: 1;
    width: 20px;
    height: 20px;
    border: 0.5px solid var(--glass-border);
    background: var(--surface-elevated);
    box-shadow: var(--shadow-sm);
    color: var(--text-2);
    opacity: 0;
  }
  .toast__close .icon {
    width: 11px;
    height: 11px;
  }
  .toast__close:hover {
    background: var(--surface-elevated);
    color: var(--text);
  }
  .toast:is(:hover, :focus-within) .toast__close {
    opacity: 1;
  }
}
@media (pointer: coarse) {
  .toast__close {
    width: 36px;
    height: 36px;
  }
}
.toast__progress {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--toast-tone, var(--accent));
  opacity: 0.45;
  transform-origin: left center;
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .toast__progress {
    animation: toast-progress var(--toast-duration, 4s) linear forwards;
  }
  .toast-root.is-paused .toast__progress {
    animation-play-state: paused;
  }
}
@media (prefers-reduced-motion: reduce) {
  .toast__progress {
    display: none;
  }
}
@keyframes toast-progress {
  to {
    transform: scaleX(0);
  }
}

/* -- Keyboard shortcut sheet — r4 · 10.11 -------------------------------------------------------- */
.shortcuts__search {
  margin-bottom: 16px;
}
.shortcuts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 20px 32px;
}
.shortcuts__group[hidden],
.shortcuts__row[hidden] {
  display: none;
}
.shortcuts__group h3 {
  margin-bottom: 4px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.shortcuts__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  box-shadow: inset 0 -0.5px 0 var(--line);
  font-size: var(--fs-md);
}
.shortcuts__row:last-child {
  box-shadow: none;
}
.shortcuts__row .kbd-combo {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 3px;
}

/* -- Spotlight (⌘K, dashboard/palette.html) — r4 · 10.9 -----------------------------------------
   The palette's base layout lives in insights.css; .spotlight lifts it to macOS Spotlight: a glass
   slab 16vh from the top over a light scrim, 56px search row with 22px text, accent selection. */
dialog.palette.spotlight {
  padding: 16vh 16px 16px;
}
dialog.palette.spotlight::backdrop {
  background: var(--scrim-light);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.spotlight .palette__panel {
  width: min(680px, 100%);
  max-height: min(620px, 100%);
  border: 0.5px solid var(--glass-border);
  border-radius: 26px;
  background: var(--glass-sheen), var(--mat-thick);
  -webkit-backdrop-filter: var(--mat-filter-strong);
  backdrop-filter: var(--mat-filter-strong);
  box-shadow: var(--glass-rim), var(--shadow-xl);
  filter: none;
  transition:
    opacity 220ms var(--ease-out),
    transform 220ms var(--ease-out),
    filter 220ms var(--ease-out);
}
@media (prefers-reduced-motion: no-preference) {
  @starting-style {
    dialog.palette.spotlight[open] .palette__panel {
      opacity: 0;
      transform: scale(0.96);
      filter: blur(6px);
    }
  }
}
dialog.palette.spotlight.is-closing .palette__panel {
  opacity: 0;
  transform: none;
  transition: opacity 140ms var(--ease-in);
}
.spotlight .palette__search {
  height: 56px;
  gap: 12px;
  padding: 0 14px 0 18px;
  border-bottom: 0.5px solid var(--line);
}
.spotlight .palette__search-icon {
  width: 22px;
  height: 22px;
}
.spotlight .palette__input {
  font-size: calc(1.375rem * var(--text-scale, 1));
  font-weight: var(--fw-regular);
  letter-spacing: var(--tracking-snug);
}
.spotlight .palette__label {
  padding: 8px 10px 4px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.spotlight .palette__item {
  min-height: 40px;
  border-radius: 12px;
}
.spotlight .palette__item.is-active {
  background: var(--selection-bg);
  color: var(--selection-fg);
}
.spotlight .palette__item.is-active :is(.palette__sub, .palette__meta, .palette__kbd, .palette__icon--task, .task-key, mark) {
  color: inherit;
}
.spotlight .palette__item.is-active mark {
  background: rgb(255 255 255 / 0.25);
}
.spotlight .palette__item.is-active::after {
  background: rgb(255 255 255 / 0.22);
  box-shadow: none;
  color: inherit;
}
.spotlight .palette__icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}
.spotlight .palette__title {
  font-size: var(--fs-md);
}
.spotlight .palette__sub {
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.spotlight .palette__footer {
  border-top: 0.5px solid var(--line);
}
@media (min-width: 1024px) and (hover: hover) {
  .spotlight .palette__panel {
    width: min(900px, 100%);
  }
  .spotlight .palette__main {
    grid-template-columns: minmax(0, 1fr) 40%;
  }
  .spotlight .palette__preview {
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 8px 8px 8px 0;
    padding: 18px;
    overflow-y: auto;
    border: 0;
    border-radius: 16px;
    background: var(--fill-1);
  }
}
/* Phones: a full-screen sheet on --bg — an iOS search field + "Cancel", results in inset groups. */
@media (max-width: 639px) {
  dialog.palette.spotlight {
    padding: 0;
  }
  .spotlight .palette__panel {
    width: 100%;
    height: 100%;
    max-height: none;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    border: 0;
    border-radius: 0;
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
  }
  @media (prefers-reduced-motion: no-preference) {
    @starting-style {
      dialog.palette.spotlight[open] .palette__panel {
        opacity: 0;
        transform: translateY(24px);
        filter: none;
      }
    }
  }
  .spotlight .palette__search {
    position: relative;
    height: 56px;
    gap: 10px;
    padding: 0 12px 0 16px;
    border-bottom: 0;
  }
  .spotlight .palette__search-icon {
    position: absolute;
    left: 25px;
    z-index: 1;
    width: 17px;
    height: 17px;
    color: var(--text-3);
    pointer-events: none;
  }
  .spotlight .palette__input {
    height: 36px;
    padding: 0 34px 0 32px;
    border-radius: 10px;
    background: var(--fill-2);
    font-size: max(16px, var(--type-body));
    letter-spacing: 0;
  }
  .spotlight .palette__busy {
    position: absolute;
    right: calc(12px + 70px);
  }
  .spotlight .palette__close {
    color: var(--accent-ink);
    font-size: var(--type-body);
  }
  .spotlight .palette__list {
    padding: 4px 16px 16px;
  }
  .spotlight .palette__section {
    margin-top: 12px;
  }
  .spotlight .palette__label {
    padding: 6px 16px;
    font-size: var(--type-footnote);
    font-weight: var(--fw-regular);
  }
  .spotlight .palette__section > :not(.palette__label, .palette__item) {
    background: var(--surface);
  }
  /* Touch lists don't wear the accent selection (iOS): a quiet pressed fill instead. */
  .spotlight .palette__item.is-active {
    background: var(--fill-2);
    color: var(--text);
  }
  .spotlight .palette__item.is-active :is(.palette__sub, .palette__meta) {
    color: var(--text-3);
  }
  .spotlight .palette__item.is-active .palette__icon--task:not(.is-done) {
    color: var(--text-3);
  }
  .spotlight .palette__item.is-active .task-key {
    color: var(--text-2);
  }
  .spotlight .palette__item {
    min-height: 48px;
    padding: 6px 16px;
    border-radius: 0;
    background: var(--surface);
  }
  .spotlight .palette__item + .palette__item {
    box-shadow: inset 52px 0.5px 0 -52px var(--line);
  }
  .spotlight .palette__label + .palette__item,
  .spotlight .palette__label + * > .palette__item:first-child {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
  }
  .spotlight .palette__item:last-child {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
  }
}

/* -- Lightbox (chat media) — r4 · 10.12: a dark glass frame, glass controls ---------------------- */
dialog.lightbox {
  background: rgb(0 0 0 / 0.92);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
dialog.lightbox .lightbox__btn {
  border: 0.5px solid rgb(255 255 255 / 0.18);
  background: rgb(255 255 255 / 0.12);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  box-shadow: inset 0 0.5px 0 rgb(255 255 255 / 0.25);
  color: var(--text-on-accent);
}
dialog.lightbox .lightbox__btn:hover {
  background: rgb(255 255 255 / 0.22);
}
:root[data-transparency="reduced"] dialog.lightbox {
  background: rgb(0 0 0);
}

/* -- Motion ghost (App.motion.zoomFrom, r4 · 7.7) ------------------------------------------------- */
.motion-ghost {
  position: fixed;
  inset: auto;
  margin: 0;
  padding: 0;
  border: 0;
  transform-origin: 0 0;
  border-radius: var(--radius-panel);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-xl);
  pointer-events: none;
  overflow: hidden;
}
