/* ============================================================
   Sash Designer — layout & "card" UI
   Tip: change --sd-accent to rebrand the interactive/active colour.
   ============================================================ */

/* Notice shown when a saved design could not be loaded (denied / expired). */
.sd-rehydration-notice {
    margin: 0 0 16px;
    padding: 12px 16px;
    border: 1px solid #f0c36d;
    background: #fdf6e3;
    color: #7a5c00;
    border-radius: 6px;
    font-size: 0.95em;
    line-height: 1.4;
}

#sd-designer-wrapper {
    --sd-accent: #6C026E;
    --sd-accent-dark: #530154;
    --sd-accent-soft: rgba(108, 2, 110, 0.12);
    --sd-surface: #fff;
    --sd-bg: #f4f6f8;
    --sd-border: #e3e7ec;
    --sd-text: #1f2733;
    --sd-muted: #6b7480;
    --sd-radius: 12px;
    --sd-gap: 16px;

    background: var(--sd-bg);
    border: 1px solid var(--sd-border);
    padding: 20px;
    border-radius: var(--sd-radius);
    margin-top: 20px;
    color: var(--sd-text);
}

/* Heading */
.sd-designer-head {
    margin-bottom: 18px;
}

.sd-designer-title {
    margin: 0 0 4px 0;
    font-size: 1.25em;
    line-height: 1.2;
}

.sd-designer-intro {
    margin: 0;
    color: var(--sd-muted);
    font-size: 0.92em;
}

/* Preview */
#sd-preview-container {
    margin: 0 auto 20px auto;
    border: 1px solid var(--sd-border);
    width: 100%;
    max-width: 100%;
    position: relative;
    border-radius: var(--sd-radius);
    overflow: hidden;
    background-color: #e9edf1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Clip each band to its own rectangle. The rotated text (Querdruck) is an
   absolutely positioned element whose PRE-rotation box is much wider than the
   narrow band; without clipping that overhang inflates the zoom scroll area
   (huge empty canvas). The visible text sits fully inside the band, so nothing
   visible is cut off. */
#sd-sash-preview,
#sd-sash-preview-2 {
    overflow: hidden;
}

#sd-sash-preview {
    transition: background-color 0.3s ease;
}

#sd-text-preview,
#sd-text-preview-2 {
    transition: color 0.3s ease;
    padding: 0;
    line-height: 1.2em;
    max-width: 100%;
    word-wrap: break-word;
}

/* Proportional scaling of the fixed-size preview so it never gets clipped.
   `margin: auto` in the (zoomed) flex scroll viewport centres the box when it
   fits AND keeps both edges reachable when it overflows — unlike
   justify-content:center, which clips the start edge on horizontal overflow. */
.sd-preview-fit {
    position: relative;
    margin: auto;
}

.sd-preview-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
}

/* Scroll viewport — becomes scrollable when the preview is zoomed in. The zoom
   button lives outside it (on the container) so it stays pinned while scrolling. */
.sd-preview-viewport {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
}

#sd-preview-container.sd-zoomed .sd-preview-viewport {
    width: 100%;
    max-height: 60vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    /* Let `.sd-preview-fit { margin:auto }` do the (scroll-safe) centering; do
       NOT use justify-content:center here — it clips the start edge on overflow. */
    align-items: flex-start;
    justify-content: flex-start;
}

/* Zoom toggle (small white button, black icon) bottom-right of the preview.
   !important beats the theme's generic button styles. */
.sd-zoom-toggle {
    position: absolute !important;
    right: 10px !important;
    bottom: 10px !important;
    left: auto !important;
    top: auto !important;
    float: none !important;
    z-index: 33 !important;
    display: flex !important;
    flex: 0 0 auto !important;
    align-items: center !important;
    justify-content: center !important;
    width: 38px !important;
    height: 38px !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 1px solid rgba(0, 0, 0, 0.15) !important;
    border-radius: 50% !important;
    background: #ffffff !important;
    color: #111111 !important;
    line-height: 1 !important;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25) !important;
}

.sd-zoom-toggle svg {
    width: 18px !important;
    height: 18px !important;
    display: block !important;
    fill: #111111 !important;
}

.sd-zoom-toggle svg path {
    fill: #111111 !important;
}


/* "Rotated for display" note (mobile landscape preview) */
.sd-rotate-note {
    position: absolute;
    left: 50%;
    bottom: 6px;
    transform: translateX(-50%);
    background: rgba(31, 39, 51, 0.7);
    color: #fff;
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 999px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 31;
    display: none;
}

#sd-preview-container.sd-rotated .sd-rotate-note {
    display: block;
}

/* Steps as cards */
.sd-controls {
    display: flex;
    flex-direction: column;
    gap: var(--sd-gap);
}

.sd-step {
    background: var(--sd-surface);
    border: 1px solid var(--sd-border);
    border-radius: var(--sd-radius);
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.sd-step-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.sd-step-num {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--sd-accent);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sd-step-title {
    font-weight: 700;
    font-size: 1.05em;
}

.sd-optional {
    font-weight: 400;
    color: var(--sd-muted);
    font-size: 0.85em;
}

.sd-surcharge-label {
    margin-left: auto;
    font-weight: 400;
    font-size: 0.9em;
    color: var(--sd-muted);
}

/* Fields */
.sd-step-body .sd-control-group {
    margin-bottom: 14px;
}

.sd-step-body .sd-control-group:last-child {
    margin-bottom: 0;
}

.sd-step-body .sd-control-group > label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.95em;
}

#sd-designer-wrapper select,
#sd-designer-wrapper input[type="number"],
#sd-designer-wrapper textarea {
    width: 100%;
    border: 1px solid var(--sd-border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 1em;
    background: #fff;
    box-sizing: border-box;
}

#sd-designer-wrapper textarea {
    line-height: 1.4;
    /* Fixed height (independent of the max-lines setting). !important beats a
       theme's inline auto-resize; box-sizing:border-box keeps it exactly 80px. */
    height: 80px !important;
    resize: none !important;
    overflow-y: auto;
}

#sd-designer-wrapper select:focus,
#sd-designer-wrapper input:focus,
#sd-designer-wrapper textarea:focus {
    outline: none;
    border-color: var(--sd-accent);
    box-shadow: 0 0 0 3px var(--sd-accent-soft);
}

/* Two-column row (font + size) inside the "Text & Schrift" step */
.sd-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.sd-field-row .sd-control-group {
    margin-bottom: 0;
}

/* Selected colour name */
.sd-selected-name {
    margin-top: 8px;
    font-size: 0.9em;
    color: var(--sd-muted);
    min-height: 1.2em;
}

/* Reverse checkbox */
.sd-reverse {
    margin-top: 12px;
}

.sd-checkbox {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    font-weight: 400 !important;
    margin: 0 !important;
    cursor: pointer;
}

.sd-checkbox input {
    width: auto !important;
}

/* Footer */
.sd-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

#sd-price-display {
    font-weight: 700;
    font-size: 1.1em;
    background: var(--sd-accent-soft);
    color: var(--sd-text);
    padding: 8px 14px;
    border-radius: 8px;
}

/* Live total price of the current configuration (own line, below the pill) */
.sd-live-total {
    flex-basis: 100%;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-top: 4px;
    padding-top: 12px;
    border-top: 1px solid var(--sd-border);
}

.sd-live-total-label {
    font-weight: 600;
    color: var(--sd-muted);
    font-size: 0.95em;
}

.sd-live-total-value {
    font-weight: 800;
    font-size: 1.35em;
    color: var(--sd-accent);
    white-space: nowrap;
}

/* Validation error box */
#sd-validation-error {
    order: 6;
    display: none;
    background: #fdecea;
    border: 1px solid #f5c2c0;
    color: #8a1f1a;
    border-radius: var(--sd-radius);
    padding: 12px 15px;
    font-size: 14px;
}

#sd-validation-error ul {
    margin: 5px 0 0 18px;
    padding: 0;
}

#sd-validation-error li {
    margin: 2px 0;
}

/* Swatches */
.sd-swatch-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sd-swatch-label {
    cursor: pointer;
    position: relative;
    display: block;
    border-radius: 8px;
    padding: 3px;
    border: 2px solid transparent;
    transition: border-color 0.15s ease;
}

.sd-swatch-label input {
    display: none;
}

.sd-swatch-color {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    /* Outer ring instead of a (semi-transparent) border: the border would sit
       ON TOP of the gradient and tint its bottom 1px, showing a thin off-colour
       line on multi-colour swatches. An outset shadow rings the swatch without
       touching the gradient. */
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.sd-swatch-label:hover {
    border-color: rgba(0, 0, 0, 0.2);
}

.sd-swatch-label:has(input:checked) {
    border-color: var(--sd-accent);
}

.sd-swatch-label:has(input:checked)::after {
    content: '';
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: var(--sd-accent);
    border: 2px solid #fff;
    border-radius: 50%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    background-size: 12px;
    background-repeat: no-repeat;
    background-position: center;
}

/* Disabled Swatches */
.sd-swatch-label.sd-disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

.sd-swatch-label.sd-disabled .sd-swatch-color::after {
    content: 'X';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
    font-weight: bold;
    color: #ff0000;
    line-height: 1;
}

.sd-swatch-label.sd-disabled input {
    pointer-events: none;
}

/* Length control (slider) */
.sd-length-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sd-length-row input[type="range"] {
    flex: 1 1 auto;
    min-width: 0;
}

.sd-length-min,
.sd-length-max {
    font-size: 0.85em;
    color: var(--sd-muted);
    min-width: 1.4em;
    text-align: center;
}

.sd-length-value {
    font-weight: 700;
    color: var(--sd-accent);
}

/* Font size control (percentage slider) */
.sd-font-size-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

#sd-designer-wrapper input[type="range"].sd-font-range,
#sd-designer-wrapper #sd-font-size-input[type="range"],
#sd-designer-wrapper #sd-length-input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: #e3e7ec;
    cursor: pointer;
}

#sd-font-size-input[type="range"]::-webkit-slider-thumb,
#sd-length-input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--sd-accent);
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

#sd-font-size-input[type="range"]::-moz-range-thumb,
#sd-length-input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--sd-accent);
    border: 2px solid #fff;
}

/* SVG palette buttons */
.sd-svg-option {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 64px;
    height: 64px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid var(--sd-border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    /* !important beats the theme's button padding (e.g. 5px 20px). */
    padding: 12px !important;
    cursor: pointer;
}

.sd-svg-option img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.sd-svg-option:hover {
    border-color: var(--sd-accent);
}

/* Currently selected symbol in the palette: accent background + white icon.
   The icon is an <img>, so recolour it to white with a filter. */
.sd-svg-option.is-active {
    background: var(--sd-accent);
    border-color: var(--sd-accent);
}

.sd-svg-option.is-active img {
    filter: brightness(0) invert(1);
}

/* Symbol side toggle (double sash) */
.sd-symbol-side-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}

.sd-symbol-side-label {
    font-size: 13px;
    color: var(--sd-muted);
}

.sd-symbol-side-btn {
    background: #f0f0f0;
    border: 1px solid var(--sd-border);
    border-radius: 6px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 13px;
}

.sd-symbol-side-btn.active {
    background: var(--sd-accent);
    color: #fff;
    border-color: var(--sd-accent);
}

.sd-symbol-hint {
    font-size: 12px;
    color: var(--sd-muted);
    margin: 0 0 10px 0;
}

.sd-symbol-limit-msg {
    color: #c0392b;
    font-size: 13px;
    margin: 8px 0 0 0;
}

/* --- Placed symbols ("stickers") --- */
.sd-symbol {
    position: absolute;
    pointer-events: auto;
    cursor: move;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.sd-symbol-graphic {
    width: 50px;
    height: 50px;
    pointer-events: none;
    /* color is set inline; inner SVG paths use fill: currentColor */
}

.sd-symbol-graphic svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Selected symbol: a dashed selection outline whose colour adapts to the sash
   (same contrast colour as the boundary box, set as --sd-line-color by JS).
   Edited via the floating toolbar. */
.sd-symbol.is-selected {
    outline: 2px dashed var(--sd-line-color, rgba(0, 0, 0, 0.55));
    outline-offset: 3px;
}

/* --- Floating toolbar for the selected symbol (placed at the symbol by JS) --- */
.sd-symbol-toolbar {
    position: fixed;
    z-index: 100000;
    display: none;
    /* JS toggles to flex */
    align-items: center;
    gap: 4px;
    padding: 5px;
    background: #fff;
    border: 1px solid var(--sd-border);
    border-radius: 10px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22);
}

.sd-symbol-tool-btn {
    box-sizing: border-box;
    width: 38px !important;
    height: 38px !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--sd-border);
    background: #fff;
    border-radius: 8px;
    font-size: 20px;
    line-height: 1;
    color: var(--sd-text);
    cursor: pointer;
    box-shadow: none;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.sd-symbol-tool-btn:hover {
    border-color: var(--sd-accent);
}

.sd-symbol-tool-btn:active {
    background: var(--sd-accent-soft);
}

.sd-symbol-tool-btn.sd-symbol-del {
    color: #c0392b;
    border-color: #e6b8b2;
}

.sd-symbol-tool-sep {
    width: 1px;
    align-self: stretch;
    margin: 4px 2px;
    background: var(--sd-border);
}

/* Center alignment guides (shown while dragging) */
.sd-guide {
    position: absolute;
    background: var(--sd-accent);
    pointer-events: none;
    z-index: 20;
    display: none;
}

.sd-guide.is-visible {
    display: block;
}

.sd-guide-v {
    top: 0;
    bottom: 0;
    width: 1px;
    left: 50%;
    transform: translateX(-50%);
}

.sd-guide-h {
    left: 0;
    right: 0;
    height: 1px;
    top: 50%;
    transform: translateY(-50%);
}

/* Rotated text (Querdruck). inline-block shrink-wraps to the text so the
   measured box is the text box; `pre` keeps the customer's manual line breaks
   (up to max_lines) but never auto-wraps. */
.sd-rotated {
    position: absolute !important;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-90deg);
    transform-origin: center center;
    width: auto !important;
    height: auto !important;
    /* must shrink-wrap to the text, not be capped by the (narrow) box width */
    max-width: none !important;
    max-height: none !important;
    white-space: pre !important;
    display: inline-block !important;
    text-align: center;
}

/* ---- Responsive ---- */

/* Mobile "sticky" preview: a FIXED bar (attached to <body>) pins the live
   preview at the top (~40vh); a spacer reserves the space so title + options
   scroll under it. position:fixed on a body-level element is immune to theme
   wrappers whose overflow/transform would break position:sticky. Toggled by the
   global setting (JS builds the bar on mobile). When off: static gallery. */
@media (max-width: 860px) {
    #sd-sticky-preview-bar {
        position: fixed;
        top: 0;
        /* JS anchors this to the gallery's position (below the header) */
        left: 0;
        right: 0;
        height: 40vh;
        /* Above the page content, but BELOW the theme's slide-in menu / overlays
           (those are typically ~100+), so the WoodMart menu opens over it. */
        z-index: 50;
        background: #fff;
        overflow: hidden;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
    }

    /* The product gallery becomes the in-flow 40vh spacer (top of the product
       content, right below the header); the fixed bar overlays it. */
    body.sd-mobile-sticky .woocommerce-product-gallery,
    body.sd-mobile-sticky .product .images,
    body.sd-mobile-sticky .product-images {
        height: 40vh !important;
        min-height: 40vh;
        max-height: 40vh;
        overflow: hidden;
    }

    #sd-sticky-preview-bar #sd-preview-container {
        height: 100%;
        margin: 0;
        border: 0;
        border-radius: 0;
        padding: 8px;
        box-sizing: border-box;
    }

    /* Keep the pinned preview within the 40vh bar; its internal viewport scrolls
       the rest (unchanged flex viewport that already works in the static view). */
    #sd-sticky-preview-bar #sd-preview-container .sd-preview-viewport,
    #sd-sticky-preview-bar #sd-preview-container.sd-zoomed .sd-preview-viewport {
        max-height: 100%;
    }
}

/* Tighter spacing on mobile → more room for the options. */
@media (max-width: 860px) {
    #sd-designer-wrapper {
        --sd-gap: 10px;
        padding: 10px;
        margin-top: 10px;
    }

    .sd-designer-head {
        margin-bottom: 10px;
    }

    .sd-step {
        padding: 10px;
    }

    .sd-step-head {
        margin-bottom: 10px;
    }

    /* Non-sticky preview padding (the sticky box sets its own). */
    #sd-preview-container {
        padding: 10px;
    }
}

@media (max-width: 600px) {

    /* Font + size stack */
    .sd-field-row {
        grid-template-columns: 1fr;
    }

    /* Larger touch targets */
    .sd-swatch-color {
        width: 44px;
        height: 44px;
    }

    .sd-svg-option {
        width: 56px;
        height: 56px;
    }
}
