/**
 * EncycloBot Styles v6.1
 * 3 modes : Barre / Popup / Chatbot mini + Dark mode auto
 * Tous se reduisent en bulle
 */

/* =========================================
   VARIABLES
   ========================================= */
:root {
    --eb-primary: #007aff;
    --eb-primary-dark: #005ecb;
    --eb-bg-light: #f2f2f7;
    --eb-bg-white: #ffffff;
    --eb-text-dark: #1c1c1e;
    --eb-text-muted: #8e8e93;
    --eb-msg-user-bg: #007aff;
    --eb-msg-bot-bg: #ffffff;
    --eb-shadow: 0 10px 50px rgba(0,0,0,0.15);
    --eb-shadow-heavy: 0 25px 80px rgba(0,0,0,0.25);
    --eb-radius: 28px;
    --eb-radius-pill: 50px;
}

/* =========================================
   OVERLAY (fond sombre pour popup)
   ========================================= */
#encyclobot-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

#encyclobot-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* =========================================
   WIDGET CONTAINER
   ========================================= */
#encyclobot-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    position: fixed;
    z-index: 99999;
}

/* Fix Firefox rendering artifacts */
#encyclobot-widget .eb-chat {
    backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    transform: translateZ(0);
}

/* =========================================
   CACHER PAR DÉFAUT
   ========================================= */
.eb-bar,
.eb-chat,
.eb-bubble-icon {
    display: none;
}

/* =========================================
   MODE 1 : BARRE DE RECHERCHE
   ========================================= */
#encyclobot-widget.bar {
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: min(700px, 90%);
}

#encyclobot-widget.bar .eb-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--eb-bg-white);
    border-radius: var(--eb-radius-pill);
    padding: 8px 8px 8px 20px;
    box-shadow: var(--eb-shadow);
    cursor: text;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    animation: ebBarIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes ebBarIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#encyclobot-widget.bar .eb-bar:hover {
    box-shadow: var(--eb-shadow-heavy);
    transform: translateY(-3px);
}

#encyclobot-widget.bar .eb-chat,
#encyclobot-widget.bar .eb-bubble-icon {
    display: none;
}

.eb-bar-icon {
    color: var(--eb-text-muted);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.eb-bar-placeholder {
    flex: 1;
    font-size: 17px;
    color: var(--eb-text-muted);
    padding: 14px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eb-bar-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--eb-primary), var(--eb-primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
}

.eb-bar-btn:hover {
    transform: scale(1.1);
}

/* =========================================
   MODE 2 : POPUP / FENÊTRE CONTEXTUELLE
   ========================================= */
#encyclobot-widget.expanded {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(750px, 92%);
    bottom: auto;
}

#encyclobot-widget.expanded .eb-bar,
#encyclobot-widget.expanded .eb-bubble-icon {
    display: none;
}

#encyclobot-widget.expanded .eb-chat {
    display: flex;
    flex-direction: column;
    background: var(--eb-bg-white);
    border-radius: 24px;
    box-shadow: 0 30px 100px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    animation: ebPopupIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes ebPopupIn {
    from {
        opacity: 0;
        transform: scale(0.88);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

#encyclobot-widget.expanded .eb-messages {
    height: 380px;
    background: var(--eb-bg-light);
}

/* =========================================
   MODE 3 : CHATBOT MINI (compact)
   ========================================= */
#encyclobot-widget.mini {
    bottom: 20px;
    right: 20px;
    left: auto;
    width: 340px;
    transform: none;
}

#encyclobot-widget.mini .eb-bar,
#encyclobot-widget.mini .eb-bubble-icon {
    display: none;
}

#encyclobot-widget.mini .eb-chat {
    display: flex;
    flex-direction: column;
    background: var(--eb-bg-white);
    border-radius: 24px;
    box-shadow: var(--eb-shadow-heavy);
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.06);
    animation: ebMiniIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes ebMiniIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#encyclobot-widget.mini .eb-header {
    padding: 14px 18px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-bottom: none;
}

#encyclobot-widget.mini .eb-avatar {
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,0.15);
}

#encyclobot-widget.mini .eb-title {
    font-size: 14px;
    color: #fff;
}

#encyclobot-widget.mini .eb-subtitle {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
}

#encyclobot-widget.mini .eb-close {
    background: rgba(255,255,255,0.1);
    color: #fff;
    width: 30px;
    height: 30px;
}

#encyclobot-widget.mini .eb-close:hover {
    background: rgba(255,255,255,0.2);
}

#encyclobot-widget.mini .eb-messages {
    height: 260px;
    padding: 14px;
    background: var(--eb-bg-light);
}

#encyclobot-widget.mini .eb-msg {
    font-size: 14px;
    padding: 11px 15px;
}

#encyclobot-widget.mini .eb-suggestions {
    padding: 12px 14px;
    background: var(--eb-bg-white);
}

#encyclobot-widget.mini .eb-suggest {
    font-size: 12px;
    padding: 7px 14px;
}

#encyclobot-widget.mini .eb-input-area {
    padding: 12px 14px;
}

#encyclobot-widget.mini .eb-input {
    font-size: 14px;
}

#encyclobot-widget.mini .eb-send {
    width: 38px;
    height: 38px;
}

/* =========================================
   MODE 4 : BULLE (état réduit)
   ========================================= */
#encyclobot-widget.bubble {
    bottom: 24px;
    left: 24px;
    width: 64px;
    height: 64px;
}

#encyclobot-widget.bubble .eb-bar,
#encyclobot-widget.bubble .eb-chat {
    display: none;
}

#encyclobot-widget.bubble .eb-bubble-icon {
    display: flex;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #1a1a2e 0%, #2d2d44 100%);
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    color: white;
    animation: ebBubbleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease;
}

@keyframes ebBubbleIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

#encyclobot-widget.bubble .eb-bubble-icon:hover {
    transform: scale(1.12);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

#encyclobot-widget.bubble .eb-bubble-icon:active {
    transform: scale(0.95);
}

/* =========================================
   COMPOSANTS CHAT PARTAGÉS
   ========================================= */

/* Header */
.eb-header {
    background: var(--eb-bg-white);
    padding: 16px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.eb-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.eb-avatar {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--eb-primary), #5856d6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.eb-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--eb-text-dark);
}

.eb-subtitle {
    font-size: 12px;
    color: var(--eb-text-muted);
    margin-top: 2px;
}

.eb-close {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.eb-close:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.05);
}

/* Messages */
.eb-messages {
    height: 350px;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: none;
}

.eb-messages::-webkit-scrollbar {
    display: none;
}

/* Bulles de message */
.eb-msg {
    max-width: 85%;
    padding: 12px 16px;
    font-size: 15px;
    line-height: 1.5;
    border-radius: 20px;
    animation: ebMsgIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes ebMsgIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.eb-msg p {
    margin: 0;
    padding: 0;
}

.eb-msg.eb-bot {
    align-self: flex-start;
    background: var(--eb-msg-bot-bg);
    color: var(--eb-text-dark);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

/* Forcer l'heritage de couleur pour le markdown dans les bulles
   (empeche le theme WP d'imposer color: #000 sur em/b en dark mode) */
.eb-msg b,
.eb-msg strong,
.eb-msg em,
.eb-msg i {
    color: inherit;
}

.eb-msg.eb-user {
    align-self: flex-end;
    background: var(--eb-msg-user-bg);
    color: #ffffff;
    border-bottom-right-radius: 6px;
}

/* Indicateur de frappe */
.eb-typing-dots {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

.eb-dot {
    width: 8px;
    height: 8px;
    background: var(--eb-text-muted);
    border-radius: 50%;
    animation: ebDotBounce 1.4s infinite ease-in-out both;
}

.eb-dot:nth-child(1) { animation-delay: -0.32s; }
.eb-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes ebDotBounce {
    0%, 80%, 100% {
        transform: scale(0.4);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Suggestions */
.eb-suggestions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 20px;
    min-height: 20px;
    background: var(--eb-bg-white);
    border-top: 1px solid rgba(0, 0, 0, 0.04);
}

.eb-suggest {
    background: var(--eb-bg-white);
    border: 1px solid rgba(0, 0, 0, 0.08);
    color: var(--eb-text-dark);
    padding: 9px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.eb-suggest:hover {
    background: var(--eb-primary);
    color: white;
    border-color: var(--eb-primary);
    transform: translateY(-2px) scale(1.02);
}

.eb-suggest:active {
    transform: translateY(0) scale(0.98);
}

/* Bouton Surprends-moi */
.eb-suggest.eb-suggest-random {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.eb-suggest.eb-suggest-random:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

/* Zone de saisie */
.eb-input-area {
    background: var(--eb-bg-white);
    padding: 16px 20px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 12px;
}

.eb-input {
    flex: 1;
    border: none !important;
    outline: none !important;
    font-size: 16px;
    padding: 0;
    margin: 0;
    height: 46px;
    line-height: 46px;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--eb-text-dark);
}

.eb-input::placeholder {
    color: var(--eb-text-muted);
    line-height: 46px;
}

.eb-send {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: var(--eb-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.3;
    transform: scale(0.75);
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    flex-shrink: 0;
}

.eb-send.active {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.eb-send.active:hover {
    transform: scale(1.08);
}

.eb-send.active:active {
    transform: scale(0.95);
}

/* =========================================
   CITATIONS & SOURCES
   ========================================= */

/* Citations inline [1], [2] — style exposant cliquable */
.eb-citation {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 1;
    color: var(--eb-primary);
    text-decoration: none;
    font-weight: 600;
    padding: 0 1px;
    cursor: pointer;
    transition: color 0.2s ease;
}

.eb-citation:hover {
    color: var(--eb-primary-dark);
    text-decoration: underline;
}

/* Section sources en pied de réponse */
.eb-sources {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 12px;
    color: var(--eb-text-muted);
    line-height: 1.6;
}

.eb-sources-label {
    font-weight: 600;
    color: var(--eb-text-dark);
}

.eb-source-link {
    color: var(--eb-text-muted);
    text-decoration: none;
    margin-right: 6px;
    cursor: pointer;
    transition: color 0.2s ease;
}

.eb-source-link:hover {
    color: var(--eb-primary);
    text-decoration: underline;
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 600px) {
    /* Popup mobile */
    #encyclobot-widget.expanded {
        width: 100%;
        top: auto;
        bottom: 0;
        left: 0;
        transform: none;
    }

    #encyclobot-widget.expanded .eb-chat {
        border-radius: 24px 24px 0 0;
        max-height: 85vh;
    }

    #encyclobot-widget.expanded .eb-messages {
        height: 280px;
    }

    /* Barre mobile */
    #encyclobot-widget.bar {
        width: 94%;
        bottom: 20px;
    }

    /* Mini mobile */
    #encyclobot-widget.mini {
        width: 100%;
        right: 0;
        bottom: 0;
    }

    #encyclobot-widget.mini .eb-chat {
        border-radius: 24px 24px 0 0;
        max-height: 70vh;
    }

    #encyclobot-widget.mini .eb-messages {
        height: 220px;
    }

    /* Bulle mobile */
    #encyclobot-widget.bubble {
        bottom: 20px;
        left: 20px;
        width: 58px;
        height: 58px;
    }

    #encyclobot-widget.bubble .eb-bubble-icon {
        width: 58px;
        height: 58px;
    }
}

/* =========================================
   DARK MODE (automatique via prefers-color-scheme)
   ========================================= */
@media (prefers-color-scheme: dark) {
    :root {
        --eb-primary: #0a84ff;
        --eb-primary-dark: #0070e0;
        --eb-bg-light: #1c1c1e;
        --eb-bg-white: #2c2c2e;
        --eb-text-dark: #f2f2f7;
        --eb-text-muted: #98989d;
        --eb-msg-user-bg: #0a84ff;
        --eb-msg-bot-bg: #3a3a3c;
        --eb-shadow: 0 10px 50px rgba(0,0,0,0.4);
        --eb-shadow-heavy: 0 25px 80px rgba(0,0,0,0.5);
    }

    #encyclobot-overlay {
        background: rgba(0, 0, 0, 0.6);
    }

    #encyclobot-widget.expanded .eb-chat {
        box-shadow: 0 30px 100px rgba(0, 0, 0, 0.6);
    }

    #encyclobot-widget.mini .eb-chat {
        border-color: rgba(255,255,255,0.08);
    }

    .eb-header {
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .eb-bar-placeholder,
    .eb-bar-icon {
        color: var(--eb-text-muted) !important;
    }

    .eb-msg.eb-bot {
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    }

    .eb-suggest {
        border-color: rgba(255, 255, 255, 0.12);
    }

    .eb-suggest:hover {
        background: var(--eb-primary);
        border-color: var(--eb-primary);
    }

    .eb-input-area {
        border-top-color: rgba(255, 255, 255, 0.08);
    }

    .eb-input {
        color: var(--eb-text-dark) !important;
    }

    .eb-input::placeholder {
        color: var(--eb-text-muted) !important;
    }

    .eb-close {
        background: rgba(255, 255, 255, 0.1);
        color: #ccc;
    }

    .eb-close:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    .eb-sources {
        border-top-color: rgba(255, 255, 255, 0.1);
    }

    .eb-citation {
        color: #4da6ff;
    }

    .eb-citation:hover {
        color: #80bfff;
    }

    .eb-sources-label {
        color: #f2f2f7;
    }

    .eb-source-link {
        color: #f2f2f7;
    }

    .eb-source-link:hover {
        color: #4da6ff;
    }

    .eb-suggestions {
        border-top-color: rgba(255, 255, 255, 0.06);
    }
}
