/* Owner-requested instant interaction policy. The Wali reference stays intact. */
html[data-ui-motion="none"],
html[data-ui-motion="none"] *,
html[data-ui-motion="none"] *::before,
html[data-ui-motion="none"] *::after {
    transition: none !important;
    scroll-behavior: auto !important;
}

html[data-ui-motion="none"] *:not(.spinner-border):not(.spinner-grow):not(.fa-spin):not(.fa-pulse),
html[data-ui-motion="none"] *::before,
html[data-ui-motion="none"] *::after {
    animation: none !important;
}

html[data-ui-motion="none"] .modal-dialog {
    transform: none !important;
}

html[data-ui-motion="none"] .modal-backdrop,
html[data-ui-motion="none"] .offcanvas-backdrop {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
}

/* Wali's native single sidebar has physical LTR offsets; complete its RTL contract. */
html[dir="rtl"][data-layout="single"] .two-col-sidebar .sidebar {
    right: 0;
    left: auto;
}

@media (min-width: 992px) {
    html[dir="rtl"][data-layout="single"] .header {
        right: 216px;
        left: 0;
    }

    html[dir="rtl"][data-layout="single"] .page-wrapper {
        margin: 0 216px 0 0;
    }

    html[dir="rtl"][data-layout="single"] .mini-sidebar .header {
        right: 72px;
    }

    html[dir="rtl"][data-layout="single"] .mini-sidebar .page-wrapper {
        margin-right: 72px;
    }

    html[dir="rtl"][data-layout="single"] .mini-sidebar.expand-menu .header {
        right: 216px;
    }
}

/* Native sidebar scrolling is available before scripts, including on slow connections. */
#sidebar-two [data-sidebar-scroll] {
    position: relative;
    top: 56px;
    height: calc(100% - 56px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-400) transparent;
}

#sidebar-two [data-sidebar-scroll] .sidebar-menu {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100%;
}

@media (max-width: 991.98px) {
    #sidebar-two [data-sidebar-scroll] {
        top: 0;
        height: 100%;
    }
}

/* Reusable full-height workspaces keep tools and the main viewport independently scrollable. */
.wali-workspace-panel {
    position: sticky;
    top: 72px;
}

.wali-workspace-scroll {
    height: clamp(430px, calc(100vh - 280px), 920px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
}

.wali-workspace-canvas {
    height: clamp(380px, calc(100vh - 420px), 760px);
    overflow: hidden;
}

.wali-workspace-canvas > iframe {
    display: block;
    height: 100%;
}

/* Bounded tool rails leave remaining width and height to the working surface. */
.page-wrapper:has(.wali-workspace) > .footer {
    display: none !important;
}

.wali-workspace {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr) 264px;
    gap: 12px;
    height: var(--wali-workspace-height, calc(100dvh - 180px));
    min-height: 0;
}

.wali-workspace.wali-workspace-focused {
    grid-template-columns: minmax(0, 1fr);
}

.wali-workspace-expanded {
    position: fixed;
    inset: 0;
    z-index: 1035;
    overflow: hidden;
}

.wali-workspace > *,
.wali-workspace-title {
    min-width: 0;
    min-height: 0;
}

.wali-workspace-title {
    max-width: 320px;
}

.wali-workspace .wali-workspace-panel {
    position: static;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    margin-bottom: 0;
}

.wali-workspace .card-header,
.wali-workspace .card-footer {
    flex-shrink: 0;
}

.wali-workspace .wali-workspace-scroll,
.wali-workspace .wali-workspace-canvas {
    flex: 1 1 0;
    height: auto;
    min-height: 0;
    max-height: none;
}

.wali-workspace .wali-workspace-toolbar {
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
}

.wali-workspace .wali-workspace-status {
    overflow: hidden;
}

@media (max-width: 991.98px) {
    .wali-workspace-panel {
        position: static;
    }

    .wali-workspace-scroll {
        height: auto;
        max-height: 65vh;
    }

    .wali-workspace-canvas {
        height: max(480px, 65vh);
    }

    .wali-workspace {
        position: relative;
        display: block;
        height: max(440px, var(--wali-workspace-height, 65dvh));
    }

    .wali-workspace .wali-workspace-main {
        height: 100%;
    }

    .wali-workspace .wali-workspace-sidebar {
        display: none;
        position: absolute;
        inset-block: 0;
        inset-inline-start: 0;
        width: min(280px, 90%);
        z-index: 5;
    }

    .wali-workspace .wali-workspace-sidebar:last-child {
        inset-inline-start: auto;
        inset-inline-end: 0;
    }

    .wali-workspace .wali-workspace-mobile-open {
        display: block;
    }
}

/* Template preview zoom is parent-owned, so sandboxed document HTML is never rewritten. */
.template-preview-modal .modal-dialog {
    width: min(1480px, calc(100vw - 32px));
    max-width: none;
    height: calc(100dvh - 32px);
    margin: 16px auto;
}

.template-preview-modal .modal-content,
.template-preview-modal .template-preview-body,
.template-preview-modal .template-preview-viewport {
    min-height: 0;
}

.template-preview-modal .modal-content {
    height: 100%;
    overflow: hidden;
}

.template-preview-header {
    flex-wrap: nowrap;
    gap: 12px;
    padding-block: 10px;
}

.template-preview-heading {
    min-width: 0;
    flex: 1 1 auto;
}

.template-preview-heading small {
    display: block;
    margin-top: 2px;
}

.template-preview-toolbar {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--bs-border-color, #e5e7eb);
    border-radius: 12px;
    background: var(--bs-body-bg, #fff);
    box-shadow: 0 4px 16px rgb(15 23 42 / 7%);
}

.template-preview-toolbar .btn {
    min-width: 38px;
    min-height: 38px;
    margin: 0;
}

.template-preview-toolbar .btn:disabled {
    opacity: .45;
}

.template-preview-zoom-value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    min-height: 38px;
    padding-inline: 8px;
    border-radius: 8px;
    background: var(--bs-tertiary-bg, #f1f5f9);
    color: var(--bs-emphasis-color, #111827);
    font-size: .875rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.template-preview-reset {
    white-space: nowrap;
}

.template-preview-body {
    overflow: hidden;
    background: var(--bs-tertiary-bg, #eef1f5);
}

.template-preview-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 420px;
    overflow: auto;
    direction: ltr;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.template-preview-stage {
    position: relative;
    width: 100%;
    height: 720px;
    margin-inline: auto;
}

.template-preview-frame {
    position: absolute;
    inset: 0 auto auto 0;
    display: block;
    width: 100%;
    height: 720px;
    background: #fff;
    transform: scale(1);
    transform-origin: top left;
}

.template-preview-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: color-mix(in srgb, var(--bs-body-bg, #fff) 88%, transparent);
    color: var(--bs-secondary-color, #64748b);
    pointer-events: none;
}

.template-preview-modal.is-loading .template-preview-loading {
    display: flex;
}

@media (max-width: 767.98px) {
    .template-preview-modal .modal-dialog {
        width: 100%;
        height: 100dvh;
        margin: 0;
    }

    .template-preview-modal .modal-content {
        border: 0;
        border-radius: 0;
    }

    .template-preview-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .template-preview-heading {
        max-width: calc(100% - 44px);
    }

    .template-preview-heading small {
        display: none;
    }

    .template-preview-toolbar {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .template-preview-header > .btn-close {
        margin-inline-start: auto;
    }

    .template-preview-viewport {
        min-height: 0;
    }
}
