/* ==========================================================================
   Made-To-Order builder
   Dedicated custom-garment builder: layered live preview on the left, the four
   option groups (garment / color / size / graphic, choosable in any order) on
   the right. Availability, preview and price are refreshed server-side on each
   selection; this stylesheet only handles layout and the available/selected states.
   ========================================================================== */

.product-info.mto {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.mto-builder {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    align-items: flex-start;
}

.mto-builder-left {
    flex: 1 1 380px;
    position: sticky;
    top: 20px;
}

.mto-builder-right {
    flex: 1 1 420px;
    min-width: 300px;
}

/* --- Live preview ------------------------------------------------------- */

.mto-preview {
    background: var(--mto-preview-bg, #f5f5f5);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

/* Spinner shown over the current preview while the next one downloads (the old image stays put
   underneath until the new one has loaded, so there's no empty/broken flash). */
.mto-preview.mto-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 42px;
    height: 42px;
    margin: -21px 0 0 -21px;
    border: 4px solid rgba(0, 0, 0, .15);
    border-top-color: rgba(0, 0, 0, .55);
    border-radius: 50%;
    animation: mto-spin .7s linear infinite;
    z-index: 5;
}

@keyframes mto-spin {
    to { transform: rotate(360deg); }
}

.mto-preview-stack {
    position: relative;
    width: 100%;
    padding-top: 100%; /* square stage */
}

.mto-preview-base,
.mto-preview-graphic,
.mto-preview-empty {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.mto-preview-base {
    object-fit: contain;
}

/* Graphic overlay: centered on the chest area of the garment photo. These values
   are an approximation that works across the standard front garment shots; adjust
   --mto-graphic-* if a client's photography needs a different print placement. */
.mto-preview-graphic {
    top: var(--mto-graphic-top, 30%);
    left: var(--mto-graphic-left, 50%);
    width: var(--mto-graphic-width, 32%);
    height: auto;
    transform: translateX(-50%);
    object-fit: contain;
    pointer-events: none;
}

.mto-preview-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 15px;
    text-align: center;
    padding: 20px;
}

/* --- Price -------------------------------------------------------------- */

.mto-price-holder {
    margin-bottom: 16px;
}

.mto-price {
    font-size: 24px;
    font-weight: 700;
}

/* --- Stepped tabs ------------------------------------------------------- */

.mto-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.mto-tab {
    flex: 1 1 0;
    min-width: 92px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-bottom: 3px solid #ddd;
    border-radius: 6px 6px 0 0;
    background: #fafafa;
    cursor: pointer;
    color: #1a1a1a;
}

.mto-tab.active {
    background: #fff;
    border-bottom-color: var(--mto-selected, #1a1a1a);
}

.mto-tab-num {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ddd;
    color: #333;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mto-tab.active .mto-tab-num { background: var(--mto-selected, #1a1a1a); color: #fff; }

/* A completed step gets a check mark in place of its number. */
.mto-tab.chosen .mto-tab-num { background: #2e7d32; color: #fff; font-size: 0; }
.mto-tab.chosen .mto-tab-num::after { content: "\2713"; font-size: 13px; }

.mto-tab-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    overflow: hidden;
}

.mto-tab-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.mto-tab-choice {
    font-size: 12px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Panels ------------------------------------------------------------- */

.mto-panel { display: none; }
.mto-panel.active { display: block; }

.mto-panel-head {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.mto-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
    padding: 2px;
}

.mto-panel-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 14px;
}

.mto-panel-nav button {
    cursor: pointer;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    color: #1a1a1a;
}

.mto-panel-nav button:hover { border-color: #999; }

.mto-option {
    cursor: pointer;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: #fff;
    color: #1a1a1a; /* explicit so labels are readable regardless of the theme's inherited text color */
    transition: border-color .12s ease, box-shadow .12s ease, opacity .12s ease;
    user-select: none;
}

.mto-option:hover {
    border-color: #999;
}

.mto-option.selected {
    border-color: var(--mto-selected, #1a1a1a);
    box-shadow: 0 0 0 1px var(--mto-selected, #1a1a1a);
}

/* Text tiles (garment / size) */
.mto-option-text {
    padding: 9px 14px;
    font-size: 14px;
    line-height: 1.2;
}

.mto-option-text .mto-option-price {
    color: #888;
    font-size: 12px;
    margin-left: 4px;
}

/* Color tiles: solid hex swatch (name shown via the tile's title tooltip) */
.mto-option-color {
    width: 44px;
    height: 44px;
    padding: 0;
    overflow: hidden;
    position: relative;
}

.mto-swatch {
    display: block;
    width: 100%;
    height: 100%;
    background: #eee; /* fallback when a colour has no hex on file */
}

/* Image tiles (graphic) — center the design in the square with flex, so it never sits off-corner */
.mto-option-image {
    width: 58px;
    height: 58px;
    padding: 0;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mto-option-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Swatch/graphic names are conveyed via the title tooltip; keep them out of the tile visually. */
.mto-option-image .mto-option-label,
.mto-option-color .mto-option-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* Graphic swatches: neutral gray backing so both light/white and dark designs read clearly.
   Inset padding lives on the container (border-box) so the centered image never overflows. */
.mto-panel[data-dim="graphic"] .mto-option-image {
    width: 72px;
    height: 72px;
    padding: 8px;
    box-sizing: border-box;
    background: #cccccc;
}

/* --- Availability states ------------------------------------------------ */

/* Only ever show options that lead to a valid, buildable combination — no greyed-out dead ends
   (e.g. no "24 Months" under an adult Raglan). Garment is the root choice and is never marked
   unavailable, so it always stays fully selectable. */
.mto-option.unavailable {
    display: none;
}

/* --- Add to cart -------------------------------------------------------- */

.mto-cart {
    margin-top: 10px;
}

.mto-form .product-info-details-buttons {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.mto-form .product-info-add-to-cart button {
    cursor: pointer;
}

.mto-form .product-info-add-to-cart button[disabled] {
    opacity: .5;
    cursor: not-allowed;
}

.mto-form .error-message {
    color: #c0392b;
    margin-top: 8px;
}

.mto-loading {
    opacity: .6;
    transition: opacity .12s ease;
}

@media (max-width: 780px) {
    .mto-builder-left { position: static; }
}

/* --- Calibration mode (?mtocal=1) --------------------------------------- */

.mto-calibrate .mto-preview-graphic {
    pointer-events: auto;
    cursor: move;
    outline: 1px dashed rgba(0, 0, 0, .55);
}

.mto-cal-panel {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 9999;
    width: 290px;
    background: #111;
    color: #eee;
    padding: 12px 14px;
    border-radius: 8px;
    font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

.mto-cal-title { font-weight: 700; margin-bottom: 6px; }

.mto-cal-values { margin: 6px 0 10px; }

.mto-cal-save {
    cursor: pointer;
    background: #2e7d32;
    color: #fff;
    border: 0;
    border-radius: 4px;
    padding: 6px 12px;
}

.mto-cal-save[disabled] { opacity: .5; cursor: not-allowed; }

.mto-cal-status { margin-left: 8px; color: #8fe6c8; }

.mto-cal-hint { color: #999; margin-top: 8px; }
