/* ==============================
   SHARED MODAL SYSTEM
   ============================== */

/* Modal styling uses color variables from base-colors.css */

/* Base modal overlay - covers entire screen with backdrop */
.standard-modal-overlay,
.modal {
    position: fixed;
    top: 0;
    left: var(--app-container-gutter-inline);
    right: var(--app-container-gutter-inline);
    width: auto;
    height: 100vh;
    height: 100dvh;
    background: var(--color-modal-backdrop);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
    /* Enable click-outside-to-close functionality */
    cursor: pointer;
    /* iOS Safari optimizations */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    display: flex;
    /* Center for legacy modals */
    justify-content: center;
    align-items: center;
}

.standard-modal-overlay.active,
.modal.modal-visible {
    opacity: 1;
    visibility: visible;
}

/* Ensure hidden state is enforced */
.modal.hidden,
.modal.modal-hidden {
    display: none;
    opacity: 0;
    visibility: hidden;
}

/* Base modal container - slides up from bottom */
.standard-modal {
    --standard-modal-inline-padding: var(--space-md);
    --standard-modal-footer-padding-bottom: calc(var(--space-md) + var(--safe-area-bottom, env(safe-area-inset-bottom, 0px)));

    position: fixed;
    left: var(--app-container-gutter-inline);
    right: var(--app-container-gutter-inline);
    width: auto;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-standard) var(--radius-standard) 0 0;
    box-sizing: border-box;
    overflow: hidden;
    z-index: var(--z-modal);
    transform: translate3d(0, 100vh, 0);
    -webkit-transform: translate3d(0, 100vh, 0);
    transition: transform var(--transition-normal);
    bottom: 0;
    font-family: var(--font-primary);
    cursor: default;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.standard-modal.active {
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
}

/* Legacy Modal Content - Centered Card Style */
.modal-content {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-standard);
    padding: var(--space-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    cursor: default;
}

.modal-content.small-modal {
    max-width: 400px;
}

.standard-modal.dragging {
    transition: none !important;
    -webkit-transition: none !important;
}

.standard-modal.closing {
    transition: transform var(--transition-normal) !important;
}

/* ==============================
   MODAL SIZE VARIANTS
   ============================== */

.standard-modal-simple {
    height: auto;
    max-height: 50vh;
}

.standard-modal-medium {
    height: 60vh;
}

.standard-modal-large {
    height: 80vh;
    overflow-y: auto;
}

.standard-modal-fullscreen {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    overflow-y: auto;
}

.standard-modal-fullscreen>.standard-modal-body:not(.standard-modal-body--scroll):not(.standard-modal-body--overflow-auto) {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    padding-bottom: 0;
    overflow: hidden;
}

.standard-modal--column {
    display: flex;
    flex-direction: column;
}

/* ==============================
   COMMON MODAL ELEMENTS
   ============================== */

.modal-topbar-shell {
    flex: 0 0 auto;
    width: 100%;
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
    padding-top: var(--space-md);
    padding-bottom: var(--space-md);
    box-sizing: border-box;
}

.standard-modal-fullscreen>.modal-topbar-shell {
    padding-top: calc(var(--space-md) + var(--safe-area-top));
}

.modal-topbar-shell .spa-topbar__center>* {
    width: 100%;
}

.modal-topbar-shell .standard-modal-title {
    margin: 0;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--text-base);
    font-weight: var(--font-weight-regular);
    line-height: var(--line-height-tight);
    text-align: center;
}

.modal-topbar-shell .modal-header-actions {
    position: static;
    top: auto;
    right: auto;
    transform: none;
    justify-content: center;
    width: 100%;
}

.modal-topbar-shell .modal-topbar-dismiss {
    cursor: grab;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.modal-topbar-shell .modal-topbar-dismiss:active {
    cursor: grabbing;
}

.modal-topbar-source-hidden {
    display: none !important;
}

.standard-modal-header,
.modal-header {
    position: relative;
    display: flex;
    flex: 0 0 auto;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding-left: var(--standard-modal-inline-padding);
    padding-right: var(--standard-modal-inline-padding);
    box-sizing: border-box;
    margin-bottom: var(--space-lg);
}

.standard-modal-header--actions-end {
    justify-content: flex-end;
}

.standard-modal-header--tight {
    min-height: calc(var(--text-xl) + var(--space-sm));
    margin-bottom: var(--space-md);
}

.standard-modal-title,
.modal h2 {
    font-family: var(--font-primary);
    font-weight: var(--font-weight-regular);
    font-size: var(--text-xl);
    color: var(--text-primary);
    margin: 0;
}

.modal-header-actions {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.modal-icon-button {
    background: transparent;
    border: none;
    padding: 6px;
    border-radius: var(--radius-standard);
    cursor: pointer;
    transition:
        background-color var(--transition-fast),
        transform var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.modal-icon-button img {
    width: 24px;
    height: 24px;
}

.modal-icon-button:hover {
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
}

.standard-modal-body,
.modal-body {
    width: 100%;
    padding-left: var(--standard-modal-inline-padding);
    padding-right: var(--standard-modal-inline-padding);
    box-sizing: border-box;
    margin-bottom: calc(var(--space-lg) + var(--safe-area-bottom));
}

.standard-modal-body--fill {
    flex: 1 1 auto;
    min-height: 0;
}

.standard-modal-body--scroll {
    margin-bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.standard-modal-body--overflow-auto {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.standard-modal-body--safe-pad-lg {
    padding-bottom: calc(var(--space-lg) + var(--safe-area-bottom, env(safe-area-inset-bottom, 0px)));
}

.standard-modal-body--centered-copy {
    align-items: center;
    text-align: center;
}

.modal-description {
    text-align: center;
}

.standard-modal-actions,
.modal-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
    width: 100%;
    padding-left: var(--standard-modal-inline-padding);
    padding-right: var(--standard-modal-inline-padding);
    padding-bottom: var(--standard-modal-footer-padding-bottom);
    box-sizing: border-box;
    margin-top: auto;
}

.standard-modal--centered-card {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    width: min(calc(100vw - (2 * var(--space-md))), 460px);
    width: min(calc(100dvw - (2 * var(--space-md))), 460px);
    max-height: calc(100vh - (2 * var(--space-md)));
    max-height: calc(100dvh - (2 * var(--space-md)));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-standard);
    background-color: var(--bg-secondary);
    transform: translate3d(0, var(--space-md), 0) scale(0.98);
    -webkit-transform: translate3d(0, var(--space-md), 0) scale(0.98);
    opacity: 0;
    overflow-y: auto;
}

.standard-modal--centered-card.active {
    transform: translate3d(0, 0, 0) scale(1);
    -webkit-transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
}

.illustrated-modal {
    display: flex;
    flex-direction: column;
}

.illustrated-modal__title-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(var(--space-xl) + var(--space-md));
    padding: var(--space-md) var(--space-md) 0;
    box-sizing: border-box;
}

.illustrated-modal__title-slot:empty::before {
    content: '';
    display: block;
    width: 100%;
}

.illustrated-modal__title {
    margin: 0;
    color: var(--text-primary);
    font-size: var(--text-xl);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-tight);
    text-align: center;
}

.illustrated-modal__media {
    display: flex;
    justify-content: center;
    padding: 0 var(--space-md);
    box-sizing: border-box;
}

.illustrated-modal__image {
    display: block;
    width: min(300px, 100%);
    height: auto;
    filter: invert(1);
}

.illustrated-modal__body {padding: var(--space-md);
    box-sizing: border-box}

.illustrated-modal__body-copy,
.illustrated-modal__supporting-text {
    margin: 0;
    text-align: center;
}

.illustrated-modal__body-copy {
    color: var(--text-primary);
    font-size: var(--text-base);
    line-height: var(--line-height-normal);
}

.illustrated-modal__supporting-text {
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: var(--line-height-normal);
}

/* Close Button (Cross Icon) */
.modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    cursor: pointer;
    z-index: 10;
}

/* ==============================
   MODAL FORM ELEMENTS
   ============================== */

/* Modal inputs handled globally in forms.css */

.standard-modal .location-item {
    color: var(--text-primary) !important;
}

/* ==============================
   RESPONSIVE ADJUSTMENTS
   ============================== */

@media (max-width: 768px) {

    .standard-modal-title {
        font-size: var(--text-xl);
    }

    .standard-modal-actions .btn {
        width: 100%;
    }

}
