/* Geometry is measured once by keyboard.js. Already-resized webviews get inset 0. */
:root {
    --pk-viewport-height: 100dvh;
    --pk-viewport-top: 0px;
    --pk-bottom-inset: 0px;
    --pk-page-height: 100lvh;
}
html [data-kb-bottom] {
    bottom: var(--pk-bottom-inset);
    max-height: calc(var(--pk-viewport-height) - 16px);
    overflow-y: auto;
    transition: transform .22s ease;
}
html [data-kb-viewport] {
    top: max(var(--pk-top, 0px), var(--pk-viewport-top));
    bottom: var(--pk-bottom-inset);
    height: auto;
    max-height: var(--pk-viewport-height);
    min-height: 0;
    transition: none;
}
html [data-kb-fixed-bottom] { bottom: 0; }
@media (hover: none) and (pointer: coarse) {
    html [data-kb-fixed-bottom] {
        top: var(--pk-page-height);
        bottom: auto;
        transform: translateY(-100%);
    }
}
html [data-kb-flow-bottom] { bottom: var(--pk-flow-rest-bottom, 0px); }
html.pk-flow-editing.pk-keyboard-open [data-kb-flow-bottom] { bottom: var(--pk-bottom-inset); }
html.pk-flow-editing [data-kb-flow-collapse] { display: none; }
html [data-kb-modal] {
    /* The backdrop covers the full surface, including behind rounded keyboard
       corners. Only the card's available space follows the visual viewport. */
    inset: 0;
    height: var(--pk-page-height);
    min-height: 100%;
    max-height: none;
    box-sizing: border-box;
    padding-block: 0;
    align-items: center;
    will-change: opacity;
    transition: opacity .18s ease-in-out;
}
/* Paint past the fixed layer edge while iOS expands the webview again. */
html [data-kb-modal]::after {
    content: '';
    position: absolute;
    inset: 100% 0 auto;
    height: max(48px, env(safe-area-inset-bottom, 0px));
    background-color: inherit;
    pointer-events: none;
}
html [data-kb-modal].visible {
    transition: opacity .28s ease-in-out;
}
@starting-style {
    html [data-kb-modal].visible { opacity: 0; }
}
html .sup-form-overlay[data-kb-backdrop] {
    display: block;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease-in-out, visibility 0s .22s;
}
html .sup-form-overlay[data-kb-backdrop].visible {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition-delay: 0s;
}
html.pk-modal-open, html.pk-modal-open body {
    overflow: hidden;
    overscroll-behavior: none;
}
html [data-kb-backdrop] { touch-action: none; }
html.pk-native-target [data-kb-modal] > :first-child {
    transition: translate .22s ease-out, transform .18s ease, opacity .18s ease;
}
html.pk-native-target [data-kb-bottom] {
    transition: bottom .22s ease-out, max-height .22s ease-out, transform .22s ease;
}
html.pk-native-target [data-kb-viewport] {
    transition: top .22s ease-out, bottom .22s ease-out, max-height .22s ease-out;
}
html [data-kb-modal] > :first-child {
    box-sizing: border-box;
    max-height: max(0px, calc(var(--pk-viewport-height) - 32px));
    translate: 0 clamp(calc(var(--pk-viewport-top) + 24px - var(--pk-page-height) / 2 + 50%), 0px,
        calc(var(--pk-viewport-top) + var(--pk-viewport-height) - var(--pk-page-height) / 2 - 50% - 8px));
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}
/* Translation alone does not hide a drawer: lifting its bottom above the
   keyboard would bring the closed drawer back into the visible viewport. */
html [data-kb-drawer][aria-hidden="true"] {
    visibility: hidden;
    pointer-events: none;
    bottom: 0;
}
/* iOS can zoom focused editors below 16px, fighting viewport positioning.
   Inline field styles in dynamic forms must follow the same mobile rule. */
@media (hover: none) and (pointer: coarse) {
    html :is(textarea, [contenteditable="true"], input:not([type]),
        input[type="text"], input[type="email"], input[type="tel"],
        input[type="url"], input[type="search"], input[type="password"], input[type="number"]) {
        font-size: max(16px, 1em) !important;
    }
}
html.pk-editing [data-kb-collapse] { display: none; }
/* With visual-only keyboard resizing, document scrolling still uses the larger
   layout viewport. Reserve the covered area so short forms can scroll up too. */
html.pk-flow-editing body::after {
    content: '';
    display: block;
    flex: none;
    height: var(--pk-bottom-inset);
    width: 1px;
    pointer-events: none;
}
html.pk-editing :is(input, textarea, [contenteditable]) { scroll-margin-block: 16px; }
@media (prefers-reduced-motion: reduce) {
    html .sup-form-overlay[data-kb-backdrop], html [data-kb-modal].visible,
    html [data-kb-bottom], html [data-kb-viewport], html [data-kb-modal],
    html.pk-native-target [data-kb-bottom], html.pk-native-target [data-kb-viewport],
    html.pk-native-target [data-kb-modal], html.pk-native-target [data-kb-modal] > :first-child { transition: none; }
}

html .sup-form [data-sheet-handle] {
    display: grid;
    place-items: center;
    position: static;
    background: transparent;
    width: 100%;
    height: 40px;
    margin: -14px 0 0;
    border: 0;
    touch-action: none;
    cursor: grab;
}
[data-sheet-handle]::before {
    content: '';
    width: 40px;
    height: 5px;
    border-radius: 4px;
    background: #898681;
}
