/**
 * Modal de Intercambio - Estilos CSS Corporativos
 * Version: 4.9.0 - Usa estilos compartidos de assets/css/shared/
 * Fecha: 19 Enero 2026
 *
 * NOTA: Este archivo usa estilos globales de:
 * - /assets/css/shared/variables.css (--ltn-*, --acf-*)
 * - /assets/css/shared/buttons.css (.ltn-button, .acf-button)
 * - /assets/css/shared/modals.css (.ltn-modal-close, .acf-modal-close)
 *
 * IMPORTANTE: NO redefinir estilos de botones o modal-close aquí.
 * Esos estilos vienen de los archivos shared/ que se cargan globalmente.
 *
 * COLORES CORPORATIVOS (definidos en shared/variables.css):
 * - Verde principal: var(--ltn-green-primary) (--ltn-green-primary)
 * - Verde oscuro: var(--ltn-green-dark) (--ltn-green-dark)
 * - Verde claro: var(--ltn-green-light) (--ltn-green-light)
 * - Terracota hover: var(--ltn-terra) (--ltn-terra)
 *
 * CHANGELOG v4.9.0:
 * - Eliminados estilos duplicados de .acf-button (ahora en shared/buttons.css)
 * - Eliminados estilos duplicados de .acf-modal-close (ahora en shared/modals.css)
 * - Actualizado header con referencia a archivos shared/
 */

/* ===========================================
   ANIMACIONES
   =========================================== */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ===========================================
   MODAL BASE - ESTILO CORPORATIVO GLOBAL
   =========================================== */
.ltn-modal {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--ltn-overlay-dark-60);
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ltn-modal.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ===========================================
   CONTENEDOR DEL MODAL
   =========================================== */
.ltn-modal-content {
    position: relative;
    transform: scale(0.9);
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px var(--ltn-overlay-black-30);
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    overflow: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.ltn-modal.active .ltn-modal-content {
    transform: scale(1);
    animation: modalSlideIn 0.3s ease forwards;
}

/* Cuando se está arrastrando, desactivar animación y transform centrado */
.ltn-modal-content.dragging,
.ltn-modal.active .ltn-modal-content.dragging {
    animation: none !important;
    transform: none !important;
    transition: none !important;
}

/* ===========================================
   HEADER DEL MODAL - ESTILO CORPORATIVO v4.8.22
   Degradado similar al header de administración
   Fallbacks corregidos Fase 3
   =========================================== */
.ltn-modal-header {
    background: linear-gradient(135deg,
        var(--ltn-green-dark) 0%,
        var(--ltn-green-primary) 50%,
        var(--ltn-green-light) 100%);
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 12px 12px 0 0;
    cursor: move;
    user-select: none;
    box-shadow: 0 2px 8px var(--ltn-shadow-green-20);
}

.ltn-modal-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Icono SVG del header v4.8.16 */
.ltn-modal-header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.ltn-modal-header-icon svg {
    width: 20px;
    height: 20px;
    stroke: white;
}

.ltn-modal-header-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ltn-modal-header h3 {
    margin: 0;
    color: white;
    font-size: 1.15em;
    font-weight: 600;
    line-height: 1.3;
}

.ltn-modal-header .modal-subtitle {
    margin: 0;
    color: var(--ltn-overlay-white-80);
    font-size: 0.85em;
    font-weight: normal;
}

/* Botón X de cierre - Usa estilos de shared/modals.css
   Clases disponibles: .ltn-modal-close, .ltn-modal-close.dark-header
   Aliases: .acf-modal-close, .acf-modal-close.dark-header */

/* ===========================================
   CUERPO DEL MODAL
   =========================================== */
.ltn-modal-body {
    padding: 24px;
    max-height: calc(90vh - 180px);
    overflow-y: auto;
}

/* ===========================================
   INFO DEL PRODUCTO - Imagen izquierda, texto derecha
   =========================================== */
.ltn-modal-product-info {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--ltn-green-bg);
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--ltn-gray-200);
}

.product-info-container {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.product-image {
    width: 70px;
    height: 70px;
    background: var(--ltn-gray-300);
    border-radius: 8px;
    flex-shrink: 0;
    overflow: hidden;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.product-details {
    flex: 1;
    min-width: 0;
}

.product-title-display {
    margin: 0 0 4px 0;
    font-weight: 600;
    color: var(--ltn-gray-700);
    font-size: 1em;
    line-height: 1.3;
}

.vendor-name-display {
    margin: 0;
    font-size: 0.9em;
    color: var(--ltn-gray-500);
}

/* ===========================================
   FORMULARIO
   =========================================== */
#ltn-intercambio-form,
.modal-form {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--ltn-gray-700);
    margin-bottom: 8px;
    font-size: 0.95em;
}

.form-group .required {
    color: var(--ltn-error);
}

.form-group textarea,
.form-group input[type="text"] {
    width: 100%;
    min-height: 90px;
    padding: 12px 14px;
    border: 1px solid var(--ltn-gray-200);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95em;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    resize: vertical;
}

.form-group textarea:focus,
.form-group input[type="text"]:focus {
    border-color: var(--ltn-green-primary);
    box-shadow: 0 0 0 3px var(--ltn-shadow-green-10);
    outline: none;
}

.form-group small {
    display: block;
    color: var(--ltn-gray-500);
    font-size: 0.8em;
    margin-top: 6px;
}

/* Info de contacto */
.contact-info {
    padding: 14px;
    background: var(--ltn-gray-100);
    border-radius: 8px;
    border-left: 3px solid var(--ltn-green-primary);
}

.contact-info .contact-title {
    margin: 0 0 8px 0;
    font-size: 0.9em;
    color: var(--ltn-gray-700);
}

.contact-info .user-detail {
    margin: 0 0 4px 0;
    font-size: 0.85em;
    color: var(--ltn-gray-500);
}

.contact-info .info-text {
    margin: 0;
    font-size: 0.9em;
    color: var(--ltn-gray-500);
    line-height: 1.5;
}

/* ===========================================
   MENSAJE DE RESULTADO
   =========================================== */
#ltn-form-message,
.form-message {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    display: none;
}

#ltn-form-message p,
.form-message p {
    margin: 0;
    font-size: 0.9em;
}

#ltn-form-message.error,
.form-message.error {
    display: block;
    background: var(--ltn-error-bg);
    border: 1px solid var(--ltn-error-border);
    color: var(--ltn-error);
}

#ltn-form-message.success,
.form-message.success {
    display: block;
    background: var(--ltn-success-bg);
    border: 1px solid var(--ltn-success-bg);
    color: var(--ltn-success-dark);
}

/* ===========================================
   FOOTER DEL MODAL - BOTONES
   =========================================== */
.modal-buttons {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    background: var(--ltn-gray-100);
    border-top: 1px solid var(--ltn-gray-200);
    border-radius: 0 0 12px 12px;
}

.modal-buttons .btn-cancel {
    flex: 1;
    padding: 12px 20px;
    background: white;
    color: var(--ltn-gray-700);
    border: 1px solid var(--ltn-gray-200);
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-buttons .btn-cancel:hover {
    background: var(--ltn-gray-100);
    border-color: var(--ltn-gray-300);
}

.modal-buttons .btn-submit {
    flex: 2;
    padding: 12px 20px;
    background: var(--ltn-green-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.modal-buttons .btn-submit:hover {
    background: var(--ltn-green-dark);
}

.modal-buttons .btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading spinner */
.btn-loading {
    display: none;
}

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--ltn-overlay-white-30);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===========================================
   BOTONES GLOBALES - Usa estilos de shared/buttons.css
   Clases disponibles:
   - .ltn-button, .ltn-btn (primario)
   - .ltn-button.cancel (cancelar)
   - .ltn-button.secondary (secundario)
   Aliases: .acf-button, .acf-btn
   =========================================== */

/* ===========================================
   RESPONSIVE
   =========================================== */
@media (max-width: 600px) {
    .ltn-modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .ltn-modal-header {
        padding: 14px 18px;
    }

    .ltn-modal-header h3 {
        font-size: 1.05em;
    }

    .ltn-modal-body {
        padding: 18px;
    }

    .ltn-modal-product-info {
        padding: 12px;
    }

    .product-image {
        width: 56px;
        height: 56px;
    }

    .modal-buttons {
        flex-direction: column-reverse;
        padding: 16px 18px;
    }

    .modal-buttons .btn-cancel,
    .modal-buttons .btn-submit {
        flex: none;
        width: 100%;
    }
}

/* ===========================================
   BOTON PROPONER INTERCAMBIO (FUERA DEL MODAL)
   =========================================== */
.ltn-btn-proponer-intercambio,
.btn-ofrecer-intercambio {
    background-color: var(--ltn-green-primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: normal;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.ltn-btn-proponer-intercambio:hover,
.btn-ofrecer-intercambio:hover {
    background-color: var(--ltn-green-dark);
}

/* ===========================================
   SELECTOR DE PRODUCTOS PROPIOS - v4.8.18
   =========================================== */
#productos-propios-section label {
    display: flex;
    align-items: center;
    gap: 8px;
}

#productos-propios-section label svg {
    color: var(--ltn-green-primary);
}

.productos-propios-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin: 10px 0;
    max-height: 200px;
    overflow-y: auto;
    padding: 5px;
}

.producto-propio-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    border: 2px solid var(--ltn-gray-200);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--ltn-white);
}

.producto-propio-item:hover {
    border-color: var(--ltn-green-light);
    box-shadow: 0 2px 8px var(--ltn-shadow-accent-10);
}

.producto-propio-item.selected {
    border-color: var(--ltn-green-primary);
    background: var(--ltn-green-bg);
    box-shadow: 0 0 0 3px var(--ltn-shadow-accent-15);
}

.producto-propio-item .producto-imagen {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
    margin-bottom: 8px;
}

.producto-propio-item .producto-nombre {
    font-size: 12px;
    text-align: center;
    color: var(--ltn-gray-700);
    line-height: 1.3;
    word-break: break-word;
    max-height: 2.6em;
    overflow: hidden;
}

.producto-propio-item .check-indicator {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background: var(--ltn-green-primary);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--ltn-white);
    font-size: 12px;
}

.producto-propio-item.selected .check-indicator {
    display: flex;
}

.producto-propio-item {
    position: relative;
}

.loading-productos {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--ltn-gray-500);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
}

.loading-spinner-small {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--ltn-gray-300);
    border-top-color: var(--ltn-green-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.no-productos-propios {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--ltn-gray-500);
    font-size: 13px;
    padding: 15px;
    background: var(--ltn-gray-100);
    border-radius: 8px;
}

@media (max-width: 600px) {
    .productos-propios-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
