/**
 * Estilos para el sistema de modales dinámicos
 * Extraído del JavaScript para mejor mantenimiento
 */

/* ========================================
   MODAL DE SELECCIÓN DE EQUIPO
   ======================================== */

.modal-equipo-selector {
    max-width: 500px;
    width: 90%;
}

.equipo-select-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}

.equipo-select-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
}

.equipo-select-item:hover {
    border-color: #3b82f6;
    background: #f0f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.equipo-select-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eff6ff;
    border-radius: 10px;
    color: #3b82f6;
}

.equipo-select-item:hover .equipo-select-icon {
    background: #dbeafe;
}

.equipo-select-info {
    flex: 1;
    min-width: 0;
}

.equipo-select-nombre {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 4px;
}

.equipo-select-details {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 14px;
    color: #6b7280;
}

.equipo-select-details span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ========================================
   MODALES DINÁMICOS BASE
   ======================================== */
.modal-container{
    background: #fff;
    border-radius: 13px;
}

.modal-overlay,
.ticket-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s;
}

.modal-content {
    background: white;
    border-radius: 16px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s;
    position: relative;
}

/* Tamaños de modales */
.modal-content.size-sm {
    max-width: 400px;
}

.modal-content.size-md {
    max-width: 600px;
}

.modal-content.size-lg {
    max-width: 900px;
}

.modal-content.size-xl {
    max-width: 1200px;
}

.modal-content.size-fullscreen {
    max-width: 95vw;
    height: 90vh;
}

/* Header del modal */
.modal-header {
    padding: 24px 24px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #111827;
}

/* Body del modal */
.modal-body {
    flex: 1;
    overflow-y: auto;
}

/* Footer del modal */
.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ========================================
   MODALES DE ESTADO (Loading, Error, etc.)
   ======================================== */

.modal-loading {
    padding: 48px;
    text-align: center;
}

.modal-loading .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 24px;
}

.modal-loading p {
    margin: 0;
    color: #6b7280;
    font-size: 16px;
}

/* Modal de éxito */
.modal-exito {
    padding: 48px;
    text-align: center;
}

.modal-exito .icon-container {
    width: 64px;
    height: 64px;
    background: #d1fae5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.modal-exito h3 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.modal-exito p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

/* Modal de error */
.modal-error {
    padding: 48px;
    text-align: center;
}

.modal-error .icon-container {
    width: 64px;
    height: 64px;
    background: #fee2e2;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.modal-error h3 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.modal-error p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

/* Modal de advertencia */
.modal-advertencia {
    padding: 48px;
    text-align: center;
}

.modal-advertencia .icon-container {
    width: 64px;
    height: 64px;
    background: #fef3c7;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.modal-advertencia h3 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.modal-advertencia p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

/* ========================================
   MODAL DE CONFIRMACIÓN
   ======================================== */

.modal-confirmacion .modal-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-confirmacion .modal-body {
    padding: 24px;
}

.modal-confirmacion .modal-body p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
    line-height: 1.6;
}

.modal-confirmacion .modal-footer {
    padding: 16px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-confirmacion .btn-cancelar {
    padding: 10px 20px;
    border: 1px solid #d1d5db;
    background: white;
    color: #374151;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-confirmacion .btn-confirmar {
    padding: 10px 20px;
    border: none;
    background: #ef4444;
    color: white;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-confirmacion .btn-cancelar:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.modal-confirmacion .btn-confirmar:hover {
    background: #dc2626;
}

/* ========================================
   MODAL SPLIT-VIEW PARA DOCUMENTOS
   ======================================== */

.modal-documento-split {
    display: grid;
    grid-template-columns: 1fr 1fr;

    gap: 0;
}

.documento-viewer {
    /* Estilos para el visor de documentos */
}

.documento-datos {
    padding: 24px;
    overflow-y: auto;
    background: white;
}

.documento-tabs {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    border-bottom: 2px solid #e5e7eb;
}

.documento-tab {
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.2s;
}

.documento-tab.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

.documento-tab:hover {
    color: #3b82f6;
}

.tab-content {
    /* Contenedor de contenido de tabs */
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* ========================================
   FORMULARIOS EN MODALES
   ======================================== */

.modal-form {
    padding: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #374151;
}

.input-field {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.input-field:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input-field.error {
    border-color: #ef4444;
}

.input-field.success {
    border-color: #10b981;
}

/* Toggle switches */
.toggle-switch-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-label {
    font-size: 14px;
    color: #374151;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #3b82f6;
}

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

/* Segmented controls */
.segmented-control {
    display: flex;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 4px;
}

.segmented-control button {
    flex: 1;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.segmented-control button.active {
    background: white;
    color: #3b82f6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ==============================================
   SELECTOR DE AVATARES
   ============================================== */

.avatar-selector {
    margin-top: 8px;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 12px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.avatar-option {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    background: #ffffff;
    max-width: 100px;
}

.avatar-option:hover {
    border-color: #3b82f6;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.avatar-option.selected {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.avatar-option.selected::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: #3b82f6;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.avatar-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ==============================================
   OVERLAY DE CARGA PARA GUARDAR USUARIO
   ============================================== */

.user-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999999999;
    border-radius: 16px;
}

.user-loading-overlay p {
    margin-top: 16px;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
}

.user-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner-inline {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* Permission switches */
.permission-switch {
    display: flex;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 4px;
}

.btn-permission-no,
.btn-permission-si {
    flex: 1;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-permission-no.active,
.btn-permission-si.active {
    background: white;
    color: #3b82f6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Resources section */
.resources-section {
    margin-top: 24px;
}

.resources-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    color: #6b7280;
    font-size: 12px;
    text-transform: uppercase;
}

.resource-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    border-bottom: 1px solid #f3f4f6;
}

.resource-row:last-child {
    border-bottom: none;
}

.resource-info {
    flex: 1;
}

.resource-title {
    font-weight: 500;
    color: #111827;
}

/* Info text */
.info-text {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 8px;
}

/* ========================================
   ANIMACIONES
   ======================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   UTILIDADES
   ======================================== */

.d-none {
    display: none !important;
}

/* Estados del body cuando hay modales abiertos */
body.modal-open {
    overflow: hidden;
}

/* Responsive */
@media (max-width: 768px) {
    /* Modales a pantalla completa en móvil */
    .modal-overlay,
    .ticket-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 16px 16px 0 0;
        margin: 0;
        animation: slideUpMobile 0.3s ease;
    }

    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    /* Header del modal */
    .modal-header {
        padding: 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .modal-header h2 {
        font-size: 18px;
        flex: 1;
        min-width: 0;
    }

    /* Body del modal */
    .modal-body {
        overflow-x: hidden;
        padding: 16px;
        max-height: calc(100vh - 140px);
        -webkit-overflow-scrolling: touch;
    }

    /* Footer del modal */
    .modal-footer {
        padding: 16px;
        flex-direction: column;
        gap: 12px;
    }

    .modal-footer .btn {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
    }

    /* Formularios en modales */
    .modal-form {
        padding: 16px;
    }

    .form-group {
        margin-bottom: 20px;
    }

    .form-group input,
    .form-group textarea,
    .form-group select,
    .input-field {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        font-size: 16px !important;
        min-height: 48px;
        padding: 14px 16px;
    }

    /* Grids dentro de modales en una sola columna */
    .modal-body .grid,
    .modal-body [class*="grid"],
    .modal-body [style*="grid"] {
        grid-template-columns: 1fr !important;
    }

    /* Split view de documentos */
    .modal-documento-split {
        grid-template-columns: 1fr;
        height: auto;
        flex-direction: column;
    }
    
    .documento-viewer {
        height: 50vh;
        order: 1;
    }

    .documento-datos {
        order: 2;
        padding: 16px;
    }

    /* Avatar selector */
    .avatar-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
        padding: 8px;
    }

    /* Segmented controls */
    .segmented-control {
        flex-direction: column;
        gap: 4px;
    }

    .segmented-control button {
        width: 100%;
        min-height: 44px;
    }

    /* Permission switches */
    .permission-switch {
        flex-direction: column;
        gap: 4px;
    }

    .btn-permission-no,
    .btn-permission-si {
        width: 100%;
        min-height: 44px;
    }

    /* Resources section */
    .resources-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .resource-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px 0;
    }
}

/* ========================================
   MODAL FACTURAE - Completa los datos (FACE)
   ======================================== */

#modal-facturae-datos .modal-content {
    max-width: 520px;
}

.modal-facturae-header h2 {
    color: #1e3a5f;
    font-weight: 700;
    border-bottom: 2px solid #2563eb;
    padding-bottom: 8px;
    display: inline-block;
}

.modal-facturae-body {
    padding: 20px 24px;
}

.facturae-info-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: #fefce8;
    border: 1px solid #fef08a;
    border-radius: 8px;
    margin-bottom: 20px;
}

.facturae-info-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border: 1px solid #ca8a04;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #a16207;
    background: #fef9c3;
}

.facturae-info-box p {
    margin: 0;
    font-size: 14px;
    color: #713f12;
    line-height: 1.5;
}

.facturae-field-required label:first-child {
    font-weight: 600;
    color: #111827;
    margin-bottom: 10px;
    display: block;
}

.facturae-radio-group {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.facturae-radio-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 15px;
    color: #374151;
}

.facturae-radio-input {
    width: 18px;
    height: 18px;
    accent-color: #2563eb;
}

.facturae-dir3-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.facturae-dir3-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #374151;
    margin: 0 0 8px 0;
}

.facturae-dir3-desc {
    font-size: 14px;
    color: #6b7280;
    margin: 0 0 16px 0;
    line-height: 1.5;
}

.facturae-dir3-desc a {
    color: #2563eb;
    text-decoration: underline;
}

.facturae-dir3-section .form-group {
    margin-bottom: 14px;
}

.facturae-dir3-section .form-group label {
    font-weight: 500;
    color: #374151;
}

.facturae-reminder {
    margin-top: 16px;
    background: #eff6ff;
    border-color: #bfdbfe;
}

.facturae-reminder .facturae-info-icon {
    border-color: #2563eb;
    color: #1d4ed8;
    background: #dbeafe;
}

.facturae-reminder p {
    color: #1e40af !important;
}

.modal-facturae-footer .btn-descargar-facturae-confirm {
    background: #ea580c;
    border-color: #ea580c;
    color: #fff;
}

.modal-facturae-footer .btn-descargar-facturae-confirm:hover {
    background: #c2410c;
    border-color: #c2410c;
    color: #fff;
}
