/* ==========================================
   1. VARIABLES GLOBALES Y RESET
   ========================================== */
:root {
    --primary: #0284c7; 
    --secondary: #0369a1; 
    --accent: #10b981; 
    --danger: #ef4444; 
    --warning: #f59e0b; 
    --bg-main: #f1f5f9; 
    --text-dark: #0f172a; 
    --text-muted: #64748b; 
    --border: #cbd5e1;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', system-ui, sans-serif; }
body { background-color: var(--bg-main); color: var(--text-dark); display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ==========================================
   2. TOPBAR
   ========================================== */
.topbar { height: 60px; background: white; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0 2rem; flex-shrink: 0; box-shadow: var(--shadow-sm); z-index: 10;}
.topbar-brand { font-size: 1.3rem; font-weight: 800; color: var(--primary); display: flex; align-items: center; gap: 10px; }
.btn-volver { background: #f8fafc; border: 1px solid var(--border); padding: 0.4rem 1rem; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--text-dark); text-decoration: none; transition: 0.2s; display: inline-flex; align-items: center; gap: 5px; font-size: 0.9rem;}
.btn-volver:hover { background: #e2e8f0; }

.workspace { display: flex; flex: 1; overflow: hidden; }

/* ==========================================
   3. PANEL IZQUIERDO (CONTROLES)
   ========================================== */
.control-panel { 
    width: 600px; 
    background: #f8fafc; 
    border-right: 1px solid var(--border); 
    padding: 1.5rem 2rem; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 1.5rem; 
}

.section-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.section-title {
    color: var(--primary);
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 1.2rem;
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.4rem; color: #475569; }

.form-control { 
    width: 100%; 
    padding: 0.6rem 0.8rem; 
    border: 1px solid var(--border); 
    border-radius: 6px; 
    font-size: 0.95rem; 
    outline: none; 
    transition: 0.2s; 
    background: white; 
    color: var(--text-dark);
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15); }
.form-control[readonly] { background: #f1f5f9; color: var(--text-muted); cursor: not-allowed; border-style: dashed; }
textarea.form-control { resize: vertical; min-height: 70px; line-height: 1.4; }

select.form-control {
    appearance: none; 
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.8rem center; background-size: 1em; padding-right: 2.5rem; cursor: pointer;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

.grid-rx { 
    display: grid; 
    grid-template-columns: 35px 1fr 1fr 1fr 1fr 1fr; 
    gap: 10px; 
    align-items: center; 
    text-align: center; 
    margin-bottom: 15px;
}
.grid-rx label { font-size: 0.8rem; color: #334155; font-weight: 700; margin: 0; }
.grid-rx input { text-align: center; padding: 0.5rem; font-size: 0.9rem; font-weight: 600; border-radius: 6px; }
.grid-rx .eye-lbl { font-weight: 900; font-size: 1.1rem; }
.eye-od { color: var(--primary); }
.eye-oi { color: var(--accent); }

.chk-container {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: #1e293b;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
    padding: 5px 0;
}
.chk-container input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.optional-box { margin-left: 28px; margin-bottom: 15px; display: none; animation: fadeIn 0.3s ease; }

/* ==========================================
   4. PANEL DERECHO (VISTA PREVIA A4)
   ========================================== */
.preview-panel { flex: 1; background: #cbd5e1; padding: 2rem; display: flex; justify-content: center; overflow-y: auto; }

.a4-paper { 
    background: white; 
    width: 210mm; 
    min-height: 297mm; 
    padding: 20mm; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.15); 
    position: relative; 
    flex-shrink: 0; 
    display: flex; 
    flex-direction: column; 
}

.cert-header { text-align: center; border-bottom: 2px solid var(--primary); padding-bottom: 15px; margin-bottom: 25px; }
.cert-header h1 { color: var(--primary); font-size: 24pt; margin-bottom: 5px; font-weight: 800; letter-spacing: -0.5px;}
.cert-header p { color: #64748b; font-size: 10pt; margin-bottom: 10px; }
.cert-header h2 { color: var(--text-dark); font-size: 13pt; text-transform: uppercase; letter-spacing: 2px; font-weight: 700; margin-top: 15px;}

.cert-intro { text-align: justify; font-size: 11pt; line-height: 1.6; margin-bottom: 25px; color: #1e293b; }

.cert-box { background: #f8fafc; border: 1px solid var(--border); padding: 15px 20px; border-radius: 8px; margin-bottom: 25px; font-size: 10.5pt; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cert-box p { margin: 0; color: #0f172a; display: flex; justify-content: space-between; border-bottom: 1px dashed #e2e8f0; padding-bottom: 4px;}
.cert-box strong { color: #475569; }

.cert-section-title { color: var(--primary); font-size: 11.5pt; font-weight: bold; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 5px; margin-top: 20px; text-transform: uppercase;}

.cert-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; font-size: 10pt; text-align: center; }
.cert-table th, .cert-table td { border: 1px solid var(--border); padding: 8px; }
.cert-table th { background: #f1f5f9; color: #334155; font-weight: bold; }
.cert-table td { color: #0f172a; font-weight: 600; }

.cert-optional-block { margin-bottom: 15px; font-size: 10.5pt; color: #1e293b; text-align: justify; line-height: 1.6; display: none; }
.cert-optional-block h4 { color: #475569; font-size: 10pt; margin-bottom: 4px; text-transform: uppercase; border-bottom: 1px dashed #cbd5e1; display: inline-block; padding-bottom: 2px;}

.cert-patologia { margin-bottom: 20px; padding: 12px 15px; background: #fffbeb; border-left: 4px solid var(--warning); border-radius: 0 6px 6px 0; }
.cert-patologia p { font-size: 11pt; color: #92400e; font-weight: 600; line-height: 1.5; margin: 0; }

.cert-obs { font-size: 10.5pt; line-height: 1.6; color: #1e293b; text-align: justify; margin-bottom: 15px; }

.cert-footer { 
    margin-top: auto; 
    width: 100%; 
    padding-top: 30px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}

.cert-firma { text-align: center; display: flex; flex-direction: column; align-items: center; width: 100%; }
.cert-firma-linea { border-top: 1px solid #000; width: 280px; margin: 0 auto; padding-top: 8px; font-size: 11pt; color: #0f172a; display: flex; flex-direction: column; gap: 4px;}

.btn { padding: 0.6rem 1.2rem; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; font-size: 0.95rem; transition: var(--transition); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: white; }
.btn-outline { background: white; border: 1px solid var(--border); color: var(--text-dark); }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.8); display: none; justify-content: center; align-items: center; z-index: 2000; padding: 1rem; backdrop-filter: blur(4px); }
.modal-content { background: white; padding: 2rem; border-radius: 12px; width: 100%; max-width: 600px; box-shadow: var(--shadow-lg); animation: popIn 0.3s ease-out; max-height: 90vh; overflow-y: auto; }
.table-modal { width: 100%; border-collapse: collapse; text-align: left; margin-top: 15px; }
.table-modal th, .table-modal td { padding: 12px 15px; border-bottom: 1px solid var(--border); }
.table-modal th { background: #f8fafc; font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { 0% { opacity: 0; transform: scale(0.95); } 100% { opacity: 1; transform: scale(1); } }

/* Reglas de impresión */
@media print {
    .topbar, .control-panel, .modal-overlay { display: none !important; }
    body { margin: 0; padding: 0; background: white; display: block; height: auto; }
    .workspace { display: block; overflow: visible; }
    .preview-panel { display: block; padding: 0; background: transparent; overflow: visible; }
    
    .a4-paper { 
        position: relative;
        width: 100%;
        height: 296mm; 
        box-shadow: none; 
        padding: 15mm; 
        margin: 0;
    }
    
    @page { size: A4; margin: 0; } 
}