/* =============================================================================
   Unified Modal Shell
   Single source for the shared .modal lifecycle host used by all customer
   modals (prepare-to-ship, increase-bid, address, confirm). Content-specific
   rules live with their own feature CSS; only the generic shell + size
   variants belong here.

   The host node (modal-system.js) carries `luna modal` itself, so rules match
   `.luna.modal` (compound): in wp-admin there is no body.luna ancestor and the
   host is the token root.
   ============================================================================= */

.luna.modal {
    --modal-width: 32.5rem;
    --modal-scrim: rgba(6, 8, 15, 0.85);
    /* Deeper than --shadow-card: the dialog floats over a scrim, not a page. */
    --modal-shadow: 0 var(--space-xl) var(--space-3xl) rgba(0, 0, 0, 0.85);
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    align-items: center;
    justify-content: center;
    background-color: var(--modal-scrim);
    padding: 0 var(--space-lg);
    overflow-y: auto;
}

.luna.modal .modal-content {
    width: min(var(--modal-width), calc(100vw - 2 * var(--space-xl)));
    max-height: calc(100vh - 2 * var(--space-xl));
    /* dvh tracks the iOS Safari toolbar; vh line above is the fallback */
    max-height: calc(100dvh - 2 * var(--space-xl));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--body-text);
    box-shadow: var(--modal-shadow);
}

.luna.modal .modal-header {
    padding: var(--space-lg);
    background: var(--surface-strong);
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space);
}

.luna.modal .modal-header h3 {
    margin: 0;
}

.luna.modal .modal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    scroll-behavior: smooth;
}

.luna.modal .modal-close {
    font-size: var(--font-size-xl);
    line-height: 1;
    color: var(--body-text);
    cursor: pointer;
    /* reset UA/theme <button> chrome so a <button> close matches a <span> one */
    -webkit-appearance: none;
    appearance: none;
    border: none;
    box-shadow: none;
    padding: 0;
    min-width: var(--field-height);
    min-height: var(--field-height);
}

.luna.modal .modal-close:hover {
    color: var(--accent);
}

.luna.modal .modal-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.luna.modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space);
    padding: var(--space-lg);
    border-top: 1px solid var(--border-soft);
    margin-top: 0;
}

/* -----------------------------------------------------------------------------
   Size variants
   ----------------------------------------------------------------------------- */

/* Prepare-to-Ship: wide (customs form). */
.luna.modal.modal--pts {
    --modal-width: 57.5rem;
}

/* Confirm + increase-bid: compact centered dialogs. */
.luna.modal.modal--confirm {
    --modal-width: 27.5rem;
}

.luna.modal.modal--increase-bid {
    --modal-width: 26.25rem;
}

.luna.modal.modal--confirm .modal-body {
    font-size: var(--font-size-md);
    line-height: 1.5;
}

/* Photo viewer (photo-viewer.js): the photo fills the viewport. */
.luna.modal.modal--viewer {
    --modal-width: 90vw;
}

.luna.modal.modal--viewer .modal-content {
    height: calc(100dvh - 2 * var(--space-xl));
}

.luna.modal .photo-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.luna.modal .photo-viewer__stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space);
}

.luna.modal .photo-viewer__image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.luna.modal .photo-viewer__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: calc(var(--field-height) * 1.5);
    height: calc(var(--field-height) * 2);
    border: 0;
    border-radius: var(--radius-md);
    background: var(--modal-scrim);
    color: var(--heading);
    font-size: var(--font-size-xl);
    cursor: pointer;
}

.luna.modal .photo-viewer__nav:hover {
    color: var(--accent);
}

.luna.modal .photo-viewer__nav[data-viewer-step="-1"] {
    left: var(--space);
}

.luna.modal .photo-viewer__nav[data-viewer-step="1"] {
    right: var(--space);
}

/* Phones: the dialog takes the whole viewport. */
@media (max-width: 768px) {
    .luna.modal {
        align-items: stretch;
        padding: 0;
    }

    .luna.modal .modal-content,
    .luna.modal.modal--viewer .modal-content {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
    }
}
