/* =============================================================================
   KouDialog — reusable modal dialog styles
   Theme-aware: follows WordPress preset colors, fullscreen on phones.
   ============================================================================= */

.kou-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(0.75rem, 3vw, 2rem);
    background: rgba(15, 20, 30, 0.6);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.2s ease;
    overscroll-behavior: contain;
}

/* Critical: the overlay is toggled via the [hidden] attribute — without this
   rule the flex display overrides it and an invisible overlay blocks clicks. */
.kou-dialog-overlay[hidden] {
    display: none !important;
}

.kou-dialog-overlay.is-open {
    opacity: 1;
}

body.kou-dialog-open {
    overflow: hidden;
}

.kou-dialog {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 640px;
    max-height: min(90vh, 90dvh);
    border: 1px solid color-mix(in srgb, var(--kou-secondary, #111111) 8%, transparent);
    border-radius: 18px;
    overflow: hidden;
    background: var(--kou-color-base, var(--wp--preset--color--background, #ffffff));
    color: var(--kou-secondary, var(--wp--preset--color--foreground, #111111));
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
    transform: translateY(14px) scale(0.97);
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.kou-dialog-overlay.is-open .kou-dialog {
    transform: none;
}

.kou-dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #ffffff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.kou-dialog-close:hover {
    background: rgba(0, 0, 0, 0.78);
    transform: scale(1.06);
}

.kou-dialog-close:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.kou-dialog-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, currentColor 35%, transparent) transparent;
}

.kou-dialog-content::-webkit-scrollbar {
    width: 8px;
}

.kou-dialog-content::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, currentColor 30%, transparent);
    border-radius: 8px;
}

/* Image dialog variant */
.kou-dialog--image {
    max-width: min(92vw, 1100px);
    background: transparent;
    color: #ffffff;
    border: none;
    box-shadow: none;
    overflow: visible;
}

.kou-dialog--image .kou-dialog-content {
    flex: none;
    overflow: visible;
}

.kou-dialog--image img {
    display: block;
    max-width: 100%;
    max-height: 84vh;
    margin: 0 auto;
    border-radius: 12px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

/* Bottom sheet on phones: content-sized, never forced full height */
@media (max-width: 640px) {
    .kou-dialog-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .kou-dialog--fullscreen-mobile.kou-dialog {
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: calc(100dvh - env(safe-area-inset-top, 0px));
        border: none;
        border-radius: 18px 18px 0 0;
        transform: translateY(12%) scale(1);
    }

    .kou-dialog--fullscreen-mobile .kou-dialog-content {
        flex: 1;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .kou-dialog--fullscreen-mobile.kou-dialog--image {
        align-self: center;
        border-radius: 0;
    }

    .kou-dialog--fullscreen-mobile.kou-dialog--image .kou-dialog-content {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kou-dialog-overlay,
    .kou-dialog,
    .kou-dialog-close {
        transition: none;
    }

    .kou-dialog {
        transform: none;
    }
}
