:root { 
    --bg-color: #0f172a; 
    --glass-bg: rgba(255, 255, 255, 0.05); 
    --glass-border: rgba(255, 255, 255, 0.1); 
    --primary: #3b82f6; 
}
body { 
    margin: 0; 
    padding: 20px; 
    font-family: 'Segoe UI', sans-serif; 
    background: var(--bg-color); 
    background-image: radial-gradient(circle at top right, #1e293b, #0f172a); 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    min-height: 100vh; 
    color: white; 
    overflow-x: hidden; 
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Protegemos los inputs para que puedas escribir */
input, textarea {
    -webkit-user-select: auto !important;
    -khtml-user-select: auto !important;
    -moz-user-select: auto !important;
    -ms-user-select: auto !important;
    user-select: auto !important;
}

.glass-panel { 
    background: var(--glass-bg); 
    backdrop-filter: blur(15px); 
    -webkit-backdrop-filter: blur(15px); 
    border: 1px solid var(--glass-border); 
    border-radius: 20px; 
    padding: 40px; 
    width: 100%; 
    max-width: 550px; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); 
    transition: opacity 0.5s ease, transform 0.5s ease; 
}
.hidden { opacity: 0; pointer-events: none; position: absolute; transform: translateY(20px); display: none !important; }
.custom-input { background: rgba(0, 0, 0, 0.3) !important; border: 1px solid var(--glass-border) !important; color: white !important; font-size: 0.9rem; }
.custom-input:focus { border-color: var(--primary) !important; box-shadow: none !important; }
.custom-input::placeholder { color: #94a3b8 !important; }
select.custom-input option { background: var(--bg-color); color: white; }
.custom-file-upload { display: block; padding: 15px; cursor: pointer; background: rgba(59, 130, 246, 0.1); border: 1px dashed var(--primary); border-radius: 10px; text-align: center; transition: 0.3s; }
.custom-file-upload:hover { background: rgba(59, 130, 246, 0.2); }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.image-wrapper { position: relative; aspect-ratio: 16/9; }
.image-wrapper img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--glass-border); }
.delete-btn { position: absolute; top: -5px; right: -5px; background: #ef4444; color: white; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 10px; display: flex; justify-content: center; align-items: center; cursor: pointer; }
.loader-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-color); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 9999; transition: opacity 0.8s ease; }
.spinner { width: 40px; height: 40px; border: 3px solid rgba(255,255,255,0.1); border-radius: 50%; border-top-color: var(--primary); animation: spin 1s linear infinite; }
.mini-spinner { width: 25px; height: 25px; border: 2px solid rgba(255,255,255,0.1); border-radius: 50%; border-top-color: var(--primary); animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* HUD DE TELEMETRÍA DUAL */
#telemetry-hud {
    position: fixed;
    top: 15px;
    left: 15px;
    right: 15px;
    display: flex;
    justify-content: space-between;
    background: rgba(10, 10, 10, 0.9);
    padding: 10px 20px;
    font-family: monospace;
    font-size: 0.9rem;
    border-radius: 6px;
    border: 1px solid #333;
    z-index: 10000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.7);
    pointer-events: none;
    backdrop-filter: blur(5px);
}

/* =========================================================================
   DISEÑO PREMIUM DEL FOLIO A4 PARA VISTA PREVIA (MODO BLINDADO)
   ========================================================================= */
#preview-workspace {
    flex-grow: 1;
    overflow-y: auto;
    background-color: #cbd5e1;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* CRÍTICO: Evita que el folio se corte por arriba */
    padding: 40px 20px;
}

#preview-content {
    background: white;
    box-sizing: border-box; /* CRÍTICO: Para que el padding no deforme los 21cm de ancho */
    width: 21cm;
    min-height: 29.7cm;
    padding: 2.54cm; /* Márgenes exactos de Microsoft Word */
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
    color: black;
    font-family: 'Calibri', 'Arial', sans-serif;
    font-size: 11pt;
    line-height: 1.5;
    text-align: justify;
    overflow-x: hidden; /* CRÍTICO: Corta por lo sano si algo intenta salirse a los lados */
}

/* BLINDAJE ANTI-DESBORDAMIENTO (Fuerza a Mammoth.js a obedecer) */
#preview-content * {
    max-width: 100% !important; /* Nada puede ser más ancho que el espacio interior del folio */
    box-sizing: border-box !important;
    word-wrap: break-word !important; /* Corta palabras o enlaces larguísimos */
}

/* Ajuste perfecto para las capturas inyectadas */
#preview-content img {
    height: auto !important;
    margin: 20px auto !important;
    display: block;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border-radius: 4px;
}

/* Tablas adaptables */
#preview-content table {
    width: 100% !important;
    border-collapse: collapse;
    margin-bottom: 20px;
}

#preview-content p {
    margin-bottom: 15px;
}