/* style.css - Versión RC8 (Folio Pre-flight) */

:root { 
    --primary: #0047bb; 
    --primary-hover: #00368c;
    --primary-bg: #eef2ff;
    --magenta: #ff00ff; 
    --cyan: #00ffff; 
    --bg-light: #f9fafb;
    --surface: #ffffff;
    --on-surface: #1f2937;
    --outline: #d1d5db;
}

body { 
    font-family: 'Poppins', sans-serif; 
    margin: 0; 
    display: flex; 
    flex-direction: column; 
    height: 100vh;
    height: 100dvh;
    overflow: hidden; 
    color: var(--on-surface); 
    background-color: var(--bg-light); 
}

@keyframes spin { 100% { transform: rotate(360deg); } }
.spinning { animation: spin 1s linear infinite; }

/* --- TOP BAR & DEBUG --- */
.top-bar { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,0.1); z-index: 1000; width: 100%; display: flex; justify-content: center; }
#debug-panel { display: flex; padding: 10px; background: #fffde7; border-bottom: 1px solid #fbc02d; gap: 20px; font-size: 11px; flex-wrap: wrap; }
.debug-item { display: flex; align-items: center; gap: 8px; }
#debug-panel input { width: 50px; border: 1px solid var(--outline); padding: 2px 5px; border-radius: 4px; font-weight: bold; }
.label-tech { font-weight: 800; text-transform: uppercase; font-size: 10px; color: #92400e; }
.val-tech { color: #000; font-weight: 900; font-family: monospace; font-size: 12px; }
.btn-ok { background: var(--primary); color: white; border: none; padding: 5px 12px; border-radius: 4px; cursor: pointer; font-weight: bold; }

/* --- VIEWER AREA --- */
.viewer-area { flex: 1; position: relative; overflow: hidden; background: #e5e7eb; cursor: grab; }
.viewer-area:active { cursor: grabbing; }
#canvas-container { position: absolute; top: 50%; left: 50%; background: #fff; filter: drop-shadow(0 4px 20px rgba(0,0,0,0.15)); transform: translate(-50%, -50%); transition: clip-path 0.3s ease; }
canvas { display: block; z-index: 1; position: relative; }
#guides-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 999; pointer-events: none; }
#canvas-loading-overlay { position: absolute; inset: 0; background: rgba(255,255,255,0.75); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.15s ease; }
#canvas-loading-overlay.visible { opacity: 1; pointer-events: auto; }
.canvas-spinner { width: 40px; height: 40px; border: 3px solid rgba(79,70,229,0.15); border-top-color: #4f46e5; border-radius: 50%; animation: spin 0.75s linear infinite; }

/* Guías Dinámicas */
body:not(.show-bleed) #canvas-container { clip-path: var(--trim-clip); }
body:not(.show-margin) .margin-guide, body:not(.show-trim) .trim-guide, body:not(.show-folds) .fold-guide { display: none !important; }

/* --- CONTROLES FLOTANTES --- */
.floating-controls { position: absolute; top: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: row; align-items: center; gap: 12px; }

.md3-split-button { display: flex; align-items: center; background: var(--surface); border-radius: 100px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); height: 48px; position: relative; }
.split-leading { display: flex; align-items: center; gap: 8px; padding: 0 16px 0 20px; border: none; background: none; font-family: 'Poppins', sans-serif; font-size: 14px; font-weight: 600; color: var(--on-surface); cursor: pointer; border-radius: 100px 0 0 100px; height: 100%; transition: background 0.2s; }
.split-leading:hover { background: #f3f4f6; }
.split-divider { width: 1px; height: 24px; background: var(--outline); }
.split-trailing { display: flex; align-items: center; justify-content: center; width: 44px; border: none; background: none; cursor: pointer; border-radius: 0 100px 100px 0; height: 100%; color: var(--on-surface); transition: background 0.2s; }
.split-trailing:hover { background: #f3f4f6; }

.md3-menu { position: absolute; top: calc(100% + 8px); right: 0; background: var(--surface); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.18); padding: 8px; display: none; flex-direction: column; min-width: 180px; z-index: 1001; }
.md3-menu.active { display: flex; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--on-surface); border-radius: 12px; transition: background 0.2s; cursor: pointer; }
.menu-item:hover { background: #f9fafb; }

.switch { position: relative; width: 30px; height: 16px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 12px; width: 12px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(14px); }

.fab { width: 56px; height: 56px; border-radius: 50%; background: var(--surface); border: none; box-shadow: 0 4px 12px rgba(0,0,0,0.15); display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--on-surface); transition: 0.2s; }
.fab:hover { background: #f9fafb; transform: scale(1.05); }

/* --- WIZARD CARD (BOTTOM SHEET RC8) --- */
.bottom-sheet-drag-handle { 
    display: block; 
    width: 40px; 
    height: 4px; 
    background: var(--outline); 
    border-radius: 10px; 
    margin: 0 auto 16px auto; 
    cursor: pointer;
    transition: background 0.2s;
}
.bottom-sheet-drag-handle:hover { background: var(--primary); }

.wizard-card {
    position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
    width: 100%; max-width: 480px; background: var(--surface);
    border-radius: 28px; box-shadow: 0 12px 48px rgba(0,0,0,0.15);
    padding: 16px 28px 24px 28px; z-index: 2000; box-sizing: border-box;
    display: flex; flex-direction: column; gap: 20px;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 85dvh; 
}

/* Estado Colapsado */
.wizard-card.collapsed {
    transform: translate(-50%, calc(100% - 110px)); 
}

.wizard-card.collapsed .wizard-body {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.wizard-body {
    transition: opacity 0.3s;
}

.wizard-header { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.wizard-title { font-size: 18px; font-weight: 700; margin: 0; color: var(--on-surface); text-align: center; }

/* Stepper */
.step-indicator { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; max-width: 320px; }
.step-dot { width: 28px; height: 28px; border-radius: 50%; background: #e5e7eb; color: #6b7280; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; transition: 0.3s; }
.step-dot.active { background: var(--primary); color: #fff; }
.step-dot.completed { background: #10b981; color: #fff; }
.step-line { flex: 1; height: 3px; background: #e5e7eb; border-radius: 2px; transition: 0.3s; }
.step-line.active { background: #10b981; }

.step-content { display: none; animation: fadeIn 0.3s ease; }
.step-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.step-desc { font-size: 14px; color: #4b5563; margin: 0 0 24px 0; line-height: 1.5; text-align: center; }

.wizard-actions { display: flex; justify-content: space-between; align-items: center; }
.action-group { display: flex; gap: 12px; }

/* Botones MD3 */
.md3-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 24px; border-radius: 100px; font-family: 'Poppins', sans-serif;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: 0.2s; border: none;
}
.md3-btn-filled { background: var(--primary); color: #fff; }
.md3-btn-filled:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(0, 71, 187, 0.2); }
.md3-btn-outlined { background: transparent; border: 1px solid var(--outline); color: var(--primary); }
.md3-btn-outlined:hover { background: var(--primary-bg); border-color: var(--primary); }
.md3-btn-text { background: transparent; color: #6b7280; padding: 10px 16px; }
.md3-btn-text:hover { background: #f3f4f6; color: var(--on-surface); }

/* --- COMPONENTES FOLIO --- */
.md3-segmented-button {
    display: flex; background: var(--surface); border-radius: 100px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); height: 48px; padding: 4px; gap: 4px;
    align-items: center; border: 1px solid var(--outline);
}
.seg-btn {
    background: transparent; border: none; border-radius: 100px; height: 100%;
    padding: 0 20px; font-family: 'Poppins', sans-serif; font-weight: 600;
    color: var(--on-surface); cursor: pointer; transition: 0.2s; font-size: 14px;
}
.seg-btn:hover { background: var(--bg-light); }
.seg-btn.active { background: var(--primary); color: white; }

.upload-boxes-container { display: flex; flex-direction: column; gap: 12px; width: 100%; margin-bottom: 16px; }

.size-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
    margin-bottom: 10px;
}
.size-badge--warn  { background: #fff3cd; color: #7d5a00; }
.size-badge--info  { background: #e0f2fe; color: #0369a1; }

#lomo-stretch-mode {
    display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px;
}
.md3-chip {
    display: inline-flex; align-items: center;
    padding: 6px 14px; border-radius: 100px;
    border: 1px solid var(--primary); background: var(--primary-bg);
    color: var(--primary); font-family: 'Poppins', sans-serif;
    font-size: 13px; font-weight: 600; cursor: pointer; transition: 0.2s;
}
.md3-chip:hover { background: var(--primary); color: #fff; }
.md3-chip--secondary { border-color: #6b7280; background: #f3f4f6; color: #374151; }
.md3-chip--secondary:hover { background: #e5e7eb; color: #111827; }
.md3-upload-box {
    display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 16px;
    border: 2px dashed var(--primary); background: var(--primary-bg); cursor: pointer; transition: 0.2s;
}
.md3-upload-box:hover.active { background: #e0e7ff; }
.md3-upload-box span.material-symbols-outlined { color: var(--primary); font-size: 28px; }
.md3-upload-box .box-text { font-weight: 600; color: var(--primary); font-size: 14px; flex: 1; text-align: left; }

.md3-upload-box.locked { border-color: var(--outline); background: var(--bg-light); cursor: not-allowed; border-style: solid; }
.md3-upload-box.locked span.material-symbols-outlined, .md3-upload-box.locked .box-text { color: #9ca3af; }

.md3-upload-box.completed { border: 2px solid #10b981; background: #f0fdf4; border-style: solid; }
.md3-upload-box.completed span.material-symbols-outlined, .md3-upload-box.completed .box-text { color: #10b981; }

.md3-upload-box.processing { opacity: 0.7; pointer-events: none; }
.md3-upload-box.processing span.material-symbols-outlined { animation: spin 1s linear infinite; }

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 900px) {
    .floating-controls { 
        top: 16px; bottom: auto; right: 16px; left: auto; 
        justify-content: flex-end; pointer-events: none; 
        flex-direction: column; gap: 12px; 
    }
    .floating-controls > * { pointer-events: auto; }
    
    .wizard-card { 
        bottom: 0; border-radius: 28px 28px 0 0; 
        padding: 16px 20px max(24px, env(safe-area-inset-bottom)); 
        max-width: 100%; gap: 16px; 
    }
    
    /* FIX RC8: Mantener centrado horizontal en mobile al colapsar */
    .wizard-card.collapsed {
        transform: translate(-50%, calc(100% - 100px)); 
    }
    
    .wizard-actions { flex-direction: column-reverse; gap: 12px; width: 100%; }
    .action-group { width: 100%; display: flex; gap: 12px; }
    .md3-btn { width: 100%; padding: 12px 16px; }
    
    .bottom-sheet-drag-handle { width: 36px; background: #cbd5e1; }
}

/* --- CANVAS & EFFECTS --- */
.page-canvas { position: absolute; top: 0; left: 0; z-index: 1; transition: opacity 0s; }
.page-canvas.active-canvas { opacity: 1; visibility: visible; }
.page-canvas.hidden-canvas { opacity: 0; visibility: hidden; pointer-events: none; }

.effect-canvas { position: absolute; top: 0; left: 0; z-index: 2; pointer-events: none; opacity: 0; transition: opacity 0.3s ease; }
.effect-canvas.active-effect { opacity: 1; }

/* --- ANIMACIONES DE EFECTOS (RC8) --- */

@keyframes shine-effect {
    0% { background-position: 200% center; }
    100% { background-position: -200% center; }
}

.effect-stamping-dor {
    background: linear-gradient(110deg, #b38728 0%, #fcf6ba 40%, #ffffff 50%, #fcf6ba 60%, #b38728 100%);
    background-size: 200% auto;
    animation: shine-effect 3s linear infinite;
}

.effect-stamping-pla {
    background: linear-gradient(110deg, #757f9a 0%, #d7dde8 40%, #ffffff 50%, #d7dde8 60%, #757f9a 100%);
    background-size: 200% auto;
    animation: shine-effect 3s linear infinite;
}

.effect-laca {
    background: linear-gradient(110deg, rgba(255,255,255,0.0) 0%, rgba(255, 255, 255, 0.82) 35%, rgba(255,255,255,0.0) 55%, rgba(255, 255, 255, 0.82) 75%, rgba(255,255,255,0.0) 100%);
    background-size: 200% auto;
    animation: shine-effect 4s linear infinite;
}

/* --- IFRAME MOCKUP 3D --- */
#mockup-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10; 
    background: var(--bg-light);
    transition: opacity 0.3s ease;
}

.hidden-iframe {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.active-iframe {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}