/* Dialog — see components/ui/Dialog.tsx. Its header is the Panel Header
   (panel-header.css), its scrim the Drawer's (.drawer-scrim). Padding 24
   all round, minimal 16 (--panel-pad, also read by the Panel Header).
   .dialog-layer covers the screen; .dialog-place centers the panel and
   keeps 24 around it. Panel = Panel Header + .dialog-body + .dialog-actions:
   when it's taller than the screen the header and actions stay put and only
   the body scrolls (scroll-fade.css masks its edges; Santiago, 2026-10-09). */

@layer components {
  .dialog-layer { position: fixed; inset: 0; z-index: 40; }
  .dialog-place {
    position: absolute; inset: 0; z-index: 41;
    display: grid; place-items: center; padding: var(--space-24);
    pointer-events: none; /* the scrim behind still takes the click-outside */
  }
  .dialog-place > * { pointer-events: auto; }

  .dialog {
    --panel-pad: var(--space-24);
    display: flex; flex-direction: column;
    width: min(480px, 100%); max-height: calc(100vh - 2 * var(--space-24)); box-sizing: border-box;
    background-color: var(--n5); border-radius: var(--radius-16); box-shadow: var(--shadow-2); /* every panel sits on n5 (2026-10-15); was n0 */
    overflow: hidden; outline: none;
  }
  .dialog-body { display: flex; flex-direction: column; flex: 0 1 auto; min-height: 0; overflow-y: auto; padding: 0 var(--panel-pad); }
  .dialog-body > * { flex-shrink: 0; }
  .dialog-body:last-child { padding-bottom: var(--panel-pad); } /* no actions */
  /* Everything between the header and the buttons sits in .dialog-content,
     which has 12 above and below, so nothing sits right under the header
     (Santiago, 2026-10-08). The pieces inside carry no padding of their own;
     the content spaces them 12 apart. */
  .dialog-content { display: flex; flex-direction: column; gap: var(--space-12); padding: var(--space-12) 0; font: var(--body-m); letter-spacing: var(--body-m-ls); color: var(--n130); }
  .dialog-content > * { margin: 0; }
  .dialog-actions { flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-8); padding: var(--space-12) var(--panel-pad) var(--panel-pad); }

  /* Minimal (confirmations): no header; padding 16; as wide as its
     message needs, up to 320; everything centered (Santiago, 2026-10-08). */
  .dialog--minimal { --panel-pad: var(--space-16); width: auto; max-width: min(320px, 100%); }
  .dialog--minimal > :first-child { padding-top: var(--panel-pad); }
  .dialog--minimal .dialog-content { align-items: center; text-align: center; }
  .dialog--minimal .dialog-actions { justify-content: center; }

  /* Stacked panels (rule: /kit/stacked-rule, 2026-10-15): a dialog opened
     over an open dialog makes the one under it step back — 16 up, 96%, a
     touch darker — as a drawer under a drawer does (drawer.css). A dialog
     over a drawer makes the drawer step back in place. The front layer's
     scrim only catches the click; it adds no second dimming. */
  .dialog-layer .dialog { transition: transform var(--dur-320) var(--ease-out), filter var(--dur-320) var(--ease-fade); }
  .dialog-layer.is-open:has(~ .dialog-layer.is-open) .dialog { transform: translateY(calc(-1 * var(--space-16))) scale(0.96); filter: brightness(0.94); }
  .dialog-layer.is-open ~ .dialog-layer .drawer-scrim,
  body:has(.drawer-layer.is-open) .dialog-layer .drawer-scrim { --scrim: transparent; }
  body:has(> .dialog-layer.is-open) :is(.drawer-layer.is-open:not(.is-stacked) .drawer:not(.drawer--top), .drawer-layer.is-stacked .drawer--top) { transform: scale(0.96); filter: brightness(0.94); }

  /* Reduced motion: the step-back (here and under a drawer) happens without a glide. */
  @media (prefers-reduced-motion: reduce) {
    .dialog-layer .dialog { transition: none; }
    body:has(> .dialog-layer.is-open) :is(.drawer-layer .drawer) { transition: none; }
  }

  @media (prefers-reduced-motion: no-preference) {
    .dialog-layer .dialog { animation: dialog-in var(--dur-240) var(--ease-out); }
    @keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
  }
}
