/* ════════════════════════════════════════════════════════
   Serigest Personalizzazioni – Frontend  v1.3.0
   Design token: stessa palette di Serigest Grid Order
   ════════════════════════════════════════════════════════ */

/* Usa le stesse variabili root definite da sgo-frontend.css;
   fallback se SGO non è caricato */
:root {
    --sp-accent:      var(--sgo-accent,      #16a34a);
    --sp-accent-bg:   var(--sgo-accent-bg,   #f0fdf4);
    --sp-accent-ring: var(--sgo-accent-ring, rgba(22,163,74,.18));
    --sp-border:      var(--sgo-border,      #e4e7ec);
    --sp-bg:          var(--sgo-bg,          #f9fafb);
    --sp-surface:     var(--sgo-surface,     #ffffff);
    --sp-text:        var(--sgo-text,        #111827);
    --sp-muted:       var(--sgo-muted,       #6b7280);
    --sp-danger:      var(--sgo-danger,      #dc2626);
    --sp-radius:      var(--sgo-radius,      8px);
    --sp-font:        var(--sgo-font,        -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif);
}

/* ── Container ──────────────────────────────────────── */
.sp-container {
    margin: 32px 0 0;
    font-family: var(--sp-font);
    font-size: 15px;
    color: var(--sp-text);
    line-height: 1.5;
}

/* ── Section header ─────────────────────────────────── */
.sp-section-header {
    margin-bottom: 20px;
    padding-bottom: 0;
    border-bottom: none;
}

.sp-section-header h3 {
    margin: 0 0 4px;
    font-family: var(--sp-font);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.02em;
    text-transform: none;
    color: var(--sp-text);
}

.sp-section-subtitle {
    margin: 0;
    font-family: var(--sp-font);
    font-size: 13px;
    font-weight: 400;
    color: var(--sp-muted);
    line-height: 1.4;
}

/* ── Position picks (same gesture as colour swatches) ─ */
.sp-picks {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 12px;
}

.sp-pick-cell {
    position: relative;
    display: flex;
    width: 124px;
}

.sp-pick__remove {
    display: none;
    position: absolute;
    top: -6px;
    left: -6px;
    z-index: 2;
    width: 20px;
    height: 20px;
    padding: 0;
    margin: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #dc2626;
    color: #fff;
    line-height: 0;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    appearance: none;
    -webkit-appearance: none;
    box-sizing: border-box;
}

.sp-pick__remove svg {
    display: block;
    flex-shrink: 0;
}

.sp-pick-cell.has-file .sp-pick__remove:not([hidden]) {
    display: flex;
}

.sp-pick__remove:hover { background: #b91c1c; }

.sp-pick {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    box-sizing: border-box;
    padding: 10px 8px 12px !important;
    margin: 0 !important;
    border: 1.5px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    font: inherit;
    color: var(--sp-text);
    line-height: 1.25;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
    box-shadow: none;
    transition: border-color .15s, background .15s, box-shadow .15s;
}

.sp-pick:hover {
    border-color: #9ca3af;
    background: #fafafa;
}

.sp-pick:focus,
.sp-pick:focus-visible {
    outline: none;
    border-color: var(--sp-accent);
    box-shadow: 0 0 0 3px var(--sp-accent-ring);
}

.sp-pick.is-on,
.sp-pick.is-editing {
    border-color: var(--sp-accent);
    background: var(--sp-accent-bg);
    box-shadow: none;
}

.sp-pick.is-editing {
    box-shadow: 0 0 0 2px var(--sp-accent-ring);
}

.sp-pick__badges {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    align-items: center;
    gap: 3px;
}

.sp-pick__ok,
.sp-pick__file {
    display: none;
    width: 16px;
    height: 16px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--sp-accent);
    color: #fff;
}

.sp-pick.is-on .sp-pick__ok { display: flex; }
.sp-pick.is-on.has-file .sp-pick__file { display: flex; }

.sp-pick__file[hidden] { display: none !important; }

.sp-pick__ok svg {
    width: 8px;
    height: 8px;
    stroke: currentColor;
}

.sp-pick__file svg {
    width: 9px;
    height: 9px;
    stroke: currentColor;
}

.sp-pick__media {
    position: relative;
    width: 84px;
    height: 84px;
    border-radius: 8px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.sp-pick__zoom {
    position: absolute;
    top: 5px;
    left: 5px;
    z-index: 2;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
}

.sp-pick__zoom svg {
    width: 16px;
    height: 16px;
    display: block;
    stroke: currentColor;
}

.sp-pick__zoom:hover,
.sp-pick__zoom:focus-visible {
    color: #111;
    outline: none;
}

.sp-zoom-modal {
    position: fixed;
    inset: 0;
    z-index: 10080;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.sp-zoom-modal[hidden] {
    display: none !important;
}

.sp-zoom-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 17, 17, .28);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.sp-zoom-modal__dialog {
    position: relative;
    z-index: 1;
    width: min(640px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: #fff;
    border-radius: 16px;
    padding: 28px 24px 22px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .28);
}

.sp-zoom-modal__close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: #f3f4f6;
    color: #111;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.sp-zoom-modal__close:hover {
    background: #e5e7eb;
}

.sp-zoom-modal__title {
    margin: 0 36px 12px 0;
    font-size: 16px;
    font-weight: 800;
    color: #111;
}

.sp-zoom-modal__img {
    display: block;
    width: 100%;
    max-height: 62vh;
    object-fit: contain;
    background: #f7f7f7;
    border-radius: 10px;
}

.sp-zoom-modal__legend {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0 0;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    color: #374151;
}

.sp-zoom-modal__swatch {
    flex: 0 0 14px;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    background: #4da3ff;
    box-shadow: inset 0 0 0 1px rgba(17, 17, 17, .12);
}

body.sp-zoom-open {
    overflow: hidden;
}

.sp-pick__media img {
    width: 84px;
    height: 84px;
    object-fit: contain;
    display: block;
}

.sp-pick__media svg {
    width: 36px;
    height: 36px;
    stroke: #9ca3af;
}

.sp-pick b {
    font-size: 11px;
    font-weight: 600;
    line-height: 1.25;
    text-align: center;
    max-width: 96px;
    min-height: 2.5em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    letter-spacing: -.01em;
}

.sp-pick__price {
    margin-top: auto;
    font-size: 10px;
    font-weight: 700;
    font-style: normal;
    color: var(--sp-accent);
    line-height: 1;
    min-height: 1em;
}

.sp-pick__price[hidden] { display: none !important; }

/* ── Work panel ─────────────────────────────────────── */
.sp-work {
    display: flex;
    align-items: stretch;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    width: 100%;
}

.sp-work--empty {
    min-height: 128px;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    border-style: dashed;
    border-color: #d1d5db;
}

.sp-work--empty .sp-work__main {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 24px;
    text-align: center;
}

.sp-work-empty__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-bottom: 10px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #9ca3af;
}
.sp-work-empty__icon svg {
    width: 20px;
    height: 20px;
}

.sp-work-empty__title {
    margin: 0 auto;
    max-width: 420px;
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -.015em;
    line-height: 1.35;
    color: var(--sp-text);
}

.sp-work-empty__hint {
    margin: 6px auto 0;
    max-width: 420px;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.45;
    color: var(--sp-muted);
}

.sp-work__main {
    flex: 1;
    min-width: 0;
    padding: 18px 20px;
    background: #f5f6f8;
}

.sp-work__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px 28px;
    padding-bottom: 14px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--sp-border);
}

.sp-work__head-left {
    min-width: 0;
    flex: 1;
}

.sp-work__head-right {
    flex-shrink: 0;
    text-align: right;
    max-width: 240px;
}

.sp-work__kicker {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--sp-muted);
}

.sp-work__hint {
    margin: 4px 0 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--sp-muted);
    line-height: 1.35;
}

.sp-item { position: relative; margin: 0; }

.sp-item[hidden],
.sp-work--empty[hidden] {
    display: none !important;
}

.sp-enable-check { display: none; }

.sp-toggle-label {
    display: block;
    min-width: 0;
}

.sp-toggle-label strong,
.sp-item__name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--sp-text);
    display: block;
}

.sp-item__desc {
    display: block;
    font-size: 13px;
    color: var(--sp-muted);
    font-weight: 400;
    margin-top: 4px;
}

.sp-item__price-hint {
    display: block;
    font-size: 15px;
    font-weight: 700;
    color: var(--sp-text);
    margin: 0;
}

.sp-item__body { padding: 0; margin-top: 8px; }

.sp-item__remove {
    display: block;
    width: max-content;
    margin: 16px 0 0 auto;
    background: none;
    border: none;
    padding: 0;
    font-family: var(--sp-font);
    font-size: 12px;
    font-weight: 500;
    color: #9ca3af;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    letter-spacing: .01em;
}

.sp-item__remove:hover { color: var(--sp-danger); }

/* ── Sub-label ──────────────────────────────────────── */
.sp-item__options-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--sp-muted);
    margin: 14px 0 8px;
    display: block;
}
.sp-item__options-label small {
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    color: var(--sp-muted);
    opacity: .7;
}

/* ── Option cards (radio chips) ─────────────────────── */
.sp-item__options {
    margin-top: 4px;
    padding-bottom: 14px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--sp-border);
}

.sp-option-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sp-option-card { cursor: pointer; }

.sp-option-card input[type="radio"] { display: none; }

.sp-option-card__inner {
    display: block;
    padding: 7px 14px;
    border: 1px solid var(--sp-border);
    border-radius: 6px;
    background: var(--sp-surface);
    transition: border-color .12s, background .12s, color .12s;
    min-width: 72px;
    text-align: center;
}

.sp-option-card.is-selected .sp-option-card__inner,
.sp-option-card input[type="radio"]:checked + .sp-option-card__inner {
    border-color: var(--sp-accent);
    background: var(--sp-accent);
    color: #fff;
}

.sp-option-card__inner strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
}

.sp-option-card__price {
    display: block;
    font-size: 11px;
    color: var(--sp-muted);
    margin-top: 2px;
}

.sp-option-card.is-selected .sp-option-card__price,
.sp-option-card input[type="radio"]:checked + .sp-option-card__inner .sp-option-card__price {
    color: rgba(255,255,255,.65);
}

.sp-option-card__price em { font-style: normal; }

.sp-option-card__price:only-child,
.sp-option-card.is-selected .sp-option-card__price,
.sp-option-card input[type="radio"]:checked + .sp-option-card__inner .sp-option-card__price {
    color: rgba(255,255,255,.65);
}

/* ── Artwork upload ─────────────────────────────────── */
.sp-item__artwork { margin-top: 4px; }

.sp-artwork-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
    margin-top: 8px;
}
.sp-artwork-row.is-full .sp-artwork-choice:has(.sp-later[hidden]) {
    display: none;
}
.sp-later-check {
    display: none !important;
}

.sp-artwork-choice {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    height: 164px;
}

.sp-artwork-row.is-full .sp-artwork-choice {
    height: auto;
    min-height: 180px;
}

.sp-upload-area {
    display: contents;
}

/* Drop zone — grey until a file is uploaded */
.sp-upload-btn,
.sp-later {
    height: 164px !important;
    min-height: 164px !important;
    max-height: 164px !important;
    margin: 0 !important;
    padding: 18px 14px !important;
    box-sizing: border-box !important;
}

.sp-upload-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    flex: 1 1 auto;
    border: 1.5px dashed #9ca3af;
    border-radius: var(--sp-radius);
    cursor: pointer;
    background: #fff;
    transition: border-color .15s, background .15s, box-shadow .15s;
    box-sizing: border-box;
}
.sp-upload-btn:hover {
    border-color: #4b5563;
    background: #f3f4f6;
    box-shadow: 0 1px 3px rgba(17, 24, 39, .08);
}

.sp-upload-btn__icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border: 1.5px solid #9ca3af;
    border-radius: 8px;
}
.sp-upload-btn__icon svg {
    width: 18px;
    height: 18px;
    stroke: #374151;
}

.sp-upload-btn__text {
    text-align: center;
}
.sp-upload-btn__text strong {
    display: block;
    font-family: var(--sp-font);
    font-size: 13px;
    font-weight: 600;
    color: var(--sp-text);
}
.sp-upload-btn__text span {
    display: block;
    font-family: var(--sp-font);
    font-size: 11px;
    color: var(--sp-muted);
    margin-top: 2px;
}

/* Preview (after upload) — green only here */
.sp-upload-preview {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    width: 100%;
    min-height: 180px;
    height: auto !important;
    max-height: none !important;
    padding: 28px 20px 22px;
    background: var(--sp-accent-bg);
    border: 1px solid var(--sp-accent);
    border-radius: var(--sp-radius);
    box-sizing: border-box;
}

.sp-upload-done {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--sp-accent);
    color: #fff;
    box-shadow: 0 0 0 5px var(--sp-accent-ring);
}

.sp-upload-done svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
}

.sp-upload-done__title {
    font-family: var(--sp-font);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -.015em;
    color: #166534;
}

.sp-upload-name {
    max-width: 100%;
    font-family: var(--sp-font);
    font-size: 12px;
    font-weight: 500;
    color: var(--sp-muted);
    word-break: break-all;
    line-height: 1.35;
}

.sp-upload-remove {
    margin-top: 4px;
    background: none;
    border: none;
    padding: 0;
    font-family: var(--sp-font);
    font-size: 12px;
    font-weight: 500;
    color: #9ca3af;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.sp-upload-remove:hover { color: var(--sp-danger); }

.sp-upload-status {
    font-family: var(--sp-font);
    font-size: 12px;
    color: var(--sp-muted);
    margin-top: 0;
    min-height: 0;
}
.sp-upload-status:empty { display: none; }
.sp-upload-status:not(:empty) {
    margin-top: 8px;
    min-height: 16px;
}
.sp-upload-status.is-error {
    color: var(--sp-danger);
    font-weight: 600;
}

/* ── Carico il file dopo (area utente) ──────────────── */
.sp-later {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    appearance: none;
    -webkit-appearance: none;
    flex: 1 1 auto;
    align-self: stretch;
    width: 100%;
    border: 1.5px solid #9ca3af;
    border-radius: var(--sp-radius);
    background: #fff;
    cursor: pointer;
    text-align: center;
    font: inherit;
    color: inherit;
    box-sizing: border-box;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.sp-later:hover {
    border-color: #4b5563;
    background: #f3f4f6;
    box-shadow: 0 1px 3px rgba(17, 24, 39, .08);
}
.sp-later.is-on {
    border-color: var(--sp-accent);
    background: var(--sp-accent-bg);
    box-shadow: 0 0 0 3px var(--sp-accent-ring);
}
.sp-later[hidden] { display: none !important; }

.sp-later__icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #f3f4f6;
    border: 1.5px solid #9ca3af;
    color: #374151;
    transition: background .15s, color .15s, border-color .15s;
}
.sp-later.is-on .sp-later__icon {
    border-color: #bbf7d0;
    color: var(--sp-accent);
}
.sp-later__icon svg {
    width: 18px;
    height: 18px;
}

.sp-later__copy {
    min-width: 0;
}
.sp-later__copy strong {
    display: block;
    font-family: var(--sp-font);
    font-size: 13px;
    font-weight: 600;
    color: var(--sp-text);
}
.sp-later__copy span {
    display: block;
    margin-top: 2px;
    font-family: var(--sp-font);
    font-size: 11px;
    color: var(--sp-muted);
    line-height: 1.35;
}
.sp-later.is-on .sp-later__copy span {
    color: #166534;
}

.sp-later__tick {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1.5px solid #9ca3af;
    color: transparent;
    background: #fff;
    transition: border-color .15s, background .15s, color .15s;
}
.sp-later.is-on .sp-later__tick {
    border-color: var(--sp-accent);
    background: var(--sp-accent);
    color: #fff;
}
.sp-later__tick svg {
    width: 10px;
    height: 10px;
}

.sp-upload-loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    width: 100%;
    height: 164px !important;
    min-height: 164px !important;
    max-height: 164px !important;
    padding: 22px 16px;
    background: #fff;
    border: 1.5px dashed #9ca3af;
    border-radius: var(--sp-radius);
    box-sizing: border-box;
}

.sp-upload-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #e5e7eb;
    border-top-color: var(--sp-muted);
    animation: sp-spin .75s linear infinite;
}

.sp-upload-loading__title {
    font-family: var(--sp-font);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -.015em;
    color: var(--sp-text);
}

.sp-upload-loading__name {
    max-width: 100%;
    font-size: 12px;
    font-weight: 500;
    color: var(--sp-muted);
    word-break: break-all;
    line-height: 1.35;
}

.sp-upload-loading__pct {
    font-size: 13px;
    font-weight: 700;
    color: var(--sp-muted);
    min-height: 1.2em;
}

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

/* ── Note textarea ──────────────────────────────────── */
.sp-item__note { margin-top: 4px; }

.sp-note-field {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--sp-border);
    border-radius: 6px;
    font-family: var(--sp-font);
    font-size: 13px;
    color: var(--sp-text);
    background: var(--sp-surface);
    resize: vertical;
    margin-top: 6px;
    transition: border-color .12s;
}
.sp-note-field::placeholder { color: var(--sp-muted); opacity: .7; }
.sp-note-field:focus {
    outline: none;
    border-color: var(--sp-text);
}

/* ── Desktop ────────────────────────────────────────── */
@media (min-width: 641px) {
    .sp-container { display: block; }
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 640px) {
    .sp-container {
        width: 100vw;
        max-width: 100vw;
        margin-left: calc(50% - 50vw);
        margin-right: calc(50% - 50vw);
        padding-left: 12px;
        padding-right: 12px;
        box-sizing: border-box;
    }
    .sp-picks {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        margin-bottom: 12px;
    }
    .sp-pick-cell {
        width: auto;
        min-width: 0;
    }
    .sp-pick {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        padding: 8px 6px 10px !important;
        gap: 6px;
    }
    .sp-pick__media {
        width: 100%;
        height: auto;
        max-width: none;
        aspect-ratio: 1;
        max-height: 96px;
    }
    .sp-pick__media img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    .sp-pick b {
        font-size: 11px;
        max-width: none;
        width: 100%;
    }
    .sp-work__head {
        flex-direction: row;
        align-items: flex-start;
        gap: 8px;
    }
    .sp-work__head-right {
        text-align: right;
        max-width: none;
    }
    .sp-artwork-row {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .sp-option-cards {
        flex-direction: column;
    }
    .sp-option-card__inner {
        text-align: left;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}
