/* Keep popup controls reachable without restructuring forms or moving focused inputs. */
dialog{max-height:calc(100dvh - 32px);box-sizing:border-box;overscroll-behavior:contain}
:is(dialog,.knowledge-dialog,.quick-dialog,.modal-dialog)>:is(header,.knowledge-dialog-head,.feed-dialog-head,.quick-head),
dialog>form>:is(header,.dialog-head){position:sticky;top:0;z-index:5;background:var(--surface,#fff);isolation:isolate;padding-top:12px;padding-bottom:12px;border-bottom:1px solid var(--line,#ddd);flex-shrink:0}
:is(dialog,.knowledge-dialog,.quick-dialog,.modal-dialog)>:is(footer,.knowledge-dialog-actions,.popup-actions,.quick-foot),
dialog>form>:is(footer,.dialog-foot,.popup-actions){position:sticky;bottom:0;z-index:5;background:var(--surface,#fff);isolation:isolate;padding-top:12px;padding-bottom:12px;border-top:1px solid var(--line,#ddd);flex-shrink:0}
/* Existing drawers/gallery dialogs already use separate flex scroll bodies. */
:is(.drawer-head,.drawer-foot,.vision-drawer-head,.vision-drawer-foot){flex-shrink:0}
:is(.drawer-body,.vision-drawer-body){min-height:0;overscroll-behavior:contain}
@media(max-width:600px){dialog{max-height:calc(100dvh - 16px)}dialog>footer,dialog>form>footer{gap:8px;flex-wrap:wrap}}

/* Visual editor: scroll only the fields, so content cannot slide behind the padded header. */
.visual-editor-modal:not(.visual-gallery) .knowledge-dialog{display:flex;flex-direction:column;overflow:hidden;max-height:calc(100dvh - 40px)}
.visual-editor-modal:not(.visual-gallery) .knowledge-dialog-head{position:relative;top:auto;z-index:auto;margin:0;padding:0 0 14px;flex-shrink:0}
.visual-editor-modal:not(.visual-gallery) #visualForm{display:flex;flex-direction:column;min-height:0;overflow:hidden}
.visual-editor-modal:not(.visual-gallery) #visualFields{min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding:0 4px 12px 0}
.visual-editor-modal:not(.visual-gallery) #visualError{flex-shrink:0}
.visual-editor-modal:not(.visual-gallery) #visualError:empty{display:none}
.visual-editor-modal:not(.visual-gallery) .knowledge-dialog-actions{position:relative;bottom:auto;flex-shrink:0;margin-top:0;padding-top:12px;border-top:1px solid var(--line);background:var(--surface)}
@media(max-width:600px){.visual-editor-modal{padding:8px}.visual-editor-modal:not(.visual-gallery) .knowledge-dialog{max-height:calc(100dvh - 16px);padding:16px}}

/* A dedicated body is the only scrollport: fieldset legends cannot paint over action bars. */
.popup-scroll-frame{overflow:hidden!important;max-height:calc(100dvh - 32px);min-height:0;box-sizing:border-box}
dialog.popup-scroll-frame[open],:not(dialog).popup-scroll-frame{display:flex;flex-direction:column}
.popup-scroll-frame>.popup-scroll-host{display:flex;flex-direction:column;flex:1 1 auto;min-height:0;max-height:100%;overflow:hidden;margin-bottom:0}
:not(dialog).popup-scroll-frame.popup-scroll-host,dialog[open].popup-scroll-frame.popup-scroll-host{display:flex;flex-direction:column}
.popup-scroll-frame .popup-scroll-body{flex:1 1 auto;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding:12px 4px 16px 0;isolation:isolate;position:relative}
.popup-scroll-frame .popup-scroll-head,.popup-scroll-frame .popup-scroll-foot{position:relative!important;top:auto!important;bottom:auto!important;z-index:1!important;flex:0 0 auto;isolation:isolate;background:var(--surface,#fff);margin-top:0;margin-bottom:0}
.popup-scroll-frame .popup-scroll-head{padding-top:0}
.popup-scroll-frame .popup-scroll-foot{padding-bottom:0}
@media(max-width:600px){.popup-scroll-frame{max-height:calc(100dvh - 16px)}.popup-scroll-frame .popup-scroll-body{padding-right:2px}}
