<?php
/**
 * VALORACION RAPIDA DE FISIOTERAPIA Y REHABILITACION
 * Version reducida de 8 secciones para consultas breves o seguimiento.
 * Tipo_formato: VALORACION_RAPIDA_FT
 * Para la historia clinica completa de rehabilitacion use el formato FISIOTERAPIA.
 */
?>
<style>
    .vr-container { font-family: 'Outfit', 'Segoe UI', sans-serif; color: #1e293b; background: #f1f5f9; padding: 20px; border-radius: 12px; }
    .vr-card { background: white; border-radius: 12px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); border: 1px solid #e2e8f0; margin-bottom: 25px; overflow: hidden; }
    .vr-header { background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%); color: white; padding: 15px 25px; display: flex; align-items: center; justify-content: space-between; }
    .vr-header h2 { margin: 0; font-size: 16px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
    .vr-section-title { background: #f8fafc; padding: 10px 20px; border-left: 4px solid #3b82f6; font-weight: 700; font-size: 13px; color: #1e3a8a; text-transform: uppercase; margin-bottom: 15px; display: flex; align-items: center; }
    .vr-section-title i { margin-right: 10px; font-size: 16px; }
    .vr-body { padding: 25px; }
    .vr-label { font-weight: 600; color: #475569; font-size: 11px; text-transform: uppercase; margin-bottom: 5px; display: block; }
    .vr-input { border-radius: 8px; border: 1px solid #cbd5e1; padding: 10px 14px; width: 100%; font-size: 13px; transition: 0.2s; background: #f8fafc; }
    .vr-input:focus { border-color: #3b82f6; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1); outline: none; background: #fff; }
    .vr-pain-scale { display: flex; justify-content: space-between; padding: 10px 0; }
    .vr-pain-num { width: 35px; height: 35px; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 700; cursor: pointer; border: 2px solid transparent; transition: 0.3s; font-size: 12px; }
    .vr-p-0 { background: #dcfce7; color: #15803d; } .vr-p-0.active { border-color: #15803d; transform: scale(1.2); }
    .vr-p-5 { background: #fef9c3; color: #854d0e; } .vr-p-5.active { border-color: #854d0e; transform: scale(1.2); }
    .vr-p-10 { background: #fee2e2; color: #991b1b; } .vr-p-10.active { border-color: #991b1b; transform: scale(1.2); }
    .vr-rom-table { width: 100%; font-size: 12px; }
    .vr-rom-table th { background: #f1f5f9; padding: 8px; text-align: center; }
    .vr-rom-table td { padding: 5px; border: 1px solid #e2e8f0; }
    .vr-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
    .vr-badge-blue { background: #dbeafe; color: #1e40af; }
</style>

<div class="vr-container">
    <form id="formulariop" name="formulariop" method="POST">
        <input type="hidden" name="idatencion" id="idatencion_vr" value="<?php echo $_POST['idatencion'] ?? ''; ?>">
        <input type="hidden" name="tipo_formato" value="VALORACION_RAPIDA_FT">

        <div class="vr-card">
            <div class="vr-header">
                <h2><i class="fa fa-bolt"></i> Valoracion Rapida de Fisioterapia</h2>
                <span class="vr-badge vr-badge-blue">Formato reducido</span>
            </div>

            <div class="vr-body">
                <div class="vr-section-title"><i class="fa fa-history"></i> 1. Anamnesis y Antecedentes</div>
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="vr-label">Motivo de Consulta y Enfermedad Actual</label>
                        <textarea class="vr-input" name="ft_motivo" rows="4" placeholder="Inicio, evolucion y estado actual de los sintomas..."></textarea>
                    </div>
                    <div class="col-md-3 mb-3">
                        <label class="vr-label">Antecedentes Quirurgicos / Traumaticos</label>
                        <textarea class="vr-input" name="ft_ant_quirurgicos" rows="4" placeholder="Cirugias, fracturas, esguinces previos..."></textarea>
                    </div>
                    <div class="col-md-3 mb-3">
                        <label class="vr-label">Ocupacion y Nivel de Actividad</label>
                        <textarea class="vr-input" name="ft_ocupacion_actividad" rows="4" placeholder="Tipo de trabajo, deporte, frecuencia..."></textarea>
                    </div>
                </div>

                <div class="vr-section-title mt-4"><i class="fa fa-eye"></i> 2. Inspeccion y Examen Fisico Inicial</div>
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="vr-label">Inspeccion Visual (Marcha y Actitud)</label>
                        <textarea class="vr-input" name="ft_inspeccion" rows="2" placeholder="Tipo de marcha, asimetrias evidentes, uso de ayudas..."></textarea>
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="vr-label">Estado de la Piel y Faneras</label>
                        <textarea class="vr-input" name="ft_piel" rows="2" placeholder="Cicatrices, edemas, hematomas, temperatura..."></textarea>
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="vr-label">Palpacion (Tono y Trofismo)</label>
                        <textarea class="vr-input" name="ft_palpacion" rows="2" placeholder="Hipertonia, atrofia, puntos gatillo, crepitacion..."></textarea>
                    </div>
                </div>

                <div class="vr-section-title mt-4"><i class="fa fa-thermometer-half"></i> 3. Evaluacion Analogica del Dolor (EVA)</div>
                <div class="row">
                    <div class="col-md-8">
                        <label class="vr-label">Nivel de Dolor (Presione para seleccionar)</label>
                        <div class="vr-pain-scale">
                            <input type="hidden" name="ft_dolor_eva" id="ft_dolor_eva_vr" value="0">
                            <?php for($i = 0; $i <= 10; $i++):
                                $class = "vr-p-0";
                                if($i > 3) $class = "vr-p-5";
                                if($i > 7) $class = "vr-p-10";
                            ?>
                                <div class="vr-pain-num <?php echo $class; ?>" onclick="selectPainVR(this, <?php echo $i; ?>)"><?php echo $i; ?></div>
                            <?php endfor; ?>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <label class="vr-label">Topografia y Comportamiento</label>
                        <textarea class="vr-input" name="ft_dolor_obs" rows="2" placeholder="Localizacion exacta, si irradia, que lo aumenta..."></textarea>
                    </div>
                </div>

                <div class="vr-section-title mt-4"><i class="fa fa-user-md"></i> 4. Valoracion Neurologica y Sensibilidad</div>
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="vr-label">Reflejos Osteotendinosos (ROT)</label>
                        <div style="background: #f8fafc; padding: 10px; border-radius: 8px;">
                            <div class="row">
                                <div class="col-md-6">Bicipital: <select name="rot_bicipital" class="vr-input mb-2"><option value="NORMAL">Normal</option><option value="HIPO">Hiporreflexia</option><option value="HIPER">Hiperreflexia</option></select></div>
                                <div class="col-md-6">Rotuliano: <select name="rot_rotuliano" class="vr-input mb-2"><option value="NORMAL">Normal</option><option value="HIPO">Hiporreflexia</option><option value="HIPER">Hiperreflexia</option></select></div>
                                <div class="col-md-6">Tricipital: <select name="rot_tricipital" class="vr-input"><option value="NORMAL">Normal</option><option value="HIPO">Hiporreflexia</option><option value="HIPER">Hiperreflexia</option></select></div>
                                <div class="col-md-6">Aquiliano: <select name="rot_aquiliano" class="vr-input"><option value="NORMAL">Normal</option><option value="HIPO">Hiporreflexia</option><option value="HIPER">Hiperreflexia</option></select></div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="vr-label">Sensibilidad (Dermatomas)</label>
                        <textarea class="vr-input" name="ft_sensibilidad" rows="3" placeholder="Superficial (tactil, termica, dolorosa), Propiocepcion..."></textarea>
                    </div>
                </div>

                <div class="vr-section-title mt-4"><i class="fa fa-arrows-alt"></i> 5. Valoracion Funcional: ROM y Fuerza Muscular</div>
                <div class="row">
                    <div class="col-md-7">
                        <label class="vr-label">Goniometria (Rangos de Movimiento)</label>
                        <table class="vr-rom-table">
                            <thead>
                                <tr>
                                    <th>Articulacion / Plano</th>
                                    <th>R / Der (&deg;)</th>
                                    <th>L / Izq (&deg;)</th>
                                    <th>End-Feel / Hallazgo</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>Cervical (Flex/Ext)</td>
                                    <td><input type="text" class="vr-input text-center" name="rom_1_r" style="padding:4px;"></td>
                                    <td><input type="text" class="vr-input text-center" name="rom_1_l" style="padding:4px;"></td>
                                    <td><input type="text" class="vr-input" name="rom_1_obs" style="padding:4px;"></td>
                                </tr>
                                <tr>
                                    <td>Hombro (Flex/Abd)</td>
                                    <td><input type="text" class="vr-input text-center" name="rom_2_r" style="padding:4px;"></td>
                                    <td><input type="text" class="vr-input text-center" name="rom_2_l" style="padding:4px;"></td>
                                    <td><input type="text" class="vr-input" name="rom_2_obs" style="padding:4px;"></td>
                                </tr>
                                <tr>
                                    <td>Rodilla (Flex/Ext)</td>
                                    <td><input type="text" class="vr-input text-center" name="rom_3_r" style="padding:4px;"></td>
                                    <td><input type="text" class="vr-input text-center" name="rom_3_l" style="padding:4px;"></td>
                                    <td><input type="text" class="vr-input" name="rom_3_obs" style="padding:4px;"></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-md-5">
                        <label class="vr-label">Fuerza Muscular (Escala de Daniels 0-5)</label>
                        <div class="list-group">
                            <div class="list-group-item d-flex justify-content-between align-items-center" style="font-size:12px;">
                                Flexores Cervicales
                                <select name="dan_1" class="vr-input" style="width:80px; padding:2px;"><option value="5">5/5</option><option value="4">4/5</option><option value="3">3/5</option><option value="2">2/5</option><option value="1">1/5</option><option value="0">0/5</option></select>
                            </div>
                            <div class="list-group-item d-flex justify-content-between align-items-center" style="font-size:12px;">
                                Extensores Lumbar
                                <select name="dan_2" class="vr-input" style="width:80px; padding:2px;"><option value="5">5/5</option><option value="4">4/5</option><option value="3">3/5</option><option value="2">2/5</option><option value="1">1/5</option><option value="0">0/5</option></select>
                            </div>
                            <div class="list-group-item d-flex justify-content-between align-items-center" style="font-size:12px;">
                                Miembro Superior (Total)
                                <select name="dan_3" class="vr-input" style="width:80px; padding:2px;"><option value="5">5/5</option><option value="4">4/5</option><option value="3">3/5</option><option value="2">2/5</option><option value="1">1/5</option><option value="0">0/5</option></select>
                            </div>
                            <div class="list-group-item d-flex justify-content-between align-items-center" style="font-size:12px;">
                                Miembro Inferior (Total)
                                <select name="dan_4" class="vr-input" style="width:80px; padding:2px;"><option value="5">5/5</option><option value="4">4/5</option><option value="3">3/5</option><option value="2">2/5</option><option value="1">1/5</option><option value="0">0/5</option></select>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="vr-section-title mt-4"><i class="fa fa-male"></i> 6. Analisis Postural y Equilibrio</div>
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="vr-label">Analisis de Postura (Plomada)</label>
                        <textarea class="vr-input" name="ft_postura" rows="3" placeholder="Vista Anterior, Posterior y Lateral..."></textarea>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="vr-label">Equilibrio y Coordinacion (Romberg, Berg, etc.)</label>
                        <textarea class="vr-input" name="ft_equilibrio" rows="3" placeholder="Estatico, Dinamico, Coordinacion fina..."></textarea>
                    </div>
                </div>

                <div class="vr-section-title mt-4"><i class="fa fa-stethoscope"></i> 7. Diagnostico Fisioterapeutico y Pruebas Especiales</div>
                <div class="row">
                    <div class="col-md-12 mb-3">
                        <label class="vr-label">Pruebas Especiales (Ortopedicas / Neurologicas)</label>
                        <textarea class="vr-input" name="ft_pruebas_especiales" rows="2" placeholder="Pruebas de rodilla, hombro, columna..."></textarea>
                    </div>
                    <div class="col-md-12">
                        <label class="vr-label">Diagnostico Funcional (CIF: Deficiencia, Limitacion, Restriccion)</label>
                        <textarea class="vr-input" name="ft_diagnostico_funcional" rows="2" placeholder="Descripcion integral del estado funcional..."></textarea>
                    </div>
                </div>

                <div class="vr-section-title mt-4" style="border-color: #10b981; color: #065f46;"><i class="fa fa-bolt"></i> 8. Plan de Intervencion y Objetivos</div>
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="vr-label">Medios Fisicos (Electro / Termo / Laser)</label>
                        <textarea class="vr-input" name="ft_electroterapia" rows="3" placeholder="Parametros tecnicos aplicados..."></textarea>
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="vr-label">Terapia Manual y Cinesiterapia</label>
                        <textarea class="vr-input" name="ft_terapia_manual" rows="3" placeholder="Ejercicios, estiramientos, movilizaciones..."></textarea>
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="vr-label">Objetivos SMART y Recomendaciones</label>
                        <textarea class="vr-input" name="ft_objetivos" rows="3" placeholder="Metas a corto y largo plazo..."></textarea>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <label class="vr-label">Sesiones Planificadas</label>
                        <input type="text" class="vr-input" name="ft_num_sesiones" value="10">
                    </div>
                </div>
            </div>
        </div>

    </form>
</div>

<script>
    function selectPainVR(el, val) {
        $(".vr-pain-num").removeClass("active");
        $(el).addClass("active");
        $("#ft_dolor_eva_vr").val(val);
        if (typeof toastr !== 'undefined') toastr.info("Dolor seleccionado: " + val + "/10", "Escala EVA");
    }
    $(document).ready(function () {
        console.log("Valoracion Rapida de Fisioterapia cargada.");
    });
</script>
