/* =====================================================================
   Probador Virtual IA — Frontend Styles
   ===================================================================== */

/* ---- Variables ---- */
:root {
    /*
     * Colores del modal: leen automáticamente las variables globales de Elementor
     * o WooCommerce. Si el tema no las define, usan el fallback neutro.
     * Se pueden sobreescribir en el CSS personalizado del tema con:
     *   :root { --pv-btn-bg: #tucolor; --pv-btn-color: #fff; }
     */
    --pv-btn-bg:        var(--e-global-color-accent,    var(--wc-highlight-color,       #1a1a1a));
    --pv-btn-color:     var(--e-global-color-base-4,    #ffffff);
    --pv-btn-buy-bg:    var(--e-global-color-accent,    var(--wc-highlight-color,       #1a1a1a));
    --pv-size-active:   var(--e-global-color-primary,   var(--wc-highlight-color,       #1a1a1a));

    --pv-bg:         #ffffff;
    --pv-overlay:    rgba(0, 0, 0, 0.65);
    --pv-radius:     12px;
    --pv-shadow:     0 20px 60px rgba(0, 0, 0, 0.3);
    --pv-transition: 0.25s ease;
    --pv-font:       'Outfit', sans-serif;
}

/* ---- Fuente global del plugin (hereda la de la web) ---- */
.pv-modal,
.pv-try-on-btn,
.pv-room {
    font-family: var(--pv-font);
}

/* ---- Botón en producto ---- */
/*
 * El botón tiene las clases "button alt" de WooCommerce para que el tema
 * lo estile exactamente igual que sus propios botones. Solo añadimos
 * layout (flex, icono) sin sobreescribir colores.
 */
.pv-try-on-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px !important;
    cursor: pointer !important;
}
.pv-try-on-btn::before { content: "👗"; font-size: 1em; }

/* Variante shortcode: ocupa el ancho del widget de Elementor */
.pv-try-on-btn--shortcode {
    margin-top: 0 !important;
    width: 100%;
    display: flex !important;
}

/* ---- Modal base ---- */
.pv-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.pv-modal[hidden] { display: none !important; }

.pv-modal__overlay {
    position: absolute;
    inset: 0;
    background: var(--pv-overlay);
}

.pv-modal__content {
    position: relative;
    background: var(--pv-bg);
    border-radius: var(--pv-radius);
    box-shadow: var(--pv-shadow);
    padding: 32px;
    width: 70vw;
    min-width: 320px;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    animation: pvSlideUp 0.3s ease;
}

@keyframes pvSlideUp {
    from { transform: translateY(24px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.pv-modal__close {
    position: absolute !important;
    top: 12px !important;
    right: 16px !important;
    /* Reset completo — neutraliza cualquier estilo global del tema sobre <button> */
    background: none !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #888 !important;
    font-size: 26px !important;
    line-height: 1 !important;
    padding: 4px 8px !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    width: auto !important;
    min-width: unset !important;
    transition: background var(--pv-transition) !important;
}
.pv-modal__close:hover {
    background: #f0f0f0 !important;
    color: #333 !important;
}

.pv-modal__title {
    margin: 0 0 20px;
    font-size: 20px;
    color: inherit;
}

/* ---- Upload zone ---- */
.pv-upload-zone {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--pv-transition), background var(--pv-transition);
    margin-bottom: 16px;
}
.pv-upload-zone:hover,
.pv-upload-zone--dragover {
    border-color: var(--pv-primary);
    background: #f8f9fa;
}

.pv-upload-zone__label { cursor: pointer; display: block; }

.pv-upload-zone__icon { font-size: 40px; display: block; margin-bottom: 8px; }

.pv-upload-zone__text {
    display: block;
    font-weight: 600;
    color: var(--pv-primary);
    margin-bottom: 4px;
}

.pv-upload-zone__hint {
    display: block;
    font-size: 13px;
    color: #888;
}

.pv-photo-preview {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 6px;
    margin-top: 12px;
}

/* ---- Foto guardada ---- */
.pv-saved-photo {
    text-align: center;
    margin-bottom: 16px;
}
.pv-saved-photo img {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid var(--pv-primary);
}
.pv-saved-photo__note {
    margin-top: 8px;
    font-size: 14px;
    color: #555;
}
.pv-link-btn {
    background: none;
    border: none;
    color: var(--pv-accent);
    cursor: pointer;
    text-decoration: underline;
    font-size: 14px;
    padding: 0;
    margin-left: 4px;
}

/* ---- Checkbox recordar ---- */
.pv-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #555;
    margin-bottom: 16px;
    cursor: pointer;
}

/* ---- Botones del modal ---- */
/*
 * Los botones con clase "button alt" reciben su color del tema.
 * Aquí solo añadimos layout (ancho, display) sin sobreescribir colores.
 */
.pv-btn {
    display: inline-block;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    font-family: var(--pv-font);
    transition: opacity var(--pv-transition);
}
.pv-btn--primary {
    width: 100%;
    display: block;
}
.pv-btn--primary:disabled {
    opacity: 0.4 !important;
    cursor: not-allowed !important;
    pointer-events: none;
}
.pv-btn--outline {
    background: transparent !important;
    color: #555 !important;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
}
.pv-btn--outline:hover {
    border-color: #888 !important;
    color: #333 !important;
    background: transparent !important;
}

/* ---- Loading ---- */
.pv-step--loading {
    text-align: center;
    padding: 32px 0;
}
.pv-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #eee;
    border-top-color: var(--pv-primary);
    border-radius: 50%;
    animation: pvSpin 0.8s linear infinite;
    margin: 0 auto 16px;
}
@keyframes pvSpin {
    to { transform: rotate(360deg); }
}
.pv-loading-hint { font-size: 13px; color: #888; }

.pv-loading-msg {
    font-size: 15px;
    font-weight: 600;
    color: var(--pv-primary);
    min-height: 24px;
    margin-bottom: 8px;
}

/* Shake para selector de talla sin seleccionar */
@keyframes pvShake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-6px); }
    40%       { transform: translateX(6px); }
    60%       { transform: translateX(-4px); }
    80%       { transform: translateX(4px); }
}
.pv-shake {
    animation: pvShake 0.55s ease;
    border: 2px solid var(--pv-accent) !important;
    border-radius: 8px;
    padding: 8px;
    margin: -8px;
}

/* ---- Tagline resultado ---- */
.pv-result__tagline {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--pv-btn-bg);
    margin: 0 0 16px;
}

/* ---- Resultado ---- */
.pv-result__images {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.pv-result__before,
.pv-result__after {
    flex: 1;
    text-align: center;
}
.pv-result__before p,
.pv-result__after p {
    font-size: 13px;
    color: #888;
    margin-bottom: 6px;
}
.pv-result__before img,
.pv-result__after img {
    width: 100%;
    max-height: 420px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid #eee;
}
.pv-result__after img { border-color: var(--pv-primary); }

/* ---- Selector de talla ---- */
.pv-size-selector {
    margin-bottom: 16px;
}
.pv-size-selector__label {
    font-size: 14px;
    font-weight: 600;
    color: #444;
    margin-bottom: 8px;
}
.pv-size-selector__options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.pv-size-btn {
    padding: 6px 14px;
    border: 2px solid #ccc;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--pv-transition);
}
.pv-size-btn:hover:not(:disabled) {
    border-color: var(--pv-primary);
    color: var(--pv-primary);
}
.pv-size-btn--selected {
    background: var(--pv-size-active);
    border-color: var(--pv-size-active);
    color: var(--pv-btn-color);
}
.pv-size-btn--out {
    opacity: 0.4;
    cursor: not-allowed;
    text-decoration: line-through;
}

/* ---- Botón comprar ---- */
.pv-btn--buy {
    flex: 1;
    /* color/background vienen de "button alt" del tema */
}
.pv-btn--buy:disabled { opacity: 0.4 !important; cursor: not-allowed !important; }

/* ---- Feedback compra ---- */
.pv-buy-feedback {
    font-size: 14px;
    margin: 10px 0 0;
    text-align: center;
    display: none;
}
.pv-buy-feedback--ok { color: #27ae60; }
.pv-buy-feedback--err { color: var(--pv-accent); }
.pv-cart-link {
    color: #27ae60;
    font-weight: 600;
    text-decoration: none;
}
.pv-cart-link:hover { text-decoration: underline; }

/* ---- Intentar de nuevo (link) ---- */
.pv-try-again-link {
    display: block;
    text-align: center;
    margin-top: 12px;
    font-size: 14px;
}

.pv-result__actions {
    display: flex;
    gap: 10px;
}
.pv-result__actions .pv-btn { flex: 1; }

/* ---- Error ---- */
.pv-error,
.pv-error-msg {
    color: var(--pv-accent);
    font-size: 14px;
    margin: 8px 0;
}
.pv-step--error { text-align: center; padding: 16px 0; }

/* ---- Scroll lock cuando modal abierto ---- */
body.pv-modal-open { overflow: hidden; }

/* =======================================================================
   RESPONSIVE — Modal, botón y componentes
   ======================================================================= */

/* Tablet (≤ 768px) */
@media (max-width: 768px) {
    .pv-modal__content {
        width: 92vw;
        padding: 24px 20px;
    }
    /* Imágenes resultado en columna */
    .pv-result__images {
        flex-direction: column;
    }
    .pv-result__before img,
    .pv-result__after img {
        max-height: 300px;
    }
}

/* Móvil (≤ 480px) — Bottom sheet */
@media (max-width: 480px) {
    /* El modal se ancla al fondo de la pantalla */
    .pv-modal {
        padding: 0;
        align-items: flex-end;
    }
    .pv-modal__content {
        width: 100%;
        min-width: unset;
        max-width: unset;
        max-height: 92vh;
        border-radius: 20px 20px 0 0;
        padding: 20px 16px 28px;
        animation: pvSlideUp 0.32s ease;
    }
    /* Indicador de arrastre (pill) */
    .pv-modal__content::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #ddd;
        border-radius: 2px;
        margin: 0 auto 16px;
    }
    .pv-modal__title {
        font-size: 17px;
        padding-right: 36px; /* espacio para el botón cerrar */
        margin-bottom: 16px;
    }
    /* Zona de upload más compacta */
    .pv-upload-zone {
        padding: 20px 12px;
    }
    .pv-upload-zone__icon { font-size: 32px; }
    .pv-upload-zone__text { font-size: 14px; }

    /* Foto guardada más pequeña */
    .pv-saved-photo img {
        width: 90px;
        height: 90px;
    }

    /* Tagline más pequeño */
    .pv-result__tagline { font-size: 16px; }

    /* Imágenes resultado: columna y más cortas */
    .pv-result__images { flex-direction: column; }
    .pv-result__before img,
    .pv-result__after img {
        max-height: 260px;
    }

    /* Botones de acción en columna */
    .pv-result__actions {
        flex-direction: column;
    }
    .pv-result__actions .pv-btn {
        width: 100%;
    }

    /* Botones generales: target táctil mínimo 48px */
    .pv-btn {
        padding: 14px 16px;
        font-size: 15px;
        min-height: 48px;
    }

    /* Botones de talla: target táctil cómodo */
    .pv-size-btn {
        padding: 10px 18px;
        min-height: 44px;
        font-size: 15px;
    }

    /* Botón principal más prominente */
    .pv-try-on-btn {
        width: 100% !important;
        justify-content: center;
        padding: 14px 20px !important;
        font-size: 16px !important;
    }

    /* Preview foto más compacto */
    .pv-photo-preview { max-height: 160px; }
}

/* =======================================================================
   SALA DE PRUEBAS (/probador)
   ======================================================================= */

.pv-room {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 16px 48px;
    font-family: var(--pv-font);
}

/* ---- Indicadores de pasos ---- */
.pv-room__steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 32px;
}

.pv-room__step {
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0.35;
    transition: opacity var(--pv-transition);
}

.pv-room__step--active { opacity: 1; }

.pv-room__step--done .pv-room__step-num {
    background: #27ae60;
    color: #fff;
}
.pv-room__step--done .pv-room__step-num::after {
    content: '✓';
}
.pv-room__step--done .pv-room__step-num span { display: none; }

.pv-room__step-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--pv-btn-bg);
    color: var(--pv-btn-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.pv-room__step-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

.pv-room__step-divider {
    flex: 1;
    height: 2px;
    background: #e0e0e0;
    margin: 0 12px;
    min-width: 32px;
    max-width: 80px;
}

/* ---- Layout principal ---- */
.pv-room__layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

.pv-room__panel {
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: var(--pv-radius);
    padding: 24px;
}

.pv-room__panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0 0 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid #f0f0f0;
}

.pv-room__panel-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--pv-btn-bg);
    color: var(--pv-btn-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

/* ---- Foto guardada (sala) ---- */
.pv-saved-photo--room {
    text-align: center;
    padding: 20px 0;
}

.pv-saved-photo__avatar {
    position: relative;
    display: inline-block;
    margin-bottom: 10px;
}

.pv-saved-photo--room img {
    width: 110px;
    height: 110px;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid var(--pv-btn-bg);
}

.pv-saved-photo__badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    background: #27ae60;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ---- Upload zone (sala) ---- */
.pv-upload-zone--room {
    padding: 24px 16px;
}

.pv-upload-zone--room .pv-upload-zone__cta {
    display: inline-block;
    margin-top: 12px;
    font-size: 13px;
    padding: 8px 16px !important;
}

.pv-photo-preview--room {
    width: 100%;
    max-height: 240px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--pv-btn-bg);
}

/* ---- Tip privacidad ---- */
.pv-room__privacy-tip {
    font-size: 12px;
    color: #999;
    margin-top: 16px;
    text-align: center;
    line-height: 1.5;
}

/* ---- Búsqueda ---- */
.pv-search-wrap {
    position: relative;
    margin-bottom: 14px;
}

.pv-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    pointer-events: none;
}

.pv-search-box {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    font-family: var(--pv-font);
    transition: border-color var(--pv-transition);
}

.pv-search-box:focus {
    outline: none;
    border-color: var(--pv-btn-bg);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

/* ---- Grid de productos ---- */
.pv-product-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-height: 440px;
    overflow-y: auto;
    padding: 2px;
}

.pv-product-grid__loading {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px;
    color: #888;
    font-size: 14px;
}

.pv-product-grid__empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px;
    color: #888;
    font-size: 14px;
}

.pv-product-grid__empty--error { color: #c00; }

.pv-product-card {
    border: 2px solid #eee;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--pv-transition), transform var(--pv-transition), box-shadow var(--pv-transition);
    background: #fff;
}

.pv-product-card:hover {
    border-color: #bbb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.pv-product-card--selected {
    border-color: var(--pv-btn-bg) !important;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.08) !important;
}

.pv-product-card__img-wrap {
    position: relative;
}

.pv-product-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.pv-product-card__check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    background: var(--pv-btn-bg);
    color: var(--pv-btn-color);
    border-radius: 50%;
    font-size: 11px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.pv-product-card--selected .pv-product-card__check {
    display: flex;
}

.pv-product-card__info {
    padding: 6px 8px 8px;
}

.pv-product-card__name {
    font-size: 11px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.pv-product-card__price {
    font-size: 11px;
    color: #888;
}

/* ---- Spinner variantes ---- */
.pv-spinner--sm {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.pv-spinner--lg {
    width: 64px;
    height: 64px;
    border-width: 5px;
    margin-bottom: 24px;
}

/* ---- Barra generar ---- */
.pv-room__generate-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: var(--pv-radius);
    padding: 16px 24px;
    margin-top: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.pv-room__generate-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.pv-room__generate-preview img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #eee;
    flex-shrink: 0;
}

.pv-room__generate-name {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pv-room__generate-placeholder {
    flex: 1;
    font-size: 14px;
    color: #aaa;
}

.pv-room__generate-bar .pv-btn--primary {
    width: auto;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 12px 28px !important;
    font-size: 15px;
}

/* ---- Loading (sala) ---- */
.pv-room__loading {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: var(--pv-radius);
    margin-top: 20px;
}

.pv-room__loading-inner {
    max-width: 400px;
    margin: 0 auto;
}

.pv-room__loading .pv-loading-msg {
    font-size: 16px;
}

/* ---- Resultado (sala) ---- */
.pv-room__result {
    margin-top: 24px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: var(--pv-radius);
    padding: 32px;
    text-align: center;
    animation: pvSlideUp 0.4s ease;
}

.pv-room__result-header {
    margin-bottom: 24px;
}

.pv-result__images--room {
    max-width: 800px;
    margin: 0 auto 24px;
}

.pv-result__images--room .pv-result__before img,
.pv-result__images--room .pv-result__after img {
    max-height: 500px;
}

.pv-room__result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    max-width: 480px;
    margin: 0 auto;
}

.pv-room__result-actions .pv-btn {
    flex: 1;
    padding: 12px 20px;
}

/* ---- Admin CSS ---- */
.pv-admin-wrap .nav-tab-wrapper { margin-bottom: 20px; }

/* =======================================================================
   SALA DE PRUEBAS — RESPONSIVE
   ======================================================================= */

@media (max-width: 900px) {
    .pv-room__layout {
        grid-template-columns: 1fr;
    }
    .pv-room__panel--photo {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0 20px;
        align-items: start;
    }
    .pv-room__panel-title {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .pv-room { padding: 20px 12px 40px; }
    .pv-room__steps { gap: 0; }
    .pv-room__step-label { display: none; }
    .pv-room__step-divider { min-width: 20px; }
    .pv-product-grid { grid-template-columns: repeat(3, 1fr); max-height: 320px; }
    .pv-room__panel--photo { display: block; }
    .pv-room__generate-bar { flex-wrap: wrap; }
    .pv-room__generate-bar .pv-btn--primary { width: 100% !important; }
}

@media (max-width: 480px) {
    .pv-product-grid { grid-template-columns: repeat(2, 1fr); max-height: 280px; }
    .pv-room__panel { padding: 16px; }
    .pv-room__result { padding: 20px 16px; }
    .pv-room__result-actions { flex-direction: column; }
    .pv-result__images--room { flex-direction: column; }
}
