/* ============================================================ */
/* LITELLM CHATBOT - STYLE ACCESSIBLE HARMONISÉ                */
/* ============================================================ */

:root {
    --chatbot-primary: #4f46e5;
    --chatbot-primary-hover: #4338ca;
    --chatbot-primary-light: #eef2ff;
    --chatbot-success: #16a34a;
    --chatbot-success-hover: #15803d;
    --chatbot-danger: #dc2626;
    --chatbot-border: #d1d5db;
    --chatbot-border-light: #e2e8f0;
    --chatbot-text: #1a1a2e;
    --chatbot-text-secondary: #475569;
    --chatbot-text-muted: #94a3b8;
    --chatbot-bg: #f8fafc;
    --chatbot-radius: 8px;
    --chatbot-shadow: 0 8px 32px rgba(15, 23, 42, 0.15);
}

/* ============================================================ */
/* CONTENEUR PRINCIPAL                                          */
/* ============================================================ */

.litellm-chatbot-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 450px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ============================================================ */
/* FENÊTRE DU CHATBOT                                           */
/* ============================================================ */

.litellm-chatbot-window {
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 480px !important;
    max-height: 60vh !important;
    min-height: 400px !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    border: none !important;
    display: flex !important;
    background: transparent !important;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================================ */
/* HEADER - Accessible                                           */
/* ============================================================ */

.litellm-chatbot-header {
    padding: 14px 20px;
    background: linear-gradient(135deg, #1e293b, #4f46e5);
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 56px;
}

.litellm-chatbot-header span {
    font-weight: 600;
    font-size: 0.95rem;
}

.litellm-chatbot-header .litellm-chatbot-credits {
    font-size: 0.8rem;
    font-weight: 400;
    opacity: 0.9;
    padding: 2px 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
}

/* ============================================================ */
/* MESSAGES - Accessible                                        */
/* ============================================================ */

.litellm-chatbot-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--chatbot-bg);
}

.litellm-chatbot-messages .message {
    margin-bottom: 12px;
    display: flex;
}

.litellm-chatbot-messages .message.user {
    justify-content: flex-end;
}

.litellm-chatbot-messages .message .message-content {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.litellm-chatbot-messages .message.bot .message-content {
    background: #ffffff;
    border: 1px solid var(--chatbot-border-light);
    border-bottom-left-radius: 4px;
    color: var(--chatbot-text);
}

.litellm-chatbot-messages .message.user .message-content {
    background: var(--chatbot-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.litellm-chatbot-messages .message.error .message-content {
    background: #fef2f2;
    color: var(--chatbot-danger);
    border: 1px solid #fca5a5;
}

/* ============================================================ */
/* INPUT AREA - Accessible                                      */
/* ============================================================ */

.litellm-chatbot-input-area {
    padding: 10px 16px 12px 16px;
    border-top: 1px solid var(--chatbot-border);
    background: #ffffff;
    flex-shrink: 0;
}

.litellm-chatbot-context {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--chatbot-text-secondary);
    margin-bottom: 6px;
    padding: 4px 8px;
    background: var(--chatbot-bg);
    border-radius: 4px;
    min-height: 32px;
}

.litellm-chatbot-context span {
    flex: 1;
    min-width: 100px;
}

.litellm-chatbot-small-btn {
    background: none;
    border: none;
    color: var(--chatbot-text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 3px;
    transition: all 0.2s;
    min-height: 28px;
}

.litellm-chatbot-small-btn:hover {
    background: var(--chatbot-border-light);
    color: var(--chatbot-text);
}

.litellm-chatbot-small-btn:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

#litellm-chatbot-input {
    width: 100%;
    border: 2px solid var(--chatbot-border);
    border-radius: var(--chatbot-radius);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    min-height: 50px;
    color: var(--chatbot-text);
    background: #ffffff;
}

#litellm-chatbot-input:focus {
    outline: none;
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

#litellm-chatbot-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================================ */
/* BOUTONS D'ACTION - Accessible                                */
/* ============================================================ */

.litellm-chatbot-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.litellm-chatbot-send-btn,
.litellm-chatbot-insert-btn {
    padding: 8px 18px;
    border: 2px solid transparent;
    border-radius: var(--chatbot-radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 40px;
}

.litellm-chatbot-send-btn {
    background: var(--chatbot-primary);
    color: #ffffff;
    border-color: var(--chatbot-primary);
    flex: 1;
}

.litellm-chatbot-send-btn:hover:not(:disabled) {
    background: var(--chatbot-primary-hover);
    border-color: var(--chatbot-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.litellm-chatbot-send-btn:disabled {
    background: #a0c4e8;
    border-color: #a0c4e8;
    cursor: not-allowed;
}

.litellm-chatbot-insert-btn {
    background: var(--chatbot-success);
    color: #ffffff;
    border-color: var(--chatbot-success);
    flex: 0 0 auto;
}

.litellm-chatbot-insert-btn:hover:not(:disabled) {
    background: var(--chatbot-success-hover);
    border-color: var(--chatbot-success-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

.litellm-chatbot-insert-btn:disabled {
    background: #a0c4a0;
    border-color: #a0c4a0;
    cursor: not-allowed;
}

.litellm-chatbot-send-btn:focus-visible,
.litellm-chatbot-insert-btn:focus-visible {
    outline: 3px solid var(--chatbot-primary);
    outline-offset: 3px;
}

/* ============================================================ */
/* STATUS - Accessible                                          */
/* ============================================================ */

.litellm-chatbot-status {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--chatbot-text-secondary);
    min-height: 20px;
}

.litellm-chatbot-status.loading {
    color: var(--chatbot-primary);
}

.litellm-chatbot-status.error {
    color: var(--chatbot-danger);
}

.litellm-chatbot-status.success {
    color: var(--chatbot-success);
}

/* ============================================================ */
/* INDICATEUR DE TAPEMENT - Accessible                          */
/* ============================================================ */

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--chatbot-text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
    .typing-indicator span {
        animation: none;
    }
}

/* ============================================================ */
/* MODAL APERÇU - Accessible                                    */
/* ============================================================ */

.litellm-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    z-index: 10000000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.litellm-preview-modal.active {
    display: flex;
}

.litellm-preview-modal-content {
    background: #ffffff;
    border-radius: 16px;
    max-width: 900px;
    width: 92%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 80px rgba(15, 23, 42, 0.4);
    animation: previewSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes previewSlideIn {
    from { transform: translateY(-20px) scale(0.97); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.litellm-preview-modal-header {
    padding: 14px 24px;
    border-bottom: 1px solid var(--chatbot-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
    color: var(--chatbot-text);
}

.litellm-preview-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--chatbot-text-muted);
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.litellm-preview-modal-close:hover {
    color: var(--chatbot-text);
    background: var(--chatbot-border-light);
}

.litellm-preview-modal-close:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

.litellm-preview-modal-body {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.preview-html,
.preview-markdown {
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    padding: 14px;
    border: 1px solid var(--chatbot-border);
}

.preview-html h4,
.preview-markdown h4 {
    margin: 0 0 8px 0;
    font-size: 0.85rem;
    color: var(--chatbot-text-secondary);
}

.preview-content {
    background: #ffffff;
    padding: 12px 16px;
    border-radius: 4px;
    border: 1px solid var(--chatbot-border-light);
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--chatbot-text);
}

.preview-content img {
    max-width: 100%;
    height: auto;
}

.preview-content.markdown-output {
    font-family: "Courier New", monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: #1e1e1e;
    color: #d4d4d4;
    border: 1px solid #333;
}

.litellm-preview-modal-footer {
    padding: 12px 24px;
    border-top: 1px solid var(--chatbot-border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.litellm-preview-modal-footer button {
    padding: 8px 18px;
    border: 2px solid transparent;
    border-radius: var(--chatbot-radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    min-height: 40px;
}

.litellm-preview-use-md {
    background: var(--chatbot-primary);
    color: #ffffff;
    border-color: var(--chatbot-primary);
}

.litellm-preview-use-md:hover {
    background: var(--chatbot-primary-hover);
    border-color: var(--chatbot-primary-hover);
}

.litellm-preview-use-html {
    background: #64748b;
    color: #ffffff;
    border-color: #64748b;
}

.litellm-preview-use-html:hover {
    background: #475569;
    border-color: #475569;
}

.litellm-preview-cancel {
    background: var(--chatbot-bg);
    color: var(--chatbot-text);
    border-color: var(--chatbot-border);
}

.litellm-preview-cancel:hover {
    background: var(--chatbot-border-light);
}

.litellm-preview-use-md:focus-visible,
.litellm-preview-use-html:focus-visible,
.litellm-preview-cancel:focus-visible {
    outline: 3px solid var(--chatbot-primary);
    outline-offset: 3px;
}

/* ============================================================ */
/* SCROLLBAR - Accessible                                       */
/* ============================================================ */

.litellm-chatbot-messages::-webkit-scrollbar,
.preview-content::-webkit-scrollbar {
    width: 6px;
}

.litellm-chatbot-messages::-webkit-scrollbar-track,
.preview-content::-webkit-scrollbar-track {
    background: var(--chatbot-bg);
    border-radius: 4px;
}

.litellm-chatbot-messages::-webkit-scrollbar-thumb,
.preview-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.litellm-chatbot-messages::-webkit-scrollbar-thumb:hover,
.preview-content::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-text-muted);
}

/* ============================================================ */
/* FOCUS VISIBLE - Accessible                                   */
/* ============================================================ */

*:focus-visible {
    outline: 3px solid var(--chatbot-primary);
    outline-offset: 2px;
}

/* ============================================================ */
/* RESPONSIVE - Accessible                                      */
/* ============================================================ */

@media (max-width: 768px) {
    .litellm-chatbot-window {
        height: 450px !important;
        max-height: 50vh !important;
        min-height: 350px !important;
    }
    
    .litellm-chatbot-header {
        padding: 10px 16px;
        min-height: 48px;
    }
    
    .litellm-chatbot-header span {
        font-size: 0.85rem;
    }
    
    .litellm-chatbot-messages {
        padding: 12px;
    }
    
    .litellm-chatbot-messages .message .message-content {
        max-width: 90%;
        font-size: 0.85rem;
        padding: 8px 12px;
    }
    
    .litellm-chatbot-input-area {
        padding: 8px 12px 10px 12px;
    }
    
    #litellm-chatbot-input {
        font-size: 0.85rem;
        min-height: 44px;
        padding: 6px 10px;
    }
    
    .litellm-chatbot-actions {
        flex-direction: column;
    }
    
    .litellm-chatbot-send-btn,
    .litellm-chatbot-insert-btn {
        width: 100%;
        justify-content: center;
    }
    
    .litellm-preview-modal-content {
        width: 96%;
        max-height: 95vh;
    }
    
    .litellm-preview-modal-body {
        padding: 14px 16px;
    }
    
    .litellm-preview-modal-header {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    
    .litellm-preview-modal-footer {
        padding: 10px 16px;
        flex-wrap: wrap;
    }
    
    .litellm-preview-modal-footer button {
        flex: 1;
        min-width: 100px;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .litellm-chatbot-window {
        height: 400px !important;
        max-height: 45vh !important;
        min-height: 300px !important;
    }
    
    .litellm-chatbot-header {
        padding: 8px 12px;
        min-height: 44px;
    }
    
    .litellm-chatbot-header span {
        font-size: 0.8rem;
    }
    
    .litellm-chatbot-messages {
        padding: 10px;
    }
    
    .litellm-chatbot-messages .message .message-content {
        max-width: 95%;
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    
    .litellm-chatbot-input-area {
        padding: 6px 10px 8px 10px;
    }
    
    #litellm-chatbot-input {
        font-size: 0.8rem;
        min-height: 40px;
        padding: 6px 8px;
    }
    
    .litellm-chatbot-context {
        font-size: 0.7rem;
        padding: 2px 6px;
        min-height: 28px;
        gap: 4px;
    }
    
    .litellm-chatbot-small-btn {
        font-size: 0.7rem;
        padding: 2px 6px;
        min-height: 24px;
    }
    
    .litellm-chatbot-send-btn,
    .litellm-chatbot-insert-btn {
        font-size: 0.8rem;
        min-height: 36px;
        padding: 6px 14px;
    }
    
    .litellm-preview-modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .litellm-preview-modal-body {
        padding: 10px 12px;
    }
    
    .preview-content {
        max-height: 150px;
        font-size: 0.8rem;
        padding: 8px 10px;
    }
    
    .litellm-preview-modal-footer button {
        width: 100%;
    }
}

/* ============================================================ */
/* IMPRESSION - Accessible                                      */
/* ============================================================ */

@media print {
    .litellm-chatbot-container {
        border: 1px solid #000;
    }
    
    .litellm-chatbot-header {
        background: #000 !important;
        color: #fff !important;
    }
    
    .litellm-chatbot-send-btn,
    .litellm-chatbot-insert-btn {
        border: 1px solid #000;
        background: #fff !important;
        color: #000 !important;
    }
    
    .litellm-preview-modal {
        background: #fff;
    }
    
    .litellm-preview-modal-content {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* ============================================================ */
/* RÉDUCTION DE MOUVEMENT - Accessible                          */
/* ============================================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .typing-indicator span {
        animation: none;
    }
    
    .litellm-preview-modal-content {
        animation: none;
    }
}

/* ============================================================ */
/* CONTRAST ÉLEVÉ - Accessible                                  */
/* ============================================================ */

@media (prefers-contrast: high) {
    .litellm-chatbot-header {
        background: #000 !important;
    }
    
    .litellm-chatbot-send-btn {
        background: #000 !important;
        border-color: #fff !important;
        color: #fff !important;
    }
    
    .litellm-chatbot-insert-btn {
        background: #000 !important;
        border-color: #fff !important;
        color: #fff !important;
    }
    
    .litellm-chatbot-small-btn {
        border: 1px solid #000;
    }
    
    #litellm-chatbot-input {
        border-width: 2px;
        border-color: #000;
    }
    
    #litellm-chatbot-input:focus {
        outline: 2px solid #000;
        outline-offset: 2px;
    }
    
    .litellm-preview-modal-content {
        border: 2px solid #000;
    }
    
    .litellm-preview-use-md {
        background: #000 !important;
        color: #fff !important;
        border-color: #fff !important;
    }
    
    .litellm-preview-use-html {
        background: #000 !important;
        color: #fff !important;
        border-color: #fff !important;
    }
    
    .message.user .message-content {
        background: #000 !important;
    }
}

/* ============================================================ */
/* DARK MODE - Accessible                                       */
/* ============================================================ */

@media (prefers-color-scheme: dark) {
    .litellm-chatbot-window {
        background: #1a1a2e !important;
    }
    
    .litellm-chatbot-messages {
        background: #1a1a2e !important;
    }
    
    .litellm-chatbot-messages .message.bot .message-content {
        background: #2d2d4a !important;
        color: #e2e8f0 !important;
        border-color: #4a4a6a !important;
    }
    
    .litellm-chatbot-input-area {
        background: #1a1a2e !important;
        border-top-color: #4a4a6a !important;
    }
    
    #litellm-chatbot-input {
        background: #2d2d4a !important;
        color: #e2e8f0 !important;
        border-color: #4a4a6a !important;
    }
    
    #litellm-chatbot-input:focus {
        border-color: var(--chatbot-primary) !important;
    }
    
    .litellm-chatbot-context {
        background: #2d2d4a !important;
        color: #94a3b8 !important;
    }
    
    .litellm-chatbot-small-btn {
        color: #94a3b8 !important;
    }
    
    .litellm-chatbot-small-btn:hover {
        background: #4a4a6a !important;
        color: #e2e8f0 !important;
    }
    
    .litellm-chatbot-status {
        color: #94a3b8 !important;
    }
    
    .preview-content {
        background: #2d2d4a !important;
        color: #e2e8f0 !important;
        border-color: #4a4a6a !important;
    }
    
    .preview-html,
    .preview-markdown {
        background: #1a1a2e !important;
        border-color: #4a4a6a !important;
    }
    
    .preview-html h4,
    .preview-markdown h4 {
        color: #94a3b8 !important;
    }
    
    .litellm-preview-modal-content {
        background: #1a1a2e !important;
        border-color: #4a4a6a !important;
    }
    
    .litellm-preview-modal-header {
        border-bottom-color: #4a4a6a !important;
        color: #e2e8f0 !important;
    }
    
    .litellm-preview-modal-close {
        color: #94a3b8 !important;
    }
    
    .litellm-preview-modal-close:hover {
        background: #4a4a6a !important;
        color: #e2e8f0 !important;
    }
    
    .litellm-preview-modal-footer {
        border-top-color: #4a4a6a !important;
    }
    
    .litellm-preview-cancel {
        background: #2d2d4a !important;
        color: #e2e8f0 !important;
        border-color: #4a4a6a !important;
    }
    
    .litellm-preview-cancel:hover {
        background: #4a4a6a !important;
    }
}