/* ==========================================================================
   .tp-modal — P1.F2.T3
   ©2026 Vexstorm Studios – All Rights Reserved

   Works two ways, because the product needs both: as a native <dialog> (the
   duplicate-match dialog in P3.F3.T2, which wants the platform's own top-layer
   and inert-background behaviour) and as an ARIA-labelled container for the
   cases where a <dialog> is not available.

   Variants   --small  --large  --danger
   Elements   __backdrop  __dialog  __header  __title  __close  __body  __footer
   States     .tp-is-open  :focus-visible  :disabled

   Focus trapping is JavaScript's job, not CSS's — this file traps nothing and
   claims nothing. What it does guarantee is that the dialog respects
   --tp-z-modal, never exceeds the viewport, and scrolls its own body rather
   than the page behind it.
   ========================================================================== */

.tp-modal {
  position: fixed;
  inset: 0;
  z-index: var(--tp-z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--tp-space-4);
}

/* Set by JavaScript when the modal opens. Never authored into a template: a
   modal that is open in the served HTML is a modal that appears before the
   page has finished loading. */
.tp-modal.tp-is-open {
  display: flex;
}

/* --------------------------------------------------------------------------
   Backdrop
   -------------------------------------------------------------------------- */

.tp-modal__backdrop {
  position: absolute;
  inset: 0;
  background-color: var(--tp-color-surface-inverse);
  opacity: var(--tp-opacity-scrim);
}

/* The native <dialog> equivalent, so the same visual result is reached whether
   the dialog is in the top layer or not. */
.tp-modal__dialog::backdrop {
  background-color: var(--tp-color-surface-inverse);
  opacity: var(--tp-opacity-scrim);
}

/* --------------------------------------------------------------------------
   Dialog
   -------------------------------------------------------------------------- */

.tp-modal__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--tp-space-prose-max);
  /* Never taller than the viewport, so the footer's buttons are always
     reachable. The body scrolls; the dialog does not. */
  max-height: calc(100vh - var(--tp-space-8));
  max-height: calc(100dvh - var(--tp-space-8));
  padding: 0;
  border: var(--tp-border-width-hairline) solid var(--tp-color-border-subtle);
  border-radius: var(--tp-radius-lg);
  background-color: var(--tp-color-surface-overlay);
  color: var(--tp-color-text-primary);
  box-shadow: var(--tp-shadow-lg);
  animation: tp-modal-enter var(--tp-motion-duration-slow)
    var(--tp-motion-ease-emphasized);
}

.tp-modal--small .tp-modal__dialog {
  max-width: var(--tp-space-sidebar-width);
}

.tp-modal--large .tp-modal__dialog {
  max-width: var(--tp-space-container-max);
}

/* A destructive confirmation. The rail is reinforcement; the dialog's title
   and its primary button both say what will be destroyed. */
.tp-modal--danger .tp-modal__dialog {
  border-block-start: var(--tp-border-width-thick) solid
    var(--tp-color-state-danger);
}

/* --------------------------------------------------------------------------
   Regions
   -------------------------------------------------------------------------- */

.tp-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--tp-space-4);
  padding: var(--tp-space-5) var(--tp-space-6);
  border-bottom: var(--tp-border-width-hairline) solid var(--tp-color-border-subtle);
}

/* Referenced by the dialog's aria-labelledby — the dialog's accessible name. */
.tp-modal__title {
  min-width: 0;
  color: var(--tp-color-text-primary);
  font-size: var(--tp-text-lg);
  font-weight: var(--tp-weight-bold);
  line-height: var(--tp-leading-tight);
  overflow-wrap: break-word;
}

.tp-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--tp-space-7);
  height: var(--tp-space-7);
  min-width: var(--tp-space-target-min);
  min-height: var(--tp-space-target-min);
  border-radius: var(--tp-radius-md);
  color: var(--tp-color-text-muted);
  cursor: pointer;
}

.tp-modal__close:hover {
  background-color: var(--tp-color-surface-sunken);
  color: var(--tp-color-text-primary);
}

.tp-modal__close:active {
  background-color: var(--tp-color-accent-subtle);
}

.tp-modal__close:disabled {
  opacity: var(--tp-opacity-disabled);
  cursor: not-allowed;
}

.tp-modal__close:focus-visible {
  outline-offset: 0;
}

.tp-modal__close-icon {
  width: var(--tp-space-icon-lg);
  height: var(--tp-space-icon-lg);
}

.tp-modal__body {
  padding: var(--tp-space-6);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}

.tp-modal__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--tp-space-2);
  padding: var(--tp-space-4) var(--tp-space-6);
  border-top: var(--tp-border-width-hairline) solid var(--tp-color-border-subtle);
  background-color: var(--tp-color-surface-sunken);
  border-end-start-radius: var(--tp-radius-lg);
  border-end-end-radius: var(--tp-radius-lg);
}

/* --------------------------------------------------------------------------
   Entry animation — disabled wholesale by the reduced-motion block in
   utilities.css (ACC-005). The modal still appears; it simply appears at once.
   -------------------------------------------------------------------------- */

@keyframes tp-modal-enter {
  from {
    opacity: 0;
    transform: translateY(var(--tp-space-3));
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
