/* ========================================
   AI Assistant - Widget Flotante
   ======================================== */

/* Botón de IA junto a campos de texto - Estilo sutil */
.ai-assist-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: transparent;
    color: #9e9e9e;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    margin-left: 6px;
    vertical-align: middle;
    padding: 0;
}

.ai-assist-btn:hover {
    color: #7c4dff;
    background: rgba(124, 77, 255, 0.08);
}

.ai-assist-btn:active {
    color: #651fff;
}

.ai-assist-btn i {
    font-size: 14px;
    line-height: 1;
}

.ai-assist-btn.disabled {
    color: #bdbdbd;
    cursor: not-allowed;
    opacity: 0.5;
}

.ai-assist-btn.disabled:hover {
    background: transparent;
    color: #bdbdbd;
}

/* ========================================
   Widget Flotante
   ======================================== */

.ai-widget {
    position: fixed;
    width: 550px;
    min-width: 400px;
    max-width: 90vw;
    height: 550px;
    min-height: 300px;
    max-height: 85vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
    font-family: 'Roboto', sans-serif;
    resize: both;
}

.ai-widget.minimized {
    max-height: 48px;
}

.ai-widget.minimized .ai-widget-body,
.ai-widget.minimized .ai-widget-footer {
    display: none;
}

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

/* Header del Widget */
.ai-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: move;
    user-select: none;
}

.ai-widget-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 14px;
}

.ai-widget-title i {
    font-size: 20px;
}

.ai-widget-actions {
    display: flex;
    gap: 4px;
}

/* Selector de modelo (en footer) */
.ai-model-selector {
    flex-shrink: 0;
    display: block;
}

.ai-model-select {
    display: block;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    color: #333;
    padding: 6px 8px;
    font-size: 11px;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    min-width: 130px;
    height: 36px;
}

.ai-model-select optgroup {
    font-weight: 600;
    color: #555;
    padding: 4px 0;
}

.ai-model-select option {
    font-weight: 400;
    padding: 4px 8px;
}

.ai-model-select:hover {
    background-color: #e8e8e8;
    border-color: #ccc;
}

.ai-model-select:focus {
    border-color: #667eea;
}

.ai-model-select option {
    background: white;
    color: #333;
    padding: 8px;
}

.ai-widget-actions {
    display: flex;
    gap: 4px;
}

.ai-widget-actions a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: white;
    opacity: 0.8;
    transition: all 0.2s;
}

.ai-widget-actions a:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

.ai-widget-actions a i {
    font-size: 18px;
}

/* Body del Widget */
.ai-widget-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f8f9fa;
}

/* Texto Original (colapsable) */
.ai-widget-original {
    background: white;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid #e0e0e0;
    overflow: hidden;
}

.ai-widget-original-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    background: #fafafa;
    transition: background 0.2s;
}

.ai-widget-original-header:hover {
    background: #f0f0f0;
}

.ai-widget-original-header span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-widget-original-content {
    padding: 10px 12px;
    font-size: 13px;
    color: #333;
    border-top: 1px solid #e0e0e0;
    overflow-y: auto;
    line-height: 1.5;
}

/* Estilos para HTML formateado en texto original */
.ai-widget-original-content p {
    margin: 0 0 8px 0;
}
.ai-widget-original-content p:last-child {
    margin-bottom: 0;
}
.ai-widget-original-content ul,
.ai-widget-original-content ol {
    margin: 4px 0;
    padding-left: 20px;
}
.ai-widget-original-content li {
    margin: 2px 0;
}
.ai-widget-original-content strong {
    font-weight: 600;
}
.ai-widget-original-content em {
    font-style: italic;
}

.ai-widget-original.collapsed .ai-widget-original-content {
    display: none;
}

.ai-widget-original.collapsed .ai-toggle-icon {
    transform: rotate(-90deg);
}

.ai-toggle-icon {
    transition: transform 0.2s;
}

/* Área de conversación */
.ai-widget-conversation {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Mensajes */
.ai-message {
    max-width: 95%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

.ai-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message.assistant {
    align-self: flex-start;
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    position: relative;
}

.ai-message-content {
    margin-bottom: 10px;
}

/* Contenedor de botones de acción */
.ai-message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

/* Estilo base para todos los botones de acción */
.ai-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: none;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.9;
    white-space: nowrap;
}

.ai-action-btn:hover {
    opacity: 1;
    transform: translateY(-1px);
}

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

.ai-action-btn i {
    font-size: 14px;
}

/* Botón "Usar" - Color primario (púrpura/gradiente) */
.ai-message-use-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ai-message-use-btn:hover {
    box-shadow: 0 3px 8px rgba(102, 126, 234, 0.4);
}

/* Botón "Copiar" - Color secundario (teal) */
.ai-message-copy-btn {
    background: #26a69a;
    color: white;
}

.ai-message-copy-btn:hover {
    background: #00897b;
    box-shadow: 0 3px 8px rgba(38, 166, 154, 0.35);
}

/* Botón "Insertar debajo" - Color terciario (azul) */
.ai-message-append-btn {
    background: #42a5f5;
    color: white;
}

.ai-message-append-btn:hover {
    background: #1e88e5;
    box-shadow: 0 3px 8px rgba(66, 165, 245, 0.35);
}

/* Estilos legacy para compatibilidad (botón insert antiguo) */
.ai-message-insert-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.85;
}

.ai-message-insert-btn:hover {
    opacity: 1;
    transform: scale(1.02);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

.ai-message-insert-btn i {
    font-size: 14px;
}

/* Responsive: en pantallas pequeñas, los botones ocupan menos espacio */
@media (max-width: 480px) {
    .ai-message-actions {
        gap: 4px;
    }
    
    .ai-action-btn {
        padding: 4px 8px;
        font-size: 10px;
    }
    
    .ai-action-btn i {
        font-size: 12px;
    }
    
    /* Ocultar texto en pantallas muy pequeñas, solo mostrar iconos */
    .ai-action-btn span {
        display: none;
    }
}

/* Formato Markdown en mensajes del asistente */
.ai-message.assistant p {
    margin: 0 0 8px 0;
}

.ai-message.assistant p:last-child {
    margin-bottom: 0;
}

.ai-message.assistant strong {
    font-weight: 600;
    color: #333;
}

.ai-message.assistant em {
    font-style: italic;
    color: #555;
}

.ai-message.assistant ul,
.ai-message.assistant ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-message.assistant li {
    margin-bottom: 4px;
}

.ai-message.assistant code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    color: #e91e63;
}

/* Indicador de escritura */
.ai-widget-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    color: #666;
    font-size: 12px;
}

.ai-typing-indicator {
    display: flex;
    gap: 4px;
}

.ai-typing-indicator span {
    width: 6px;
    height: 6px;
    background: #667eea;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.ai-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Error */
.ai-widget-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #ffebee;
    border-radius: 8px;
    color: #c62828;
    font-size: 12px;
}

/* Footer del Widget */
.ai-widget-footer {
    padding: 12px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

/* Sugerencias */
.ai-widget-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.ai-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    font-size: 11px;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.ai-chip:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.ai-chip i {
    font-size: 14px;
}

/* Input wrapper */
.ai-widget-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-widget-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-widget-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.ai-widget-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ai-widget-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.ai-widget-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-widget-send i {
    font-size: 18px;
}

/* Acciones finales */
.ai-widget-final-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e8e8e8;
}

.ai-widget-final-actions .btn-flat {
    color: #666;
}

.ai-widget-final-actions .btn {
    font-size: 12px;
}

/* Animaciones */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   Temas oscuros
   ======================================== */

[data-theme="black"] .ai-widget,
[data-theme="medusa"] .ai-widget {
    background: var(--card-background);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="black"] .ai-widget-body,
[data-theme="medusa"] .ai-widget-body {
    background: var(--background-color);
}

[data-theme="black"] .ai-widget-original,
[data-theme="medusa"] .ai-widget-original {
    background: var(--card-background);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="black"] .ai-widget-original-header,
[data-theme="medusa"] .ai-widget-original-header {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
}

[data-theme="black"] .ai-widget-original-content,
[data-theme="medusa"] .ai-widget-original-content {
    color: var(--text-color);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="black"] .ai-message.assistant,
[data-theme="medusa"] .ai-message.assistant {
    background: var(--card-background);
    color: var(--text-color);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="black"] .ai-widget-footer,
[data-theme="medusa"] .ai-widget-footer {
    background: var(--card-background);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="black"] .ai-chip,
[data-theme="medusa"] .ai-chip {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

[data-theme="black"] .ai-widget-input,
[data-theme="medusa"] .ai-widget-input {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

/* ========================================
   Responsive
   ======================================== */

@media only screen and (max-width: 600px) {
    .ai-widget {
        width: calc(100% - 20px);
        right: 10px;
        left: 10px;
        bottom: 10px;
        max-height: 60vh;
    }

    .ai-widget-body {
        max-height: 200px;
    }

    .ai-widget-suggestions {
        gap: 4px;
    }

    .ai-chip {
        font-size: 10px;
        padding: 3px 8px;
    }
}

/* Posición cuando está dentro del sidenav */
#slide-out .ai-widget {
    position: fixed;
    bottom: 20px;
    right: auto;
    left: 320px;
}

@media only screen and (max-width: 992px) {
    #slide-out .ai-widget {
        left: 10px;
        right: 10px;
        width: auto;
    }
}

/* ========================================
   AI Buttons para Comentarios
   ======================================== */

/* Botón de IA en el editor de nuevos comentarios */
.ai-comment-btn,
.ai-comment-edit-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: auto;
    height: 36px;
    padding: 0 12px;
    border-radius: 4px;
    background: transparent;
    color: #7c4dff;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid rgba(124, 77, 255, 0.3);
    vertical-align: middle;
}

.ai-comment-btn:hover,
.ai-comment-edit-btn:hover {
    background: rgba(124, 77, 255, 0.08);
    border-color: #7c4dff;
}

.ai-comment-btn:active,
.ai-comment-edit-btn:active {
    background: rgba(124, 77, 255, 0.15);
}

.ai-comment-btn i,
.ai-comment-edit-btn i {
    font-size: 18px;
    line-height: 1;
}

.ai-comment-btn.disabled,
.ai-comment-edit-btn.disabled {
    color: #bdbdbd;
    border-color: #e0e0e0;
    cursor: not-allowed;
    opacity: 0.5;
}

.ai-comment-btn.disabled:hover,
.ai-comment-edit-btn.disabled:hover {
    background: transparent;
    color: #bdbdbd;
}

/* Alinear botón de IA con los botones de guardar/cancelar en edición de comentarios */
.comment-wrapper .ai-comment-edit-btn {
    margin-bottom: 0;
    vertical-align: middle;
}
