/**
 * KOAEE Thinking Display Styles
 * Intégré au style général Koaee - Sombre avec accent bleu
 */

/* ============================================
   ÉTAPES DE THINKING (horizontale sur une ligne)
   ============================================ */

.koaee-thinking-steps-container {
    display: flex;
    flex-wrap: nowrap; /* Force sur une seule ligne */
    gap: 6px; /* Réduit de 8px à 6px */
    margin-bottom: 8px; /* Réduit de 12px à 8px */
    padding: 0;
    overflow-x: auto; /* Scroll horizontal si trop d'étapes */
    scroll-behavior: smooth;
    justify-content: center; /* Centrer les thinking steps */

    /* Hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.koaee-thinking-steps-container::-webkit-scrollbar {
    display: none;
}

/* Enlever le gros cadre autour du message contenant les thinking steps */
.koaee_message.koaee_gpt:has(.koaee-thinking-steps-container) {
    border: none !important;
    box-shadow: none !important;
}

/* Enlever le double cadre autour des réponses (garder seulement le wrapper) */
.koaee_message.koaee-response-message {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.koaee-thinking-step {
    background: linear-gradient(
        to bottom right,
        rgba(0, 183, 255, 0.05),
        rgba(0, 0, 0, 0.1)
    );
    border: 1px solid rgba(0, 183, 255, 0.3);
    border-radius: 3px;
    padding: 3px 7px; /* Réduit de 4px 8px à 3px 7px */
    display: inline-flex;
    align-items: center;
    gap: 5px; /* Réduit de 6px à 5px */
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 4px rgba(0, 183, 255, 0.1);
    flex: 0 1 auto;
}

.koaee-thinking-step.visible {
    opacity: 1;
    transform: scale(1);
}

.koaee-thinking-step.completed {
    background: linear-gradient(
        to bottom right,
        rgba(0, 183, 255, 0.08),
        rgba(0, 0, 0, 0.15)
    );
}

/* Version compacte pour affichage horizontal */
.koaee-thinking-step-details {
    display: none; /* Cacher les détails en mode horizontal pour gagner de la place */
}

/* Icône de l'étape */
.koaee-thinking-step-icon {
    font-size: 12px; /* Réduit de 14px à 12px */
    flex-shrink: 0;
    width: 18px; /* Réduit de 22px à 18px */
    height: 18px; /* Réduit de 22px à 18px */
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 183, 255, 0.15);
    border-radius: 50%;
}

/* Contenu de l'étape */
.koaee-thinking-step-content {
    flex: 1;
    color: #ffffff;
}

.koaee-thinking-step-message {
    font-size: 10px; /* Réduit de 11px à 10px */
    font-weight: 600;
    color: #00b7ff;
    margin-bottom: 0;
}

.koaee-thinking-step-details {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.4;
}

/* Checkmark */
.koaee-thinking-step-check {
    flex-shrink: 0;
    width: 12px; /* Réduit de 14px à 12px */
    height: 12px; /* Réduit de 14px à 12px */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px; /* Réduit de 10px à 9px */
    color: #00b7ff;
    background: rgba(0, 183, 255, 0.15);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.koaee-thinking-step.completed .koaee-thinking-step-check {
    opacity: 1;
    transform: scale(1);
}

/* ============================================
   MESSAGE DE DÉBUT/FIN DE THINKING (supprimé)
   ============================================ */

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

/* ============================================
   LOGO GPT DANS LA RÉPONSE
   ============================================ */

.koaee_message.koaee-response-message {
    position: relative;
}

.koaee_message.koaee-response-message .koaee_gpt-icon {
    position: absolute;
    width: 18px; /* Réduit de 20px à 18px */
    height: 18px; /* Réduit de 20px à 18px */
    min-width: 18px;
    min-height: 18px;
    left: -10px; /* Réduit de -12px à -10px */
    top: -20px; /* Réduit de -25px à -20px */
    content: var(--koaee_gpt-icon-url);
}

/* ============================================
   CONTAINER DE RÉPONSE (sans scroll)
   ============================================ */

.koaee-response-wrapper {
    background: linear-gradient(
        to bottom right,
        rgba(26, 26, 26, 0.1),
        rgba(0, 0, 0, 0.2)
    );
    border: 1px solid rgba(0, 183, 255, 0.3);
    border-radius: 4px;
    padding: 12px; /* Réduit de 16px à 12px pour réduire la hauteur */
    box-shadow: 0 2px 8px rgba(0, 183, 255, 0.1), 0 4px 16px rgba(0, 183, 255, 0.05);
}

.koaee-response-final {
    color: #ffffff;
    line-height: 1.7;
    /* PAS de max-height ni overflow */
}

.koaee-response-final h1,
.koaee-response-final h2,
.koaee-response-final h3 {
    color: #00b7ff;
    margin-top: 12px; /* Réduit de 16px à 12px */
    margin-bottom: 6px; /* Réduit de 8px à 6px */
}

.koaee-response-final h1 {
    font-size: 1.5em;
    border-bottom: 2px solid rgba(0, 183, 255, 0.3);
    padding-bottom: 8px;
}

.koaee-response-final h2 {
    font-size: 1.3em;
}

.koaee-response-final h3 {
    font-size: 1.1em;
}

.koaee-response-final p {
    margin-bottom: 12px;
}

.koaee-response-final ul,
.koaee-response-final ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.koaee-response-final li {
    margin-bottom: 6px;
}

.koaee-response-final code {
    background: rgba(0, 183, 255, 0.1);
    border: 1px solid rgba(0, 183, 255, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.koaee-response-final pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 183, 255, 0.2);
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 12px;
}

.koaee-response-final pre code {
    background: none;
    border: none;
    padding: 0;
}

.koaee-response-final a {
    color: #00b7ff;
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 183, 255, 0.3);
    transition: all 0.2s;
}

.koaee-response-final a:hover {
    color: #40d9ff;
    border-bottom-color: #40d9ff;
}

.koaee-response-final strong {
    color: #00b7ff;
    font-weight: 600;
}

.koaee-response-final em {
    color: rgba(255, 255, 255, 0.9);
    font-style: italic;
}

/* ============================================
   IMAGES DANS LA RÉPONSE
   ============================================ */

.koaee-response-final img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid rgba(0, 183, 255, 0.3);
    margin: 12px 0;
    box-shadow: 0 4px 12px rgba(0, 183, 255, 0.15);
}

/* ============================================
   SOURCES
   ============================================ */

.koaee-sources-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 183, 255, 0.2);
}

.koaee-sources-title {
    color: #00b7ff;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
}

.koaee-source-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: rgba(0, 183, 255, 0.05);
    border-left: 2px solid rgba(0, 183, 255, 0.3);
    border-radius: 2px;
}

.koaee-source-number {
    color: #00b7ff;
    font-weight: 600;
    font-size: 12px;
    min-width: 20px;
}

.koaee-source-content {
    flex: 1;
}

.koaee-source-link {
    color: #00b7ff;
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    transition: color 0.2s;
}

.koaee-source-link:hover {
    color: #40d9ff;
}

.koaee-source-description {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    margin-top: 2px;
}

/* ============================================
   IMAGES SECTION
   ============================================ */

.koaee-images-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 183, 255, 0.2);
}

.koaee-images-title {
    color: #00b7ff;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
}

.koaee-images-grid {
    display: flex;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px;
}

.koaee-image-item {
    position: relative;
    border-radius: 0;
    overflow: hidden;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    flex: 0 0 auto;
    width: 100px;
    height: 75px;
}

.koaee-image-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.koaee-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: none;
    margin: 0;
}

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

@media (max-width: 768px) {
    .koaee-thinking-step {
        padding: 10px 12px;
    }

    .koaee-thinking-step-icon {
        font-size: 18px;
        width: 28px;
        height: 28px;
    }

    .koaee-thinking-step-message {
        font-size: 13px;
    }

    .koaee-thinking-step-details {
        font-size: 11px;
    }

    .koaee-response-final h1 {
        font-size: 1.3em;
    }

    .koaee-response-final h2 {
        font-size: 1.2em;
    }

    .koaee-images-grid {
        gap: 6px;
    }

    .koaee-image-item {
        width: 80px;
        height: 60px;
    }
}

/* ============================================
   DIAGRAMMES MERMAID
   ============================================ */

.koaee-response-final .mermaid,
.koaee-response-final .mermaid-diagram {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 183, 255, 0.3);
    border-radius: 0;
    padding: 24px 0;
    margin: 16px 0;
    text-align: center;
}

.koaee-response-final .mermaid svg,
.koaee-response-final .mermaid-diagram svg {
    max-width: 100%;
    height: auto;
    filter: drop-shadow(0 2px 8px rgba(0, 183, 255, 0.2));
}

/* ============================================
   FORMULES LATEX (KaTeX)
   ============================================ */

.koaee-response-final .katex {
    font-size: 1.1em;
}

.koaee-response-final .katex-display {
    margin: 16px 0;
    padding: 12px;
    background: rgba(0, 183, 255, 0.05);
    border-left: 3px solid #00b7ff;
    border-radius: 4px;
}

/* ============================================
   LOADER (mini spinner dans l'étape)
   ============================================ */

.koaee-loading-step {
    background: linear-gradient(
        to bottom right,
        rgba(0, 183, 255, 0.08),
        rgba(0, 0, 0, 0.15)
    ) !important;
}

.koaee-loading-step.completed {
    background: linear-gradient(
        to bottom right,
        rgba(0, 183, 255, 0.1),
        rgba(0, 0, 0, 0.2)
    ) !important;
}

.koaee-loading-step .koaee-thinking-step-icon {
    color: #00b7ff;
    font-weight: bold;
    font-size: 16px;
}

.koaee-loader-spinner-mini {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 183, 255, 0.3);
    border-top-color: #00b7ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   ERREURS
   ============================================ */

.koaee-error-message {
    background: linear-gradient(
        to bottom right,
        rgba(255, 50, 50, 0.1),
        rgba(0, 0, 0, 0.15)
    );
    border: 1px solid rgba(255, 50, 50, 0.3);
    border-radius: 4px;
    padding: 12px 16px;
    color: #ff6b6b;
    font-size: 13px;
    margin: 8px 0;
}

/* ============================================
   BANDE MEDIA (IMAGES + SOURCES)
   ============================================ */

.koaee-media-strip-message {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin-bottom: 16px;
}

.koaee-media-strip {
    position: relative;
    background: transparent;
    border-radius: 0;
    padding: 16px;
    overflow: hidden;
}

.koaee-images-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 4px;
    margin-bottom: 8px;

    /* Hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.koaee-images-scroll::-webkit-scrollbar {
    display: none;
}

.koaee-image-card {
    flex: 0 0 auto;
    width: 100px;
    height: 75px;
    border-radius: 0;
    border: none;
    overflow: hidden;
    background: #000;
    cursor: pointer;
    transition: opacity 0.2s;
}

.koaee-image-card:hover {
    opacity: 0.92;
}

.koaee-image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Badge Sources */
.koaee-sources-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    padding: 8px 16px;
    background: rgba(0, 183, 255, 0.9);
    border: 2px solid #00b7ff;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 183, 255, 0.3);
}

.koaee-sources-badge:hover {
    background: #00b7ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 183, 255, 0.5);
}

/* Modal Sources */
.koaee-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    animation: fadeIn 0.2s;
}

.koaee-sources-modal {
    background: #1a1a1a;
    border: 1px solid rgba(0, 183, 255, 0.3);
    border-radius: 12px;
    max-width: 700px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s;
}

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

.koaee-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(0, 183, 255, 0.2);
}

.koaee-modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: #00b7ff;
    margin: 0;
}

.koaee-modal-header button {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    font-size: 18px;
    color: #ffffff;
    transition: all 0.2s;
}

.koaee-modal-header button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.koaee-sources-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.koaee-source-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 8px;
    border: 1px solid rgba(0, 183, 255, 0.2);
    background: rgba(0, 183, 255, 0.05);
    text-decoration: none;
    transition: all 0.2s;
}

.koaee-source-item:hover {
    border-color: #00b7ff;
    background: rgba(0, 183, 255, 0.1);
    transform: translateX(4px);
}

.koaee-source-favicon {
    width: 24px;
    height: 24px;
    min-width: 24px;
    border-radius: 4px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px;
}

.koaee-source-content {
    flex: 1;
    min-width: 0;
}

.koaee-source-title {
    font-weight: 600;
    color: #ffffff;
    font-size: 14px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.koaee-source-description {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.koaee-source-url {
    font-size: 11px;
    color: #00b7ff;
}

.koaee-source-icon {
    font-size: 18px;
    color: rgba(0, 183, 255, 0.5);
    flex-shrink: 0;
}
