// ============================================================================
// Imports
// ============================================================================

@use "../../variables" as *;
@use "../head_layout" as *;
@use "../soul_type" as *;
@use "../body_molecules" as *;
@use "../body_atoms" as *;
@use "../soul_object" as *;

// ============================================================================
// Mixins
// ============================================================================

/// Modal container - hidden by default, shown via .modal--open class or JS
/// Uses fixed positioning to overlay the entire viewport
@mixin modal {
    // Hidden by default
    display: none;

    // Full viewport overlay
    position: fixed;
    inset: 0;
    z-index: z("modal");

    // Center content
    align-items: center;
    justify-content: center;

    // Prevent body scroll when open
    &.modal--open,
    &:not([hidden]) {
        display: flex;
    }

    // Support for hidden attribute
    &[hidden] {
        display: none !important;
    }
}

@mixin modal_header {
    @include text_align--center;
    margin-top: baseline(4);
    margin-bottom: baseline(2);
}

@mixin modal_content {
    // Content box styling
    position: relative;
    z-index: 1;
    @include sizing--border;
    width: 90%;
    max-width: q(500);
    max-height: calc(100vh - baseline(8));
    overflow-y: auto;
    margin: auto;
    background-color: var(--modal_background, rgb(255, 255, 255));
    padding: baseline(4);
    border-radius: baseline(2);
    box-shadow: 0 baseline(2) baseline(4) rgba(0, 0, 0, 0.15);

    // Animation
    opacity: 0;
    transform: scale(0.95) translateY(q(-10));
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;

    .modal--open & {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@mixin modal_footer {
    margin-top: baseline(2);
    margin-bottom: baseline(4);
}

@mixin modal_form {
    @include flex--col;
}

@mixin modal_fieldset {
    @include flex--col;

    legend {
        width: 100%;
    }

    label {
        width: 100%;
    }

    input {
        width: 100%;
    }
}

@mixin modal_backdrop {
    // Full screen backdrop
    position: absolute;
    inset: 0;
    z-index: 0;
    background-color: var(--modal_backdrop, rgba(0, 0, 0, 0.5));

    // Fade animation
    opacity: 0;
    transition: opacity 0.2s ease;

    .modal--open & {
        opacity: 1;
    }

    // Clickable area for closing
    cursor: pointer;
}

@mixin modal_dialog {
    position: relative;
    width: auto;
    margin: baseline(4);
    pointer-events: none;

    .modal--open & {
        pointer-events: auto;
    }
}

@mixin modal--sm {
    .modal__content {
        max-width: q(300);
    }
}

@mixin modal--md {
    .modal__content {
        max-width: q(500);
    }
}

@mixin modal--lg {
    .modal__content {
        max-width: q(800);
    }
}

@mixin modal--xl {
    .modal__content {
        max-width: q(1140);
    }
}

@mixin modal--fullscreen {
    .modal__content {
        width: 100vw;
        max-width: none;
        height: 100vh;
        max-height: none;
        margin: 0;
        border-radius: 0;
    }
}

@mixin modal--centered {
    align-items: center;
    justify-content: center;
}

@mixin modal--scrollable {
    .modal__content {
        max-height: calc(100vh - baseline(16));
        overflow-y: auto;
    }
}

@mixin modal--static {
    // Handled via JS - modal won't close when clicking backdrop
    &[data-backdrop="static"] .modal__backdrop {
        cursor: default;
    }
}

@mixin modal--fade {
    .modal__content {
        opacity: 0;
        transition: opacity 0.15s linear;
    }

    &.modal--open .modal__content {
        opacity: 1;
    }
}

@mixin modal--slide-top {
    .modal__content {
        transform: translateY(-100%);
        transition: transform 0.3s ease-out;
    }

    &.modal--open .modal__content {
        transform: translateY(0);
    }
}

@mixin modal--slide-bottom {
    align-items: flex-end;

    .modal__content {
        transform: translateY(100%);
        transition: transform 0.3s ease-out;
        border-radius: baseline(2) baseline(2) 0 0;
    }

    &.modal--open .modal__content {
        transform: translateY(0);
    }
}

@mixin modal--scale {
    .modal__content {
        transform: scale(0.7);
        transition: transform 0.3s ease-out;
    }

    &.modal--open .modal__content {
        transform: scale(1);
    }
}
