/* [srdss_modal] — enqueued by the shortcode when it renders.
 *
 * Every value a setting can change is read with this file's own default as
 * the var() fallback, so a blank setting declares nothing and the default
 * renders. A site styles one modal by redeclaring the variables on its class:
 *
 *     .srd-modal.booking { --srd-modal-max-width: 900px; }
 *
 * The backdrop and Full Screen Below are written by srdss_modal_css() from
 * PHP — see the comments there for why. */

/* The <dialog> is a transparent frame; .srd-modal__box is the modal. No
   padding on the frame, so a click whose target is the dialog itself was
   outside the box — that is how the backdrop click is detected. */
.srd-modal {
    box-sizing: border-box;
    width: calc(100% - 32px);
    max-width: var(--srd-modal-max-width, 560px);
    max-height: none;
    margin: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--srd-modal-text, inherit);
    overflow: visible;
}

.srd-modal::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.srd-modal__box {
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    max-height: var(--srd-modal-max-height, calc(100vh - 32px));
    padding: var(--srd-modal-padding, 32px);
    background: var(--srd-modal-bg, #ffffff);
    border-width: var(--srd-modal-border-width, 0);
    border-style: var(--srd-modal-border-style, solid);
    border-color: var(--srd-modal-border-color, #e0e0e0);
    border-radius: var(--srd-modal-border-radius, 8px);
    box-shadow: var(--srd-modal-box-shadow, 0 20px 50px rgba(0, 0, 0, 0.25));
}

/* The body scrolls, not the box, so the close button stays put on a long
   modal. min-height: 0 lets a flex child shrink below its content. */
.srd-modal__body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.srd-modal__body > :first-child { margin-top: 0; }
.srd-modal__body > :last-child  { margin-bottom: 0; }

.srd-modal__title {
    margin: 0 0 16px;
    padding-right: 32px; /* clear of the close button */
}

/* ------------------------------------------------------------------ close */

.srd-modal__close {
    appearance: none;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--srd-modal-close-color, currentColor);
    cursor: pointer;
    line-height: 1;
}

.srd-modal__close svg {
    display: block;
    width: 20px;
    height: 20px;
}

.srd-modal__close:hover {
    background: rgba(127, 127, 127, 0.15);
}

.srd-modal__close:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Outside: above the box's top-right corner, over the backdrop. The frame
   takes 44px of padding to make room, and the box gives the same 44px back
   out of its max height, or a tall modal would push the button off screen. */
.srd-modal-close-outside {
    padding-top: 44px;
}

.srd-modal-close-outside .srd-modal__box {
    max-height: calc(var(--srd-modal-max-height, 100vh - 32px) - 44px);
}

.srd-modal-close-outside .srd-modal__close {
    top: -44px;
    right: 0;
    color: var(--srd-modal-close-color, #ffffff);
}

/* -------------------------------------------------------------- animation */

/* The frame animates rather than the box, so an outside close button moves
   with the modal. Closing runs a separate "out" animation, not the "in" one
   reversed — changing only animation-direction does not restart an animation
   that has already finished. modal.js waits for its duration, then closes. */

@keyframes srd-modal-in-fade      { from { opacity: 0; } }
@keyframes srd-modal-out-fade     { to   { opacity: 0; } }
@keyframes srd-modal-in-zoom      { from { opacity: 0; transform: scale(0.94); } }
@keyframes srd-modal-out-zoom     { to   { opacity: 0; transform: scale(0.94); } }
@keyframes srd-modal-in-slide-up  { from { opacity: 0; transform: translateY(24px); } }
@keyframes srd-modal-out-slide-up { to   { opacity: 0; transform: translateY(24px); } }

.srd-modal-anim-fade[open]     { animation: srd-modal-in-fade var(--srd-modal-duration, 200ms) ease-out; }
.srd-modal-anim-zoom[open]     { animation: srd-modal-in-zoom var(--srd-modal-duration, 200ms) ease-out; }
.srd-modal-anim-slide-up[open] { animation: srd-modal-in-slide-up var(--srd-modal-duration, 200ms) ease-out; }

/* [open] as well, so these outrank the rules above at (0,3,0) rather than
   winning a (0,2,0) tie on source order — the dialog is still open while it
   closes. */
.srd-modal-anim-fade[open].srd-modal-closing     { animation: srd-modal-out-fade var(--srd-modal-duration, 200ms) ease-in forwards; }
.srd-modal-anim-zoom[open].srd-modal-closing     { animation: srd-modal-out-zoom var(--srd-modal-duration, 200ms) ease-in forwards; }
.srd-modal-anim-slide-up[open].srd-modal-closing { animation: srd-modal-out-slide-up var(--srd-modal-duration, 200ms) ease-in forwards; }

/* The backdrop fades whatever the box does. A browser that does not pass
   custom properties into ::backdrop reads the 200ms fallback. */
.srd-modal[open]:not(.srd-modal-anim-none)::backdrop {
    animation: srd-modal-in-fade var(--srd-modal-duration, 200ms) ease-out;
}

.srd-modal[open].srd-modal-closing:not(.srd-modal-anim-none)::backdrop {
    animation: srd-modal-out-fade var(--srd-modal-duration, 200ms) ease-in forwards;
}

@media (prefers-reduced-motion: reduce) {
    .srd-modal,
    .srd-modal::backdrop {
        animation: none !important;
    }
}

/* ------------------------------------------------------------ image popup */

/* The frame shrinks to the image instead of taking the modal width, and
   the box loses its card: the image sits straight on the backdrop.
   (0,2,0), so these beat the base rules above whatever the print order. */
.srd-modal.srd-modal-image {
    width: fit-content;
    max-width: calc(100% - 32px);
}

.srd-modal-image .srd-modal__box {
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    /* The box can be wider than an image max-height has shrunk. Clicks
       there go through to the dialog, which counts as the backdrop. */
    pointer-events: none;
}

.srd-modal-image .srd-modal__body {
    overflow: visible;
}

.srd-modal-image .srd-modal__image,
.srd-modal-image .srd-modal__close {
    pointer-events: auto;
}

.srd-modal__image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100vh - 32px);
    margin: 0 auto;
}

.srd-modal-close-outside .srd-modal__image {
    max-height: calc(100vh - 32px - 44px);
}

/* Inside, the button sits on the photo, so it gets a dark disc of its own
   to stay readable whatever is under it. */
.srd-modal-image:not(.srd-modal-close-outside) .srd-modal__close {
    background: rgba(0, 0, 0, 0.55);
    color: var(--srd-modal-close-color, #ffffff);
}

.srd-modal-image:not(.srd-modal-close-outside) .srd-modal__close:hover {
    background: rgba(0, 0, 0, 0.75);
}

/* The class the site puts on an image or its module. */
.srd-image-popup {
    cursor: zoom-in;
}

/* ------------------------------------------------------------ scroll lock */

html.srd-modal-open,
html.srd-modal-open body {
    overflow: hidden;
}
