/**
 * KOAEE Response Styling
 * Styles pour les réponses formatées KOAEE avec support markdown
 */

/* ===== Container principal ===== */
.koaee-response {
    max-width: 900px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-size: 16px;
    line-height: 1.7;
    color: #2c3e50;
    background: #ffffff;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    animation: fadeInUp 0.4s ease-out;
}

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

/* ===== Bande média (images + sources) ===== */
.koaee-media-strip {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding: 12px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 8px;
    flex-wrap: wrap;
}

.koaee-images {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.koaee-images img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
}

.koaee-images img:hover {
    transform: scale(1.05);
}

.koaee-sources-badge {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.koaee-sources-badge:hover {
    background: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* ===== Contenu markdown ===== */
.koaee-response-content {
    margin-bottom: 24px;
}

/* Titres */
.koaee-response-content h1 {
    font-size: 32px;
    font-weight: 700;
    color: #1a202c;
    margin: 0 0 24px 0;
    padding-bottom: 12px;
    border-bottom: 3px solid #667eea;
}

.koaee-response-content h2 {
    font-size: 24px;
    font-weight: 600;
    color: #2d3748;
    margin: 32px 0 16px 0;
    padding-left: 12px;
    border-left: 4px solid #667eea;
}

.koaee-response-content h3 {
    font-size: 20px;
    font-weight: 600;
    color: #4a5568;
    margin: 24px 0 12px 0;
}

/* Section réflexion */
.koaee-response-content h2:has(+ ul):first-of-type,
.koaee-response-content h2:contains("🤔") {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 8px;
    border-left: none;
    margin: 0 0 20px 0;
}

/* Paragraphes */
.koaee-response-content p {
    margin: 16px 0;
    text-align: justify;
}

.koaee-response-content p:first-of-type {
    font-size: 18px;
    font-weight: 400;
    color: #1a202c;
}

/* Emphase */
.koaee-response-content strong {
    font-weight: 600;
    color: #667eea;
}

.koaee-response-content em {
    font-style: italic;
    color: #718096;
}

/* Listes */
.koaee-response-content ul {
    list-style: none;
    padding-left: 0;
    margin: 16px 0;
}

.koaee-response-content ul li {
    position: relative;
    padding-left: 28px;
    margin: 12px 0;
    line-height: 1.6;
}

.koaee-response-content ul li::before {
    content: "•";
    position: absolute;
    left: 8px;
    color: #667eea;
    font-size: 20px;
    line-height: 1.6;
}

.koaee-response-content ol {
    padding-left: 28px;
    margin: 16px 0;
}

.koaee-response-content ol li {
    margin: 12px 0;
    padding-left: 8px;
}

.koaee-response-content ol li::marker {
    color: #667eea;
    font-weight: 600;
}

/* Blocs de code */
.koaee-response-content pre {
    background: #2d3748;
    border-radius: 8px;
    padding: 20px;
    overflow-x: auto;
    margin: 20px 0;
}

.koaee-response-content code {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
}

.koaee-response-content :not(pre) > code {
    background: #edf2f7;
    color: #d63384;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
}

/* Formules mathématiques */
.koaee-response-content .katex {
    font-size: 1.1em;
}

.koaee-response-content .katex-display {
    margin: 24px 0;
    padding: 16px;
    background: #f7fafc;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

/* Blockquotes */
.koaee-response-content blockquote {
    margin: 24px 0;
    padding: 16px 20px;
    background: #f7fafc;
    border-left: 4px solid #667eea;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: #4a5568;
}

/* Tableaux */
.koaee-response-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 24px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.koaee-response-content th {
    background: #667eea;
    color: white;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
}

.koaee-response-content td {
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.koaee-response-content tr:hover {
    background: #f7fafc;
}

/* ===== Boutons d'action ===== */
.koaee-response-actions {
    display: flex;
    gap: 12px;
    margin: 24px 0;
    padding: 16px 0;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
}

.koaee-action-btn {
    padding: 10px 20px;
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.koaee-action-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

/* ===== Test your knowledge ===== */
.koaee-test-knowledge {
    margin: 32px 0;
    padding: 24px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-radius: 12px;
    color: white;
}

.koaee-test-knowledge h3 {
    margin: 0 0 16px 0;
    font-size: 20px;
    font-weight: 600;
}

.koaee-test-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.koaee-test-btn {
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.95);
    color: #f5576c;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.koaee-test-btn:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

/* ===== Métadonnées ===== */
.koaee-metadata {
    margin-top: 24px;
    padding: 12px 0;
    font-size: 14px;
    color: #718096;
    text-align: center;
    border-top: 1px solid #e2e8f0;
}

/* ===== Modal sources ===== */
.koaee-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.koaee-modal-content {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s;
}

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

.koaee-modal-content h2 {
    margin: 0 0 24px 0;
    color: #1a202c;
}

.koaee-sources-list {
    list-style: none;
    padding: 0;
    margin: 0 0 24px 0;
}

.koaee-sources-list li {
    margin: 16px 0;
    padding: 16px;
    background: #f7fafc;
    border-radius: 8px;
    transition: all 0.2s;
}

.koaee-sources-list li:hover {
    background: #edf2f7;
    transform: translateX(4px);
}

.koaee-sources-list a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    font-size: 16px;
}

.koaee-sources-list a:hover {
    text-decoration: underline;
}

.koaee-sources-list p {
    margin: 8px 0 0 0;
    font-size: 14px;
    color: #4a5568;
}

.koaee-modal-content button {
    padding: 12px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.koaee-modal-content button:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .koaee-response {
        padding: 20px;
        border-radius: 0;
    }

    .koaee-response-content h1 {
        font-size: 26px;
    }

    .koaee-response-content h2 {
        font-size: 20px;
    }

    .koaee-response-content h3 {
        font-size: 18px;
    }

    .koaee-response-actions {
        flex-wrap: wrap;
    }

    .koaee-action-btn {
        flex: 1 1 calc(50% - 6px);
        min-width: 140px;
    }

    .koaee-modal-content {
        margin: 20px;
        padding: 24px;
    }
}

/* ===== Dark mode support ===== */
@media (prefers-color-scheme: dark) {
    .koaee-response {
        background: #1a202c;
        color: #e2e8f0;
    }

    .koaee-response-content h1,
    .koaee-response-content h2,
    .koaee-response-content h3 {
        color: #f7fafc;
    }

    .koaee-response-content p:first-of-type {
        color: #e2e8f0;
    }

    .koaee-response-content :not(pre) > code {
        background: #2d3748;
        color: #f687b3;
    }

    .koaee-response-content blockquote {
        background: #2d3748;
        color: #cbd5e0;
    }

    .koaee-response-content .katex-display {
        background: #2d3748;
    }

    .koaee-action-btn {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .koaee-modal-content {
        background: #1a202c;
        color: #e2e8f0;
    }

    .koaee-sources-list li {
        background: #2d3748;
    }

    .koaee-sources-list li:hover {
        background: #4a5568;
    }
}

/* ===== Animations ===== */
.koaee-response-content > * {
    animation: fadeInContent 0.5s ease-out forwards;
    opacity: 0;
}

.koaee-response-content > *:nth-child(1) { animation-delay: 0.1s; }
.koaee-response-content > *:nth-child(2) { animation-delay: 0.2s; }
.koaee-response-content > *:nth-child(3) { animation-delay: 0.3s; }
.koaee-response-content > *:nth-child(4) { animation-delay: 0.4s; }
.koaee-response-content > *:nth-child(5) { animation-delay: 0.5s; }

@keyframes fadeInContent {
    to {
        opacity: 1;
    }
}

/* ===== Print styles ===== */
@media print {
    .koaee-response {
        box-shadow: none;
        padding: 0;
    }

    .koaee-response-actions,
    .koaee-test-knowledge,
    .koaee-sources-badge {
        display: none;
    }

    .koaee-response-content {
        color: black;
    }
}

/* ===== Attribution Unsplash (requis par guidelines) ===== */
.koaee-image-attribution {
    display: none;
}

.koaee-image-attribution a {
    color: rgba(0, 183, 255, 0.9);
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 183, 255, 0.3);
    transition: all 0.2s ease;
}

.koaee-image-attribution a:hover {
    color: rgba(64, 217, 255, 1);
    border-bottom-color: rgba(0, 183, 255, 0.6);
}

.koaee-image-item {
    position: relative;
    display: block;
    background: transparent;
    border-radius: 0;
    border: none !important;
    padding: 0;
    transition: opacity 0.2s ease;
    flex: 0 0 auto;
    width: 100px;
    height: 75px;
    overflow: hidden;
}

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

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

/* Force images grid en ligne */
.koaee-images-grid,
.koaee-images-section .koaee-images-grid {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px;
}
