/* Mobile shell only. Desktop geometry remains owned by editor-shell.css. */

@media (max-width: 768px) {
     :root {
        --toolbar-h: calc(60px + env(safe-area-inset-top, 0px));
        --editor-mobile-dock: 60px;
    }
    .editor-page .topbar.editor-header {
        padding: env(safe-area-inset-top, 0px) 10px 0 !important;
        gap: 8px !important;
        min-width: 0 !important;
        flex-wrap: nowrap !important;
    }
    .editor-page .editor-header .topbar-left {
        gap: 8px !important;
        min-width: 0 !important;
        flex: 0 1 auto !important;
    }
    .editor-page .editor-header .editor-brand-lockup {
        margin: 0 !important;
        padding: 0 !important;
        min-width: 0 !important;
    }
    .editor-page .editor-header .brand-lockup__mark {
        width: 78px !important;
        max-width: 78px !important;
        height: 28px !important;
        flex: 0 0 78px !important;
        object-fit: contain !important;
    }
    .editor-page .editor-header .topbar-design-actions {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 0 !important;
        margin: 0 !important;
        border: 0 !important;
    }
    .editor-page .editor-header :is(.back-btn, .btn-save, .btn-preview, .btn-confirm-order) {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex: 0 0 40px !important;
        width: 40px !important;
        min-width: 40px !important;
        max-width: 40px !important;
        height: 40px !important;
        min-height: 40px !important;
        max-height: 40px !important;
        padding: 0 !important;
        gap: 0 !important;
        border: 1px solid #dce5f4 !important;
        border-radius: 11px !important;
        line-height: 1 !important;
        box-shadow: none !important;
        transform: none !important;
    }
    .editor-page .editor-header :is(.back-btn, .btn-save) {
        color: #3356b5 !important;
        background: #fff !important;
    }
    .editor-page .editor-header .btn-preview {
        color: #3155bd !important;
        background: #eef3ff !important;
    }
    .editor-page .editor-header .btn-confirm-order {
        color: #fff !important;
        background: #0051bb !important;
        border-color: #0051bb !important;
    }
    .editor-page .editor-header #btnSaveLabel,
    .editor-page .editor-header .btn-preview>span,
    .editor-page .editor-header .btn-confirm-order>span {
        display: none !important;
    }
    .editor-page .editor-header #btnSaveIcon {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 18px !important;
        height: 18px !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .editor-page .editor-header :is(.back-btn, .btn-save, .btn-preview, .btn-confirm-order) :is(i, svg) {
        display: block !important;
        width: 18px !important;
        min-width: 18px !important;
        max-width: 18px !important;
        height: 18px !important;
        min-height: 18px !important;
        max-height: 18px !important;
        flex: 0 0 18px !important;
        padding: 0 !important;
        margin: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        color: inherit !important;
        font-size: 18px !important;
        line-height: 18px !important;
        transform: none !important;
    }
    .editor-page .editor-header i::before {
        display: block;
        line-height: 1;
    }
    .editor-page .editor-body>.left-panel {
        position: fixed !important;
        top: auto !important;
        left: 8px !important;
        right: 8px !important;
        bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
        display: grid !important;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        align-items: center !important;
        justify-items: center;
        gap: 2px !important;
        height: var(--editor-mobile-dock) !important;
        min-height: 0 !important;
        padding: 6px !important;
        margin: 0 !important;
        transform: none !important;
        overflow: visible !important;
        z-index: 160;
        border-radius: 15px !important;
        backdrop-filter: none !important;
    }
    .editor-page .editor-body>.left-panel .tool-btn {
        position: relative !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 50px !important;
        height: 44px !important;
        min-height: 44px !important;
        max-height: 44px !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
        border-radius: 11px !important;
        transform: none !important;
        box-shadow: none !important;
    }
    .editor-page .editor-body>.left-panel .tool-btn .tool-svg {
        width: 23px !important;
        min-width: 23px !important;
        max-width: 23px !important;
        height: 23px !important;
        min-height: 23px !important;
        max-height: 23px !important;
        flex: 0 0 23px !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
    }
    .editor-page .left-panel .tool-svg [stroke] {
        stroke: currentColor !important;
    }
    .editor-page .left-panel .tool-btn-label,
    .editor-page .left-panel .tool-btn::before,
    .editor-page .left-panel .tool-btn::after {
        display: none !important;
    }
    .editor-page .left-panel #layerCountBadge {
        top: 1px !important;
        right: 2px !important;
        min-width: 14px !important;
        height: 14px !important;
        padding: 0 3px !important;
        font-size: 8px !important;
        line-height: 12px !important;
        transform: none !important;
    }
    .editor-page .editor-body>#canvasArea {
        bottom: calc(var(--editor-mobile-dock) + 24px + env(safe-area-inset-bottom, 0px)) !important;
        border-radius: 16px !important;
    }
    /* Explicit mobile anchoring: bottom/right alone do not position a static row. */
    .editor-page #canvasArea>.canvas-stage-controls {
        position: absolute !important;
        top: auto !important;
        right: auto !important;
        bottom: 10px !important;
        left: 50% !important;
        width: calc(100% - 20px) !important;
        max-width: calc(100% - 20px) !important;
        margin: 0 !important;
        gap: 6px !important;
        transform: translateX(-50%) !important;
        z-index: 82 !important;
    }
    .editor-page #canvasArea>.canvas-stage-controls>.editor-quick-toolbar {
        position: relative !important;
        inset: auto !important;
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: none !important;
        height: 40px !important;
        min-height: 40px !important;
        padding: 3px 4px !important;
        flex-wrap: nowrap !important;
        transform: none !important;
    }
    .editor-page #canvasArea .editor-quick-toolbar>.editor-history-btn {
        width: 30px !important;
        height: 30px !important;
        min-height: 30px !important;
        flex: 0 0 30px !important;
    }
    .editor-page #canvasArea>.canvas-stage-controls>.zoom-controls {
        flex: 1 1 0 !important;
        width: auto !important;
        min-width: 0 !important;
        display: grid !important;
        position: relative !important;
        inset: auto !important;
        grid-template-columns: 30px minmax(0, 1fr) 30px 32px !important;
        gap: 4px !important;
        height: 40px !important;
        min-height: 40px !important;
        padding: 4px !important;
        transform: none !important;
    }
    .editor-page #canvasArea .zoom-controls .zoom-percent-control {
        display: none !important;
    }
    .editor-page #canvasArea .zoom-controls :is(.zoom-btn, .zoom-pan-btn, .zoom-reset-btn) {
        width: 30px !important;
        min-width: 0 !important;
        height: 30px !important;
        min-height: 30px !important;
        padding: 5px !important;
    }
    .editor-page #canvasArea .zoom-controls .zoom-range {
        min-width: 0 !important;
        width: 100% !important;
    }
    .editor-page .editor-body>#canvasArea>#canvasWrap {
        inset: 60px 10px 110px !important;
    }
    .editor-page .editor-body>#canvasArea:not(.is-3d-mode)>#canvasWrap {
        inset: 0 !important;
    }
    .editor-page #canvasArea .object-toolbar:not(.text-mode):not(.image-mode),
    .editor-page #canvasArea .object-toolbar.text-mode,
    .editor-page #canvasArea .image-edit-dock {
        position: absolute !important;
        top: 56px !important;
        bottom: auto !important;
        left: 50% !important;
        right: auto !important;
        width: max-content !important;
        max-width: calc(100% - 20px) !important;
        margin: 0 !important;
        transform: translateX(-50%) !important;
    }
    .editor-page #canvasArea.is-3d-mode>.canvas-stage-controls {
        display: flex !important;
        width: max-content !important;
        bottom: 72px !important;
    }
    .editor-page .editor-body>#canvasArea.is-3d-mode>#canvasWrap {
        inset: 60px 10px 10px !important;
    }
    .editor-page #product3DStage .product-3d-help {
        right: 10px !important;
        left: 10px !important;
        bottom: 10px !important;
        width: auto !important;
        max-width: none !important;
        white-space: normal !important;
        text-align: center;
        font-size: 9px !important;
        line-height: 1.4 !important;
        padding: 7px 9px !important;
        transform: none !important;
    }
    .editor-page #toast {
        width: min(420px, calc(100vw - 20px));
        max-height: calc(100dvh - 24px);
        overflow-y: auto;
    }
    .editor-page .editor-body>#sidePanel {
        top: auto !important;
        bottom: calc(var(--editor-mobile-dock) + 18px + env(safe-area-inset-bottom, 0px)) !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        min-width: 0 !important;
        min-height: 0 !important;
        height: min(54dvh, 400px) !important;
        max-height: calc(100dvh - var(--toolbar-h) - var(--editor-mobile-dock) - 40px - env(safe-area-inset-bottom, 0px)) !important;
        padding: 0 !important;
        border-radius: 18px !important;
        overflow: hidden !important;
        z-index: 150;
    }
    .editor-page #sidePanel>.side-panel-body {
        min-width: 0 !important;
        min-height: 0 !important;
        padding: 10px !important;
        overscroll-behavior: contain;
    }
    /* The product form shares the full-height left drawer. */
    .editor-page .editor-body>#sidePanel.product-panel-active {
        height: auto !important;
    }
    .editor-page #sidePanel.product-panel-active>.side-panel-body {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }
    .editor-page #sidePanel.product-panel-active #tab-product.active:not(.product-selector-open) {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }
    .editor-page #sidePanel.product-panel-active #tab-product.active:not(.product-selector-open)>.product-settings-card {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 !important;
        border-radius: 12px !important;
        overflow: visible !important;
    }
    .editor-page #sidePanel .product-basic-title {
        padding: 12px !important;
    }
    .editor-page #sidePanel .product-basic-title strong {
        font-size: 13px !important;
    }
    .editor-page #sidePanel .product-panel-summary {
        margin: 10px 0 !important;
    }
    .editor-page #sidePanel :is(.product-basic-title, .side-panel-floating-header) button {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }
    .editor-page #sidePanel :is(.product-basic-title, .side-panel-floating-header) button svg {
        width: 16px !important;
        height: 16px !important;
    }
    .editor-page #canvasArea>#productDisplayModeToggle {
        top: 50% !important;
        left: 10px !important;
        padding: 3px !important;
    }
    .editor-page #productDisplayModeToggle button {
        min-height: 32px !important;
        padding: 5px 9px !important;
        font-size: 11px !important;
    }
    .editor-page #productDisplayModeToggle svg {
        width: 15px !important;
        height: 15px !important;
    }
    .editor-page #canvasWrap.is-3d-mode {
        overflow: hidden !important;
    }
    .editor-page #product3DStage .product-3d-interaction-btn {
        min-height: 34px !important;
        padding: 7px 10px !important;
        font-size: 11px !important;
    }
    .editor-page #product3DStage .product-3d-interaction-btn svg {
        width: 16px !important;
        height: 16px !important;
    }
}

@media (max-width: 359px) {
    .editor-page .editor-header .brand-lockup__mark {
        width: 66px !important;
        max-width: 66px !important;
        flex-basis: 66px !important;
    }
    .editor-page .editor-header .topbar-left {
        gap: 5px !important;
    }
}

@media (max-width: 768px) and (max-height: 500px) {
     :root {
        --toolbar-h: calc(52px + env(safe-area-inset-top, 0px));
        --editor-mobile-dock: 56px;
    }
    .editor-page .editor-body>#sidePanel {
        height: min(54dvh, 250px) !important;
    }
}


/* Give the mobile header a compact identity row and a clear action row. */

@media (max-width: 768px) {
     :root {
        --toolbar-h: calc(112px + env(safe-area-inset-top, 0px));
    }
    .editor-page .topbar.editor-header {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: 44px 44px;
        align-content: start;
        gap: 8px !important;
        box-sizing: border-box;
        padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px !important;
        border-bottom: 1px solid #dfe6f1 !important;
        background: #fff !important;
        box-shadow: 0 8px 24px rgb(15 23 42 / 8%) !important;
    }
    .editor-page .editor-header .topbar-left {
        grid-row: 1;
        width: 100%;
        min-width: 0;
        height: 44px;
        gap: 8px !important;
        align-items: center;
        justify-content: flex-start;
    }
    .editor-page .editor-header .back-btn {
        border-color: #dce5f2 !important;
        background: #f8faff !important;
        color: #3157bd !important;
    }
    .editor-page .editor-header .product-chip.product-switch-chip {
        border-color: #dce5f2 !important;
        background: #f8faff !important;
        box-shadow: none !important;
        transform: none !important;
    }
    .editor-page .editor-header .topbar-right {
        grid-row: 2;
        width: 100% !important;
        min-width: 0 !important;
        justify-self: stretch;
        margin: 0 !important;
    }
}

.editor-page .editor-mobile-backdrop,
.editor-page .editor-action-label--short,
.editor-page .editor-preview-icon {
    display: none;
}

.editor-page .editor-header #editorPreviewButton>.editor-action-label--short,
.editor-page .editor-header .btn-confirm-order>.editor-action-label--short {
    display: none !important;
}

@media (max-width: 768px) {
    .editor-page .editor-mobile-backdrop:not([hidden]) {
        display: block;
        position: fixed;
        top: var(--toolbar-h);
        right: 0;
        bottom: calc(var(--editor-mobile-dock) + 18px + env(safe-area-inset-bottom, 0px));
        left: 0;
        z-index: 145;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: rgb(20 31 52 / 32%);
        cursor: pointer;
    }
    .editor-page .editor-body>#sidePanel {
        position: fixed !important;
        top: var(--toolbar-h) !important;
        right: auto !important;
        bottom: calc(var(--editor-mobile-dock) + 18px + env(safe-area-inset-bottom, 0px)) !important;
        left: 0 !important;
        width: min(360px, calc(100vw - 40px)) !important;
        max-width: calc(100vw - 40px) !important;
        height: auto !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 16px 16px 0 !important;
        transform: none !important;
        z-index: 150;
    }
    .editor-page .editor-body>#sidePanel:not([hidden]) {
        display: flex !important;
        flex-direction: column;
        opacity: 1 !important;
        pointer-events: auto !important;
        animation: editorMobileDrawerEnter .22s ease-out;
    }
    .editor-page #sidePanel>.side-panel-body {
        padding: 0 !important;
        scrollbar-width: thin;
        scrollbar-color: #cbd7eb transparent;
    }
    .editor-page #sidePanel.product-panel-active #tab-product.active:not(.product-selector-open),
    .editor-page #sidePanel.product-panel-active #tab-product.active:not(.product-selector-open)>.product-settings-card {
        height: 100% !important;
        min-height: 0 !important;
        border-radius: 0 16px 16px 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }
    .editor-page #sidePanel .product-basic-title {
        position: sticky;
        top: 0;
        z-index: 5;
        padding: 14px 16px !important;
        background: #fff;
    }
    .editor-page #sidePanel :is(.product-basic-title, .side-panel-floating-header) button {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        border: 1px solid #dce5f4;
        border-radius: 10px;
        background: #fff;
        color: #52627b;
        box-shadow: none;
    }
    .editor-page #sidePanel :is(.product-basic-title, .side-panel-floating-header) button:focus-visible {
        outline: 2px solid #0051bb;
        outline-offset: 2px;
    }
    .editor-page .editor-header .topbar-right {
        width: 100% !important;
        min-width: 0 !important;
        justify-self: stretch !important;
    }
    .editor-page .editor-header .topbar-design-actions {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100% !important;
        gap: 8px !important;
    }
    .editor-page .editor-header .topbar-design-actions :is(#btnSave, #editorPreviewButton, .btn-confirm-order) {
        box-sizing: border-box;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 44px !important;
        min-height: 44px !important;
        max-height: 44px !important;
        padding: 0 10px !important;
        gap: 7px !important;
        border-radius: 12px !important;
        box-shadow: none !important;
        font-family: 'Montserrat', sans-serif !important;
        transition: border-color .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease !important;
    }
    .editor-page .editor-header .topbar-design-actions #btnSave {
        border-color: #d8e1ee !important;
        background: #fff !important;
        color: #34445e !important;
    }
    .editor-page .editor-header .topbar-design-actions #editorPreviewButton {
        border-color: #cbdaf5 !important;
        background: #eef4ff !important;
        color: #2854be !important;
    }
    .editor-page .editor-header .topbar-design-actions .btn-confirm-order {
        border-color: #2d55c7 !important;
        background: #2d55c7 !important;
        color: #fff !important;
        box-shadow: 0 6px 14px rgb(45 85 199 / 22%) !important;
    }
    .editor-page .editor-header .topbar-design-actions #btnSaveLabel,
    .editor-page .editor-header .topbar-design-actions #editorPreviewButton>.editor-action-label--short,
    .editor-page .editor-header .topbar-design-actions .btn-confirm-order>.editor-action-label--short {
        display: block !important;
        min-width: 0;
        font-size: 11px !important;
        font-weight: 700 !important;
        line-height: 1.3 !important;
        color: inherit !important;
        white-space: nowrap;
    }
    .editor-page .editor-header .topbar-design-actions #editorPreviewButton>.editor-action-label--full,
    .editor-page .editor-header .topbar-design-actions .btn-confirm-order>.editor-action-label--full {
        display: none !important;
    }
    .editor-page .editor-header #editorPreviewButton .editor-preview-icon {
        display: block;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }
    .editor-page .editor-header .topbar-design-actions .btn-confirm-order>i {
        margin-left: 1px !important;
    }
    .editor-page .editor-header .topbar-design-actions :is(#btnSave, #editorPreviewButton, .btn-confirm-order):active {
        transform: translateY(1px) !important;
    }
    .editor-page .editor-header .topbar-design-actions :is(#btnSave, #editorPreviewButton, .btn-confirm-order):focus-visible {
        outline: 3px solid rgb(59 130 246 / 24%);
        outline-offset: 2px;
    }
    .editor-page .editor-header .topbar-design-actions button:disabled {
        opacity: .6;
        cursor: wait;
    }
}

@keyframes editorMobileDrawerEnter {
    from {
        translate: -100% 0;
    }
    to {
        translate: 0 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .editor-page .editor-body>#sidePanel:not([hidden]) {
        animation: none;
    }
}
