/* =================================================================
   MODALES COMUNES - LIMSLINK
   Sistema de modales reutilizables para toda la aplicación
   ================================================================= */

/* =================================
   MODAL BASE
   ================================= */

/* Contenedor principal del modal */
.modal-async {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 20px;
    box-sizing: border-box;
}

.modal-async.show {
    opacity: 1;
    visibility: visible;
}

/* Overlay semitransparente */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Contenido base del modal */
.modal-content-base {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-async.show .modal-content-base {
    transform: scale(1);
}

/* =================================
   MODAL PRELOADER
   ================================= */

/* Contenido del preloader */
.modal-content-preloader {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s ease;
    min-width: 300px;
    max-width: 400px;
}

.modal-async.show .modal-content-preloader {
    transform: scale(1);
}

/* Spinner SVG */
.preloader-spinner {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.spinner-svg {
    width: 60px;
    height: 60px;
    animation: rotate 2s linear infinite;
}

.spinner-circle {
    animation: dash 1.5s ease-in-out infinite;
}

/* Animaciones del spinner */
@keyframes rotate {
    100% {
        transform: rotate(360deg);
    }
}

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

/* Texto del preloader */
.preloader-text {
    color: #333;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.preloader-text span {
    display: inline-block;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

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

.modal-content-confirm {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s ease;
    min-width: 400px;
    max-width: 500px;
}

.modal-async.show .modal-content-confirm {
    transform: scale(1);
}

.confirm-icon {
    font-size: 48px;
    margin-bottom: 20px;
    color: #f39c12;
}

.confirm-title {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
}

.confirm-message {
    font-size: 16px;
    color: #666;
    margin-bottom: 30px;
    line-height: 1.5;
}

.confirm-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn-confirm {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
}

.btn-confirm-primary {
    background: #007bff;
    color: white;
}

.btn-confirm-primary:hover {
    background: #0056b3;
}

.btn-confirm-secondary {
    background: #6c757d;
    color: white;
}

.btn-confirm-secondary:hover {
    background: #545b62;
}

.btn-confirm-danger {
    background: #dc3545;
    color: white;
}

.btn-confirm-danger:hover {
    background: #c82333;
}

/* =================================
   MODAL NOTIFICACIÓN
   ================================= */

.modal-content-notification {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 16px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s ease;
    min-width: 350px;
    max-width: 450px;
}

.modal-async.show .modal-content-notification {
    transform: scale(1);
}

.notification-icon {
    font-size: 40px;
    margin-bottom: 15px;
}

.notification-icon.success {
    color: #28a745;
}

.notification-icon.error {
    color: #dc3545;
}

.notification-icon.warning {
    color: #ffc107;
}

.notification-icon.info {
    color: #17a2b8;
}

.notification-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}

.notification-message {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.btn-notification-close {
    background: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.btn-notification-close:hover {
    background: #0056b3;
}

/* =================================
   RESPONSIVE DESIGN
   ================================= */

@media (max-width: 768px) {
    .modal-content-preloader,
    .modal-content-confirm,
    .modal-content-notification {
        margin: 20px;
        padding: 30px 20px;
        min-width: auto;
        max-width: calc(100% - 40px);
    }
    
    .spinner-svg {
        width: 50px;
        height: 50px;
    }
    
    .preloader-text {
        font-size: 14px;
    }
    
    .confirm-title {
        font-size: 18px;
    }
    
    .confirm-message {
        font-size: 14px;
    }
    
    .confirm-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn-confirm {
        width: 100%;
    }
}

/* =================================
   MODAL GESTIÓN DE ESTADOS
   ================================= */

/* Modal de gestión de estados */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    display: none;
    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-window {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.5rem;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #666;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: #f5f5f5;
    color: #333;
}

.modal-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.info-message {
    background: #e3f2fd;
    color: #1976d2;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-message i {
    font-size: 1.2rem;
}

.tabla-estados-container {
    margin-bottom: 30px;
    overflow-x: auto;
}

.tabla-estados {
    width: 100%;
    border-collapse: collapse;
}

.tabla-estados th,
.tabla-estados td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.tabla-estados th {
    font-weight: 600;
    color: #333;
    background: #f9f9f9;
}

.tabla-estados td input[type="text"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.tabla-estados td input[type="color"] {
    padding: 0;
    width: 50px;
    height: 30px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.form-nuevo-estado {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
}

.form-nuevo-estado h4 {
    margin: 0 0 15px 0;
    font-size: 1.1rem;
    color: #333;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.9rem;
    color: #666;
}

.form-group input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.form-group input[type="color"] {
    padding: 2px;
    height: 36px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-footer button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
}

.btn-primario {
    background: #007bff;
    color: white;
}

.btn-primario:hover {
    background: #0056b3;
}

.btn-secundario {
    background: #6c757d;
    color: white;
}

.btn-secundario:hover {
    background: #5a6268;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

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

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

/* Clase para desactivar scroll del body cuando el modal está activo */
.modal-active {
    overflow: hidden;
}

/* =================================
   MODAL DE FORMULARIO
   ================================= */

/* Contenido del modal de formulario */
.modal-content-form {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 600px;
    max-height: calc(100vh - 40px);
    min-height: 300px;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: modalSlideIn 0.3s ease-out;
    overflow: hidden;
}

.modal-async.show .modal-content-form {
    transform: scale(1);
}

/* Header del formulario */
.form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 0 24px;
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 0;
    background: #f8f9fa;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0; /* No se comprime */
    min-height: 60px;
}

.form-title {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
    color: #212529;
}

.btn-form-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #6c757d;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    transition: all 0.2s ease;
}

.btn-form-close:hover {
    background: #e9ecef;
    color: #495057;
}

/* Cuerpo del formulario */
.form-body {
    padding: 24px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 100px;
    /* Scroll suave en navegadores webkit */
    -webkit-overflow-scrolling: touch;
    /* Personalizar scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.form-body::-webkit-scrollbar {
    width: 6px;
}

.form-body::-webkit-scrollbar-track {
    background: transparent;
}

.form-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.form-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.modal-form {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Campos del formulario */
.form-field {
    margin-bottom: 20px;
}

.form-field:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #374151;
    font-size: 0.9rem;
}

.form-label .required {
    color: #dc3545;
    margin-left: 2px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: white;
    color: #374151;
}

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

.form-input.error {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

/* Textarea específico */
textarea.form-input {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
}

/* Select específico */
select.form-input {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 40px;
    appearance: none;
}

/* Mensajes de error */
.form-error {
    color: #dc3545;
    font-size: 0.85rem;
    margin-top: 4px;
    display: block;
}

/* Footer del formulario */
.form-footer {
    padding: 20px 24px 24px 24px;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: #f8f9fa;
    border-radius: 0 0 16px 16px;
    flex-shrink: 0; /* No se comprime */
    min-height: 60px;
}

/* Botones del formulario */
.btn-form {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 100px;
    justify-content: center;
}

.btn-form-primary {
    background: #3b82f6;
    color: white;
}

.btn-form-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-form-secondary {
    background: #6c757d;
    color: white;
}

.btn-form-secondary:hover {
    background: #5a6268;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.4);
}

.btn-form:active {
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
    .modal-async {
        padding: 15px;
    }
    
    .modal-content-form {
        min-width: 300px;
        width: 100%;
        max-height: calc(100vh - 30px);
        min-height: 300px;
    }
    
    .form-header,
    .form-body,
    .form-footer {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .form-header {
        padding-top: 20px;
        padding-bottom: 0;
    }
    
    .form-footer {
        flex-direction: column-reverse;
        padding-top: 16px;
        padding-bottom: 20px;
    }
    
    .btn-form {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .modal-async {
        padding: 10px;
    }
    
    .modal-content-form {
        min-width: 280px;
        width: 100%;
        max-height: calc(100vh - 20px);
        border-radius: 12px;
    }
    
    .form-header,
    .form-body,
    .form-footer {
        padding-left: 12px;
        padding-right: 12px;
    }
    
    .form-header {
        padding-top: 16px;
        border-radius: 12px 12px 0 0;
    }
    
    .form-footer {
        padding-top: 12px;
        padding-bottom: 16px;
        border-radius: 0 0 12px 12px;
    }
    
    .form-title {
        font-size: 1.2rem;
    }
}

@media (min-height: 500px) and (max-height: 600px) {
    .modal-content-form {
        max-height: 95vh;
        margin: 10px;
    }
}

@media (max-height: 500px) {
    .modal-content-form {
        max-height: 98vh;
        margin: 5px;
    }
    
    .form-header {
        padding-top: 16px;
        padding-bottom: 0;
    }
    
    .form-footer {
        padding-top: 12px;
        padding-bottom: 16px;
    }
}

/* Animación de fade in/out para contenido dinámico */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

/* Estilos para campos custom */
.form-field-custom {
    margin-bottom: 20px;
}

.form-field-custom .form-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    color: #374151;
    font-size: 0.9rem;
}

.form-field-custom .analisis-section {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    margin-top: 5px;
}

.form-field-custom .analisis-input-group {
    margin-bottom: 10px;
}

.form-field-custom .analisis-input-group:last-child {
    margin-bottom: 0;
}

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