/* ═══════════════════════════════════════════
   MESSAGERIE (AGENT CONVERSATIONNEL)
   ═══════════════════════════════════════════ */

/* Header spécifique au chat */
.chat-page {
    /* Cache l'en-tête de page standard pour laisser la place au chat */
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0;
    overflow: hidden;
    /* Empêche le scrolling du body */
    background-color: var(--bg-color);
}

.chat-header {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-4);
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 10;
    box-shadow: 0 4px 20px oklch(35% 0 0);
}

.chat-header h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.chat-header .back-link {
    margin-bottom: 0;
    font-weight: 500;
}

.chat-status {
    font-size: 0.85rem;
    color: oklch(50% 0 0);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.chat-status::before {
    content: "";
    display: block;
    width: 8px;
    height: 8px;
    background-color: var(--color-green-600);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 oklch(59% 0.16 150);
    }

    70% {
        box-shadow: 0 0 0 6px oklch(59% 0.16 150);
    }

    100% {
        box-shadow: 0 0 0 0 oklch(59% 0.16 150);
    }
}

/* Zone des boutons de suggestions (Quick replies) */
.chat-suggestions {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4) 0;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
    /* Firefox */
}

.chat-suggestions::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.suggestion-btn {
    background-color: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 8px 16px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    color: var(--text-color);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.suggestion-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px oklch(90% 0 0);
}

:root[data-theme="dark"] .suggestion-btn:hover {
    box-shadow: 0 4px 12px oklch(10% 0 0);
}

/* Zone de la conversation */
.chat-window {
    flex-grow: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    scroll-behavior: smooth;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
}

.message.bot {
    align-self: flex-start;
}

.message-bubble {
    padding: var(--space-2) var(--space-3);
    border-radius: 18px;
    font-size: 1rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background-color: var(--accent-color);
    color: var(--text-inverted);
    border-bottom-right-radius: 4px;
}

.message.bot .message-bubble {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px oklch(35% 0 0);
}

/* Highlight markdown bold text inside chat */
.message.bot .message-bubble strong {
    color: var(--text-color);
    font-weight: 700;
}

.message-time {
    font-size: 0.75rem;
    color: oklch(60% 0 0);
    margin-top: 4px;
    align-self: flex-end;
}

.message.bot .message-time {
    align-self: flex-start;
}

/* Zone de frappe */
.chat-input-area {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-4);
    background-color: var(--card-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--space-2);
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.chat-input-wrapper {
    flex-grow: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-family: var(--font-main);
    font-size: 1rem;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    resize: none;
    min-height: 52px;
    max-height: 150px;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.4;
}

.chat-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent-color) 15%, var(--bg-color));
}

.chat-input::placeholder {
    color: oklch(60% 0 0);
}

.chat-send-btn {
    background-color: var(--accent-color);
    color: var(--text-inverted);
    border: none;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    background-color: var(--accent-hover);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--border-color);
}

.chat-send-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    margin-left: 4px;
    /* Centrage visuel */
}

/* Loading animation for bot */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 18px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: oklch(60% 0 0);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Responsiveness */
@media (max-width: 768px) {
    .chat-header h1 {
        font-size: 1.2rem;
    }

    .chat-header {
        padding: var(--space-2) var(--space-3);
    }

    .chat-window {
        padding: var(--space-2);
        max-width: 100%;
    }

    .chat-input-area {
        padding: var(--space-2) var(--space-3);
    }

    .message {
        max-width: 90%;
    }

    .theme-toggle {
        top: 12px;
        right: 12px;
    }

    .settings-toggle {
        display: none;
        /* Cache les réglages sur mobile pour gagner de la place en chat */
    }
}