/**
 * WebAR 3D Viewer Pro — Frontend Viewer CSS
 * Autor: Marcelo Araya / wide.cl
 * Versión: 1.0.0 FINAL con Loader Mejorado
 */

:root {
    --webar-v-primary:   #2271b1;
    --webar-v-dark:      #1d2327;
    --webar-v-white:     #ffffff;
    --webar-v-overlay:   rgba(0,0,0,.75);
    --webar-v-radius:    12px;
    --webar-v-shadow:    0 4px 24px rgba(0,0,0,.15);
    --webar-v-btn-h:     44px;
    --webar-v-ctrl-bg:   rgba(255,255,255,.95);
    --webar-v-ctrl-sz:   40px;
}

/* ==========================================
   WRAPPER
   ========================================== */
.webar-viewer-wrapper {
    position: relative;
    display: block;
    border-radius: var(--webar-v-radius);
    overflow: hidden;
    box-shadow: var(--webar-v-shadow);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ==========================================
   MODEL VIEWER
   ========================================== */
.webar-model-viewer {
    display: block;
    width: 100%;
    --poster-color: transparent;
    transition: opacity .4s ease;
    opacity: 0;
}

.webar-model-viewer.webar-loaded {
    opacity: 1;
}

/* Asegurar que el canvas sea correcto */
.webar-model-viewer::part(default-ar-button) {
    display: none;
}

/* ==========================================
   LOADER / PROGRESS - MEJORADO
   ========================================== */
.webar-progress-slot {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 10;
    transition: opacity .4s;
}

/* Loader 3D animado */
.webar-loader-3d {
    position: relative;
    width: 120px;
    height: 120px;
    margin-bottom: 30px;
}

.webar-cube {
    position: absolute;
    width: 60px;
    height: 60px;
    transform-style: preserve-3d;
    animation: webar-cube-rotate 3s infinite ease-in-out;
}

.webar-cube-face {
    position: absolute;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
}

.webar-cube-face.front  { transform: rotateY(0deg) translateZ(30px); }
.webar-cube-face.back   { transform: rotateY(180deg) translateZ(30px); }
.webar-cube-face.right  { transform: rotateY(90deg) translateZ(30px); }
.webar-cube-face.left   { transform: rotateY(-90deg) translateZ(30px); }
.webar-cube-face.top    { transform: rotateX(90deg) translateZ(30px); }
.webar-cube-face.bottom { transform: rotateX(-90deg) translateZ(30px); }

@keyframes webar-cube-rotate {
    0% { transform: rotateX(0deg) rotateY(0deg); }
    50% { transform: rotateX(180deg) rotateY(180deg); }
    100% { transform: rotateX(360deg) rotateY(360deg); }
}

/* Loader circular alternativo */
.webar-loader-spinner {
    width: 80px;
    height: 80px;
    margin-bottom: 30px;
    position: relative;
}

.webar-spinner-circle {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #fff;
    border-radius: 50%;
    animation: webar-spin 1s linear infinite;
}

.webar-spinner-circle:nth-child(2) {
    width: 60px;
    height: 60px;
    top: 10px;
    left: 10px;
    border-top-color: rgba(255, 255, 255, 0.6);
    animation-duration: 1.5s;
}

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

/* Barra de progreso mejorada */
.webar-loader-bar {
    width: 280px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.webar-loader-fill {
    height: 100%;
    background: linear-gradient(90deg, #fff, #f0f0f0, #fff);
    background-size: 200% 100%;
    border-radius: 10px;
    width: 0%;
    transition: width .3s ease;
    animation: webar-loader-shimmer 2s ease-in-out infinite;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

@keyframes webar-loader-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Porcentaje de carga */
.webar-loader-percentage {
    font-size: 28px;
    font-weight: 700;
    color: white;
    margin-bottom: 12px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    animation: webar-pulse-scale 2s ease-in-out infinite;
}

@keyframes webar-pulse-scale {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Texto del loader */
.webar-loader-text {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
    text-align: center;
    animation: webar-fade-in-out 2s ease-in-out infinite;
}

@keyframes webar-fade-in-out {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Puntos animados */
.webar-loader-dots::after {
    content: '';
    animation: webar-dots 1.5s steps(4) infinite;
}

@keyframes webar-dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Tips instructivos */
.webar-loader-tip {
    margin-top: 30px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    max-width: 320px;
    text-align: center;
}

.webar-tip-icon {
    font-size: 24px;
    margin-bottom: 8px;
    display: block;
    animation: webar-bounce 2s ease-in-out infinite;
}

@keyframes webar-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.webar-tip-text {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.5;
}

/* Mensaje de error */
.webar-error-msg {
    font-size: 14px;
    color: #fff;
    background: rgba(214, 54, 56, 0.9);
    padding: 15px 20px;
    border-radius: 10px;
    text-align: center;
    margin: 0 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* ==========================================
   AR LOADING OVERLAY (Quick Look / Scene Viewer)
   ========================================== */
.webar-ar-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    animation: webar-fade-in .3s ease;
}

.webar-ar-loading-overlay.active {
    display: flex;
}

.webar-ar-loading-content {
    text-align: center;
    color: white;
}

.webar-ar-loading-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: webar-bounce 1.5s ease-in-out infinite;
}

.webar-ar-loading-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 10px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.webar-ar-loading-subtitle {
    font-size: 16px;
    opacity: 0.9;
    margin: 0 0 30px;
}

.webar-ar-loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: webar-spin 1s linear infinite;
    margin: 0 auto;
}

/* Instrucciones AR */
.webar-ar-instructions {
    margin-top: 40px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    max-width: 350px;
}

.webar-ar-step {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    text-align: left;
}

.webar-ar-step-number {
    width: 36px;
    height: 36px;
    background: white;
    color: #667eea;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-right: 15px;
    flex-shrink: 0;
}

.webar-ar-step-text {
    font-size: 14px;
    line-height: 1.4;
}

/* ==========================================
   AR BUTTON (slot="ar-button")
   ========================================== */
.webar-ar-btn {
    position: absolute;
    bottom: 72px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--webar-v-primary);
    color: var(--webar-v-white);
    border: none;
    border-radius: 24px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(34,113,177,.4);
    transition: all .2s ease;
    z-index: 20;
    letter-spacing: .3px;
}

.webar-ar-btn:hover {
    background: #135e96;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(34,113,177,.5);
}

.webar-ar-btn:active {
    transform: translateY(0);
}

.webar-ar-icon {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1);
}

/* Pulse animation */
.webar-ar-btn::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 28px;
    border: 2px solid var(--webar-v-primary);
    opacity: 0;
    animation: webar-ar-pulse 2s ease-out infinite;
}

@keyframes webar-ar-pulse {
    0%   { transform: scale(1); opacity: .6; }
    100% { transform: scale(1.3); opacity: 0; }
}

/* ==========================================
   CONTROLS BAR
   ========================================== */
.webar-controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--webar-v-ctrl-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid rgba(0,0,0,.08);
}

.webar-anim-controls,
.webar-audio-controls,
.webar-extra-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ==========================================
   CONTROL BUTTONS
   ========================================== */
.webar-ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: var(--webar-v-ctrl-sz);
    height: var(--webar-v-ctrl-sz);
    border: 1px solid rgba(0,0,0,.12);
    border-radius: 10px;
    background: var(--webar-v-white);
    color: var(--webar-v-dark);
    cursor: pointer;
    font-size: 16px;
    transition: all .2s ease;
    padding: 0;
    white-space: nowrap;
    overflow: hidden;
}

.webar-ctrl-btn:hover {
    background: var(--webar-v-primary);
    color: var(--webar-v-white);
    border-color: var(--webar-v-primary);
    transform: scale(1.05);
}

.webar-ctrl-btn:active {
    transform: scale(.97);
}

/* Botón de audio con label */
.webar-audio-btn {
    width: auto;
    padding: 0 12px;
    gap: 6px;
}

.webar-audio-icon {
    width: 18px;
    height: 18px;
}

.webar-audio-label {
    font-size: 12px;
    font-weight: 500;
}

.webar-audio-btn--active {
    background: #e8f4fd;
    border-color: var(--webar-v-primary);
    color: var(--webar-v-primary);
}

/* Fullscreen */
.webar-fullscreen-btn {
    font-size: 18px;
}

/* ==========================================
   AR FAILURE SLOT
   ========================================== */
.webar-ar-failure {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.7);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 30;
    white-space: nowrap;
}

/* ==========================================
   QR SECTION (escritorio) - MEJORADO
   ========================================== */
.webar-qr-section {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: var(--webar-v-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999999 !important;
    animation: webar-fade-in .3s ease;
}

.webar-qr-inner {
    background: var(--webar-v-white);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,.3);
    max-width: 400px;
    position: relative;
    z-index: 1000000;
    animation: webar-scale-in .3s ease;
}

@keyframes webar-scale-in {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.webar-qr-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 20px;
    color: var(--webar-v-dark);
    line-height: 1.4;
}

.webar-qr-code {
    margin: 0 auto 16px;
    width: 256px !important;
    height: 256px !important;
    background: #ffffff;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,.1);
    overflow: visible !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.webar-qr-code img,
.webar-qr-code canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: 226px !important;
    max-height: 226px !important;
    object-fit: contain !important;
    transform: none !important;
    display: block !important;
    margin: 0 auto !important;
    image-rendering: crisp-edges !important;
    -ms-interpolation-mode: nearest-neighbor !important;
}

.webar-qr-url {
    font-size: 11px;
    color: #666;
    word-break: break-all;
    margin: 0 0 20px;
    padding: 10px 14px;
    background: #f5f5f5;
    border-radius: 8px;
    max-width: 320px;
    line-height: 1.4;
}

.webar-qr-close {
    width: auto !important;
    padding: 12px 30px !important;
    font-size: 14px !important;
    border-radius: 10px !important;
    background: var(--webar-v-primary) !important;
    color: white !important;
    border: none !important;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s ease;
    box-shadow: 0 2px 8px rgba(34,113,177,.3);
}

.webar-qr-close:hover {
    background: #135e96 !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(34,113,177,.4);
}

.webar-qr-close:active {
    transform: translateY(0);
}

/* ==========================================
   EDITOR PLACEHOLDER (Elementor)
   ========================================== */
.webar-editor-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    background: linear-gradient(135deg, #f0f6fc, #e8f4fd);
    border: 2px dashed #72aee6;
    border-radius: var(--webar-v-radius);
    text-align: center;
    padding: 40px 20px;
    color: #2271b1;
}

.webar-placeholder-icon {
    font-size: 64px;
    margin-bottom: 16px;
    animation: webar-float 3s ease-in-out infinite;
}

.webar-editor-placeholder p {
    margin: 4px 0;
    font-size: 14px;
}

.webar-badge-preview {
    display: inline-block;
    background: #2271b1;
    color: #fff;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    margin: 4px 2px;
}

/* ==========================================
   ERROR INLINE
   ========================================== */
.webar-error {
    display: block;
    padding: 12px 16px;
    background: #fce8e8;
    border-left: 4px solid #d63638;
    border-radius: 4px;
    font-size: 13px;
    color: #6a0000;
    margin: 8px 0;
}

/* ==========================================
   ANIMACIONES
   ========================================== */
@keyframes webar-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes webar-float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-8px); }
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 600px) {
    .webar-ar-btn {
        bottom: 60px;
        right: 12px;
        padding: 8px 14px;
        font-size: 12px;
    }

    .webar-controls-bar {
        padding: 6px 8px;
    }

    .webar-ctrl-btn {
        --webar-v-ctrl-sz: 36px;
        font-size: 14px;
    }

    .webar-audio-label {
        display: none;
    }

    .webar-audio-btn {
        width: 36px;
        padding: 0;
    }

    .webar-qr-section {
        display: none !important;
    }
    
    .webar-qr-inner {
        padding: 30px 20px;
        max-width: 90%;
    }
    
    .webar-qr-code {
        width: 200px !important;
        height: 200px !important;
        padding: 10px;
    }
    
    .webar-qr-code img,
    .webar-qr-code canvas {
        max-width: 180px !important;
        max-height: 180px !important;
    }

    .webar-loader-bar {
        width: 240px;
    }

    .webar-ar-loading-title {
        font-size: 20px;
    }

    .webar-ar-instructions {
        padding: 15px;
        max-width: 300px;
    }
}

/* ==========================================
   FULLSCREEN
   ========================================== */
.webar-viewer-wrapper:fullscreen {
    border-radius: 0;
}

.webar-viewer-wrapper:fullscreen .webar-model-viewer {
    height: 100vh !important;
}

/* ==========================================
   ACCESIBILIDAD
   ========================================== */
.webar-ctrl-btn:focus,
.webar-ar-btn:focus,
.webar-qr-close:focus {
    outline: 2px solid var(--webar-v-primary);
    outline-offset: 2px;
}

/* Reducir movimiento */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .webar-ar-btn::before {
        animation: none;
    }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --webar-v-ctrl-bg: rgba(30,30,30,.95);
    }
}