/*
 * Safari compatibility layer.
 * Keep this file structural: no module colours, spacing systems, or business UI.
 */

html.bjas-browser-safari {
    --bjas-layout-viewport-height: 100vh;
    --bjas-visual-viewport-height: 100vh;
    --bjas-visual-viewport-width: 100vw;
    --bjas-visual-viewport-offset-top: 0px;
    --bjas-keyboard-height: 0px;
    --bjas-safe-area-top: env(safe-area-inset-top, 0px);
    --bjas-safe-area-right: env(safe-area-inset-right, 0px);
    --bjas-safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --bjas-safe-area-left: env(safe-area-inset-left, 0px);
    width: 100%;
    min-width: 0;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html.bjas-browser-safari body {
    min-width: 0;
    min-height: 100vh;
    min-height: var(--bjas-layout-viewport-height);
    -webkit-font-smoothing: antialiased;
}

html.bjas-display-standalone,
html.bjas-display-standalone body {
    min-height: var(--bjas-layout-viewport-height);
}

html.bjas-browser-safari :where(
    .modal-body,
    .drawer-body,
    .table-responsive,
    .table-scroll,
    .sidebar-scroll,
    [data-scroll-container]
) {
    -webkit-overflow-scrolling: touch;
}

html.bjas-platform-ios :where(
    input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    select,
    textarea,
    [contenteditable="true"]
) {
    font-size: 16px;
}

html.bjas-platform-ios :where(
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="week"]
) {
    display: block;
    min-width: 0;
    max-width: 100%;
}

html.bjas-platform-ios :where(button, [role="button"], a, input, select, textarea) {
    touch-action: manipulation;
}

html.bjas-platform-ios :where(dialog, [role="dialog"], .app-modal, .shell-modal, .modal-dialog) {
    max-height: calc(
        var(--bjas-visual-viewport-height) -
        var(--bjas-safe-area-top) -
        var(--bjas-safe-area-bottom) -
        16px
    );
}

html.bjas-platform-ios.bjas-virtual-keyboard-open :where(
    dialog,
    [role="dialog"],
    .app-modal,
    .shell-modal,
    .modal-dialog
) {
    max-height: calc(var(--bjas-visual-viewport-height) - 12px);
}

html.bjas-platform-ios :where(img, video, canvas) {
    image-orientation: from-image;
}

@media (max-width: 768px) {
    html.bjas-platform-ios :where(.modal-body, .drawer-body, [data-scroll-container]) {
        overscroll-behavior: contain;
    }
}
