/* SerenIA - Assistant Pédagogique */
/* Utilise les variables CSS du site pour la cohérence */

.seren-ia {
    width: 100%;
    height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
    background: var(--color-gray-light);
}

.seren-ia__container {
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--color-white);
    border-radius: var(--border-radius-2xl);
    overflow: hidden;
}

/* Header */
.seren-ia__header {
    padding: var(--spacing-lg) var(--spacing-xl);
    border-bottom: var(--border-width-thin) solid var(--color-gray);
    background: var(--color-white);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.seren-ia__title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-black);
    margin: 0;
}

.seren-ia__subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    margin: var(--spacing-xs) 0 0 0;
}

.seren-ia__header-stats {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.seren-ia__stat-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-lg);
    font-size: var(--font-size-sm);
    transition: all 300ms ease;
}

.seren-ia__stat-item:hover {
    opacity: 0.8;
}

/* Tokens - Background bleu subtil */
.seren-ia__stat-item:first-child {
    background: rgba(12, 129, 228, 0.04);
}

/* Énergie - Background jaune subtil */
.seren-ia__stat-item:last-child {
    background: rgba(255, 193, 7, 0.06);
}

.seren-ia__stat-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.seren-ia__stat-icon--tokens svg {
    width: 16px;
    height: 16px;
    color: rgba(12, 129, 228, 0.7);
}

.seren-ia__stat-icon--energy svg {
    width: 18px;
    height: 18px;
    color: rgba(245, 124, 0, 0.7);
}

.seren-ia__stat-content {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-xs);
}

.seren-ia__stat-item:first-child .seren-ia__stat-value {
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
    font-size: var(--font-size-sm);
}

.seren-ia__stat-item:first-child .seren-ia__stat-label {
    color: rgba(12, 129, 228, 0.6);
    font-size: var(--font-size-xs);
}

.seren-ia__stat-item:last-child .seren-ia__stat-value {
    font-weight: var(--font-weight-semibold);
    color: #f57c00;
    font-size: var(--font-size-sm);
}

.seren-ia__stat-item:last-child .seren-ia__stat-label {
    color: rgba(245, 124, 0, 0.6);
    font-size: var(--font-size-xs);
}

/* Messages Container - Les nouveaux messages arrivent en bas */
.seren-ia__messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xl);
    display: flex;
    flex-direction: column; /* Ordre normal: nouveaux messages en bas */
    gap: var(--spacing-lg);
    background: var(--color-white);
}

/* Welcome Screen */
.seren-ia__welcome {
    max-width: 600px;
    margin: auto; /* Centré verticalement */
    text-align: center;
    padding: var(--spacing-2xl) var(--spacing-lg);
}

.seren-ia__welcome-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.seren-ia__welcome-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-black);
    margin: 0 0 var(--spacing-md) 0;
}

.seren-ia__welcome-description {
    font-size: var(--font-size-base);
    color: var(--color-text-medium);
    margin: 0 0 var(--spacing-lg) 0;
    line-height: var(--line-height-relaxed);
}

.seren-ia__welcome-features {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
    text-align: left;
}

.seren-ia__welcome-feature {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-medium);
    line-height: var(--line-height-relaxed);
}

.seren-ia__welcome-feature-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    background: #ecfdf5;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.seren-ia__welcome-feature-icon svg {
    color: var(--color-success);
}

/* Section sécurité - Simple et épuré */
.seren-ia__security {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    background: #ecfdf5;
    border: var(--border-width-thin) solid #a7f3d0;
    border-radius: var(--border-radius-md);
}

.seren-ia__security-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seren-ia__security-icon svg {
    color: var(--color-success);
}

.seren-ia__security-text {
    font-size: var(--font-size-sm);
    color: #065f46;
    line-height: var(--line-height-relaxed);
}

/* Messages - Assistant LEFT, User RIGHT */
.seren-ia__message {
    display: flex;
    gap: var(--spacing-md);
    align-items: flex-start;
    animation: slideUp 0.3s ease-out;
}

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

/* Assistant = LEFT */
.seren-ia__message--assistant {
    justify-content: flex-start;
}

/* User = RIGHT */
.seren-ia__message--user {
    justify-content: flex-end;
}

.seren-ia__message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.seren-ia__message-avatar--user {
    background: var(--gradient-main);
    color: var(--color-white);
    order: 2; /* Avatar à droite pour user */
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
}

.seren-ia__message-avatar--assistant {
    background: transparent;
}

.seren-ia__message-avatar--assistant svg {
    width: 100%;
    height: 100%;
    max-width: 28px;
    max-height: 28px;
}

.seren-ia__message-body {
    max-width: 70%;
    position: relative;
}

.seren-ia__message-content {
    color: var(--color-black);
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    word-wrap: break-word;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--border-radius-lg);
}

/* Style pour utilisateur */
.seren-ia__message--user .seren-ia__message-content {
    background: var(--gradient-main);
    color: var(--color-white);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 var(--border-radius-lg);
}

/* Style pour assistant */
.seren-ia__message--assistant .seren-ia__message-content {
    background: var(--color-gray-light);
    color: var(--color-black);
    border: var(--border-width-thin) solid var(--color-gray);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) var(--border-radius-lg) 0;
}

.seren-ia__message-content h1 {
    margin: var(--spacing-lg) 0 var(--spacing-md) 0;
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-xl);
    color: var(--color-black);
    border-bottom: 2px solid var(--color-gray);
    padding-bottom: var(--spacing-sm);
}

.seren-ia__message-content h2 {
    margin: var(--spacing-md) 0 var(--spacing-sm) 0;
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-lg);
    color: var(--color-black);
}

.seren-ia__message-content h3 {
    margin: var(--spacing-md) 0 var(--spacing-sm) 0;
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-base);
    color: var(--color-text-medium);
}

.seren-ia__message-content p {
    margin: var(--spacing-sm) 0;
    line-height: var(--line-height-relaxed);
}

.seren-ia__message-content strong {
    font-weight: var(--font-weight-semibold);
    color: var(--color-black);
}

.seren-ia__message-content em {
    font-style: italic;
    color: var(--color-text-medium);
}

.seren-ia__message-content code {
    background: rgba(0,0,0,0.08);
    padding: 2px 6px;
    border-radius: var(--border-radius-sm);
    font-family: 'Courier New', monospace;
    font-size: var(--font-size-sm);
    color: #d63384;
}

.seren-ia__message--user .seren-ia__message-content code {
    background: rgba(255,255,255,0.2);
    color: var(--color-white);
}

.seren-ia__message-content pre {
    background: #1f2937;
    color: #f3f4f6;
    padding: var(--spacing-md);
    border-radius: var(--border-radius-md);
    overflow-x: auto;
    margin: var(--spacing-md) 0;
}

.seren-ia__message-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.seren-ia__message-content ul,
.seren-ia__message-content ol {
    padding-left: var(--spacing-xl);
    margin: var(--spacing-sm) 0;
    line-height: var(--line-height-relaxed);
}

.seren-ia__message-content li {
    margin: 2px 0;
    padding-left: var(--spacing-xs);
}

.seren-ia__message-content ul li {
    list-style-type: disc;
}

.seren-ia__message-content ol li {
    list-style-type: decimal;
}

/* Listes imbriquées */
.seren-ia__message-content ul ul,
.seren-ia__message-content ol ul,
.seren-ia__message-content ul ol,
.seren-ia__message-content ol ol {
    margin: var(--spacing-xs) 0;
    padding-left: var(--spacing-lg);
}

.seren-ia__message-content blockquote {
    border-left: 4px solid var(--color-primary);
    padding-left: var(--spacing-md);
    margin: var(--spacing-md) 0;
    color: var(--color-text-medium);
    font-style: italic;
}

/* Lien de téléchargement d'image */
.seren-ia__message-content .seren-ia__download-link {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--gradient-main);
    color: var(--color-white);
    text-decoration: none;
    border-radius: var(--border-radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    transition: var(--transition-fast);
    margin-top: var(--spacing-sm);
}

.seren-ia__message-content .seren-ia__download-link:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Animation du spinner de téléchargement */
.seren-ia__spinner {
    animation: spin 1s linear infinite;
}

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

.seren-ia__message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--spacing-md) 0;
}

.seren-ia__message-content table th,
.seren-ia__message-content table td {
    border: var(--border-width-thin) solid var(--color-gray);
    padding: var(--spacing-sm);
    text-align: left;
}

.seren-ia__message-content table th {
    background: var(--color-gray-light);
    font-weight: var(--font-weight-semibold);
}

.seren-ia__message-content hr {
    border: none;
    border-top: var(--border-width-thin) solid var(--color-gray);
    margin: var(--spacing-lg) 0;
}

.seren-ia__message-files {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.seren-ia__message-file {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: rgba(0,0,0,0.04);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
}

/* Typing Indicator - Animation de vague avec 3 points */
.seren-ia__typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.seren-ia__typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-primary);
    animation: wave 1.4s ease-in-out infinite;
}

.seren-ia__typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.seren-ia__typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.seren-ia__typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes wave {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Copy Button */
.seren-ia__copy-btn {
    position: absolute;
    top: -4px;
    right: 0;
    background: var(--color-white);
    border: var(--border-width-thin) solid var(--color-gray);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-xs);
    cursor: pointer;
    opacity: 0;
    transition: var(--transition-fast);
    color: var(--color-text-medium);
}

.seren-ia__message-body:hover .seren-ia__copy-btn {
    opacity: 1;
}

.seren-ia__copy-btn:hover {
    background: var(--color-gray-light);
    color: var(--color-black);
}

/* Token Badge */
.seren-ia__message-tokens {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    margin-top: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--color-gray-light);
    border-radius: var(--border-radius-sm);
}

/* Input Area */
.seren-ia__input-wrapper {
    border-top: var(--border-width-thin) solid var(--color-gray);
    background: var(--color-white);
    padding: var(--spacing-lg) var(--spacing-xl) var(--spacing-xl);
    flex-shrink: 0;
}

.seren-ia__footer-disclaimer {
    text-align: center;
    padding: var(--spacing-sm) 0;
    font-size: 11px;
    color: var(--color-text-light);
    line-height: var(--line-height-normal);
}

/* Files Container */
.seren-ia__files {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.seren-ia__file-tag {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-gray-light);
    border: var(--border-width-thin) solid var(--color-gray);
    border-radius: var(--border-radius-md);
    font-size: var(--font-size-sm);
}

.seren-ia__file-tag-name {
    color: var(--color-text-medium);
}

.seren-ia__file-tag-remove {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--color-text-light);
    display: flex;
    align-items: center;
    transition: var(--transition-fast);
}

.seren-ia__file-tag-remove:hover {
    color: var(--color-error);
}

/* Input Container */
.seren-ia__input-container {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
    background: var(--color-white);
    border: var(--border-width-medium) solid var(--color-gray);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-sm);
    transition: var(--transition-fast);
}

.seren-ia__input-container:focus-within {
    border-color: var(--color-primary);
}

.seren-ia__attach-btn,
.seren-ia__send-btn {
    background: none;
    border: none;
    padding: var(--spacing-sm);
    cursor: pointer;
    color: var(--color-text-medium);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-sm);
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.seren-ia__attach-btn:hover {
    background: var(--color-gray-light);
    color: var(--color-black);
}

.seren-ia__send-btn {
    background: var(--gradient-main);
    color: var(--color-white);
}

.seren-ia__send-btn:hover:not(:disabled) {
    opacity: 0.9;
}

.seren-ia__send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.seren-ia__input {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    outline: none;
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    padding: var(--spacing-sm);
    color: var(--color-black);
    font-family: var(--font-primary);
    max-height: 200px;
    overflow-y: auto;
}

.seren-ia__input::placeholder {
    color: var(--color-text-light);
}

/* Token Notification - Animation simple vers le haut */
.seren-ia__token-notification {
    position: fixed;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-error);
    z-index: var(--z-index-notification);
    pointer-events: none;
}

/* Energy Notification - Animation simple vers le haut */
.seren-ia__energy-notification {
    position: fixed;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: #ff9800;
    z-index: var(--z-index-notification);
    pointer-events: none;
}

/* Animation unique qui monte vers le haut (plus rapide) */
@keyframes flyUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-80px) scale(0.9);
    }
}

.seren-ia__token-notification.animating,
.seren-ia__energy-notification.animating {
    animation: flyUp 1s ease-out forwards;
}

/* Scrollbar */
.seren-ia__messages::-webkit-scrollbar {
    width: 6px;
}

.seren-ia__messages::-webkit-scrollbar-track {
    background: var(--color-gray-light);
}

.seren-ia__messages::-webkit-scrollbar-thumb {
    background: var(--color-gray);
    border-radius: var(--border-radius-sm);
}

.seren-ia__messages::-webkit-scrollbar-thumb:hover {
    background: var(--color-gray-dark);
}

/* Responsive */
@media (max-width: 768px) {
    .seren-ia__header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
        padding: var(--spacing-md);
    }

    .seren-ia__messages {
        padding: var(--spacing-md);
    }

    .seren-ia__input-wrapper {
        padding: var(--spacing-md);
    }

    .seren-ia__message-body {
        max-width: 85%;
    }
}
