/* --- Basic Reset & Mobile-First Styles --- */

#app-container {
    max-width: var(--wp--style--global--wide-size);
    height: 100%;
    display: flex;
    flex-direction: column;
    /* Mobile: Top-to-bottom */
    background: #fff;
    position: relative;
}

#canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Prevents scrollbars if canvas is 1px too big */
}

#product-canvas {
    display: block;
    /* Removes default inline spacing */
    width: 100% !important;
    height: 100% !important;
    outline: none;
    cursor: grab;
}

#product-canvas.is-dragging {
    cursor: grabbing;
}

/* --- Sidebar: mobile-first --- */
#sidebar {
    /* Mobile: place in normal document flow under the canvas */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar-content {
    padding: 16px;
    overflow-y: auto;
    flex-grow: 1;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

#sidebar-content::-webkit-scrollbar {
    width: 6px;
}

#sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

#sidebar-content::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* --- Sidebar Action Bar (bottom) --- */
#sidebar-action-bar {
    border: 1px solid #eee;
    border-left: none;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: end;
    align-items: center;
}

#sidebar-action-bar button span {
    padding-left: 4px;
}

.add-to-cart-container {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

/* WC cart form merges into the flex row; express payment buttons appear alongside. */
.dprcu-express-form {
    display: contents;
}

.dprcu-price-cart-wrapper{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* Native WC add-to-cart button styled to match the customizer action buttons. */
.dprcu-cart-btn {
    display: flex !important;
    align-items: center;
    gap: 6px;
    background: #fff;
    color: #111;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.dprcu-cart-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}



/* --- Mobile Menu Grid --- */
.mobile-menu-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    /* 2-column grid */
    gap: 10px;
}

.mobile-submenu-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mobile-menu-button {
    padding: 10px 8px;
    background: #f9f9f9;
    border: 1px solid #eee;
    min-height: 100px;
    border-radius: 8px;
    text-align: center;
    /* Center text for grid */
    font-size: 14px;
    /* Slightly smaller for grid */
    font-weight: 500;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    /* Stack icon and text */
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.mobile-section-description {
    font-size: 12px;
    color: rgb(102, 102, 102);
    padding: 12px 16px;
    margin: 0px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgb(238, 238, 238);
}

#btn-mobile-back {
    padding: 14px 12px;
    background: #f0f0f0;
    border: 1px solid #eee;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-submenu-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.mobile-submenu-header h3 {
    margin: 0;
    font-size: 18px;
}

.cust-section {
    margin-bottom: 24px;
    border-bottom: 1px solid #eee;
    padding-bottom: 16px;
}

.cust-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.cust-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 12px;
}

.color-swatches {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.swatch-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    /* Space between swatch and name */
    cursor: pointer;
    transition: transform 0.1s ease;
}

.swatch-wrapper:hover {
    transform: scale(1.05);
}

.swatch-name {
    font-size: 12px;
    color: #555;
    text-align: center;
}

/* Desktop Swatch Size */
.color-swatch {
    width: 100%;
    height: 80px;
    border-radius: 4px;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #ccc;
    background-color: #ffffff;
    position: relative;
    overflow: hidden;
}

.logic-swatch {
    overflow: hidden;
    width: 100%;
    height: 80px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    position: relative;
}

.swatch-price-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    white-space: nowrap;
}

/* Active State (applied to wrapper) */
.swatch-wrapper.active .color-swatch,
.swatch-wrapper.active .logic-swatch {
    box-shadow: 0 0 0 2px #096dd9;
}

.swatch-wrapper.active .swatch-name {
    font-weight: 600;
    color: #000;
}


/* --- View Controls (Left) --- */
#view-controls {
    height: 100%;
    position: absolute;
    left: 16px;
    top: 0px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: start;
    gap: 4px;
    z-index: 10;
}

.control-btn,
.btn-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    line-height: 0;
    min-width: 44px;
    min-height: 44px;
    width: auto;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.7);
    border: none;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s, color 0.2s;
    color: #333333;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.btn-back {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.control-btn.floating {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    padding: 12px 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.control-btn:hover {
    transform: scale(1.1);
    color: #096dd9;
}

.control-btn:disabled {
    opacity: 0.4;
    color: #aaa;
    cursor: not-allowed;
    transform: none;
}

/* --- Desktop Layout (min-width: 769px) --- */
@media (min-width: 769px) {

    body,
    html {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    #app-container {
        /* Use most of the viewport width on desktop while keeping a small page margin */
        height: 80vh;
        flex-direction: row;
        /* Side-by-side */
        overflow: hidden;
    }

    #canvas-container {
        flex-grow: 1;
        flex-basis: 0;
    }

    /* Ensure the canvas fills the entire canvas container on desktop so it isn't narrow */
    #canvas-container {
        height: 100%;
        min-height: 0;
        display: flex;
        align-items: stretch;
    }

    /* Higher-specificity selector to avoid needing !important */
    #app-container #canvas-container>#product-canvas,
    #app-container #canvas-container canvas {
        width: 100%;
        height: 100%;
        display: block;
        object-fit: cover;
    }

    /* Desktop: fix the sidebar to the right and restore canvas margin */
    #sidebar {
        display: flex;
        width: 420px;
        flex-direction: column;
        z-index: 50;
    }

    /* Ensure mobile-only UI is hidden on desktop widths */
    .mobile-menu-container,
    .mobile-submenu-container,
    #btn-mobile-back {
        display: none;
    }
}

.customizer-title {
    padding: .25em;
    margin: 0px;
}

.step-icon-img {
    width: 75%;
    object-fit: contain;
    border-radius: 4px;
}


/* Loader Container */
#customizer-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    /* Semi-transparent white */
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    pointer-events: none;
    /* Let clicks pass through when fading out */
}

#customizer-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Spinner Animation */
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top: 4px solid #333;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

#loader-text {
    font-family: sans-serif;
    font-size: 14px;
    color: #333;
    font-weight: 600;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ── Viewer-only mode ──────────────────────────────────────────────────────
 *
 * The outer wrapper uses WooCommerce's own gallery CSS classes, so the
 * theme's column layout positions it correctly. We only need to give the
 * canvas a height and hide the sidebar shell.
 * ─────────────────────────────────────────────────────────────────────── */

.psc-viewer-only #app-container {
    display: block;
    width: 100%;
    height: 500px;
}

/* The base #canvas-container rule already sets width/height 100% */

.psc-viewer-only #btn-undo,
.psc-viewer-only #btn-redo {
    display: none;
}

.psc-viewer-only #sidebar.psc-hidden {
    display: none;
}



/* ── Share Modal ──────────────────────────────────────────────────────────── */

#share-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

#share-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.share-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.share-modal-content {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 12px;
    max-width: 480px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.share-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.share-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.share-modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.share-modal-close:hover {
    color: #333;
}

.share-modal-body {
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.share-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #f5f5f5;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #eee;
}

.share-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.share-option label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #888;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.share-link-container {
    display: flex;
    gap: 8px;
}

#share-link-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    font-family: monospace;
    background: #f9f9f9;
    color: #333;
}

/* --- Watermark / Branding --- */
.dprcu-watermark {
    position: absolute;
    bottom: 12px;
    right: 12px;
    opacity: 0.5;
    transition: opacity 0.3s ease;
    z-index: 10;
    background-color: black;
}

.dprcu-watermark:hover {
    opacity: 0.7;
}

.dprcu-watermark a {
    padding: 4px 8px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 14px;
    text-decoration: none;
}

.dprcu-watermark img {
    max-width: 100px !important;
    max-height: 40px;
    width: auto;
    height: auto;
    display: block;
}

.btn-link-copy {
    padding: 10px 16px;
    background: #096dd9;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-link-copy:hover {
    background: #0753c3;
}

.share-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.share-btn {
    padding: 10px 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.share-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.share-btn-facebook {
    color: #1877f2;
    border-color: #1877f2;
}

.share-btn-facebook:hover {
    background: #f0f2f5;
}

.share-btn-twitter {
    color: #1da1f2;
    border-color: #1da1f2;
}

.share-btn-twitter:hover {
    background: #f7f9fa;
}

.share-btn-linkedin {
    color: #0a66c2;
    border-color: #0a66c2;
}

.share-btn-linkedin:hover {
    background: #f3f6f8;
}

.share-btn-pinterest {
    color: #e60023;
    border-color: #e60023;
}

.share-btn-pinterest:hover {
    background: #fff5f5;
}

.btn-download-image {
    width: 100%;
    padding: 12px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: #333;
}

.btn-download-image svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.btn-download-image:hover {
    background: #e8e8e8;
}

@media (max-width: 768px) {
    .share-modal-content {
        max-width: 100%;
        width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 90vh;
        position: fixed;
        bottom: 0;
        left: 0;
    }

    #share-modal.active {
        align-items: flex-end;
    }

    .share-buttons {
        grid-template-columns: 1fr;
    }
}

/* --- Help Modal --- */
#help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    -webkit-transform: translateZ(0);
}

#help-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.help-modal-content {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.help-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.help-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.help-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-modal-close:hover {
    color: #333;
}

.help-modal-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex-grow: 1;
}

.shortcuts-section {
    margin-bottom: 24px;
}

.shortcuts-section:last-child {
    margin-bottom: 0;
}

.shortcuts-section h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    gap: 8px;
}

.shortcut-item:last-child {
    border-bottom: none;
}

.shortcut-item kbd:first-of-type {
    margin-left: auto;
}

.shortcut-keys {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0;
}

.shortcut-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    color: #666;
    flex-shrink: 0;
}

kbd {
    background: #f9f9f9;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 3px 6px;
    font-family: monospace;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    display: inline-block;
    margin: 0 2px;
}

.kbd-plus {
    margin: 0 4px;
    color: #333;
    font-size: 11px;
    font-weight: 600;
}

.shortcut-desc {
    flex-grow: 0;
    padding: 0 8px;
    font-size: 13px;
    color: #666;
}

.help-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

@media (max-width: 768px) {
    .help-modal-content {
        max-width: 100%;
        width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 90dvh;
        margin-top: auto;
    }

    #help-modal.active {
        align-items: flex-end;
    }

    .shortcut-key {
        font-size: 10px;
        padding: 3px 6px;
    }

    .shortcut-desc {
        font-size: 12px;
    }

    .shortcut-icon {
        width: 18px;
        height: 18px;
    }

    kbd {
        font-size: 11px;
        padding: 2px 5px;
    }

    .customizer-title {
        padding: 12px 0px;
    }

    /* Make canvas square on mobile: use aspect-ratio so it stays width x width */
    #canvas-container {
        margin-right: 0;
        margin-bottom: 0;
    }

    #product-canvas {
        aspect-ratio: 1 / 1.5;
        width: 100%;
        height: auto;
    }

    #sidebar-content {
        padding: 8px;
        overflow: auto;
    }

    /* Larger swatch sizes for the mobile bottom bar */
    #sidebar-content .color-swatch {
        height: 100px;
    }

    #sidebar-content .logic-swatch {
        height: 100px;
    }

    #sidebar-content .swatch-name {
        font-size: 13px;
    }

    #view-controls {
        left: 4px;
    }

    .color-swatches {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .control-btn.floating {
        bottom: unset;
        left: unset;
        top: 16px;
        right: 16px;
        padding: 10px 14px;
    }
}


.dprcu-ar-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    /* container is transparent to taps */
    z-index: 2147483647;
    /* WebXR puts it above canvas anyway, but be explicit for non-XR fallback */
    font-family: system-ui, sans-serif;
    color: #fff;
    -webkit-user-select: none;
    user-select: none;
}

.dprcu-ar-overlay>* {
    pointer-events: auto;
    /* children are tappable */
}

.dprcu-ar-overlay[hidden] {
    display: none;
}

/* Exit button — top right, large tap target */
.dprcu-ar-exit {
    position: absolute;
    top: env(safe-area-inset-top, 16px);
    right: env(safe-area-inset-right, 16px);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

/* Hints — centered top */
.dprcu-ar-hint {
    position: absolute;
    top: calc(env(safe-area-inset-top, 16px) + 16px);
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 18px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    font-size: 14px;
    white-space: nowrap;
}

/* Controls — bottom center bar */
.dprcu-ar-controls {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
}

.dprcu-ar-btn {
    min-width: 64px;
    height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.dprcu-ar-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

[hidden] {
    display: none !important;
}