<?php
// =============================================================================
// HISTORIA CLINICA DE FISIOTERAPIA Y REHABILITACION
// Basado en el formato oficial de Historia Clinica en Rehabilitacion.
// Estilo MSP del sistema (clases msp-*). Form name "formulariop" para
// que el guardado generico de atencion.php capture el JSON serializado.
// Tipo_formato: FISIOTERAPIA
// =============================================================================
?>
<style>
    .ft-rh-table { width:100%; border-collapse:collapse; font-size:11px; margin-bottom:10px; }
    .ft-rh-table th, .ft-rh-table td { border:1px solid #cfd8dc; padding:4px 6px; vertical-align:top; }
    .ft-rh-table th { background:#eceff1; font-weight:700; text-align:center; color:#37474f; font-size:11px; text-transform:uppercase; letter-spacing:0.3px; }
    .ft-rh-table td.lbl { background:#f5f7fa; font-weight:600; width:22%; }
    .ft-rh-table td.cell-sn { width:6%; text-align:center; }
    .ft-rh-table td.cell-num { width:8%; text-align:center; }
    .ft-rh-table input.cell-input, .ft-rh-table textarea.cell-input,
    .ft-rh-table select.cell-input { width:100%; border:0; padding:2px 3px; background:transparent; font-size:11px; }
    .ft-rh-table input.cell-input:focus, .ft-rh-table textarea.cell-input:focus,
    .ft-rh-table select.cell-input:focus { background:#fffde7; outline:1px solid #fbc02d; }
    .ft-rh-table tr.sub th { background:#cfd8dc; color:#102027; }
    .ft-rh-mini { background:#eceff1; padding:4px 8px; font-weight:700; font-size:11px; color:#263238; margin:8px 0 4px 0; border-left:3px solid #00838f; }
    .ft-rh-note { background:#fffde7; border-left:3px solid #fbc02d; padding:6px 10px; font-size:11px; color:#5d4037; margin:4px 0 8px 0; }
    .ft-rh-eva-wrap { display:flex; gap:4px; justify-content:space-between; padding:6px 0; }
    .ft-rh-eva { flex:1; min-width:34px; height:34px; display:flex; align-items:center; justify-content:center;
        border-radius:50%; font-weight:700; cursor:pointer; border:2px solid transparent; font-size:12px; transition:.15s; }
    .ft-rh-eva.lvl-0 { background:#c8e6c9; color:#1b5e20; }
    .ft-rh-eva.lvl-1 { background:#dcedc8; color:#33691e; }
    .ft-rh-eva.lvl-2 { background:#fff9c4; color:#f57f17; }
    .ft-rh-eva.lvl-3 { background:#ffe0b2; color:#e65100; }
    .ft-rh-eva.lvl-4 { background:#ffccbc; color:#bf360c; }
    .ft-rh-eva.lvl-5 { background:#ffcdd2; color:#b71c1c; }
    .ft-rh-eva.active { border-color:#263238; transform:scale(1.15); }
    .ft-rh-silh { display:flex; gap:6px; justify-content:center; flex-wrap:wrap; }
    .ft-rh-silh svg { background:#fafafa; border:1px solid #cfd8dc; border-radius:4px; }
    .ft-rh-silh figcaption { text-align:center; font-size:10px; color:#546e7a; margin-top:2px; }
    .ft-rh-glasgow td { font-size:11px; }
    .ft-rh-glasgow .gtot { background:#e0f2f1; font-weight:700; font-size:13px; text-align:center; color:#004d40; }
    .ft-rh-table td.editable { background:#fafafa; }
    details.ft-rh-acc { margin-bottom:6px; }
    details.ft-rh-acc > summary { background:#eceff1; padding:6px 10px; cursor:pointer; font-weight:600; font-size:11px; color:#263238; border-left:3px solid #00838f; }
    details.ft-rh-acc[open] > summary { background:#cfd8dc; }
</style>

<form name="formulariop" id="formulariop" method="POST">
    <input type="hidden" name="idatencion" id="idatencion_ft" value="<?php echo $_POST['idatencion'] ?? ''; ?>">
    <input type="hidden" name="tipo_formato" value="FISIOTERAPIA">

    <div class="msp-002-header" style="background-color:#00838f; color:#fff; padding:10px; text-align:center; font-weight:bold; border:1px solid #006064; margin-bottom:10px; border-radius:3px;">
        HISTORIA CLINICA DE FISIOTERAPIA Y REHABILITACION
    </div>

    <?php include 'partials/patient_header.php'; ?>

    <div class="msp-container">

    <!-- ========================================================== -->
    <!-- 1. DATOS GENERALES DE LA CONSULTA                            -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">1. DATOS GENERALES DE LA CONSULTA</div>
        <table class="ft-rh-table">
            <tr>
                <td class="lbl">No. Expediente</td>
                <td><input class="cell-input" name="ft_no_expediente"></td>
                <td class="lbl">Cama / Cubiculo</td>
                <td><input class="cell-input" name="ft_cama_cubiculo"></td>
                <td class="lbl">Fecha</td>
                <td><input type="date" class="cell-input" name="ft_fecha" value="<?php echo date('Y-m-d'); ?>"></td>
                <td class="lbl">Hora</td>
                <td><input type="time" class="cell-input" name="ft_hora" value="<?php echo date('H:i'); ?>"></td>
            </tr>
            <tr>
                <td class="lbl">Diagnostico medico</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="ft_dx_medico"></textarea></td>
                <td class="lbl">Tratamientos previos</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="ft_tx_previos"></textarea></td>
            </tr>
            <tr>
                <td class="lbl">Motivo de consulta</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="ft_motivo_consulta"></textarea></td>
                <td class="lbl">Mecanismo de lesion</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="ft_mecanismo_lesion"></textarea></td>
            </tr>
            <tr>
                <td class="lbl">Medico tratante</td>
                <td colspan="3"><input class="cell-input" name="ft_medico_tratante"></td>
                <td class="lbl">Remision</td>
                <td colspan="3"><input class="cell-input" name="ft_remision"></td>
            </tr>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 2. PACIENTE DEPORTIVO (opcional)                             -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">
            2. EN CASO DE PACIENTE DEPORTIVO
            <label style="font-weight:normal; font-size:11px; margin-left:10px;">
                <input type="checkbox" id="ft_deportivo_on" name="ft_deportivo_on" value="1"
                       onclick="$('#ft_deportivo_box').toggle(this.checked);"> Aplica
            </label>
        </div>
        <div id="ft_deportivo_box" style="display:none;">
            <table class="ft-rh-table">
                <tr>
                    <td class="lbl">Disciplina deportiva</td>
                    <td><input class="cell-input" name="ft_dep_disciplina"></td>
                    <td class="lbl">Categoria</td>
                    <td><input class="cell-input" name="ft_dep_categoria"></td>
                </tr>
                <tr>
                    <td class="lbl">Deporte de alto rendimiento</td>
                    <td>
                        <select class="cell-input" name="ft_dep_alto_rend">
                            <option value="">Seleccione</option><option value="SI">Si</option><option value="NO">No</option>
                        </select>
                    </td>
                    <td class="lbl">Nombre del entrenador</td>
                    <td><input class="cell-input" name="ft_dep_entrenador"></td>
                </tr>
                <tr>
                    <td class="lbl">Arte competitivo</td>
                    <td><input class="cell-input" name="ft_dep_arte"></td>
                    <td class="lbl">Club o liga deportiva</td>
                    <td><input class="cell-input" name="ft_dep_club"></td>
                </tr>
            </table>
        </div>
    </div>

    <!-- ========================================================== -->
    <!-- 3. MEDIDAS FISICAS Y SIGNOS VITALES                          -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">3. MEDIDAS FISICAS Y SIGNOS VITALES</div>
        <table class="ft-rh-table">
            <tr>
                <th colspan="4" class="ft-rh-mini" style="border:0;">Medidas Fisicas</th>
                <th colspan="4" class="ft-rh-mini" style="border:0;">Signos Vitales</th>
            </tr>
            <tr>
                <td class="lbl">Peso (kg)</td>
                <td><input type="text" step="0.01" class="cell-input" name="ft_peso" id="ft_peso" oninput="calcImc()"></td>
                <td class="lbl">Talla (m)</td>
                <td><input type="text" step="0.01" class="cell-input" name="ft_talla" id="ft_talla" oninput="calcImc()"></td>
                <td class="lbl">Temperatura (&deg;C)</td>
                <td><input type="text" step="0.1" class="cell-input" name="ft_temp"></td>
                <td class="lbl">F. Cardiaca (lpm)</td>
                <td><input type="text" class="cell-input" name="ft_fc"></td>
            </tr>
            <tr>
                <td class="lbl">Estatura</td>
                <td><input class="cell-input" name="ft_estatura"></td>
                <td class="lbl">IMC</td>
                <td><input class="cell-input" name="ft_imc" id="ft_imc" readonly style="background:#fff9c4;"></td>
                <td class="lbl">F. Respiratoria (rpm)</td>
                <td><input type="text" class="cell-input" name="ft_fr"></td>
                <td class="lbl">Tension Arterial</td>
                <td><input class="cell-input" name="ft_ta" placeholder="120/80"></td>
            </tr>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 4. FICHA DE IDENTIFICACION COMPLEMENTARIA                    -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">4. FICHA DE IDENTIFICACION COMPLEMENTARIA</div>
        <div class="ft-rh-note">Los datos basicos del paciente provienen del encabezado. Complemente solo la informacion adicional.</div>
        <table class="ft-rh-table">
            <tr>
                <td class="lbl">Escolaridad</td>
                <td><input class="cell-input" name="ft_id_escolaridad"></td>
                <td class="lbl">Ocupacion</td>
                <td><input class="cell-input" name="ft_id_ocupacion"></td>
                <td class="lbl">Estado civil</td>
                <td><input class="cell-input" name="ft_id_estado_civil"></td>
            </tr>
            <tr>
                <td class="lbl">Domicilio</td>
                <td colspan="3"><input class="cell-input" name="ft_id_domicilio"></td>
                <td class="lbl">Telefono</td>
                <td><input class="cell-input" name="ft_id_telefono"></td>
            </tr>
            <tr>
                <td class="lbl">Religion</td>
                <td><input class="cell-input" name="ft_id_religion"></td>
                <td class="lbl">Telefono de emergencia</td>
                <td><input class="cell-input" name="ft_id_tel_emergencia"></td>
                <td class="lbl">Nacionalidad</td>
                <td><input class="cell-input" name="ft_id_nacionalidad"></td>
            </tr>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 5. ANTECEDENTES PATOLOGICOS Y HEREDOFAMILIARES               -->
    <!-- ========================================================== -->
    <?php
        $antecPato = [
            'diabetes' => 'Diabetes',
            'neurologica' => 'Neurologica',
            'has' => 'Hipertension arterial (HAS)',
            'neoplasias' => 'Neoplasias',
            'cardiopatias' => 'Cardiopatias',
            'reumaticas' => 'Reumaticas',
            'respiratorias' => 'Respiratorias',
            'geneticas' => 'Geneticas',
            'endocrinologicas' => 'Endocrinologicas',
            'infecciosas' => 'Infecciosas',
            'accidentes' => 'Accidentes',
            'hospitalizaciones' => 'Hospitalizaciones',
            'traumatismos' => 'Traumatismos',
            'fracturas' => 'Fracturas',
            'cirugias' => 'Cirugias',
            'alergias' => 'Alergias',
            'otras' => 'Otras',
        ];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">5. ANTECEDENTES PATOLOGICOS Y HEREDOFAMILIARES</div>
        <table class="ft-rh-table">
            <thead>
                <tr><th style="width:30%;">Enfermedad</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th style="width:25%;">Parentesco</th><th>Especifique</th></tr>
            </thead>
            <tbody>
            <?php foreach($antecPato as $k => $lbl): ?>
                <tr>
                    <td class="lbl"><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="ap_<?php echo $k; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="ap_<?php echo $k; ?>" value="NO"></td>
                    <td><input class="cell-input" name="ap_<?php echo $k; ?>_parentesco"></td>
                    <td><input class="cell-input" name="ap_<?php echo $k; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 6. ANTECEDENTES NO PATOLOGICOS                               -->
    <!-- ========================================================== -->
    <?php
        $antecNoPato = [
            'toxicomanias' => ['Toxicomanias', ''],
            'inmunizaciones' => ['Inmunizaciones', ''],
            'automedicacion' => ['Automedicacion', ''],
            'sueno' => ['Trastornos del sueno', 'Tipo y cantidad de horas que duerme'],
            'alimentacion' => ['Alimentacion', 'Numero, cantidad, calidad, litros de agua/dia'],
            'habitacion' => ['Habitacion', 'Piso, ventilacion, iluminacion, servicios, ambiente'],
            'higiene' => ['Habitos higienicos', 'Bano diario, lavado de manos, higiene bucal, cambio de ropa'],
            'zoonosis' => ['Zoonosis', ''],
            'act_fisica' => ['Actividad fisica', ''],
            'ocupacion' => ['Ocupacion', 'Ambiente, higiene, jornada'],
            'ocio' => ['Actividades de ocio', ''],
        ];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">6. ANTECEDENTES NO PATOLOGICOS</div>
        <table class="ft-rh-table">
            <thead>
                <tr><th style="width:25%;">Antecedente</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr>
            </thead>
            <tbody>
            <?php foreach($antecNoPato as $k => $row): ?>
                <tr>
                    <td class="lbl">
                        <?php echo $row[0]; ?>
                        <?php if($row[1]): ?><br><small style="font-weight:normal; color:#78909c;"><?php echo $row[1]; ?></small><?php endif; ?>
                    </td>
                    <td class="cell-sn"><input type="radio" name="anp_<?php echo $k; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="anp_<?php echo $k; ?>" value="NO"></td>
                    <td><input class="cell-input" name="anp_<?php echo $k; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 7. ANTECEDENTES GINECO-OBSTETRICOS                           -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">
            7. ANTECEDENTES GINECO-OBSTETRICOS
            <label style="font-weight:normal; font-size:11px; margin-left:10px;">
                <input type="checkbox" id="ft_gineco_on" name="ft_gineco_on" value="1"
                       onclick="$('#ft_gineco_box').toggle(this.checked);"> Aplica (paciente femenina)
            </label>
        </div>
        <div id="ft_gineco_box" style="display:none;">
        <?php
            $gineco = [
                'menarca' => 'Menarca',
                'dismenorreas' => 'Dismenorreas',
                'gesta_actual' => 'Gesta actual',
                'num_gestas' => 'Numero de gestas',
                'num_partos' => 'Numero de partos',
                'cesareas' => 'Cesareas',
                'aborto' => 'Aborto',
                'productos_vivos' => 'Numero de productos nacidos vivos',
                'menopausia' => 'Menopausia',
            ];
        ?>
        <table class="ft-rh-table">
            <thead><tr><th style="width:35%;">Antecedente</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($gineco as $k => $lbl): ?>
                <tr>
                    <td class="lbl"><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="gin_<?php echo $k; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="gin_<?php echo $k; ?>" value="NO"></td>
                    <td><input class="cell-input" name="gin_<?php echo $k; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </div>
    </div>

    <!-- ========================================================== -->
    <!-- 8. ANTECEDENTES PERINATALES (PEDIATRICO)                     -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">
            8. ANTECEDENTES PERINATALES
            <label style="font-weight:normal; font-size:11px; margin-left:10px;">
                <input type="checkbox" id="ft_peri_on" name="ft_peri_on" value="1"
                       onclick="$('#ft_peri_box').toggle(this.checked);"> Aplica (paciente pediatrico)
            </label>
        </div>
        <div id="ft_peri_box" style="display:none;">
        <?php
            $peri = [
                'num_embarazo' => 'Numero de embarazo',
                'multiple' => 'Embarazo multiple',
                'alim_embarazo' => 'Alimentacion durante el embarazo',
                'meds_vitaminas' => 'Medicamentos o vitaminas',
                'control_perinatal' => 'Control perinatal',
                'periodo_intrauterino' => 'Periodo de vida intrauterina (Inmaduro 21-28 sem / Pretermino 28-37 / Termino 37-41 / Postermino 42+)',
                'parto_cesarea' => 'Parto o cesarea',
                'problemas_embarazo' => 'Problemas durante embarazo o parto',
                'traumatismo' => 'Traumatismo durante embarazo o parto',
                'reanimacion' => 'Amerito maniobras de reanimacion',
                'incubadora' => 'Amerito estar en incubadora',
                'peso_medida_nino' => 'Peso y medida del nino',
                'tamiz_metabolico' => 'Tamiz metabolico (calificacion)',
                'apgar' => 'Puntaje APGAR (>=7 normal / <=6 atencion hospitalaria)',
            ];
        ?>
        <table class="ft-rh-table">
            <thead><tr><th style="width:35%;">Antecedente</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($peri as $k => $lbl): ?>
                <tr>
                    <td class="lbl"><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="peri_<?php echo $k; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="peri_<?php echo $k; ?>" value="NO"></td>
                    <td><input class="cell-input" name="peri_<?php echo $k; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </div>
    </div>

    <!-- ========================================================== -->
    <!-- 9. EXPLORACION FISICA - OBSERVACION                          -->
    <!-- ========================================================== -->
    <?php
        $facies = ['Normal','Dolorosa','Ansiosa','Palida','Cianotica','Rubicunda','Ictericia','Lupica','Hipertiroidea','Hipotiroidea','Otra'];
        $actitud = ['Neutra','Colaboradora','Pesimista','Agresiva','Otra'];
        $marcha = ['Libre','Claudicante','Con ayuda','Espastica','Ataxia','Otra'];
        $movilidad = ['Independiente','Dependiente','Silla de ruedas','Andadera','Muletas o baston','Otra'];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">9. EXPLORACION FISICA - OBSERVACION GENERAL</div>
        <div class="ft-rh-note">Inventario general y sistematico (corporal, emocional, personal, social) desde el primer contacto visual.</div>

        <div class="ft-rh-mini">Facies</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Tipo</th><th style="width:10%;">Seleccione</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($facies as $i => $f): ?>
                <tr>
                    <td><?php echo $f; ?></td>
                    <td class="cell-sn"><input type="radio" name="ef_facies" value="<?php echo $f; ?>"></td>
                    <td><input class="cell-input" name="ef_facies_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Actitud</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Tipo</th><th style="width:10%;">Seleccione</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($actitud as $i => $a): ?>
                <tr>
                    <td><?php echo $a; ?></td>
                    <td class="cell-sn"><input type="radio" name="ef_actitud" value="<?php echo $a; ?>"></td>
                    <td><input class="cell-input" name="ef_actitud_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Marcha / Deambulacion</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Tipo</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($marcha as $i => $m): ?>
                <tr>
                    <td><?php echo $m; ?></td>
                    <td class="cell-sn"><input type="radio" name="ef_marcha_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="ef_marcha_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="ef_marcha_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Movilidad y Traslados</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Tipo</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($movilidad as $i => $m): ?>
                <tr>
                    <td><?php echo $m; ?></td>
                    <td class="cell-sn"><input type="radio" name="ef_movilidad_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="ef_movilidad_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="ef_movilidad_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 10. ESCALA VISUAL ANALOGICA DEL DOLOR (EVA) + SEMIOLOGIA     -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">10. ESCALA VISUAL ANALOGICA DEL DOLOR (EVA) Y SEMIOLOGIA</div>

        <table class="ft-rh-table">
            <tr>
                <td class="lbl" style="width:20%;">Segmento evaluado</td>
                <td colspan="2"><input class="cell-input" name="eva_segmento" placeholder="Region anatomica afectada"></td>
                <td class="lbl" style="width:12%;">Resultado EVA</td>
                <td style="width:18%;">
                    <input type="hidden" name="eva_valor" id="eva_valor" value="0">
                    <span id="eva_lbl" style="font-weight:700; color:#b71c1c;">0 / 10</span>
                </td>
            </tr>
            <tr>
                <td colspan="5">
                    <div class="ft-rh-eva-wrap">
                        <?php for($i = 0; $i <= 10; $i++):
                            $lvl = 0;
                            if($i >= 1) $lvl = 1;
                            if($i >= 3) $lvl = 2;
                            if($i >= 5) $lvl = 3;
                            if($i >= 7) $lvl = 4;
                            if($i >= 9) $lvl = 5;
                        ?>
                            <div class="ft-rh-eva lvl-<?php echo $lvl; ?>" onclick="selEva(this, <?php echo $i; ?>)"><?php echo $i; ?></div>
                        <?php endfor; ?>
                    </div>
                </td>
            </tr>
        </table>

        <div class="ft-rh-mini">Semiologia del dolor</div>
        <?php
            $semio = ['circunstancias'=>'Circunstancias','tipo'=>'Tipo','antiguedad'=>'Antiguedad',
                'localizacion'=>'Localizacion','irradiacion'=>'Irradiacion','aumento'=>'Aumento',
                'atenuantes'=>'Atenuantes','duracion'=>'Duracion','avd'=>'AVD limitadas'];
        ?>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Dato</th><th>Especificar</th></tr></thead>
            <tbody>
            <?php foreach($semio as $k => $lbl): ?>
                <tr>
                    <td class="lbl"><?php echo $lbl; ?></td>
                    <td><input class="cell-input" name="sem_<?php echo $k; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 11. INSPECCION Y PALPACION POR SEGMENTOS                     -->
    <!-- ========================================================== -->
    <?php
        $craneo = ['Perimetro','Plano transversal','Plano longitudinal','Diametro','Borde occipital','Apofisis mastoides','Articulacion temporomandibular','Tuberosidad del masetero','Otro'];
        $cuello = ['Cartilago tiroides','Cartilago cricoides','Vallecula','Otro'];
        $piel   = ['Dolor','Pigmentacion','Puntos de presion','Temperatura','Tumoracion','Acumulacion de liquidos','Sensibilidad','Masas','Pulsaciones','Otro'];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">11. INSPECCION Y PALPACION POR SEGMENTOS</div>
        <div class="ft-rh-note">Evaluar el lado afectado y comparar con el lado contralateral.</div>

        <div class="ft-rh-mini">Craneo</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Parametro</th><th style="width:8%;">Normal</th><th style="width:8%;">Alterado</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($craneo as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="craneo_<?php echo $i; ?>" value="NORMAL"></td>
                    <td class="cell-sn"><input type="radio" name="craneo_<?php echo $i; ?>" value="ALTERADO"></td>
                    <td><input class="cell-input" name="craneo_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Cuello</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Parametro</th><th style="width:8%;">Normal</th><th style="width:8%;">Alterado</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($cuello as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="cuello_<?php echo $i; ?>" value="NORMAL"></td>
                    <td class="cell-sn"><input type="radio" name="cuello_<?php echo $i; ?>" value="ALTERADO"></td>
                    <td><input class="cell-input" name="cuello_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Piel</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Parametro</th><th style="width:8%;">Normal</th><th style="width:8%;">Alterado</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($piel as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="piel_<?php echo $i; ?>" value="NORMAL"></td>
                    <td class="cell-sn"><input type="radio" name="piel_<?php echo $i; ?>" value="ALTERADO"></td>
                    <td><input class="cell-input" name="piel_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <table class="ft-rh-table">
            <tr>
                <td class="lbl" style="width:20%;">Observaciones</td>
                <td><textarea rows="2" class="cell-input" name="obs_seg_inspeccion"></textarea></td>
            </tr>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 12. INSPECCION ESTATICA                                      -->
    <!-- ========================================================== -->
    <?php
        $insPiel = ['Coloracion','Humedad','Textura','Espesor','Temperatura','Elasticidad','Turgencia','Sensibilidad','Higiene'];
        $insLes  = ['Manchas','Papulas','Tumores','Ampollas','Vesiculas','Excoriaciones','Ulceras','Costras','Fisuras','Cicatrices','Atrofias','Estrias','Pliegues','Edema','Eritema','Abscesos','Otros'];
        $cabello = ['Cantidad','Distribucion','Implantacion','Color','Brillo','Consistencia'];
        $unas    = ['Forma','Coloracion','Brillo','Espesor','Lesiones'];
        $postura = ['Ideal','Cifolordotica','Espalda arqueada','Militar','Aplanada'];
        $biotipo = ['Ectomorfo','Mesomorfo','Endomorfo'];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">12. INSPECCION ESTATICA</div>
        <div class="ft-rh-note">Examen postural. Comparar con el lado contralateral.</div>

        <details class="ft-rh-acc" open><summary>Piel - Caracteristicas</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Caracteristica</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($insPiel as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="iep_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="iep_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="iep_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table></details>

        <details class="ft-rh-acc" open><summary>Lesiones cutaneas</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Lesion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($insLes as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="iel_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="iel_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="iel_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table></details>

        <details class="ft-rh-acc" open><summary>Cabello</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Caracteristica</th><th style="width:10%;">Normal</th><th style="width:10%;">Irregular</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($cabello as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="iec_<?php echo $i; ?>" value="NORMAL"></td>
                    <td class="cell-sn"><input type="radio" name="iec_<?php echo $i; ?>" value="IRREGULAR"></td>
                    <td><input class="cell-input" name="iec_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table></details>

        <details class="ft-rh-acc" open><summary>Unas</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Caracteristica</th><th style="width:10%;">Normal</th><th style="width:10%;">Irregular</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($unas as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="ieu_<?php echo $i; ?>" value="NORMAL"></td>
                    <td class="cell-sn"><input type="radio" name="ieu_<?php echo $i; ?>" value="IRREGULAR"></td>
                    <td><input class="cell-input" name="ieu_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table></details>

        <div class="ft-rh-mini">Postura</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Tipo</th><th style="width:10%;">Seleccione</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($postura as $i => $p): ?>
                <tr>
                    <td><?php echo $p; ?></td>
                    <td class="cell-sn"><input type="radio" name="ie_postura" value="<?php echo $p; ?>"></td>
                    <td><input class="cell-input" name="ie_postura_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Biotipo</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:25%;">Tipo</th><th style="width:10%;">Seleccione</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($biotipo as $i => $b): ?>
                <tr>
                    <td><?php echo $b; ?></td>
                    <td class="cell-sn"><input type="radio" name="ie_biotipo" value="<?php echo $b; ?>"></td>
                    <td><input class="cell-input" name="ie_biotipo_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 13. VISTAS ANTERIOR / LATERAL / POSTERIOR                    -->
    <!-- ========================================================== -->
    <?php
        $vaAnt = [
            'craneo' => ['Craneo', ['Simetria','Tamano','Forma']],
            'ojos' => ['Ojos', ['Simetria','Tamano de pupila','Forma de pupila','Coloracion esclerotica','Movimientos']],
            'oidos' => ['Oidos', ['Simetria','Tamano','Forma','Coloracion']],
            'boca' => ['Boca', ['Simetria','Tamano','Forma','Coloracion','Movimientos']],
        ];
        $vaAntReg = ['Cabeza centrada','Inclinacion lateral de cabeza','Rotacion de cabeza','Claviculas simetricas','Hombros nivelados','Hombro derecho elevado','Hombro izquierdo elevado','Pectorales alineados','Tronco centrado','Inclinacion de tronco','Rotacion de tronco','Alineacion de manos y brazos','Dedos en garra','Dedos en martillo','Caderas niveladas','Cadera derecha elevada','Cadera izquierda elevada','Rotacion de cadera','Rodillas niveladas','Genu varum','Genu valgum','Rotulas niveladas','Rotulas en rotacion','Angulo Q normal','Angulo Q incrementado','Rotacion de tobillos','Inversion de tobillos','Eversion de tobillos','Alineacion de pies y dedos','Dedos en garra (pie)','Dedos en martillo (pie)','Hallux valgus'];
        $vaLatOidos = ['Tamano','Forma','Coloracion'];
        $vaLatReg = ['Inclinacion de cabeza','Rotacion de cabeza','Antepulsion de cabeza','Retropulsion de cabeza','Flexion de tronco','Extension de tronco','Rotacion de tronco','Antepulsion de hombros','Retropulsion de hombros','Pecho en tonel','Pectus carinatum','Cifosis dorsal normal','Hipercifosis de columna','Lordosis normal','Hiperlordosis de columna','Rectificacion de columna','Abdomen prominente','Inclinacion de cadera y pelvis','Trocanter mayor antepulsion','Trocanter mayor retropulsion','Rodillas normales','Hiperextension de rodillas','Flexion de rodillas','Pie plano','Pie cavo'];
        $vaPosReg = ['Cabeza centrada','Inclinacion lateral de cabeza','Rotacion de cabeza','Hombros nivelados','Hombro derecho elevado','Hombro izquierdo elevado','Escapulas alineadas','Escapulas aladas','Escoliosis','Espina bifida / meningocele','Tronco centrado','Inclinacion de tronco','Rotacion de tronco','Alineacion de manos y brazos','Dedos en garra','Dedos en martillo','Caderas niveladas','Cadera derecha elevada','Cadera izquierda elevada','Rotacion de cadera','Huecos popliteos nivelados','Genu varum','Genu valgum','Rotacion de tobillos','Inversion de tobillos','Eversion de tobillos','Pies alineados'];

        if (!function_exists('silueta_svg')) {
        function silueta_svg($etiqueta) {
            // SVG simple: silueta humana esquematica (cabeza + tronco + brazos + piernas).
            $svg = '<figure style="margin:0;"><svg width="90" height="180" viewBox="0 0 90 180" xmlns="http://www.w3.org/2000/svg">';
            $svg .= '<circle cx="45" cy="18" r="12" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '<rect x="30" y="32" width="30" height="55" rx="6" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '<rect x="14" y="34" width="14" height="48" rx="4" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '<rect x="62" y="34" width="14" height="48" rx="4" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '<rect x="30" y="87" width="13" height="70" rx="4" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '<rect x="47" y="87" width="13" height="70" rx="4" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '<rect x="27" y="157" width="17" height="8" rx="2" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '<rect x="46" y="157" width="17" height="8" rx="2" fill="#eceff1" stroke="#546e7a" stroke-width="1.2"/>';
            $svg .= '</svg><figcaption>' . $etiqueta . '</figcaption></figure>';
            return $svg;
        }
        }
    ?>
    <div class="msp-section">
        <div class="msp-section-title">13. INSPECCION ESTATICA - VISTAS ANTERIOR, LATERAL Y POSTERIOR</div>

        <div class="ft-rh-silh" style="margin-bottom:8px;">
            <?php echo silueta_svg('Vista anterior'); ?>
            <?php echo silueta_svg('Vista lateral'); ?>
            <?php echo silueta_svg('Vista posterior'); ?>
        </div>
        <div class="ft-rh-note">Las siluetas son ilustrativas. Use las tablas siguientes para registrar los hallazgos.</div>

        <details class="ft-rh-acc" open><summary>Vista anterior - Segmentos craneofaciales</summary>
        <?php foreach($vaAnt as $k => $seg): ?>
            <div class="ft-rh-mini"><?php echo $seg[0]; ?></div>
            <table class="ft-rh-table">
                <thead><tr><th style="width:30%;">Parametro</th><th style="width:8%;">Normal</th><th style="width:8%;">Alterado</th><th>Especifique</th></tr></thead>
                <tbody>
                <?php foreach($seg[1] as $i => $lbl): ?>
                    <tr>
                        <td><?php echo $lbl; ?></td>
                        <td class="cell-sn"><input type="radio" name="vant_<?php echo $k.'_'.$i; ?>" value="NORMAL"></td>
                        <td class="cell-sn"><input type="radio" name="vant_<?php echo $k.'_'.$i; ?>" value="ALTERADO"></td>
                        <td><input class="cell-input" name="vant_<?php echo $k.'_'.$i; ?>_esp"></td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        <?php endforeach; ?>
        </details>

        <details class="ft-rh-acc" open><summary>Vista anterior - Regiones corporales</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:45%;">Region</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Observaciones</th></tr></thead>
            <tbody>
            <?php foreach($vaAntReg as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="vantreg_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="vantreg_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="vantreg_obs_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>

        <details class="ft-rh-acc" open><summary>Vista lateral - Oidos</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Parametro</th><th style="width:8%;">Normal</th><th style="width:8%;">Alterado</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($vaLatOidos as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="vlat_oidos_<?php echo $i; ?>" value="NORMAL"></td>
                    <td class="cell-sn"><input type="radio" name="vlat_oidos_<?php echo $i; ?>" value="ALTERADO"></td>
                    <td><input class="cell-input" name="vlat_oidos_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>

        <details class="ft-rh-acc" open><summary>Vista lateral - Regiones</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:45%;">Region</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Observaciones</th></tr></thead>
            <tbody>
            <?php foreach($vaLatReg as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="vlatreg_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="vlatreg_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="vlatreg_obs_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>

        <details class="ft-rh-acc" open><summary>Vista posterior - Regiones</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:45%;">Region</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Observaciones</th></tr></thead>
            <tbody>
            <?php foreach($vaPosReg as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="vposreg_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="vposreg_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="vposreg_obs_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>
    </div>

    <!-- ========================================================== -->
    <!-- 14. INSPECCION DINAMICA - ANALISIS DE LA MARCHA              -->
    <!-- ========================================================== -->
    <?php
        $faseApoyo = ['Contacto inicial','Respuesta a la carga','Apoyo medio (fase inicial)','Apoyo medio','Apoyo medio (fase final)'];
        $faseBal   = ['Apoyo final','Pre-balanceo','Balanceo inicial','Balanceo medio','Balanceo final'];
        $marchaCar = [
            'inicio' => ['Inicio de la marcha', ['Duda o multiples intentos para comenzar','Vacilante']],
            'continuidad' => ['Continuidad de los pasos', ['Para o discontinuidad','Pasos continuos']],
            'trayectoria' => ['Trayectoria', ['Balanceo marcado o usa ayudas','Sin balanceo pero con flexion de rodillas y espalda','Sin balanceo, flexion, ni ayudas']],
            'cg' => ['Desplazamiento del centro de gravedad', ['Anormal','Normal']],
        ];
        $adapt = ['Cabeza','Hombros','Brazos','Columna','Cadera y pelvis','Rodillas','Tobillos y pies'];
        $coord = ['Prueba dedo-nariz-dedo','Prueba indice-nariz','Prueba talon-rodilla','Movimientos alternantes rapidos','Prueba de Miller-Fisher','Prueba de Romberg'];
        $tipoMarcha = ['Cerebelosa','Ataxia sensorial','Espastica','Parkinsoniana','Estepaje','Vestibular','Miopatica'];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">14. INSPECCION DINAMICA - ANALISIS DE LA MARCHA</div>

        <div class="ft-rh-mini">Analisis cualitativo - Fase de apoyo</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:6%;">#</th><th style="width:40%;">Estadio</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($faseApoyo as $i => $lbl): ?>
                <tr>
                    <td class="cell-sn"><?php echo $i+1; ?></td>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="apoyo_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="apoyo_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="apoyo_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Analisis cualitativo - Fase de balanceo</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:6%;">#</th><th style="width:40%;">Estadio</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($faseBal as $i => $lbl): ?>
                <tr>
                    <td class="cell-sn"><?php echo $i+6; ?></td>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="balanc_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="balanc_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="balanc_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Caracteristicas</div>
        <?php foreach($marchaCar as $k => $row): ?>
            <table class="ft-rh-table">
                <thead><tr><th colspan="5" class="sub" style="text-align:left;"><?php echo $row[0]; ?></th></tr>
                <tr><th style="width:50%;">Descriptor</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
                <tbody>
                <?php foreach($row[1] as $i => $lbl): ?>
                    <tr>
                        <td><?php echo $lbl; ?></td>
                        <td class="cell-sn"><input type="radio" name="mar_<?php echo $k.'_'.$i; ?>" value="SI"></td>
                        <td class="cell-sn"><input type="radio" name="mar_<?php echo $k.'_'.$i; ?>" value="NO"></td>
                        <td><input class="cell-input" name="mar_<?php echo $k.'_'.$i; ?>_esp"></td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        <?php endforeach; ?>

        <div class="ft-rh-mini">Analisis cuantitativo de la marcha (valores referenciales)</div>
        <table class="ft-rh-table">
            <thead>
                <tr>
                    <th rowspan="2" style="width:25%;">Dato</th>
                    <th colspan="2">Valores normales</th>
                    <th colspan="2">Paciente</th>
                </tr>
                <tr><th>Hombres</th><th>Mujeres</th><th>Derecha</th><th>Izquierda</th></tr>
            </thead>
            <tbody>
                <tr><td>Longitud del paso</td><td>79 cm</td><td>66 cm</td><td><input class="cell-input" name="cuant_paso_d"></td><td><input class="cell-input" name="cuant_paso_i"></td></tr>
                <tr><td>Longitud de zancada</td><td>158 cm</td><td>132 cm</td><td><input class="cell-input" name="cuant_zancada_d"></td><td><input class="cell-input" name="cuant_zancada_i"></td></tr>
                <tr><td>Anchura de paso</td><td>8.1 cm</td><td>7.1 cm</td><td><input class="cell-input" name="cuant_anchura_d"></td><td><input class="cell-input" name="cuant_anchura_i"></td></tr>
                <tr><td>Pasos por minuto</td><td>117</td><td>117</td><td><input class="cell-input" name="cuant_ppm_d"></td><td><input class="cell-input" name="cuant_ppm_i"></td></tr>
                <tr><td>Angulo del pie</td><td>7-10&deg;</td><td>6&deg;</td><td><input class="cell-input" name="cuant_ang_d"></td><td><input class="cell-input" name="cuant_ang_i"></td></tr>
                <tr><td>Velocidad</td><td>1.54 m/s</td><td>1.31 m/s</td><td><input class="cell-input" name="cuant_vel_d"></td><td><input class="cell-input" name="cuant_vel_i"></td></tr>
            </tbody>
        </table>

        <div class="ft-rh-mini">Adaptaciones durante la marcha</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Region</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($adapt as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="adap_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="adap_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="adap_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Evaluacion de la coordinacion</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:40%;">Prueba</th><th>Resultado</th></tr></thead>
            <tbody>
            <?php foreach($coord as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td><input class="cell-input" name="coord_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Tipo de marcha</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Tipo</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especifique</th></tr></thead>
            <tbody>
            <?php foreach($tipoMarcha as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="tmar_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="tmar_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="tmar_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 15. EXPLORACION ARTICULAR - GONIOMETRIA                      -->
    <!-- ========================================================== -->
    <?php
        $artSup = [
            'raquis_cervical' => ['Raquis cervical', [
                ['Flexion','0-35/45'],['Extension','0-35/45'],
                ['Inclinacion lateral derecha','0-45'],['Inclinacion lateral izquierda','0-45'],
                ['Rotacion izquierda','0-60/80'],['Rotacion derecha','0-60/80'],
            ]],
            'raquis_dorsolumbar' => ['Raquis dorsolumbar', [
                ['Flexion','0-80'],['Extension','0-30'],
                ['Inclinacion lateral izquierda','0-30/35'],['Inclinacion lateral derecha','0-30/35'],
                ['Rotacion izquierda','0-30/45'],['Rotacion derecha','0-30/45'],
            ]],
            'hombro' => ['Hombro', [
                ['Flexion','0-150/170'],['Extension','0-40/60'],
                ['Abduccion','0-160/180'],['Aduccion','0-30'],
                ['Rotacion interna','0-70'],['Rotacion externa','0-70/90'],
            ]],
            'codo' => ['Codo', [
                ['Flexion','0-150'],['Extension','0'],
                ['Pronacion','0-80/90'],['Supinacion','0-60/80'],
            ]],
            'muneca' => ['Muneca', [
                ['Flexion','0-50/80'],['Extension','0-35/70'],
                ['Desviacion radial','0-20/30'],['Desviacion cubital','0-60/40'],
            ]],
            'pulgar' => ['Pulgar', [
                ['Abduccion CMC','0-70'],['Aduccion CMC','0'],
                ['Oposicion CMC','>8 cm'],['Flexion MCF','0-50'],
                ['Extension MCF','0'],['Flexion IF','0-80'],['Extension IF','0-20'],
            ]],
            'dedos_mano' => ['Dedos de la mano', [
                ['Flexion MCF','0-90'],['Extension MCF','0-45'],
                ['Flexion IFP','0-100'],['Extension IFP','0'],
                ['Flexion IFD','0-90'],['Extension IFD','0'],
            ]],
        ];
        $artInf = [
            'cadera' => ['Cadera', [
                ['Flexion','0-120/140'],['Extension','0-10/30'],
                ['Abduccion','0-45/50'],['Aduccion','0-30'],
                ['Rotacion interna','0-40/45'],['Rotacion externa','0-45/50'],
            ]],
            'rodilla' => ['Rodilla', [
                ['Flexion','0-135/150'],['Extension','0/10 pasiva'],
            ]],
            'tobillo' => ['Tobillo', [
                ['Flexion plantar','0-50'],['Flexion dorsal','0-20/30'],
            ]],
            'subastragalina' => ['Articulacion subastragalina', [
                ['Inversion','0-50'],['Eversion','0-20/30'],
            ]],
            'hallux' => ['Hallux', [
                ['Flexion MTTF','0-45'],['Extension MTTF','0-70'],
                ['Flexion IF','0-80/90'],['Extension IF','0'],
            ]],
            'dedos_pie' => ['Dedos de los pies', [
                ['Flexion MTTF','0-40'],['Extension MTTF','0-40'],
                ['Flexion IFP','0-35'],['Extension IFP','0'],
                ['Flexion IFD','0-60'],['Extension IFD','0-30'],
            ]],
        ];

        if (!function_exists('tabla_rom')) {
        function tabla_rom($prefix, $articulaciones) {
            $html = '';
            foreach($articulaciones as $k => $art) {
                $html .= '<div class="ft-rh-mini">' . $art[0] . '</div>';
                $html .= '<table class="ft-rh-table"><thead>';
                $html .= '<tr><th rowspan="2" style="width:30%;">Movimiento</th>';
                $html .= '<th colspan="2">Izquierda</th><th rowspan="2">Rangos normales</th>';
                $html .= '<th colspan="2">Derecha</th></tr>';
                $html .= '<tr><th>Inicial</th><th>Final</th><th>Inicial</th><th>Final</th></tr></thead><tbody>';
                foreach($art[1] as $i => $mov) {
                    $name = $prefix . '_' . $k . '_' . $i;
                    $html .= '<tr><td>' . $mov[0] . '</td>';
                    $html .= '<td><input class="cell-input" name="' . $name . '_ii"></td>';
                    $html .= '<td><input class="cell-input" name="' . $name . '_if"></td>';
                    $html .= '<td style="text-align:center; background:#f5f7fa;">' . $mov[1] . '&deg;</td>';
                    $html .= '<td><input class="cell-input" name="' . $name . '_di"></td>';
                    $html .= '<td><input class="cell-input" name="' . $name . '_df"></td></tr>';
                }
                $html .= '</tbody></table>';
            }
            return $html;
        }
        }
    ?>
    <div class="msp-section">
        <div class="msp-section-title">15. EXPLORACION ARTICULAR - EXTREMIDAD SUPERIOR</div>
        <div class="ft-rh-note">Evalue primero el lado sano (no afectado) y compare con el contralateral.</div>

        <details class="ft-rh-acc" open><summary>Sistema oseo - Inspeccion y palpacion (MM.SS.)</summary>
        <?php
            $oseoInsp = ['Simetria osea','Deformidades','Tumefaccion','Edema en partes blandas'];
            $oseoPalp = ['Dolor','Disminucion del volumen','Depresiones oseas','Crepitacion','Derrame (intra o extra articular)','Sensacion final (End Feel)'];
        ?>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Inspeccion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($oseoInsp as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="ossup_insp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="ossup_insp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="ossup_insp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Palpacion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($oseoPalp as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="ossup_palp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="ossup_palp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="ossup_palp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>

        <?php echo tabla_rom('rom_sup', $artSup); ?>
    </div>

    <div class="msp-section">
        <div class="msp-section-title">16. EXPLORACION ARTICULAR - EXTREMIDAD INFERIOR</div>

        <details class="ft-rh-acc" open><summary>Sistema oseo - Inspeccion y palpacion (MM.II.)</summary>
        <?php $oseoPalpInf = ['Puntos dolorosos','Disminucion del volumen','Depresiones oseas','Crepitacion','Derrame (intra o extra articular)','Sensacion final (End Feel)']; ?>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Inspeccion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($oseoInsp as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="osinf_insp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="osinf_insp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="osinf_insp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Palpacion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($oseoPalpInf as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="osinf_palp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="osinf_palp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="osinf_palp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>

        <?php echo tabla_rom('rom_inf', $artInf); ?>
    </div>

    <!-- ========================================================== -->
    <!-- 17. EVALUACION MUSCULAR - DANIELS                            -->
    <!-- ========================================================== -->
    <?php
        $musSup = [
            'cuello' => ['Cuello', ['Extension cervical','Flexion cervical','Rotacion cervical']],
            'tronco' => ['Tronco', ['Extension lumbar','Extension toracica','Elevacion pelvica','Flexion','Rotacion']],
            'hombro' => ['Hombro', ['Flexion','Extension','Abduccion','Aduccion','Rotacion externa','Rotacion interna']],
            'codo' => ['Codo', ['Flexion','Extension','Pronacion','Supinacion']],
            'muneca' => ['Muneca', ['Flexion','Extension','Desviacion radial','Desviacion cubital']],
            'dedos' => ['Dedos de la mano', ['Flexion MCF','Flexion IFP','Flexion IFD','Extension MCF','Abduccion de dedo','Aduccion de dedo','Flexion MCF pulgar','Flexion IF pulgar','Extension MCF pulgar','Extension IF pulgar','Abduccion CMC pulgar']],
        ];
        $musInf = [
            'cadera' => ['Cadera', ['Flexion','Extension','Extension (asistida)','Abduccion','Abduccion y flexion','Aduccion','Rotacion externa','Rotacion interna']],
            'rodilla' => ['Rodilla', ['Flexion','Extension']],
            'tobillo' => ['Tobillo', ['Flexion plantar','Flexion plantar (soleo)','Flexion dorsal e inversion','Inversion','Eversion con flexion plantar','Eversion con flexion dorsal']],
            'dedos_pie' => ['Dedos de los pies', ['Flexion MTTF dedo gordo','Flexion MTTF dedos','Flexion IF dedo gordo','Flexion IF dedos','Extension MTTF dedo gordo','Extension MTTF dedos','Extension IF dedo gordo','Extension IF dedos']],
        ];

        if (!function_exists('tabla_daniels')) {
        function tabla_daniels($prefix, $grupos) {
            $html = '';
            foreach($grupos as $k => $g) {
                $html .= '<div class="ft-rh-mini">' . $g[0] . '</div>';
                $html .= '<table class="ft-rh-table"><thead>';
                $html .= '<tr><th rowspan="2" style="width:35%;">Movimiento</th>';
                $html .= '<th colspan="2">Inicial</th><th colspan="2">Final</th></tr>';
                $html .= '<tr><th>D</th><th>I</th><th>D</th><th>I</th></tr></thead><tbody>';
                foreach($g[1] as $i => $mov) {
                    $name = $prefix . '_' . $k . '_' . $i;
                    $opts = '<option value="">-</option><option value="5">5</option><option value="4">4</option><option value="3">3</option><option value="2">2</option><option value="1">1</option><option value="0">0</option>';
                    $html .= '<tr><td>' . $mov . '</td>';
                    $html .= '<td><select class="cell-input" name="' . $name . '_id">' . $opts . '</select></td>';
                    $html .= '<td><select class="cell-input" name="' . $name . '_ii">' . $opts . '</select></td>';
                    $html .= '<td><select class="cell-input" name="' . $name . '_fd">' . $opts . '</select></td>';
                    $html .= '<td><select class="cell-input" name="' . $name . '_fi">' . $opts . '</select></td></tr>';
                }
                $html .= '</tbody></table>';
            }
            return $html;
        }
        }
    ?>
    <div class="msp-section">
        <div class="msp-section-title">17. EVALUACION MUSCULAR (DANIELS) - EXTREMIDAD SUPERIOR</div>
        <div class="ft-rh-note">Escala de Daniels 0-5. D = Derecha, I = Izquierda.</div>
        <details class="ft-rh-acc" open><summary>Sistema muscular - Inspeccion y palpacion (MM.SS.)</summary>
        <?php
            $musInspSup = ['Volumen','Atrofia o hipertrofia','Tumoraciones','Tono muscular','Movilidad activa'];
            $musPalpSup = ['Puntos dolorosos','Consistencia','Espasmos','Contracturas'];
        ?>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Inspeccion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($musInspSup as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="mus_sup_insp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="mus_sup_insp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="mus_sup_insp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Palpacion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($musPalpSup as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="mus_sup_palp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="mus_sup_palp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="mus_sup_palp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>

        <?php echo tabla_daniels('dan_sup', $musSup); ?>
    </div>

    <div class="msp-section">
        <div class="msp-section-title">18. EVALUACION MUSCULAR (DANIELS) - EXTREMIDAD INFERIOR</div>
        <details class="ft-rh-acc" open><summary>Sistema muscular - Inspeccion y palpacion (MM.II.)</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Inspeccion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($musInspSup as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="mus_inf_insp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="mus_inf_insp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="mus_inf_insp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Palpacion</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($musPalpSup as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="mus_inf_palp_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="mus_inf_palp_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="mus_inf_palp_<?php echo $i; ?>_esp"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        </details>
        <?php echo tabla_daniels('dan_inf', $musInf); ?>

        <table class="ft-rh-table">
            <tr>
                <td class="lbl" style="width:20%;">Observaciones musculares</td>
                <td><textarea rows="2" class="cell-input" name="obs_musculares"></textarea></td>
            </tr>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 19. VALORACION NEUROLOGICA - GLASGOW Y MINI-MENTAL           -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">19. VALORACION NEUROLOGICA - FUNCIONES SUPERIORES</div>

        <div class="ft-rh-mini">Escala de Glasgow</div>
        <table class="ft-rh-table ft-rh-glasgow">
            <thead><tr><th colspan="3">Respuesta ocular</th><th colspan="3">Respuesta verbal</th><th colspan="3">Respuesta motora</th></tr></thead>
            <tbody>
                <tr>
                    <td>Espontanea</td><td>4</td><td><input type="radio" name="gl_ocular" value="4"></td>
                    <td>Orientado</td><td>5</td><td><input type="radio" name="gl_verbal" value="5"></td>
                    <td>Obedece ordenes</td><td>6</td><td><input type="radio" name="gl_motora" value="6"></td>
                </tr>
                <tr>
                    <td>A estimulos verbales</td><td>3</td><td><input type="radio" name="gl_ocular" value="3"></td>
                    <td>Desorientado / confuso</td><td>4</td><td><input type="radio" name="gl_verbal" value="4"></td>
                    <td>Localiza el dolor</td><td>5</td><td><input type="radio" name="gl_motora" value="5"></td>
                </tr>
                <tr>
                    <td>Al dolor</td><td>2</td><td><input type="radio" name="gl_ocular" value="2"></td>
                    <td>Incoherente</td><td>3</td><td><input type="radio" name="gl_verbal" value="3"></td>
                    <td>Retirada al dolor</td><td>4</td><td><input type="radio" name="gl_motora" value="4"></td>
                </tr>
                <tr>
                    <td>Ausencia</td><td>1</td><td><input type="radio" name="gl_ocular" value="1"></td>
                    <td>Sonidos incomprensibles</td><td>2</td><td><input type="radio" name="gl_verbal" value="2"></td>
                    <td>Flexion anormal</td><td>3</td><td><input type="radio" name="gl_motora" value="3"></td>
                </tr>
                <tr>
                    <td colspan="3"></td>
                    <td>Ausencia</td><td>1</td><td><input type="radio" name="gl_verbal" value="1"></td>
                    <td>Extension anormal</td><td>2</td><td><input type="radio" name="gl_motora" value="2"></td>
                </tr>
                <tr>
                    <td colspan="6"></td>
                    <td>Ausencia</td><td>1</td><td><input type="radio" name="gl_motora" value="1"></td>
                </tr>
                <tr>
                    <td colspan="6" class="gtot">TOTAL GLASGOW (3-15)</td>
                    <td colspan="3" class="gtot"><input id="gl_total" name="gl_total" class="cell-input" readonly style="text-align:center; font-size:13pt; background:#e0f2f1;"></td>
                </tr>
            </tbody>
        </table>
        <div class="ft-rh-note">13-15 TCE leve | 9-12 TCE moderado | 3-8 TCE grave</div>

        <div class="ft-rh-mini">Mini-examen del estado mental</div>
        <table class="ft-rh-table">
            <tr>
                <td class="lbl" style="width:30%;">Puntaje obtenido (0-30)</td>
                <td><input type="text" class="cell-input" name="minimental_pts" min="0" max="30"></td>
                <td class="lbl" style="width:30%;">Interpretacion</td>
                <td>
                    <select class="cell-input" name="minimental_interp">
                        <option value="">Seleccione</option>
                        <option>27-30 Sin deterioro</option>
                        <option>25-26 Dudoso o posible deterioro</option>
                        <option>10-24 Demencia leve a moderada</option>
                        <option>6-9 Demencia moderada a severa</option>
                        <option>&lt;6 Demencia severa</option>
                    </select>
                </td>
            </tr>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 20. PARES CRANEALES                                          -->
    <!-- ========================================================== -->
    <?php
        $pares = ['I. Olfatorio','II. Optico','III. Oculomotor','IV. Patetico (Troclear)','V. Trigemino','VI. Abducens','VII. Facial','VIII. Acustico-vestibular','IX. Glosofaringeo','X. Neumogastrico (Vago)','XI. Espinal','XII. Hipogloso'];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">20. EXPLORACION DE PARES CRANEALES</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Par craneal</th><th style="width:8%;">Normal</th><th style="width:8%;">Alterado</th><th>Observaciones</th></tr></thead>
            <tbody>
            <?php foreach($pares as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="par_<?php echo $i; ?>" value="NORMAL"></td>
                    <td class="cell-sn"><input type="radio" name="par_<?php echo $i; ?>" value="ALTERADO"></td>
                    <td><input class="cell-input" name="par_obs_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 21. TONO MUSCULAR (ASHWORTH / CAMPBELL / RIGIDEZ)            -->
    <!-- ========================================================== -->
    <?php
        $caracTono = ['Temblor en reposo','Temblor en movimiento','Distonia','Otros movimientos anormales'];
        $topog = ['Monoplejia','Monoparesia','Hemiplejia','Hemiparesia','Paraplejia','Paraparesia','Diplejia','Diparesia','Cuadriplejia','Cuadriparesia'];
        $tono = ['Normal','Hipertonia','Hipotonia'];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">21. TONO MUSCULAR</div>

        <table class="ft-rh-table">
            <tr>
                <td class="lbl" style="width:25%;">Ashworth modificada (hipertonia)</td>
                <td>
                    <select class="cell-input" name="ashworth">
                        <option value="">Seleccione grado</option>
                        <option>0 - Sin aumento del tono</option>
                        <option>1 - Discreto, resistencia minima</option>
                        <option>1+ - Discreto, resistencia en todo el mov.</option>
                        <option>2 - Disminucion ROM 50%-100%</option>
                        <option>3 - ROM limitada <50%</option>
                        <option>4 - Limitacion severa</option>
                    </select>
                </td>
                <td class="lbl" style="width:25%;">Campbell (hipotonia)</td>
                <td>
                    <select class="cell-input" name="campbell">
                        <option value="">Seleccione grado</option>
                        <option>-3 Hipotonia severa</option>
                        <option>-2 Hipotonia moderada</option>
                        <option>-1 Hipotonia leve</option>
                        <option>0 Normal</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="lbl">Rigidez (0-4)</td>
                <td>
                    <select class="cell-input" name="rigidez">
                        <option value="">Seleccione</option>
                        <option>0 - Sin rigidez</option>
                        <option>1 - Leve o apenas detectable</option>
                        <option>2 - Leve a moderada</option>
                        <option>3 - Pronunciada con mov. completo</option>
                        <option>4 - Intensa, mov. incompleto o nulo</option>
                    </select>
                </td>
                <td class="lbl">Tono predominante</td>
                <td>
                    <select class="cell-input" name="tono_predom">
                        <option value="">Seleccione</option>
                        <?php foreach($tono as $t): ?><option><?php echo $t; ?></option><?php endforeach; ?>
                    </select>
                </td>
            </tr>
        </table>

        <div class="ft-rh-mini">Caracteristicas - Movimientos anormales</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:35%;">Caracteristica</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($caracTono as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="ctono_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="ctono_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="ctono_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>

        <div class="ft-rh-mini">Topografia</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:35%;">Topografia</th><th style="width:6%;">Si</th><th style="width:6%;">No</th><th>Especificaciones</th></tr></thead>
            <tbody>
            <?php foreach($topog as $i => $lbl): ?>
                <tr>
                    <td><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="topo_<?php echo $i; ?>" value="SI"></td>
                    <td class="cell-sn"><input type="radio" name="topo_<?php echo $i; ?>" value="NO"></td>
                    <td><input class="cell-input" name="topo_esp_<?php echo $i; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 22. REFLEJOS OSTEOTENDINOSOS (SEIDEL)                        -->
    <!-- ========================================================== -->
    <?php
        $reflejos = ['Maseterino','Bicipital','Tricipital','Estilorradial','Cutaneo abdominal','Rotuliano','Aquiliano','Plantar'];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">22. REFLEJOS OSTEOTENDINOSOS - ESCALA DE SEIDEL</div>
        <table class="ft-rh-table">
            <thead>
                <tr>
                    <th style="width:24%;">Reflejo</th>
                    <th>Arreflexia (0)</th>
                    <th>Hiporreflexia (1)</th>
                    <th>Normal (2)</th>
                    <th>Hiperreflexia (3)</th>
                    <th>Clonus (4)</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($reflejos as $i => $lbl): ?>
                <tr>
                    <td class="lbl"><?php echo $lbl; ?></td>
                    <td class="cell-sn"><input type="radio" name="ref_<?php echo $i; ?>" value="0"></td>
                    <td class="cell-sn"><input type="radio" name="ref_<?php echo $i; ?>" value="1"></td>
                    <td class="cell-sn"><input type="radio" name="ref_<?php echo $i; ?>" value="2"></td>
                    <td class="cell-sn"><input type="radio" name="ref_<?php echo $i; ?>" value="3"></td>
                    <td class="cell-sn"><input type="radio" name="ref_<?php echo $i; ?>" value="4"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 23. ASIA - VALORACION SENSITIVA Y MOTORA                     -->
    <!-- ========================================================== -->
    <?php
        $dermatomas = ['C2','C3','C4','C5','C6','C7','C8','T1','T2','T3','T4','T5','T6','T7','T8','T9','T10','T11','T12','L1','L2','L3','L4','L5','S1','S2','S3','S4','S5'];
        $miotomas = [
            'C5' => 'Flexores de codo',
            'C6' => 'Extensores de muneca',
            'C7' => 'Extensores de codo',
            'C8' => 'Flexores de dedos de la mano',
            'T1' => 'Abductores del meñique',
            'L2' => 'Flexores de cadera',
            'L3' => 'Flexores de rodilla',
            'L4' => 'Dorsiflexores de tobillo',
            'L5' => 'Extensores del dedo gordo',
            'S1' => 'Plantiflexores de tobillo',
        ];
    ?>
    <div class="msp-section">
        <div class="msp-section-title">23. VALORACION NEUROLOGICA SENSITIVA Y MOTORA (ASIA)</div>
        <div class="ft-rh-note">Escala sensitiva: 0 sin sensibilidad / 1 deterioro o reducida / 2 normal o conservada. Escala motora: 0-5 (0 paralisis, 5 contra resistencia total, NT no examinable).</div>

        <details class="ft-rh-acc" open><summary>Valoracion sensitiva por dermatoma (C2 - S5)</summary>
        <table class="ft-rh-table">
            <thead>
                <tr>
                    <th rowspan="2" style="width:14%;">Dermatoma</th>
                    <th colspan="2">Tacto fino</th>
                    <th colspan="2">Pinchazo</th>
                </tr>
                <tr><th>Izquierda (TFI)</th><th>Derecha (TFD)</th><th>Izquierda (PPI)</th><th>Derecha (PPD)</th></tr>
            </thead>
            <tbody>
            <?php foreach($dermatomas as $d):
                $opts = '<option value="">-</option><option value="2">2</option><option value="1">1</option><option value="0">0</option><option value="NT">NT</option>';
            ?>
                <tr>
                    <td class="lbl"><?php echo $d; ?></td>
                    <td><select class="cell-input" name="asia_s_<?php echo $d; ?>_tfi"><?php echo $opts; ?></select></td>
                    <td><select class="cell-input" name="asia_s_<?php echo $d; ?>_tfd"><?php echo $opts; ?></select></td>
                    <td><select class="cell-input" name="asia_s_<?php echo $d; ?>_ppi"><?php echo $opts; ?></select></td>
                    <td><select class="cell-input" name="asia_s_<?php echo $d; ?>_ppd"><?php echo $opts; ?></select></td>
                </tr>
            <?php endforeach; ?>
                <tr>
                    <td class="lbl">TOTAL</td>
                    <td colspan="2"><input class="cell-input" name="asia_s_total_tf" placeholder="Tacto fino total"></td>
                    <td colspan="2"><input class="cell-input" name="asia_s_total_pp" placeholder="Pinchazo total"></td>
                </tr>
            </tbody>
        </table>
        </details>

        <details class="ft-rh-acc" open><summary>Valoracion motora por miotoma</summary>
        <table class="ft-rh-table">
            <thead><tr><th style="width:10%;">Miotoma</th><th style="width:45%;">Musculos</th><th>Izquierda</th><th>Derecha</th></tr></thead>
            <tbody>
            <?php foreach($miotomas as $k => $musculo):
                $opts = '<option value="">-</option><option value="5">5</option><option value="4">4</option><option value="3">3</option><option value="2">2</option><option value="1">1</option><option value="0">0</option><option value="NT">NT</option>';
            ?>
                <tr>
                    <td class="lbl"><?php echo $k; ?></td>
                    <td><?php echo $musculo; ?></td>
                    <td><select class="cell-input" name="asia_m_<?php echo $k; ?>_i"><?php echo $opts; ?></select></td>
                    <td><select class="cell-input" name="asia_m_<?php echo $k; ?>_d"><?php echo $opts; ?></select></td>
                </tr>
            <?php endforeach; ?>
                <tr>
                    <td class="lbl" colspan="2">TOTAL</td>
                    <td><input class="cell-input" name="asia_m_total_i" placeholder="Izq total"></td>
                    <td><input class="cell-input" name="asia_m_total_d" placeholder="Der total"></td>
                </tr>
            </tbody>
        </table>
        </details>

        <div class="ft-rh-mini">Escala de deficiencia ASIA y Niveles neurologicos</div>
        <table class="ft-rh-table">
            <tr>
                <td class="lbl" style="width:25%;">Escala de deficiencia ASIA</td>
                <td colspan="3">
                    <select class="cell-input" name="asia_grado">
                        <option value="">Seleccione</option>
                        <option>A - Lesion completa</option>
                        <option>B - Preservacion sensitiva escasa</option>
                        <option>C - Preservacion motora no funcional</option>
                        <option>D - Preservacion motora funcional</option>
                        <option>E - Normal, sin deficits</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="lbl">Nivel sensitivo</td>
                <td><input class="cell-input" name="nivel_sens_i" placeholder="Izquierda"></td>
                <td class="lbl">Derecha</td>
                <td><input class="cell-input" name="nivel_sens_d"></td>
            </tr>
            <tr>
                <td class="lbl">Nivel motor</td>
                <td><input class="cell-input" name="nivel_mot_i" placeholder="Izquierda"></td>
                <td class="lbl">Derecha</td>
                <td><input class="cell-input" name="nivel_mot_d"></td>
            </tr>
            <tr>
                <td class="lbl">Nivel neurologico de lesion (NNL)</td>
                <td colspan="3"><input class="cell-input" name="nnl"></td>
            </tr>
            <tr>
                <td class="lbl">Zona de preservacion parcial (ZPP)</td>
                <td><input class="cell-input" name="zpp_sens_i" placeholder="Sens. Izq"></td>
                <td><input class="cell-input" name="zpp_sens_d" placeholder="Sens. Der"></td>
                <td>
                    <input class="cell-input" name="zpp_mot_i" placeholder="Mot. Izq"
                           style="display:inline-block; width:48%;">
                    <input class="cell-input" name="zpp_mot_d" placeholder="Mot. Der"
                           style="display:inline-block; width:48%;">
                </td>
            </tr>
            <tr>
                <td class="lbl">Lesion completa o incompleta</td>
                <td colspan="3">
                    <label><input type="radio" name="lesion_tipo" value="COMPLETA"> Completa</label> &nbsp;
                    <label><input type="radio" name="lesion_tipo" value="INCOMPLETA"> Incompleta</label>
                </td>
            </tr>
            <tr>
                <td class="lbl">Observaciones</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="asia_obs"></textarea></td>
            </tr>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 24. MANIOBRAS / TEST EXPLORATORIOS                           -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">24. MANIOBRAS, ESCALAS O TEST EXPLORATORIOS</div>
        <table class="ft-rh-table" id="tbl_maniobras">
            <thead><tr><th style="width:25%;">Nombre</th><th style="width:30%;">Que evalua</th><th>Resultado y observaciones</th><th style="width:6%;">&nbsp;</th></tr></thead>
            <tbody>
                <?php for($i = 0; $i < 5; $i++): ?>
                <tr>
                    <td><input class="cell-input" name="man_nombre_<?php echo $i; ?>"></td>
                    <td><input class="cell-input" name="man_evalua_<?php echo $i; ?>"></td>
                    <td><input class="cell-input" name="man_resultado_<?php echo $i; ?>"></td>
                    <td class="cell-sn"><button type="button" class="btn btn-default btn-xs" onclick="$(this).closest('tr').find('input').val('');">Limpiar</button></td>
                </tr>
                <?php endfor; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 25. ESTUDIOS DE IMAGEN / EXAMENES COMPLEMENTARIOS            -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">25. ESTUDIO DE IMAGEN Y EXAMENES COMPLEMENTARIOS</div>
        <table class="ft-rh-table">
            <thead><tr><th style="width:30%;">Tipo de examen</th><th style="width:25%;">Proyeccion</th><th>Resultado y observaciones</th></tr></thead>
            <tbody>
                <?php for($i = 0; $i < 5; $i++): ?>
                <tr>
                    <td><input class="cell-input" name="img_tipo_<?php echo $i; ?>"></td>
                    <td><input class="cell-input" name="img_proy_<?php echo $i; ?>"></td>
                    <td><input class="cell-input" name="img_res_<?php echo $i; ?>"></td>
                </tr>
                <?php endfor; ?>
            </tbody>
        </table>
    </div>

    <!-- ========================================================== -->
    <!-- 26. PLAN ANALITICO DE ATENCION EN REHABILITACION             -->
    <!-- ========================================================== -->
    <div class="msp-section">
        <div class="msp-section-title">26. PLAN ANALITICO DE ATENCION EN REHABILITACION</div>
        <table class="ft-rh-table">
            <tr>
                <td class="lbl" style="width:25%;">Padecimiento actual</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="plan_padecimiento"></textarea></td>
            </tr>
            <tr>
                <td class="lbl">Diagnostico basado en la CIF</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="plan_dx_cif"></textarea></td>
            </tr>
            <tr>
                <td class="lbl">Pronostico de la enfermedad</td>
                <td colspan="3"><textarea rows="2" class="cell-input" name="plan_pronostico"></textarea></td>
            </tr>
            <tr>
                <td class="lbl">Objetivos generales</td>
                <td><textarea rows="3" class="cell-input" name="plan_obj_gen"></textarea></td>
                <td class="lbl">Objetivos especificos</td>
                <td><textarea rows="3" class="cell-input" name="plan_obj_esp"></textarea></td>
            </tr>
            <tr>
                <td class="lbl">Plan de atencion y tratamiento</td>
                <td colspan="3"><textarea rows="3" class="cell-input" name="plan_tratamiento"></textarea></td>
            </tr>
            <tr>
                <td class="lbl">Total de sesiones</td>
                <td><input type="text" class="cell-input" name="plan_total_sesiones"></td>
                <td class="lbl">Sesiones semanales</td>
                <td><input type="text" class="cell-input" name="plan_ses_semanales"></td>
            </tr>
            <tr>
                <td class="lbl">Duracion de cada sesion (min)</td>
                <td><input type="text" class="cell-input" name="plan_duracion_min"></td>
                <td class="lbl">Observaciones finales</td>
                <td><textarea rows="2" class="cell-input" name="plan_obs_finales"></textarea></td>
            </tr>
        </table>
    </div>

    </div><!-- /msp-container -->
</form>

<script>
    function selEva(el, val) {
        $(".ft-rh-eva").removeClass("active");
        $(el).addClass("active");
        $("#eva_valor").val(val);
        $("#eva_lbl").text(val + " / 10");
    }

    function calcImc() {
        var p = parseFloat($("#ft_peso").val());
        var t = parseFloat($("#ft_talla").val());
        if(p > 0 && t > 0) {
            var imc = p / (t * t);
            $("#ft_imc").val(imc.toFixed(2));
        } else {
            $("#ft_imc").val("");
        }
    }

    function calcGlasgow() {
        var o = parseInt($("input[name='gl_ocular']:checked").val()) || 0;
        var v = parseInt($("input[name='gl_verbal']:checked").val()) || 0;
        var m = parseInt($("input[name='gl_motora']:checked").val()) || 0;
        $("#gl_total").val(o + v + m || "");
    }

    $(document).ready(function() {
        $("input[name='gl_ocular'], input[name='gl_verbal'], input[name='gl_motora']").on('change', calcGlasgow);
        console.log("Modulo Fisioterapia y Rehabilitacion cargado.");
    });
</script>
