/* Chatbot Widget */
#chatbot-widget {
    position: fixed;
    z-index: 9999;
    font-family: 'Roboto', sans-serif;
}

/* Position variations */
#chatbot-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

#chatbot-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

#chatbot-widget.top-right {
    top: 20px;
    right: 20px;
}

#chatbot-widget.top-left {
    top: 20px;
    left: 20px;
}

#chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6e48ff 0%, #9d4edd 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(110, 72, 255, 0.5);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
}

#chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(110, 72, 255, 0.7);
}

#chatbot-toggle.active {
    background: linear-gradient(135deg, #f44336 0%, #e91e63 100%);
}

#chatbot-container {
    position: fixed;
    width: 380px;
    height: 550px;
    background: rgba(18, 18, 18, 0.98);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    resize: both;
    min-width: 300px;
    max-width: 800px;
    min-height: 400px;
    max-height: 900px;
}

/* Container position variations */
#chatbot-widget.bottom-right #chatbot-container {
    bottom: 100px;
    right: 20px;
}

#chatbot-widget.bottom-left #chatbot-container {
    bottom: 100px;
    left: 20px;
}

#chatbot-widget.top-right #chatbot-container {
    top: 100px;
    right: 20px;
}

#chatbot-widget.top-left #chatbot-container {
    top: 100px;
    left: 20px;
}

#chatbot-container.active {
    display: flex;
}

/* Resize handles */
.chatbot-resize-handle {
    position: absolute;
    background: transparent;
    z-index: 10;
}

.chatbot-resize-right {
    right: 0;
    top: 0;
    width: 10px;
    height: 100%;
    cursor: ew-resize;
}

.chatbot-resize-bottom {
    left: 0;
    bottom: 0;
    width: 100%;
    height: 10px;
    cursor: ns-resize;
}

.chatbot-resize-corner {
    right: 0;
    bottom: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: rgba(110, 72, 255, 0.3);
    border-radius: 0 0 20px 0;
}

.chatbot-resize-corner:hover {
    background: rgba(110, 72, 255, 0.5);
}

#chatbot-header {
    background: linear-gradient(135deg, #6e48ff 0%, #9d4edd 100%);
    padding: 20px;
    color: white;
    border-radius: 20px 20px 0 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

#chatbot-header .bot-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    position: relative;
    flex-shrink: 0;
    padding: 3px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Avatar image style Snapchat */
#chatbot-header .bot-avatar .avatar-image {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

#chatbot-header .bot-avatar .avatar-image:hover {
    transform: scale(1.05);
}

/* Badge de statut "En ligne" (point vert) */
#chatbot-header .bot-avatar .avatar-status-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #4CAF50;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

#chatbot-header .bot-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#chatbot-header .bot-info p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

#chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

#chatbot-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

#chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(110, 72, 255, 0.5);
    border-radius: 3px;
}

.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    flex-direction: row;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.message.bot .message-avatar {
    background: white;
    color: white;
    padding: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Avatar image in messages */
.message-avatar .avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.message.user .message-avatar {
    background: rgba(0, 255, 204, 0.2);
    color: #00ffcc;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    flex: 1;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
}

/* Wrapper pour les blocs de code - s'adapte au contenu */
.code-block-wrapper {
    width: fit-content;
    max-width: 100%; /* Ne pas déborder du chatbot */
    margin: 8px 0;
    display: block;
}

/* Placeholder pour indiquer la position du code */
.code-block-placeholder {
    padding: 8px 12px;
    background: rgba(110, 72, 255, 0.1);
    border-left: 3px solid rgba(110, 72, 255, 0.5);
    border-radius: 5px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    margin: 8px 0;
}

/* Markdown formatting */
.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

/* Conteneur de bloc de code avec header */
.code-block-container {
    margin: 0;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(110, 72, 255, 0.3);
    max-width: 100%;
    width: fit-content;
    min-width: 300px; /* Largeur minimale pour lisibilité */
    box-sizing: border-box;
}

.code-block-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(110, 72, 255, 0.2);
}

.code-lang {
    font-size: 11px;
    color: #00ffcc;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Footer du bloc de code avec bouton Copier */
.code-block-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid rgba(110, 72, 255, 0.2);
}

.copy-code-btn {
    padding: 4px 10px;
    background: rgba(110, 72, 255, 0.3);
    border: 1px solid rgba(110, 72, 255, 0.5);
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.copy-code-btn:hover {
    background: rgba(110, 72, 255, 0.5);
    transform: translateY(-1px);
}

.copy-code-btn:active {
    transform: translateY(0);
}

.copy-code-btn i {
    font-size: 10px;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    border-left: 3px solid rgba(110, 72, 255, 0.6);
}

.code-block-container pre {
    margin: 0;
    border-radius: 0;
    border-left: none;
    max-width: 100%;
    overflow-x: auto;
    white-space: pre;
    word-wrap: normal;
}

.message-content pre code {
    background: none;
    padding: 0;
    font-size: 12px;
    line-height: 1.4;
}

.message-content strong {
    font-weight: 600;
    color: #fff;
}

.message-content em {
    font-style: italic;
}

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-content a {
    color: #00ffcc;
    text-decoration: underline;
    transition: all 0.2s ease;
    word-break: break-word;
}

.message-content a:hover {
    color: #00d4aa;
    text-decoration: none;
    background: rgba(0, 255, 204, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
}

/* Style spécial pour les liens du chatbot (avec icône externe) */
.message-content a.chatbot-link::after {
    content: " \f35d";
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 10px;
    margin-left: 3px;
    opacity: 0.7;
}

.message.bot .message-content {
    background: rgba(110, 72, 255, 0.15);
    color: #f8f9fa;
    border-bottom-left-radius: 4px;
}

.message.user .message-content {
    background: rgba(0, 255, 204, 0.15);
    color: #f8f9fa;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 4px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: rgba(110, 72, 255, 0.15);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(110, 72, 255, 0.8);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

#chatbot-input-container {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 10px;
    align-items: center;
}

.web-search-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 16px;
    transition: all 0.3s ease;
}

.web-search-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.8);
}

.web-search-toggle.active {
    background: linear-gradient(135deg, #00ffcc 0%, #00d4aa 100%);
    border-color: #00ffcc;
    color: #0f172a;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.5);
}

#chatbot-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 25px;
    padding: 12px 18px;
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

#chatbot-input:focus {
    background: rgba(255, 255, 255, 0.15);
    border-color: #6e48ff;
}

#chatbot-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#chatbot-send {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6e48ff 0%, #9d4edd 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    transition: all 0.3s ease;
}

#chatbot-send:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(110, 72, 255, 0.5);
}

#chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: scale(1);
}

/* Quick replies */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.quick-reply {
    background: rgba(110, 72, 255, 0.2);
    color: #6e48ff;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid rgba(110, 72, 255, 0.3);
}

.quick-reply:hover {
    background: rgba(110, 72, 255, 0.3);
    transform: translateY(-2px);
}

/* Mobile responsive */
@media (max-width: 768px) {
    /* Mobile: Chatbot takes full screen ONLY when active */
    #chatbot-widget.bottom-right #chatbot-container.active,
    #chatbot-widget.bottom-left #chatbot-container.active,
    #chatbot-widget.top-right #chatbot-container.active,
    #chatbot-widget.top-left #chatbot-container.active {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        min-width: 100% !important;
        min-height: 100% !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        margin: 0 !important;
        overflow: hidden !important;
    }

    #chatbot-toggle {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    /* Hide toggle when chatbot is open on mobile */
    #chatbot-container.active ~ #chatbot-toggle,
    #chatbot-container.fullscreen ~ #chatbot-toggle {
        display: none !important;
    }

    #chatbot-header {
        flex-shrink: 0;
        padding: 6px 10px;
        border-radius: 0;
        position: relative;
        z-index: 10000;
        display: flex;
        align-items: center;
        gap: 6px;
        min-height: 48px;
    }

    #chatbot-header .bot-avatar {
        width: 28px;
        height: 28px;
    }

    #chatbot-header .bot-info {
        flex: 1;
        min-width: 0;
    }

    #chatbot-header .bot-info h3 {
        font-size: 12px;
        margin: 0;
        line-height: 1.2;
    }

    #chatbot-header .bot-info p {
        font-size: 9px;
        margin: 0;
        line-height: 1.2;
        opacity: 0.8;
    }

    .chatbot-close-btn {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        font-size: 16px;
        background: rgba(255, 255, 255, 0.3) !important;
        z-index: 99999 !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
        cursor: pointer;
        pointer-events: auto !important;
        position: relative;
        display: flex !important;
        align-items: center;
        justify-content: center;
        border: none;
        outline: none;
        border-radius: 50%;
        /* Augmenter la zone de clic */
        padding: 6px;
        margin: -6px;
    }

    #chatbot-messages {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 10px 8px;
        min-height: 0;
        max-width: 100%;
    }

    .message-content {
        max-width: 85%;
        font-size: 14px;
        padding: 10px 12px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    /* Blocs de code sur mobile - pleine largeur via wrapper */
    .message.bot .message-content {
        max-width: 85%;
    }

    .code-block-wrapper {
        width: 100%;
        max-width: 100%;
        margin: 8px 0;
    }

    .code-block-container {
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        border-radius: 8px;
    }

    .code-block-header {
        padding: 6px 8px;
        font-size: 10px;
    }

    .code-lang {
        font-size: 9px;
    }

    .copy-code-btn {
        padding: 3px 8px;
        font-size: 10px;
        gap: 3px;
    }

    .code-block-container pre {
        padding: 8px;
        font-size: 11px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .code-block-container pre code {
        font-size: 11px;
        white-space: pre;
        word-wrap: normal;
    }

    #chatbot-input-container {
        flex-shrink: 0;
        padding: 10px;
        background: rgba(18, 18, 18, 0.98);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        width: 100%;
        box-sizing: border-box;
        gap: 8px;
    }

    #chatbot-input {
        font-size: 14px !important;
        padding: 10px 12px;
        touch-action: manipulation;
    }

    .web-search-toggle {
        width: 34px;
        height: 34px;
        font-size: 13px;
        flex-shrink: 0;
    }

    #chatbot-send {
        width: 38px;
        height: 38px;
        font-size: 15px;
        flex-shrink: 0;
    }

    /* Masquer les handles de resize sur mobile */
    .chatbot-resize-handle {
        display: none !important;
    }
}

/* Fullscreen mode */
#chatbot-container.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    z-index: 10000;
    animation: expandFullscreen 0.3s ease-out;
}

@keyframes expandFullscreen {
    from {
        transform: scale(0.9);
        opacity: 0.8;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Header buttons */
.chatbot-header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    opacity: 1;
    flex-shrink: 0;
    margin-left: 8px;
}

.chatbot-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.chatbot-header-btn:active {
    transform: scale(0.95);
}

/* Clear history button - red tint */
#chatbot-clear-history {
    background: rgba(255, 68, 68, 0.15);
}

#chatbot-clear-history:hover {
    background: rgba(255, 68, 68, 0.3);
}

/* Close button */
.chatbot-close-btn {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    opacity: 1;
    flex-shrink: 0;
}

.chatbot-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Hide resize handles in fullscreen */
#chatbot-container.fullscreen .chatbot-resize-handle {
    display: none;
}

/* Adjust messages padding in fullscreen */
#chatbot-container.fullscreen #chatbot-messages {
    padding: 40px 20%;
}

@media (max-width: 1200px) {
    #chatbot-container.fullscreen #chatbot-messages {
        padding: 30px 10%;
    }
}

@media (max-width: 768px) {
    #chatbot-container.fullscreen #chatbot-messages {
        padding: 20px;
    }
}
