/* 1. RESET GLOBAL Y VARIABLES */
* { 
    box-sizing: border-box; /* Fundamental: el padding no suma al ancho total */
    margin: 0; 
    padding: 0; 
}

:root {
    --primary: #003366;
    --secondary: #555;
    --card-w: 300px;
    --card-h: 460px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 15px;
}

/* 2. CONTENEDOR PRINCIPAL */
.main-container {
    display: flex;
    background: #ffffff;
    padding: 35px;
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 1000px;
    gap: 40px;
    align-items: flex-start;
}

/* 3. SECCIÓN DEL FORMULARIO */
.form-section { 
    flex: 1; 
    width: 100%;
    min-width: 0; /* Evita desbordamiento en flex */
}

.header-text h2 { 
    color: var(--primary); 
    margin-bottom: 8px; 
    font-size: 24px; 
    display: flex; 
    align-items: center; 
    gap: 12px; 
}

.header-text p { 
    color: #777; 
    margin-bottom: 25px; 
    font-size: 14px; 
}

.form-group { 
    margin-bottom: 18px; 
    width: 100%;
}

label { 
    display: block; 
    font-size: 13px; 
    font-weight: 700; 
    margin-bottom: 6px; 
    color: #333; 
}

/* INPUTS ESTILIZADOS */
input[type="text"] { 
    width: 100%;
    padding: 12px 15px; 
    border: 2px solid #e1e4e8; 
    border-radius: 10px; 
    font-size: 14px; 
    transition: var(--transition);
    outline: none;
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

/* INPUT DE FOTO PERSONALIZADO */
.custom-file-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px;
    background: #f8f9fa;
    border: 2px dashed #ccd1d6;
    border-radius: 10px;
    color: #555;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    font-size: 14px;
}

.custom-file-upload:hover {
    background: #eef2f7;
    border-color: var(--primary);
    color: var(--primary);
}

#foto {
    display: none; /* Ocultamos el input feo original */
}

/* 4. BOTONES */
.button-panel { 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    margin-top: 25px;
    width: 100%;
}

button { 
    width: 100%;
    padding: 14px; 
    border: none; 
    border-radius: 10px; 
    color: white; 
    font-weight: 700; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 10px; 
    font-size: 15px;
    transition: var(--transition);
}

.btn-flip { background: var(--secondary); }
.btn-flip:hover { background: #333; transform: translateY(-2px); }

.btn-print { background: var(--primary); }
.btn-print:hover { background: #002244; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0, 51, 102, 0.3); }

/* 5. VISTA PREVIA (CARNET) */
.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 15px;
    padding: 30px;
    min-height: 520px;
}

.flip-container {
    perspective: 1000px;
    width: var(--card-w);
    height: var(--card-h);
}

.flipper {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.flipper.flipped { transform: rotateY(180deg); }

.carnet-card {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    background: white;
    border: 1px solid #ddd;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.back { transform: rotateY(180deg); }

.watermark {
    position: absolute;
    top: 55%; left: 50%;
    transform: translate(-50%, -50%);
    width: 230px;
    opacity: 0.07;
    z-index: 0;
    pointer-events: none;
}

/* DISEÑO INTERNO CARNET */
.c-header { background: var(--primary); color: white; text-align: center; padding: 18px 10px; position: relative; z-index: 1; }
.c-header h3 { font-size: 14px; margin-bottom: 4px; letter-spacing: 0.5px; }
.c-header p { font-size: 8px; text-transform: uppercase; opacity: 0.9; }

.c-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; position: relative; z-index: 1; }
.img-box img { width: 135px; height: 135px; border-radius: 50%; border: 5px solid var(--primary); object-fit: cover; background: white; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }

.info-box { text-align: center; margin-top: 20px; width: 100%; }
.info-box h4 { font-size: 19px; color: #111; margin-bottom: 8px; text-transform: uppercase; font-weight: 800; }
.badge { background: var(--primary); color: white; padding: 6px 16px; border-radius: 25px; font-size: 13px; display: inline-block; margin-bottom: 12px; font-weight: 700; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.info-box p { font-size: 16px; color: #333; font-weight: 700; letter-spacing: 1px; }

.c-footer { background: #f1f1f1; padding: 12px; font-size: 10px; font-weight: 800; text-align: center; color: #666; border-top: 1px solid #e1e1e1; position: relative; z-index: 1; }

/* REVERSO */
.reverso-inner { flex: 1; padding: 30px; display: flex; flex-direction: column; justify-content: space-between; position: relative; z-index: 1; }
.rules { font-size: 11px; color: #333; line-height: 1.6; }
.rules strong { color: var(--primary); display: block; margin-bottom: 8px; }
.rules li { margin-bottom: 5px; }

.auth-area { text-align: center; }
.sign-line { width: 85%; margin: 0 auto; border-top: 1.5px solid #000; margin-top: 45px; }
.auth-area p { font-size: 10px; font-weight: 800; margin-top: 8px; color: #000; }
.stamp-circle { width: 80px; height: 80px; border: 2px dashed #bbb; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #bbb; margin: 15px auto 0; font-weight: 700; }

/* 6. RESPONSIVE (MÓVIL) */
@media (max-width: 850px) {
    .main-container { flex-direction: column; padding: 20px; gap: 25px; }
    .form-section { min-width: 100%; }
    .preview-section { padding: 20px 10px; min-height: auto; }
    
    :root {
        --card-w: 285px;
        --card-h: 437px;
    }
}

/* 7. IMPRESIÓN (PDF) */
@media print {
    html, body { visibility: hidden; background: white !important; margin: 0 !important; }
    .preview-section, .preview-section *, .flipper, .carnet-card, .carnet-card * { visibility: visible; }
    .preview-section { position: absolute; left: 0; top: 0; width: 100%; padding: 0 !important; }
    .flip-container { perspective: none !important; width: auto !important; height: auto !important; }
    .flipper { display: flex !important; flex-direction: row !important; transform: none !important; width: 602px !important; margin: 1.5cm auto; }
    .carnet-card { position: relative !important; transform: none !important; backface-visibility: visible !important; border: 1.5px solid #000 !important; border-radius: 0 !important; box-shadow: none !important; width: 300px !important; height: 460px !important; }
    .back { transform: none !important; border-left: none !important; }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    @page { size: landscape; margin: 0; }
}