/*
 * EU guarantee notice modal
 *
 * Styles for the <dialog> created by eu-guarantee-notice.js.
 * Everything is scoped under the .eu-guarantee-notice-* prefix so it
 * cannot leak into the surrounding theme.
 *
 * Progressive enhancement:
 *  - <dialog> / ::backdrop are Baseline (Chrome 37+, Firefox 98+, Safari 15.4+).
 *  - The open/close animation uses @starting-style and
 *    transition-behavior: allow-discrete. Browsers without support simply
 *    show/hide the dialog instantly, nothing breaks.
 */

.eu-guarantee-notice-dialog {
    --egn-radius: 6px;
    --egn-gap: 16px;
    --egn-header-height: 56px;
    --egn-color-text: #222;
    --egn-color-muted: #666;
    --egn-color-border: #e2e2e2;
    --egn-color-surface: #fff;
    --egn-color-surface-alt: #f5f5f5;
    --egn-color-focus: #1a73e8;
    --egn-duration: 220ms;
    --egn-easing: cubic-bezier(0.2, 0, 0, 1);

    /* Override UA dialog defaults (max-width: calc(100% - 6px - 2em) etc.) */
    box-sizing: border-box;
    inset: 0;
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: var(--egn-radius);
    width: min(100vw - 2 * var(--egn-gap), 960px);
    height: min(100vh - 2 * var(--egn-gap), 1100px);
    height: min(100dvh - 2 * var(--egn-gap), 1100px);
    max-width: none;
    max-height: none;
    overflow: hidden;
    background: var(--egn-color-surface);
    color: var(--egn-color-text);
    box-shadow:
            0 24px 64px rgb(0 0 0 / 0.28),
            0 2px 8px rgb(0 0 0 / 0.12);
    font: inherit;
    line-height: 1.4;

    /* Closed state (animation start/end point) */
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    transition:
            opacity var(--egn-duration) var(--egn-easing),
            transform var(--egn-duration) var(--egn-easing),
            overlay var(--egn-duration) allow-discrete,
            display var(--egn-duration) allow-discrete;
}

.eu-guarantee-notice-dialog[open] {
    opacity: 1;
    transform: none;
}

/* Entry animation: state the element starts from when [open] is first applied */
@starting-style {
    .eu-guarantee-notice-dialog[open] {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
}

.eu-guarantee-notice-dialog::backdrop {
    /* Literal values: ::backdrop does not inherit custom properties in older engines */
    background: rgb(0 0 0 / 0);
    -webkit-backdrop-filter: blur(0px);
    backdrop-filter: blur(0px);
    transition:
            background 220ms cubic-bezier(0.2, 0, 0, 1),
            -webkit-backdrop-filter 220ms cubic-bezier(0.2, 0, 0, 1),
            backdrop-filter 220ms cubic-bezier(0.2, 0, 0, 1),
            overlay 220ms allow-discrete,
            display 220ms allow-discrete;
}

.eu-guarantee-notice-dialog[open]::backdrop {
    background: rgb(0 0 0 / 0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

@starting-style {
    .eu-guarantee-notice-dialog[open]::backdrop {
        background: rgb(0 0 0 / 0);
        -webkit-backdrop-filter: blur(0px);
        backdrop-filter: blur(0px);
    }
}

/* Prevent the page behind the modal from scrolling (class toggled by JS) */
.eu-guarantee-notice-open {
    overflow: hidden;
}

/* ---------------------------------------------------------------------- */
/* Inner layout                                                           */
/* ---------------------------------------------------------------------- */

.eu-guarantee-notice-dialog__inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.eu-guarantee-notice-dialog__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
    min-height: var(--egn-header-height);
    padding: 0 12px 0 20px;
    border-bottom: 1px solid var(--egn-color-border);
    background: var(--egn-color-surface);
}

.eu-guarantee-notice-dialog__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.eu-guarantee-notice-dialog__close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--egn-color-text);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: background-color 120ms ease;
}

.eu-guarantee-notice-dialog__close:hover {
    background: var(--egn-color-surface-alt);
}

.eu-guarantee-notice-dialog__close:focus-visible {
    outline: 2px solid var(--egn-color-focus);
    outline-offset: 2px;
}

.eu-guarantee-notice-dialog__close svg {
    width: 20px;
    height: 20px;
    display: block;
}

.eu-guarantee-notice-dialog__body {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--egn-color-surface-alt);
    /* Allows touch scrolling of the PDF on mobile engines that only render inline */
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.eu-guarantee-notice-dialog__frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
}

/* Loading indicator, shown until the iframe fires "load" */
.eu-guarantee-notice-dialog__loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--egn-color-muted);
    font-size: 0.95rem;
    pointer-events: none;
    background: var(--egn-color-surface-alt);
    transition: opacity 160ms ease, visibility 160ms ease;
}

.eu-guarantee-notice-dialog:not([data-state="loading"]) .eu-guarantee-notice-dialog__loading {
    opacity: 0;
    visibility: hidden;
}

.eu-guarantee-notice-dialog__spinner {
    width: 22px;
    height: 22px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: eu-guarantee-notice-spin 800ms linear infinite;
}

@keyframes eu-guarantee-notice-spin {
    to {
        transform: rotate(360deg);
    }
}

.eu-guarantee-notice-dialog__footer {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: start;
    gap: 8px 16px;
    padding: 10px 20px;
    border-top: 1px solid var(--egn-color-border);
    font-size: 0.875rem;
    color: var(--egn-color-muted);
    background: var(--egn-color-surface);
}

.eu-guarantee-notice-dialog__footer a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.eu-guarantee-notice-dialog__footer a:hover {
    color: var(--egn-color-text);
}

.eu-guarantee-notice-dialog__footer a:focus-visible {
    outline: 2px solid var(--egn-color-focus);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ---------------------------------------------------------------------- */
/* Small screens: use the full viewport                                   */
/* ---------------------------------------------------------------------- */

@media (max-width: 640px) {
    .eu-guarantee-notice-dialog {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }

    .eu-guarantee-notice-dialog__header {
        padding-left: 16px;
    }

    .eu-guarantee-notice-dialog__footer {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ---------------------------------------------------------------------- */
/* Reduced motion                                                         */
/* ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .eu-guarantee-notice-dialog,
    .eu-guarantee-notice-dialog::backdrop,
    .eu-guarantee-notice-dialog__loading,
    .eu-guarantee-notice-dialog__close {
        transition: none;
    }

    .eu-guarantee-notice-dialog {
        transform: none;
    }

    .eu-guarantee-notice-dialog__spinner {
        animation-duration: 1600ms;
    }
}
