/* PRISM dialog and sheet (WP06; boards A24, A25; export Dialog and Overlays).
   Native <dialog> opened with showModal() by js/prism/dialog.js. The same
   classes style the static reference markup (div.pr-dialog, div.pr-sheet).
   Motion: enter --pr-dur-base fade and 8px rise with --pr-ease-enter, leave
   --pr-dur-fast with --pr-ease-exit; a sheet rises from the bottom; nothing
   moves under reduced motion. */

.pr-dialog {
  box-sizing: border-box;
  width: 480px;
  max-width: calc(100vw - 2 * var(--pr-space-lg));
  border-radius: var(--pr-radius-lg);
  background: var(--pr-surface-card);
  border: 1px solid var(--pr-border-strong);
  box-shadow: var(--pr-shadow-overlay);
  padding: var(--pr-space-xl);
  display: grid;
  gap: var(--pr-space-lg);
  color: var(--pr-text-primary);
  font: var(--text-pr-body);
}
.pr-dialog--sm { width: 360px; }
.pr-dialog--lg { width: 720px; }

/* The native element: reset the user-agent box, keep it hidden until open. */
dialog.pr-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  max-height: calc(100dvh - 2 * var(--pr-space-xl));
  overflow: auto;
  z-index: var(--pr-z-dialog);
}
dialog.pr-dialog:not([open]) { display: none; }
dialog.pr-dialog[open] { animation: pr-dialog-in var(--pr-dur-base) var(--pr-ease-enter); }
dialog.pr-dialog.is-closing {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--pr-dur-fast) var(--pr-ease-exit), transform var(--pr-dur-fast) var(--pr-ease-exit);
}
dialog.pr-dialog::backdrop {
  background: var(--pr-scrim);
  animation: pr-dialog-fade var(--pr-dur-base) var(--pr-ease-enter);
}
dialog.pr-dialog.is-busy { cursor: progress; }

@keyframes pr-dialog-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes pr-dialog-fade { from { opacity: 0; } }
@keyframes pr-sheet-in { from { transform: translateY(100%); } }

.pr-dialog__head { display: flex; align-items: center; gap: var(--pr-space-sm); min-width: 0; }
.pr-dialog__t { margin: 0; font: var(--text-pr-heading-lg); color: var(--pr-text-primary); overflow-wrap: anywhere; }
.pr-dialog--sheet .pr-dialog__t,
.pr-dialog--full .pr-dialog__t { font: var(--text-pr-heading-md); }

.pr-dialog__body {
  display: grid;
  gap: 10px;
  font: var(--text-pr-body-sm);
  color: var(--pr-text-secondary);
  overflow-wrap: anywhere;
}
.pr-dialog__body p { margin: 0; }
.pr-dialog__strong { color: var(--pr-text-primary); font-weight: 600; }
.pr-dialog__list { margin: 0; padding-left: 18px; display: grid; gap: var(--pr-space-xs); }
.pr-dialog__list b { color: var(--pr-text-primary); }
.pr-dialog__list .is-rejected { color: var(--pr-danger-text); }

/* Typed confirmation (level 3). The field look comes from components/field.css. */
.pr-dialog__typed { display: grid; gap: var(--pr-space-xs); margin-top: var(--pr-space-xs); }
.pr-dialog__typed input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: var(--text-pr-body-sm);
}

/* Checklist (level 4). A real checkbox sits over the drawn box. */
.pr-dialog__checks { border: 0; margin: 0; padding: 0; display: grid; gap: 0; min-width: 0; }
.pr-dialog__legend {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.pr-dialog__check {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 36px;
  padding: var(--pr-space-xs) 0;
  color: var(--pr-text-primary);
  cursor: pointer;
}
.pr-dialog__check .pr-check { flex: none; margin-top: 2px; }
.pr-dialog__check .pr-check:not(.is-on) .pr-g { visibility: hidden; }
.pr-dialog__cb {
  position: absolute;
  left: 0;
  top: var(--pr-space-xs);
  width: 20px;
  height: 20px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.pr-dialog__cb:focus-visible + .pr-check {
  outline: var(--pr-border-focus) solid var(--pr-focus-ring);
  outline-offset: var(--pr-border-focus);
}

.pr-dialog__err { margin: 0; }
.pr-dialog__err[hidden] { display: none; }

.pr-dialog__foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--pr-space-sm); }

/* ---------- sheets (768px and below) ---------- */

.pr-sheet,
dialog.pr-dialog--sheet {
  box-sizing: border-box;
  background: var(--pr-surface-card);
  border-radius: var(--pr-radius-lg) var(--pr-radius-lg) 0 0;
  border: 1px solid var(--pr-border-strong);
  border-bottom: 0;
  box-shadow: var(--pr-shadow-overlay);
  padding: var(--pr-space-sm) var(--pr-space-lg) calc(var(--pr-space-lg) + env(safe-area-inset-bottom));
  display: grid;
  gap: var(--pr-space-md);
}
dialog.pr-dialog--sheet {
  width: 100%;
  max-width: 100%;
  margin: auto 0 0;
  max-height: 90dvh;
}
dialog.pr-dialog--sheet[open] { animation: pr-sheet-in var(--pr-dur-base) var(--pr-ease-enter); }
dialog.pr-dialog--sheet.is-closing { transform: translateY(100%); opacity: 1; }
.pr-sheet__grab {
  width: 36px;
  height: 4px;
  border-radius: 4px;
  background: var(--pr-border-control);
  justify-self: center;
}

/* Full-height sheet with a top bar: more than three actions, or a long form. */
dialog.pr-dialog--full {
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 0 0 env(safe-area-inset-bottom);
  grid-template-rows: auto 1fr auto;
  gap: 0;
}
dialog.pr-dialog--full[open] { animation: pr-sheet-in var(--pr-dur-base) var(--pr-ease-enter); }
dialog.pr-dialog--full .pr-dialog__head {
  position: sticky;
  top: 0;
  min-height: 56px;
  padding: 0 var(--pr-space-xs) 0 var(--pr-space-lg);
  background: var(--pr-surface-card);
  border-bottom: 1px solid var(--pr-border-subtle);
}
dialog.pr-dialog--full .pr-dialog__head .pr-btn--icon { margin-left: calc(-1 * var(--pr-space-sm)); }
dialog.pr-dialog--full .pr-dialog__body { padding: var(--pr-space-lg); align-content: start; overflow: auto; }
dialog.pr-dialog--full .pr-dialog__err { margin: 0 var(--pr-space-lg) var(--pr-space-md); }
dialog.pr-dialog--full .pr-dialog__foot {
  padding: var(--pr-space-md) var(--pr-space-lg);
  border-top: 1px solid var(--pr-border-subtle);
}

.pr-scrim { background: var(--pr-scrim); padding: var(--pr-space-xl); display: grid; place-items: center; }

@media (max-width: 768px) {
  .pr-dialog__foot { flex-direction: column-reverse; }
  .pr-dialog__foot .pr-btn { width: 100%; }
  .pr-dialog__typed input { font: var(--text-pr-body); }   /* 16px stops iOS zoom */
  .pr-dialog__check { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  dialog.pr-dialog[open],
  dialog.pr-dialog::backdrop,
  dialog.pr-dialog--sheet[open],
  dialog.pr-dialog--full[open] { animation: none; }
  dialog.pr-dialog.is-closing { transition: none; }
}
