/**
 * Estilos para Búsqueda Semántica con IA (RAG)
 * Compatible con v1_tarjetas_grid.php
 */

/* === AJUSTES BUSCADOR CON IA === */
.search-container {
    position: relative !important;
    max-width: 900px !important; /* Más ancho */
}

/* Ocultar lupa */
.search-container .search-icon {
    display: none !important;
}

/* Ajustar padding del input para el botón IA */
.search-container .search-box {
    padding-right: 180px !important; /* Espacio para botón IA */
    font-size: 1.05rem !important;
}

/* Sincronizar movimiento del botón cuando el input tiene focus */
.search-box:focus ~ .ai-search-button {
    transform: translateY(calc(-50% - 2px)); /* Mueve junto con el input */
}

.ai-badge {
    display: none !important; /* Oculto - el botón ya indica IA */
}

.ai-search-button {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    z-index: 50;
    white-space: nowrap;
}

.ai-search-button:hover {
    transform: translateY(-50%) scale(1.05);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
}

.ai-search-button:active {
    transform: translateY(-50%) scale(0.98);
}

/* === MODAL DE RESULTADOS IA === */
.rag-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.rag-modal.active {
    opacity: 1;
}

.rag-modal-content {
    background: white;
    border-radius: 24px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    transform: translateY(-20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.rag-modal.active .rag-modal-content {
    transform: translateY(0);
}

/* Header del modal */
.rag-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 30px 20px;
    border-bottom: 2px solid #f0f0f0;
    background: linear-gradient(135deg, #667eea15, #764ba215);
}

.rag-header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.rag-icon {
    font-size: 2rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.rag-modal-header h2 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2C3E50;
    margin: 0;
}

.rag-modal-close {
    background: #f0f0f0;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #666;
}

.rag-modal-close:hover {
    background: #e74c3c;
    color: white;
    transform: rotate(90deg);
}

/* Body del modal */
.rag-modal-body {
    padding: 30px;
}

/* Sección de consulta */
.rag-query-section {
    background: linear-gradient(135deg, #667eea10, #764ba210);
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 25px;
    border-left: 4px solid #667eea;
}

.rag-query-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rag-query-text {
    font-size: 1.1rem;
    color: #2C3E50;
    font-style: italic;
}

/* Sección de respuesta IA */
.rag-answer-section {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 16px;
    margin-bottom: 25px;
}

.rag-answer-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: #007FA3;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rag-answer-text {
    font-size: 1rem;
    line-height: 1.8;
    color: #2C3E50;
}

.rag-answer-text strong {
    color: #007FA3;
    font-weight: 600;
}

/* Sección de capacidades */
.rag-capacidades-section {
    margin-top: 30px;
}

.rag-section-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2C3E50;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.rag-capacidades-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rag-capacidad-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.rag-capacidad-item:hover {
    border-color: #007FA3;
    box-shadow: 0 4px 15px rgba(0, 127, 163, 0.15);
    transform: translateX(5px);
}

.rag-cap-rank {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.rag-cap-content {
    flex: 1;
}

.rag-cap-title {
    font-size: 1rem;
    font-weight: 600;
    color: #2C3E50;
    margin-bottom: 5px;
}

.rag-cap-meta {
    display: flex;
    gap: 15px;
    font-size: 0.85rem;
    color: #6C757D;
}

.rag-cap-trl,
.rag-cap-responsable {
    display: flex;
    align-items: center;
    gap: 5px;
}

.rag-cap-arrow {
    font-size: 1.5rem;
    color: #007FA3;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.rag-capacidad-item:hover .rag-cap-arrow {
    opacity: 1;
}

/* Footer del modal */
.rag-modal-footer {
    display: flex;
    gap: 15px;
    padding-top: 25px;
    border-top: 2px solid #f0f0f0;
    margin-top: 25px;
}

.rag-btn-primary,
.rag-btn-secondary {
    flex: 1;
    padding: 15px 25px;
    border: none;
    border-radius: 12px;
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.rag-btn-primary {
    background: linear-gradient(135deg, #007FA3, #CE0058);
    color: white;
}

.rag-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 127, 163, 0.3);
}

.rag-btn-secondary {
    background: white;
    border: 2px solid #007FA3;
    color: #007FA3;
}

.rag-btn-secondary:hover {
    background: #007FA3;
    color: white;
}

/* === MODAL DE CARGA === */
.rag-loading-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.rag-loading-modal.active {
    opacity: 1;
}

.rag-loading-content {
    text-align: center;
    color: white;
}

.rag-loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.rag-loading-text {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.rag-loading-subtext {
    font-size: 0.95rem;
    opacity: 0.8;
}

/* === NOTIFICACIONES === */
.rag-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 12px;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    z-index: 10002;
    transform: translateX(400px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.rag-notification.active {
    transform: translateX(0);
}

.rag-notification-info {
    background: #3498db;
    color: white;
}

.rag-notification-success {
    background: #2ecc71;
    color: white;
}

.rag-notification-warning {
    background: #f39c12;
    color: white;
}

.rag-notification-error {
    background: #e74c3c;
    color: white;
}

/* === BADGE DE FILTRADO CON IA === */
.ai-filter-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    animation: slideInRight 0.4s ease;
}

@keyframes slideInRight {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.ai-badge-icon {
    font-size: 1.2rem;
    animation: rotate 3s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.ai-badge-text {
    font-weight: 600;
}

.ai-badge-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 700;
}

.ai-badge-close:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: rotate(90deg);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .search-container {
        max-width: 100% !important;
    }

    .search-container .search-box {
        padding-right: 140px !important;
        font-size: 0.9rem !important;
    }

    .ai-search-button {
        right: 10px;
        padding: 8px 12px;
        font-size: 0.75rem;
    }

    .ai-badge {
        display: none !important;
    }

    .rag-modal-content {
        max-width: 100%;
        margin: 10px;
        max-height: 95vh;
    }

    .rag-modal-header {
        padding: 20px;
    }

    .rag-modal-body {
        padding: 20px;
    }

    .rag-modal-footer {
        flex-direction: column;
    }

    .rag-capacidad-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .rag-cap-arrow {
        display: none;
    }
}

/* === NUEVO: RESULTADOS EXPANDIDOS (SIN MODAL) === */
.ai-results-container {
    display: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    padding: 30px;
    margin: 20px auto;
    max-width: 1200px;
    box-shadow: 0 10px 40px rgba(102, 126, 234, 0.3);
    animation: expandDown 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes expandDown {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
        max-height: 0;
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        max-height: 1000px;
    }
}

.ai-results-container.collapsing {
    animation: collapseUp 0.3s ease-out forwards;
}

@keyframes collapseUp {
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
        max-height: 0;
        padding: 0;
        margin: 0;
    }
}

.ai-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.ai-thinking-indicator {
    display: flex;
    align-items: center;
    gap: 15px;
    color: white;
}

.thinking-dots {
    display: flex;
    gap: 8px;
}

.thinking-dots span {
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.thinking-text {
    font-weight: 600;
    font-size: 0.95rem;
}

.ai-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.3s ease;
    line-height: 1;
}

.ai-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.ai-answer-box {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 0;
    min-height: 200px;
    max-height: 600px;
    overflow-y: auto;
    font-size: 1.05rem;
    line-height: 1.9;
    color: #2d3748;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* Formateo de contenido markdown */
.ai-answer-box h3 {
    color: #667eea !important;
    font-size: 1.3rem !important;
    margin: 30px 0 20px 0 !important;
    font-weight: 700 !important;
    border-bottom: 3px solid #667eea !important;
    padding-bottom: 10px !important;
    background: none !important;
}

.ai-answer-box strong {
    color: #667eea !important;
    font-weight: 700 !important;
    background: none !important;
}

/* Estilo para el disclaimer */
.ai-answer-box .ai-disclaimer {
    font-size: 0.9rem;
    font-weight: 500;
    color: #856404;
    line-height: 1.6;
    margin-bottom: 30px !important;
    padding: 15px 20px;
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    border-radius: 8px;
    border-left: 4px solid #ff9800;
    box-shadow: 0 2px 4px rgba(255, 152, 0, 0.1);
    display: block;
}

.ai-answer-box .ai-intro-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: #2d3748;
    line-height: 1.7;
    margin-bottom: 25px !important;
    padding: 20px;
    background: linear-gradient(135deg, #f7faff, #ffffff);
    border-radius: 12px;
    border-left: 4px solid #667eea;
    border-right: 4px solid #667eea;
}

.ai-answer-box ol {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: capacity-counter;
}

.ai-answer-box ol li {
    counter-increment: capacity-counter;
    margin-bottom: 25px;
    padding: 25px;
    background: #ffffff !important;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    position: relative;
    color: #2d3748 !important;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.08);
    transition: all 0.3s ease;
    overflow: hidden;
}

.ai-answer-box ol li:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(102, 126, 234, 0.15);
    border-color: #a3bffa;
}

/* Título de la capacidad */
.ai-answer-box ol li strong:first-child,
.ai-answer-box ol li > strong {
    display: block;
    font-size: 1.2rem;
    font-weight: 700 !important;
    color: #1a202c !important;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
    position: relative;
}

/* Añadir número a la tarjeta */
.ai-answer-box ol li > strong:first-child::before {
    content: counter(capacity-counter);
    position: absolute;
    top: -25px;
    left: -25px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom-right-radius: 16px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}


/* Contenedor para los campos de información */
.info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px; /* Aumentar el espacio entre elementos */
    margin-top: 10px;
}

/* Estilo para cada campo (Ventaja, Grupo, etc.) */
.info-item {
    display: flex;
    align-items: flex-start; /* Alinear al inicio para textos largos */
    gap: 15px; /* Espacio entre icono y texto */
    font-size: 0.95rem;
    line-height: 1.6;
    padding: 12px;
    background-color: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #c7d2fe;
    transition: all 0.3s ease;
}

.info-item:hover {
    background-color: #f1f5f9;
    border-left-color: #667eea;
    transform: translateX(5px);
}

.info-item i {
    font-size: 1.2rem; /* Icono un poco más grande */
    color: #667eea;
    margin-top: 3px; /* Ajuste vertical del icono */
    flex-shrink: 0;
    width: 22px;
    text-align: center;
}

.info-item-content {
    text-align: left;
    flex: 1;
}

.info-item-content strong {
    display: block;
    font-weight: 700 !important; /* Más peso */
    color: #4a5568 !important;
    margin-bottom: 4px; /* Espacio entre título y texto */
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-item-content span {
    color: #2d3748;
}

/* Estilo para las palabras clave (tags) */
.keyword-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.keyword-tag {
    background-color: #eef2ff;
    color: #4338ca;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid #c7d2fe;
}

/* Botón para ver detalles */
.details-button-container {
    margin-top: 20px;
    text-align: right;
}

.details-button {
    background: none;
    border: 2px solid #667eea;
    color: #667eea;
    padding: 8px 18px;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.details-button:hover {
    background: #667eea;
    color: white;
    transform: scale(1.05);
}

/* Eliminar estilos antiguos de sub-item */
.ai-answer-box .sub-item {
    display: none;
}

.ai-answer-box ol li::before {
    display: none !important;
}

.ai-answer-box p {
    margin: 15px 0 !important;
    color: #2d3748 !important;
    line-height: 1.8 !important;
    background: none !important;
}

.ai-answer-box hr {
    border: none !important;
    border-top: 3px solid #e2e8f0 !important;
    margin: 30px 0 !important;
    background: none !important;
}

.ai-answer-box::-webkit-scrollbar {
    width: 8px;
}

.ai-answer-box::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.ai-answer-box::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

/* Chips eliminados - ahora solo se filtran en el grid */

/* Efecto highlight en tarjetas */
.capacity-card.highlighted {
    animation: highlightPulse 2s ease;
    box-shadow: 0 0 0 4px #667eea, 0 15px 40px rgba(102, 126, 234, 0.4);
}

@keyframes highlightPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(102, 126, 234, 0.3);
    }
}

/* Responsive para nueva interfaz */
@media (max-width: 768px) {
    .ai-results-container {
        padding: 20px;
        border-radius: 15px;
    }

    .ai-answer-box {
        padding: 15px;
        font-size: 0.9rem;
        max-height: 300px;
    }
    
    /* CRÍTICO: Prevenir overflow horizontal en móvil cuando aparece el chat */
    body.chat-active {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    .header-with-wave.has-conversation {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    .conversation-container {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    .chat-messages {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    .message-content {
        max-width: calc(100vw - 80px) !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

}
