/* ===========================================
   Component: Chat — Soelya
   Premium conversational UI
   =========================================== */

/* ---- Chat Section ---- */
.chat {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: calc(var(--header-height) + var(--space-8)) var(--space-6) var(--space-6);
    display: none;
}

.chat--active {
    display: block;
}

.chat__messages {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

/* ---- Message Bubble ---- */
.chat__message {
    display: flex;
    gap: var(--space-3);
    max-width: 85%;
    opacity: 0;
    animation: msgAppear 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.chat__message--user {
    align-self: flex-end;
    flex-direction: row-reverse;
    animation-name: msgAppearRight;
}

.chat__message--bot {
    align-self: flex-start;
    animation-name: msgAppearLeft;
}

@keyframes msgAppearLeft {
    from { opacity: 0; transform: translateX(-16px) translateY(8px); }
    to   { opacity: 1; transform: translateX(0) translateY(0); }
}

@keyframes msgAppearRight {
    from { opacity: 0; transform: translateX(16px) translateY(8px); }
    to   { opacity: 1; transform: translateX(0) translateY(0); }
}

/* ---- Avatar ---- */
.chat__avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    margin-top: 2px;
    transition: transform 0.3s ease;
}

.chat__message:hover .chat__avatar {
    transform: scale(1.08);
}

.chat__avatar--user {
    background: linear-gradient(135deg, var(--color-accent), #5a3fd4);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 12px rgba(124, 92, 252, 0.3);
}

.chat__avatar--bot {
    background: var(--color-bg-secondary);
    border: 1px solid rgba(124, 92, 252, 0.2);
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 12px rgba(124, 92, 252, 0.15);
}

.chat__avatar--bot::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: var(--radius-full);
    background: conic-gradient(from 0deg, var(--color-accent), transparent, var(--color-accent));
    opacity: 0;
    transition: opacity 0.6s ease;
    z-index: -1;
    animation: avatarGlow 3s linear infinite;
}

.chat__message--bot:last-child .chat__avatar--bot::before {
    opacity: 0.6;
}

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

.chat__avatar--bot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ---- Bubble ---- */
.chat__bubble {
    padding: var(--space-3) var(--space-5);
    border-radius: 20px;
    font-size: var(--font-size-base);
    line-height: 1.75;
    word-wrap: break-word;
    position: relative;
}

/* User bubble — gradient accent */
.chat__message--user .chat__bubble {
    background: linear-gradient(135deg, var(--color-accent) 0%, #5a3fd4 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow:
        0 2px 16px rgba(124, 92, 252, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Bot bubble — glassmorphism premium */
.chat__message--bot .chat__bubble {
    background: rgba(22, 22, 31, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(124, 92, 252, 0.1);
    color: var(--color-text-primary);
    border-bottom-left-radius: 6px;
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.03);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.chat__message--bot:hover .chat__bubble {
    border-color: rgba(124, 92, 252, 0.2);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.3),
        0 0 20px rgba(124, 92, 252, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.chat__bubble strong {
    font-weight: 600;
    color: var(--color-accent-hover);
}

/* ---- Timestamp (optional future) ---- */
.chat__time {
    font-size: 0.68rem;
    color: var(--color-text-tertiary);
    margin-top: var(--space-1);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat__message:hover .chat__time {
    opacity: 1;
}

/* ---- Typing Indicator ---- */
.chat__typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: var(--space-3) var(--space-4);
}

.chat__typing-dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: var(--color-accent);
    opacity: 0.4;
    animation: typingPulse 1.4s ease-in-out infinite;
}

.chat__typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat__typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
    0%, 60%, 100% { transform: scale(1); opacity: 0.3; }
    30% { transform: scale(1.4); opacity: 1; }
}

/* ---- Cursor blink for typing effect ---- */
.chat__cursor {
    display: inline-block;
    width: 2px;
    height: 1.15em;
    background: var(--color-accent);
    margin-left: 2px;
    vertical-align: text-bottom;
    border-radius: 1px;
    animation: cursorBlink 0.9s steps(2) infinite;
    box-shadow: 0 0 6px var(--color-accent-glow);
}

@keyframes cursorBlink {
    0% { opacity: 1; }
    50% { opacity: 0; }
}

/* ---- Input Area ---- */
/* En mode hero : dans le flux, sous les suggestions */
.chat__input-area {
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-6) var(--space-8);
}

/* En mode chat : fixe en bas */
body.chat-active .chat__input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: none;
    z-index: 50;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid rgba(124, 92, 252, 0.08);
    padding: var(--space-4) var(--space-6);
}

body.chat-active .chat__input-area .search {
    max-width: 780px;
    margin: 0 auto;
}

/* ---- Hero adjustments when in chat mode ---- */
.hero--hidden {
    display: none;
}

/* ---- Markdown in bot bubbles ---- */
.chat__bubble--md p {
    margin: 0 0 0.5em;
}
.chat__bubble--md p:last-child {
    margin-bottom: 0;
}
.chat__bubble--md strong {
    font-weight: 600;
    color: var(--color-accent-hover);
}
.chat__bubble--md em {
    font-style: italic;
    opacity: 0.9;
}
.chat__bubble--md code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.88em;
    background: rgba(124, 92, 252, 0.12);
    color: #c4b5fd;
    padding: 0.15em 0.4em;
    border-radius: 4px;
}
.chat__bubble--md pre {
    margin: 0.6em 0;
    padding: var(--space-3);
    background: rgba(0, 0, 0, 0.35);
    border-radius: var(--radius-md);
    overflow-x: auto;
}
.chat__bubble--md pre code {
    background: none;
    padding: 0;
    color: #e2e8f0;
    font-size: 0.85em;
}
.chat__bubble--md ul {
    margin: 0.4em 0;
    padding-left: 1.2em;
    list-style: none;
}
.chat__bubble--md ul li {
    position: relative;
    padding-left: 0.2em;
    margin-bottom: 0.25em;
}
.chat__bubble--md ul li::before {
    content: '›';
    position: absolute;
    left: -1em;
    color: var(--color-accent);
    font-weight: 600;
}

/* ---- Content wrapper (bubble + chips) ---- */
.chat__content {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
}

/* ---- Suggestion Chips ---- */
.chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-1);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}
.chat__suggestions--visible {
    opacity: 1;
    transform: translateY(0);
}
.chat__suggestion-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.4em 0.9em;
    font-size: var(--font-size-sm);
    font-family: inherit;
    color: var(--color-accent);
    background: rgba(124, 92, 252, 0.08);
    border: 1px solid rgba(124, 92, 252, 0.2);
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
}
.chat__suggestion-chip:hover {
    background: rgba(124, 92, 252, 0.18);
    border-color: rgba(124, 92, 252, 0.4);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 10px rgba(124, 92, 252, 0.2);
}
