/*
 * FormWiz responsive builder POC.
 *
 * Desktop keeps the existing resizable split pane. Phones use a full-width
 * canvas with a bottom-sheet inspector; sufficiently wide phone-landscape
 * viewports turn that inspector into a right-hand split pane.
 */

.ezwp-mobile-builder-ui,
.ezwp-mobile-builder-backdrop,
.ezwp-mobile-panel-header {
    display: none;
}

@media (max-width: 700px),
       ((max-width: 1024px) and (hover: none) and (pointer: coarse)) {
    :root {
        --ezwp-builder-header-height: 58px;
        --ezwp-mobile-dock-height: 62px;
        --ezwp-mobile-selection-height: 0px;
        --ezwp-mobile-sheet-height: 56dvh;
        --ezwp-mobile-available-height: 100dvh;
        --ezwp-mobile-inspector-width: clamp(280px, 38vw, 360px);
    }

    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        padding-top: var(--ezwp-builder-header-height) !important;
        padding-bottom: calc(var(--ezwp-mobile-dock-height) + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.ezwp-mobile-has-selection {
        --ezwp-mobile-selection-height: 52px;
        padding-bottom: calc(var(--ezwp-mobile-dock-height) + var(--ezwp-mobile-selection-height) + env(safe-area-inset-bottom, 0px)) !important;
    }

    body .form-builder-header {
        min-height: var(--ezwp-builder-header-height) !important;
        height: var(--ezwp-builder-header-height);
        padding: 6px 8px !important;
        align-items: center !important;
    }

    body .form-builder-header-content {
        min-height: 44px !important;
        height: 44px;
        align-items: center !important;
        gap: 4px;
    }

    body .form-builder-logo {
        font-size: 1rem !important;
        white-space: nowrap;
    }

    body #ezwpFormBuilderHamburger {
        width: 42px;
        height: 42px;
        padding: 7px !important;
        flex: 0 0 42px;
    }

    body .sidebar-overlay.active {
        z-index: 1101;
    }

    body .sidebar-menu.active {
        z-index: 1102;
    }

    body #id_header_builder_toolbar.builder-toolbar {
        position: static !important;
        left: auto !important;
        right: auto !important;
        display: flex !important;
        flex: 1 1 auto;
        min-width: 0;
        height: 44px;
        margin: 0 !important;
        padding: 0 2px;
        gap: 2px !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    body #id_header_builder_toolbar::-webkit-scrollbar {
        display: none;
    }

    body #id_header_builder_toolbar .ezwp-toolbar-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        min-width: 42px;
        height: 42px;
        padding: 0 !important;
        font-size: 1rem !important;
        flex: 0 0 42px;
    }

    body #id_header_builder_toolbar > span {
        flex: 0 0 1px;
        margin: 11px 3px !important;
    }

    body .container-fluid {
        width: 100%;
        padding: 0 !important;
    }

    body #id_ezwp_form_builder_container {
        display: block;
        width: 100%;
        margin: 0;
    }

    body .ezwp-main-content {
        width: 100%;
        max-width: 100%;
        margin-left: 0 !important;
        margin-right: 0;
        padding: 0;
        transition: margin-right .2s ease;
    }

    body #id_form_frame {
        width: 100%;
        max-width: none;
        padding: 6px 8px 20px;
        margin: 0;
    }

    body #id_form_frame > .container-flex > div:first-child {
        min-width: 0;
        overflow: visible;
    }

    body #formTabs {
        flex-wrap: nowrap;
        min-width: max-content;
    }

    body #id_email_tab_toolbar {
        min-width: 0;
        overflow: visible;
    }

    body #id_the_form_container > .row,
    body #id_ezwp_email_view_container > .row {
        flex-wrap: wrap;
    }

    body #id_the_form_container > .row > .draggable-item,
    body #id_ezwp_email_view_container > .row > .draggable-item {
        flex: 1 1 100%;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    body .ezwp-sidebar-divider {
        display: none !important;
    }

    body .ezwp-sidebar-dialog {
        position: fixed !important;
        z-index: 1060;
        left: 0 !important;
        right: 0;
        top: auto !important;
        bottom: calc(var(--ezwp-mobile-dock-height) + var(--ezwp-mobile-selection-height) + env(safe-area-inset-bottom, 0px));
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: min(var(--ezwp-mobile-sheet-height), calc(var(--ezwp-mobile-available-height) - var(--ezwp-builder-header-height) - var(--ezwp-mobile-dock-height)));
        max-height: calc(var(--ezwp-mobile-available-height) - var(--ezwp-builder-header-height) - var(--ezwp-mobile-dock-height));
        margin: 0 !important;
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -12px 40px rgba(15, 23, 42, .22);
        transform: translateY(calc(100% + var(--ezwp-mobile-dock-height) + var(--ezwp-mobile-selection-height) + 32px));
        visibility: hidden;
        transition: transform .22s ease, visibility 0s linear .22s, height .18s ease;
        overflow: hidden;
    }

    body .ezwp-sidebar-dialog.ezwp-mobile-panel-open {
        transform: translateY(0);
        visibility: visible;
        transition: transform .22s ease, visibility 0s;
    }

    body.ezwp-mobile-panel-fields .ezwp-sidebar-dialog,
    body.ezwp-mobile-panel-settings .ezwp-sidebar-dialog {
        --ezwp-mobile-sheet-height: 74dvh;
    }

    body.ezwp-mobile-panel-expanded .ezwp-sidebar-dialog,
    body.ezwp-mobile-keyboard-editing .ezwp-sidebar-dialog {
        --ezwp-mobile-sheet-height: calc(var(--ezwp-mobile-available-height) - var(--ezwp-builder-header-height) - var(--ezwp-mobile-dock-height) - 4px);
        border-radius: 12px 12px 0 0;
    }

    body .ezwp-sidebar-header {
        flex: 0 0 auto;
        margin-top: 0 !important;
        padding: 0 8px !important;
    }

    body .ezwp-sidebar-header .nav-tabs {
        padding: 0;
        margin-top: 0;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }

    body .ezwp-sidebar-header .nav-link {
        min-height: 44px;
        white-space: nowrap;
    }

    body .ezwp-sidebar-scroll {
        padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px));
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    body .ezwp-field-buttons-container {
        gap: 8px;
    }

    body .ezwp-field-buttons-container .ezwp-formFieldBtn,
    body .ezwp-sidebar-dialog .ezwp-formFieldBtn,
    body .ezwp-sidebar-dialog .ezwp-formFieldBtn:hover {
        flex: 1 1 calc(50% - 4px);
        width: auto;
        max-width: none;
        min-width: 132px;
        min-height: 48px;
        cursor: pointer;
        touch-action: manipulation;
    }

    .ezwp-mobile-panel-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        flex: 0 0 auto;
        min-height: 52px;
        padding: 8px 10px 6px;
        border-bottom: 1px solid #e2e8f0;
        background: #fff;
    }

    .ezwp-mobile-panel-grip {
        position: absolute;
        top: 5px;
        left: 50%;
        width: 42px;
        height: 5px;
        border: 0;
        border-radius: 999px;
        background: #cbd5e1;
        transform: translateX(-50%);
        cursor: ns-resize;
        touch-action: none;
    }

    .ezwp-mobile-panel-heading {
        min-width: 0;
        padding-top: 5px;
    }

    .ezwp-mobile-panel-eyebrow {
        display: block;
        color: #64748b;
        font-size: .67rem;
        font-weight: 800;
        letter-spacing: .06em;
        line-height: 1.1;
        text-transform: uppercase;
    }

    .ezwp-mobile-panel-title {
        display: block;
        overflow: hidden;
        color: #0f172a;
        font-size: .92rem;
        font-weight: 800;
        line-height: 1.25;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ezwp-mobile-panel-actions {
        display: flex;
        gap: 4px;
        padding-top: 4px;
    }

    .ezwp-mobile-panel-actions button,
    .ezwp-mobile-selection-actions button,
    .ezwp-mobile-builder-dock button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
        border: 1px solid #dbe3ef;
        border-radius: 10px;
        background: #fff;
        color: #334155;
        touch-action: manipulation;
    }

    .ezwp-mobile-panel-actions button:disabled,
    .ezwp-mobile-selection-actions button:disabled,
    .ezwp-mobile-builder-dock button:disabled {
        opacity: .42;
    }

    body.ezwp-mobile-panel-fields [data-ezwp-mobile-previous],
    body.ezwp-mobile-panel-fields [data-ezwp-mobile-next],
    body.ezwp-mobile-panel-settings [data-ezwp-mobile-previous],
    body.ezwp-mobile-panel-settings [data-ezwp-mobile-next] {
        display: none;
    }

    .ezwp-mobile-builder-ui {
        display: block;
    }

    .ezwp-mobile-builder-backdrop {
        position: fixed;
        z-index: 1055;
        inset: var(--ezwp-builder-header-height) 0 calc(var(--ezwp-mobile-dock-height) + var(--ezwp-mobile-selection-height) + env(safe-area-inset-bottom, 0px));
        display: block;
        border: 0;
        background: rgba(15, 23, 42, .38);
        opacity: 0;
        visibility: hidden;
        transition: opacity .2s ease, visibility 0s linear .2s;
    }

    body.ezwp-mobile-panel-visible .ezwp-mobile-builder-backdrop {
        opacity: 1;
        visibility: visible;
        transition: opacity .2s ease, visibility 0s;
    }

    .ezwp-mobile-builder-dock {
        position: fixed;
        z-index: 1070;
        left: 0;
        right: 0;
        bottom: 0;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        min-height: var(--ezwp-mobile-dock-height);
        padding: 7px 8px calc(7px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #dbe3ef;
        background: rgba(255, 255, 255, .96);
        box-shadow: 0 -8px 24px rgba(15, 23, 42, .12);
        backdrop-filter: blur(12px);
    }

    .ezwp-mobile-builder-dock button {
        gap: 7px;
        min-width: 0;
        color: #334155;
        font-size: .78rem;
        font-weight: 800;
    }

    .ezwp-mobile-builder-dock button.is-active {
        border-color: #2563eb;
        background: #eff6ff;
        color: #1d4ed8;
    }

    .ezwp-mobile-selection-bar {
        position: fixed;
        z-index: 1068;
        left: 0;
        right: 0;
        bottom: calc(var(--ezwp-mobile-dock-height) + env(safe-area-inset-bottom, 0px));
        display: flex;
        align-items: center;
        gap: 8px;
        height: var(--ezwp-mobile-selection-height);
        padding: 4px 8px;
        border-top: 1px solid #dbe3ef;
        background: #f8fafc;
        transform: translateY(110%);
        transition: transform .18s ease;
    }

    body.ezwp-mobile-has-selection .ezwp-mobile-selection-bar {
        transform: translateY(0);
    }

    .ezwp-mobile-selected-label {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        color: #334155;
        font-size: .78rem;
        font-weight: 800;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ezwp-mobile-selection-actions {
        display: flex;
        gap: 4px;
        flex: 0 0 auto;
    }

    .ezwp-mobile-selection-actions button {
        min-width: 40px;
        min-height: 40px;
    }

    body .draggable-item.ezwp-field-click-selected {
        scroll-margin-top: calc(var(--ezwp-builder-header-height) + 12px);
        scroll-margin-bottom: calc(var(--ezwp-mobile-dock-height) + var(--ezwp-mobile-selection-height) + 20px);
    }

    body.modal-open {
        overflow: hidden !important;
    }

    body .modal.ezwp-mobile-modal-fullscreen.show {
        display: block !important;
        overflow: hidden !important;
        padding: 0 !important;
    }

    body .modal.ezwp-mobile-modal-fullscreen .modal-dialog {
        width: 100vw !important;
        max-width: none !important;
        height: var(--ezwp-mobile-available-height) !important;
        min-height: var(--ezwp-mobile-available-height) !important;
        max-height: var(--ezwp-mobile-available-height) !important;
        margin: 0 !important;
        transform: none !important;
    }

    body .modal.ezwp-mobile-modal-fullscreen .modal-content {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        max-height: none !important;
        border: 0;
        border-radius: 0;
    }

    body .modal.ezwp-mobile-modal-fullscreen .modal-header {
        flex: 0 0 auto;
        padding-top: calc(.75rem + env(safe-area-inset-top, 0px));
    }

    body .modal.ezwp-mobile-modal-fullscreen .modal-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    body .modal.ezwp-mobile-modal-fullscreen .modal-footer {
        flex: 0 0 auto;
        padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
        background: #fff;
    }

    body .note-modal,
    body .note-modal.modal {
        inset: 0 !important;
        width: 100vw !important;
        height: var(--ezwp-mobile-available-height) !important;
        transform: none !important;
        overflow: auto !important;
    }

    body .note-modal .note-modal-content {
        width: 100% !important;
        max-width: none !important;
        min-height: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    body .ezwp-modal-content {
        width: 100% !important;
        max-width: none !important;
        height: var(--ezwp-mobile-available-height) !important;
        max-height: var(--ezwp-mobile-available-height) !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    body .ezwp-image-manager-content {
        height: var(--ezwp-mobile-available-height) !important;
    }

    body .ezwp-modal-header {
        flex: 0 0 auto;
        padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
    }

    body .ezwp-modal-body {
        min-height: 0;
        overflow-y: auto;
    }

    body .ezwp-img-main-container {
        min-height: 0;
    }
}

@media (max-width: 430px) {
    body .form-builder-logo {
        display: none;
    }

    body .ezwp-field-buttons-container .ezwp-formFieldBtn,
    body .ezwp-sidebar-dialog .ezwp-formFieldBtn,
    body .ezwp-sidebar-dialog .ezwp-formFieldBtn:hover {
        min-width: 118px;
    }
}

@media (orientation: landscape)
       and (min-width: 720px)
       and (max-width: 1024px)
       and (max-height: 600px)
       and (hover: none)
       and (pointer: coarse) {
    :root {
        --ezwp-mobile-dock-height: 54px;
    }

    body.ezwp-mobile-panel-visible .ezwp-main-content {
        margin-right: var(--ezwp-mobile-inspector-width) !important;
        width: calc(100% - var(--ezwp-mobile-inspector-width));
    }

    body .ezwp-sidebar-dialog {
        left: auto !important;
        right: 0;
        top: var(--ezwp-builder-header-height) !important;
        bottom: calc(var(--ezwp-mobile-dock-height) + var(--ezwp-mobile-selection-height) + env(safe-area-inset-bottom, 0px));
        width: var(--ezwp-mobile-inspector-width) !important;
        height: auto;
        max-height: none;
        border-left: 1px solid #dbe3ef;
        border-radius: 0;
        box-shadow: -10px 0 30px rgba(15, 23, 42, .12);
        transform: translateX(105%);
    }

    body .ezwp-sidebar-dialog.ezwp-mobile-panel-open {
        transform: translateX(0);
    }

    body.ezwp-mobile-panel-expanded .ezwp-sidebar-dialog,
    body.ezwp-mobile-keyboard-editing .ezwp-sidebar-dialog,
    body.ezwp-mobile-panel-fields .ezwp-sidebar-dialog,
    body.ezwp-mobile-panel-settings .ezwp-sidebar-dialog {
        height: auto;
    }

    .ezwp-mobile-builder-backdrop,
    body.ezwp-mobile-panel-visible .ezwp-mobile-builder-backdrop {
        display: none;
    }

    .ezwp-mobile-panel-grip,
    [data-ezwp-mobile-panel-expand] {
        display: none !important;
    }

    body .ezwp-sidebar-scroll {
        padding-bottom: 12px;
    }

    body #id_form_frame {
        padding-left: 10px;
        padding-right: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    body .ezwp-sidebar-dialog,
    .ezwp-mobile-builder-backdrop,
    .ezwp-mobile-selection-bar {
        transition: none !important;
    }
}
