/* ═══════════════════════════════════════════════════════════
   Zo — Bulle flottante + fenêtre de chat
   Thème adaptatif : sombre par défaut, clair si OS clair
   ═══════════════════════════════════════════════════════════ */

/* ─── Dark Theme (défaut) ────────────────────────────────── */

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #111111;
    --bg-input: #161616;
    --surface: #1a1a1a;
    --border: #222222;
    --border-hover: #333333;
    --text-primary: #f0f0f0;
    --text-secondary: #8a8a8a;
    --text-muted: #505050;
    --accent: #a78bfa;
    --accent-hover: #b89dff;
    --accent-glow: rgba(167, 139, 250, 0.15);
    --accent-glow-strong: rgba(167, 139, 250, 0.3);
    --bot-bubble: #151515;
    --bot-bubble-border: #222222;
    --user-bubble: #a78bfa;
    --user-text: #0a0a0a;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-bubble: 0 4px 20px rgba(0, 0, 0, 0.6);
    --code-bg: #0d0d0d;
    --scrollbar: #2a2a2a;
}

/* ─── Light Theme ────────────────────────────────────────── */

@media (prefers-color-scheme: light) {
    :root {
        --bg-primary: #ffffff;
        --bg-secondary: #f7f7f7;
        --bg-input: #f2f2f2;
        --surface: #f5f5f5;
        --border: #e5e5e5;
        --border-hover: #d0d0d0;
        --text-primary: #111111;
        --text-secondary: #666666;
        --text-muted: #aaaaaa;
        --accent: #7c3aed;
        --accent-hover: #6d28d9;
        --accent-glow: rgba(124, 58, 237, 0.1);
        --accent-glow-strong: rgba(124, 58, 237, 0.2);
        --bot-bubble: #f0f0f0;
        --bot-bubble-border: #e0e0e0;
        --user-bubble: #7c3aed;
        --user-text: #ffffff;
        --shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
        --shadow-bubble: 0 4px 20px rgba(0, 0, 0, 0.15);
        --code-bg: #e8e8e8;
        --scrollbar: #d0d0d0;
    }
}

/* ─── Base ────────────────────────────────────────────────── */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════
   BULLE FLOTTANTE
   ═══════════════════════════════════════════════════════════ */

#chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-bubble);
    z-index: 9999;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease;
}

#chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px var(--accent-glow-strong);
}

#chat-bubble:active {
    transform: scale(0.95);
}

#chat-bubble.hidden {
    transform: scale(0);
    pointer-events: none;
}

.bubble-sparkle {
    width: 26px;
    height: 26px;
    color: var(--user-text);
    animation: sparkle-spin 8s linear infinite;
}

@keyframes sparkle-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Pulse ring */
.bubble-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--accent);
    animation: pulse-ring 2.5s ease-out infinite;
    pointer-events: none;
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════
   FENETRE DE CHAT
   ═══════════════════════════════════════════════════════════ */

#chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 48px);
    max-width: calc(100vw - 32px);
    background: var(--bg-primary);
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.3s ease;
    transform-origin: bottom right;
}

#chat-window.closed {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

#chat-window.open {
    transform: scale(1);
    opacity: 1;
}

/* ─── Header ─────────────────────────────────────────────── */

#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sparkle-icon {
    width: 16px;
    height: 16px;
    color: var(--accent);
}

.header-info h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.status-text {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-secondary);
}

.status-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 6px rgba(52, 211, 153, 0.5);
}

.header-actions {
    display: flex;
    gap: 4px;
}

.header-actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.header-actions button:hover {
    color: var(--text-primary);
    background: var(--surface);
}

/* ─── Messages ───────────────────────────────────────────── */

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: msg-in 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.bot-message { align-self: flex-start; }

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.bot-message .message-avatar {
    background: var(--accent-glow);
    color: var(--accent);
}

.user-message .message-avatar {
    background: var(--user-bubble);
    color: var(--user-text);
}

.sparkle-icon-sm {
    width: 13px;
    height: 13px;
    color: var(--accent);
}

.user-icon-sm {
    width: 13px;
    height: 13px;
}

/* Bulles */

.message-bubble {
    padding: 11px 15px;
    border-radius: 14px;
    line-height: 1.55;
    font-size: 13.5px;
}

.bot-message .message-bubble {
    background: var(--bot-bubble);
    border: 1px solid var(--bot-bubble-border);
    border-top-left-radius: 4px;
    color: var(--text-primary);
}

.user-message .message-bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-top-right-radius: 4px;
    font-weight: 500;
}

.message-bubble p { margin-bottom: 6px; }
.message-bubble p:last-child { margin-bottom: 0; }

.message-bubble ul,
.message-bubble ol {
    margin: 6px 0;
    padding-left: 18px;
}

.message-bubble li { margin-bottom: 3px; }

.message-bubble strong {
    font-weight: 600;
    color: var(--accent);
}

.user-message .message-bubble strong {
    color: var(--user-text);
}

.message-bubble code {
    background: var(--code-bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12.5px;
    font-family: 'JetBrains Mono', monospace;
    border: 1px solid var(--border);
}

.user-message .message-bubble code {
    background: rgba(0, 0, 0, 0.12);
    border-color: rgba(0, 0, 0, 0.08);
}

.message-bubble pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 6px 0;
    overflow-x: auto;
}

.message-bubble pre code {
    background: none;
    border: none;
    padding: 0;
}

.message-bubble a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.message-bubble a:hover {
    border-bottom-color: var(--accent);
}

.sources {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
}

/* ─── Typing ─────────────────────────────────────────────── */

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 6px 2px;
}

.typing-indicator span {
    width: 5px;
    height: 5px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* ─── Suggestions ────────────────────────────────────────── */

#quick-suggestions {
    display: flex;
    gap: 6px;
    padding: 4px 16px 2px;
    overflow-x: auto;
    flex-shrink: 0;
}

#quick-suggestions::-webkit-scrollbar { display: none; }

.suggestion {
    white-space: nowrap;
    padding: 6px 14px;
    border: 1px solid var(--border-hover);
    border-radius: 100px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

/* ─── Input ──────────────────────────────────────────────── */

#chat-input-container {
    padding: 10px 16px 14px;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#chat-input {
    flex: 1;
    resize: none;
    border: none;
    background: transparent;
    padding: 7px 0;
    font-size: 13.5px;
    font-family: 'DM Sans', sans-serif;
    line-height: 1.5;
    max-height: 100px;
    outline: none;
    color: var(--text-primary);
}

#chat-input::placeholder {
    color: var(--text-muted);
}

#btn-send {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: var(--user-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

#btn-send:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

#btn-send:active {
    transform: scale(0.95);
}

#btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.input-hint {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 5px;
}

/* ─── Scrollbar ──────────────────────────────────────────── */

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 2px;
}

/* ─── Mobile ─────────────────────────────────────────────── */

@media (max-width: 440px) {
    #chat-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
        border: none;
    }

    #chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .bubble-sparkle { width: 22px; height: 22px; }
}
