/* ============================================================================
BUILD FORM CSS - Sistema completo de estilos para buildForm
Diseños modernos, responsive, compatibilidad total
Namespaced con prefijo bf- para evitar conflictos
============================================================================ */

/* ============================================================================
VARIABLES Y RESET
============================================================================ */
:root {
    --bf-primary-color: #007bff;
    --bf-secondary-color: #6c757d;
    --bf-success-color: #28a745;
    --bf-danger-color: #dc3545;
    --bf-warning-color: #ffc107;
    --bf-info-color: #17a2b8;
    --bf-light-color: #f8f9fa;
    --bf-dark-color: #343a40;
    --bf-border-color: #ced4da;
    --bf-border-radius: 4px;
    --bf-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bf-box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    --bf-transition: all 0.3s ease;
}

/* Reset específico para componentes buildForm */
.bf-form * {
    box-sizing: border-box;
}

/* ============================================================================
FORMULARIOS BASE
============================================================================ */
.bf-form {
    font-family: var(--bf-font-family);
    line-height: 1.5;
    color: var(--bf-dark-color);
    max-width: 100%;
}

.bf-field-container {
    margin-bottom: 1.5rem;
    position: relative;
}

.bf-field-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--bf-dark-color);
    font-size: 0.9rem;
}

.bf-required-label::after {
    content: " *";
    color: var(--bf-danger-color);
}

/* ============================================================================
CAMPOS DE TEXTO Y TEXTAREA
============================================================================ */
.bf-field {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--bf-border-color);
    border-radius: var(--bf-border-radius);
    background-color: white;
    transition: var(--bf-transition);
    font-family: var(--bf-font-family);
}

.bf-field:focus {
    outline: none;
    border-color: var(--bf-primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.bf-field:hover {
    border-color: #adb5bd;
}

.bf-field.bf-has-value {
    border-color: var(--bf-success-color);
}

.bf-field.bf-error {
    border-color: var(--bf-danger-color);
    background-color: rgba(220, 53, 69, 0.02);
}

.bf-field.bf-error:focus {
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.bf-field:disabled {
    background-color: var(--bf-light-color);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Textarea específico */
.bf-textarea {
    min-height: 100px;
    resize: vertical;
    line-height: 1.5;
}

/* ============================================================================
SELECT
============================================================================ */
.bf-select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'><path fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
    padding-right: 2.5rem;
}

.bf-select.bf-error {
    background-image: url("data:image/svg+xml;charset=US-ASCII,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'><path fill='%23dc3545' d='M2 0L0 2h4zm0 5L0 3h4z'/></svg>");
}

/* ============================================================================
CHECKBOX Y RADIO
============================================================================ */
.bf-checkbox,
.bf-radio {
    margin-right: 0.5rem;
    transform: scale(1.2);
}

.bf-checkbox-label,
.bf-radio-label {
    display: inline-flex;
    align-items: center;
    margin-right: 1rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-weight: normal;
}

.bf-checkbox:focus,
.bf-radio:focus {
    outline: 2px solid var(--bf-primary-color);
    outline-offset: 2px;
}

/* Grupo de checkboxes/radios */
.bf-checkbox-group,
.bf-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* ============================================================================
SWITCH/INTERRUPTOR
============================================================================ */
.bf-switch-container {
    display: inline-flex;
    align-items: center;
    position: relative;
    cursor: pointer;
}

.bf-switch-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.bf-switch-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
}

.bf-switch-slider {
    position: relative;
    width: 50px;
    height: 24px;
    background-color: var(--bf-border-color);
    border-radius: 34px;
    margin-right: 0.75rem;
    transition: var(--bf-transition);
}

.bf-switch-slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: var(--bf-transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.bf-switch-input:checked + .bf-switch-label .bf-switch-slider {
    background-color: var(--bf-success-color);
}

.bf-switch-input:checked + .bf-switch-label .bf-switch-slider::before {
    transform: translateX(26px);
}

.bf-switch-input:focus + .bf-switch-label .bf-switch-slider {
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.25);
}

.bf-switch-on .bf-switch-slider {
    background-color: var(--bf-success-color);
}

.bf-switch-off .bf-switch-slider {
    background-color: var(--bf-border-color);
}

/* ============================================================================
UPLOAD DE ARCHIVOS
============================================================================ */
.bf-file-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--bf-primary-color);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 10;
}

.bf-upload-container {
    position: relative;
    border: 2px dashed var(--bf-border-color);
    border-radius: var(--bf-border-radius);
    padding: 2rem;
    text-align: center;
    transition: var(--bf-transition);
    background-color: var(--bf-light-color);
    cursor: pointer;
}

.bf-upload-container::before {
    content: "📁 Arrastra archivos aquí o haz clic para seleccionar";
    display: block;
    color: var(--bf-primary-color);
    font-weight: 500;
    margin-bottom: 0.5rem;
    pointer-events: none;
}

.bf-upload-container::after {
    content: "-";
    display: block;
    color: var(--bf-secondary-color);
    font-size: 0.8rem;
    pointer-events: none;
}

/* Para móviles mostrar texto diferente */
@media (max-width: 768px) {
    .bf-upload-container::before {
        content: "📱 Toca para subir archivos" !important;
    }

    .bf-upload-container::after {
        content: "Toca para seleccionar desde tu dispositivo" !important;
    }
}

.bf-touch-label {
    display: none !important;
}

/* Cuando hay archivos seleccionados, ocultar textos de ayuda */
.bf-upload-container:has(.bf-file-preview)::before,
.bf-upload-container:has(.bf-file-preview)::after,
.bf-upload-container.has-files::before,
.bf-upload-container.has-files::after {
    display: none;
}

.bf-upload-container:hover {
    border-color: var(--bf-primary-color);
    background-color: rgba(0, 123, 255, 0.02);
}

.bf-upload-container.bf-drag-over {
    border-color: var(--bf-primary-color);
    background-color: rgba(0, 123, 255, 0.1);
}

.bf-upload {
    width: 100%;
    height: 100%;
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    cursor: pointer;
}

.bf-upload-preview {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bf-file-preview {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background: white;
    border: 1px solid var(--bf-border-color);
    border-radius: var(--bf-border-radius);
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    transition: var(--bf-transition);
}

.bf-file-preview:hover {
    border-color: var(--bf-primary-color);
    box-shadow: var(--bf-box-shadow);
}

.bf-file-thumbnail {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 3px;
}

.bf-file-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 0.25rem;
}

.bf-file-name {
    font-weight: 500;
    font-size: 0.9rem;
    word-break: break-word;
}

.bf-file-size {
    color: var(--bf-secondary-color);
    font-size: 0.8rem;
}

.bf-remove-file {
    background: none;
    border: none;
    color: var(--bf-danger-color);
    cursor: pointer;
    font-size: 1.2rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--bf-transition);
    flex-shrink: 0;
}

.bf-remove-file:hover {
    background-color: var(--bf-danger-color);
    color: white;
    transform: scale(1.1);
}

.bf-touch-label {
    color: var(--bf-primary-color);
    font-weight: 500;
    pointer-events: none;
}

/* ============================================================================
FIRMA DIGITAL - MEJORADO CON BORDES VISIBLES
============================================================================ */
.bf-signature-container {
    border: 2px solid var(--bf-border-color);
    border-radius: var(--bf-border-radius);
    overflow: hidden;
    background: white;
    max-width: 423px; /* Ancho máximo */
    margin: 0 auto; /* Centrado */
}

.bf-signature-pad {
    background: 
    linear-gradient(45deg, #f8f9fa 25%, transparent 25%), 
    linear-gradient(-45deg, #f8f9fa 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #f8f9fa 75%), 
    linear-gradient(-45deg, transparent 75%, #f8f9fa 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    cursor: crosshair;
    position: relative;
    border: 1px dashed #dee2e6;
    margin: 10px;
}

.bf-signature-pad canvas {
    display: block;
    width: 100% !important; /* Forzar ancho completo */
    background: rgba(255, 255, 255, 0.9); /* Fondo semi-transparente */
    cursor: crosshair;
}

.bf-signature-instruction {
    text-align: center;
    padding: 10px;
    background: var(--bf-light-color);
    border-bottom: 1px solid var(--bf-border-color);
    color: var(--bf-secondary-color);
    font-size: 0.9rem;
}

.bf-signature-actions {
    padding: 1rem;
    background: var(--bf-light-color);
    border-top: 1px solid var(--bf-border-color);
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.bf-clear-button {
    padding: 0.5rem 1.5rem;
    background: var(--bf-danger-color);
    color: white;
    border: none;
    border-radius: var(--bf-border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--bf-transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bf-clear-button:hover {
    background: #c82333;
    transform: translateY(-1px);
}

.bf-clear-button::before {
    content: "🗑️";
}

/* Estados de la firma */
.bf-signature-empty .bf-signature-pad {
    background-color: #fff8f8;
}

.bf-signature-has-data .bf-signature-pad {
    background-color: #f8fff8;
}

/* Responsive */
@media (max-width: 768px) {
    .bf-signature-container {
        max-width: 100%;
        margin: 0;
    }

    .bf-signature-pad {
        margin: 5px;
    }

    .bf-signature-pad canvas {
        height: 150px !important;
    }
}

/* ============================================================================
BOTONES
============================================================================ */
.bf-button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border: none;
    border-radius: var(--bf-border-radius);
    cursor: pointer;
    transition: var(--bf-transition);
    font-family: var(--bf-font-family);
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.bf-submit {
    background-color: var(--bf-primary-color);
    color: white;
}

.bf-submit:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
    box-shadow: var(--bf-box-shadow);
}

.bf-reset {
    background-color: var(--bf-secondary-color);
    color: white;
}

.bf-reset:hover {
    background-color: #545b62;
}

.bf-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.bf-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

/* ============================================================================
VALIDACIÓN Y ERRORES
============================================================================ */
.bf-field-error {
    color: var(--bf-danger-color);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    display: none;
}

.bf-field-error.show {
    display: block;
}

.bf-validation-failed {
    border-color: var(--bf-danger-color) !important;
}

.bf-validation-passed {
    border-color: var(--bf-success-color) !important;
}

.bf-validation-failed-sel {
    border-color: var(--bf-danger-color) !important;
}

.bf-validation-passed-sel {
    border-color: var(--bf-success-color) !important;
}

.bf-validation-failed-cr {
    outline: 2px solid var(--bf-danger-color);
}

.bf-validation-passed-cr {
    outline: 2px solid var(--bf-success-color);
}

/* ============================================================================
SISTEMA DE AYUDA Y TOOLTIPS
============================================================================ */
.bf-help-text {
    color: var(--bf-secondary-color);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    line-height: 1.4;
}

.bf-tooltip {
    position: absolute;
    background: var(--bf-dark-color);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: var(--bf-border-radius);
    font-size: 0.8rem;
    z-index: 1000;
    max-width: 200px;
    word-wrap: break-word;
    box-shadow: var(--bf-box-shadow);
}

.bf-tooltip::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--bf-dark-color);
}

.bf-field[title] {
    cursor: help;
}

/* ============================================================================
CAMPOS HTML5 ESPECIALES
============================================================================ */
.bf-date,
.bf-time,
.bf-week,
.bf-datetime,
.bf-color,
.bf-number,
.bf-email {
    /* Estilos específicos para campos HTML5 */
}

.bf-color {
    height: 45px;
    padding: 0.25rem;
}

.bf-number {
    text-align: right;
}

.bf-money {
    text-align: left;
    direction: ltr;
}

/* ============================================================================
LAYOUT RESPONSIVE
============================================================================ */
.bf-form-grid {
    display: grid;
    gap: 1.5rem;
}

.bf-form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.bf-form-col {
    flex: 1;
    min-width: 0;
}

/* ============================================================================
ESTADOS DE CARGA Y DESHABILITADO
============================================================================ */
.bf-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.bf-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--bf-border-color);
    border-top: 2px solid var(--bf-primary-color);
    border-radius: 50%;
    animation: bf-spin 1s linear infinite;
}

@keyframes bf-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================================================
RESPONSIVE DESIGN
============================================================================ */
@media (max-width: 768px) {
    .bf-form-row {
        flex-direction: column;
        gap: 1rem;
    }

    .bf-form-col {
        width: 100%;
    }

    .bf-checkbox-group,
    .bf-radio-group {
        flex-direction: column;
        align-items: flex-start;
    }

    .bf-signature-actions {
        flex-direction: column;
    }

    .bf-button {
        width: 100%;
        justify-content: center;
    }

    .bf-file-preview {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }

    .bf-file-thumbnail {
        align-self: flex-start;
    }
}

@media (max-width: 480px) {
    .bf-field {
        padding: 0.625rem 0.75rem;
        font-size: 16px; /* Previene zoom en iOS */
    }

    .bf-switch-label {
        font-size: 0.8rem;
    }

    .bf-upload-container {
        padding: 1.5rem;
    }
}

/* ============================================================================
ACCESIBILIDAD
============================================================================ */
@media (prefers-reduced-motion: reduce) {
    .bf-field,
    .bf-button,
    .bf-switch-slider,
    .bf-upload-container {
        transition: none;
    }
}

@media (prefers-contrast: high) {
    .bf-field {
        border-width: 2px;
    }

    .bf-field:focus {
        border-width: 3px;
    }
}

/* ============================================================================
ESTADOS DE FOCO MEJORADOS
============================================================================ */
.bf-field:focus-visible {
    outline: 2px solid var(--bf-primary-color);
    outline-offset: 2px;
}

/* Soporte para navegadores antiguos sin :focus-visible */
.bf-field:focus:not(:focus-visible) {
    outline: none;
}

/* ============================================================================
ICONOGRAFÍA Y ELEMENTOS VISUALES
============================================================================ */
.bf-icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    stroke-width: 0;
    stroke: currentColor;
    fill: currentColor;
    vertical-align: middle;
}

.bf-success-icon {
    color: var(--bf-success-color);
}

.bf-error-icon {
    color: var(--bf-danger-color);
}

.bf-warning-icon {
    color: var(--bf-warning-color);
}

.bf-info-icon {
    color: var(--bf-info-color);
}

/* ============================================================================
UTILIDADES
============================================================================ */
.bf-hidden {
    display: none !important;
}

.bf-visible {
    display: block !important;
}

.bf-text-left { text-align: left; }
.bf-text-center { text-align: center; }
.bf-text-right { text-align: right; }

.bf-mt-1 { margin-top: 0.25rem; }
.bf-mt-2 { margin-top: 0.5rem; }
.bf-mt-3 { margin-top: 1rem; }
.bf-mb-1 { margin-bottom: 0.25rem; }
.bf-mb-2 { margin-bottom: 0.5rem; }
.bf-mb-3 { margin-bottom: 1rem; }

.bf-p-1 { padding: 0.25rem; }
.bf-p-2 { padding: 0.5rem; }
.bf-p-3 { padding: 1rem; }

/* ============================================================================
COMPATIBILIDAD CON NAVEGADORES ANTIGUOS
============================================================================ */
/* IE11 específico */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .bf-select {
        background-image: none;
        padding-right: 1rem;
    }

    .bf-switch-container {
        display: block;
    }
}

/* Safari específico */
@media not all and (min-resolution:.001dpcm) { 
    @supports (-webkit-appearance:none) {
        .bf-select {
        background-image: none;
        padding-right: 1rem;
    }
}
}

/* ============================================================================
ESTADOS READONLY MEJORADOS
============================================================================ */
.bf-field[readonly],
.bf-field[data-readonly="true"] {
    background-color: #f8f9fa;
    border-color: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.8;
    user-select: none;
}

/* Select readonly específico */
.bf-select[readonly],
.bf-select[data-readonly="true"] {
    background-image: none;
    pointer-events: none;
}

/* Checkbox y Radio readonly */
.bf-checkbox[readonly],
.bf-radio[readonly],
.bf-checkbox[data-readonly="true"],
.bf-radio[data-readonly="true"] {
    opacity: 0.6;
    pointer-events: none;
}

/* Switch readonly */
.bf-switch-input[readonly] + .bf-switch-label,
.bf-switch-input[data-readonly="true"] + .bf-switch-label {
    opacity: 0.6;
    cursor: not-allowed;
}

.bf-switch-input[readonly] + .bf-switch-label .bf-switch-slider,
.bf-switch-input[data-readonly="true"] + .bf-switch-label .bf-switch-slider {
    background-color: #6c757d !important;
}

/* Upload readonly */
.bf-upload[readonly],
.bf-upload[data-readonly="true"] {
    pointer-events: none;
    cursor: not-allowed;
}

.bf-upload-container[data-readonly="true"] {
    background-color: #e9ecef;
    border-color: #dee2e6;
    opacity: 0.7;
}

.bf-upload-container[data-readonly="true"]::before {
    content: "📁 Subida deshabilitada" !important;
    color: #6c757d !important;
}

/* Botones readonly */
.bf-button[readonly],
.bf-button[data-readonly="true"] {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.bf-button[readonly]:hover,
.bf-button[data-readonly="true"]:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* Firma digital readonly */
.bf-signature-container[data-readonly="true"] {
    opacity: 0.7;
    pointer-events: none;
}

.bf-signature-container[data-readonly="true"] .bf-clear-button {
    display: none;
}