/* 
 * Masquer complètement le bouton d'upload de fichiers dans Chainlit
 * Ce bouton permet de joindre des fichiers au chat
 */

/* CIBLE PRINCIPALE : Le bouton d'upload avec id="upload-button" */
#upload-button,
button#upload-button {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Masquer tous les inputs de type file */
input[type="file"] {
    display: none !important;
}

/* Sécurité supplémentaire : masquer tout bouton avec role="presentation" contenant un SVG de pièce jointe */
button[role="presentation"]:has(svg path[d*="M9 7C9 4.23858"]) {
    display: none !important;
}

/* Masquer les boutons avec le SVG de pièce jointe (path spécifique) */
button:has(svg path[fill-rule="evenodd"][d*="M9 7C9 4.23858 11.2386 2 14 2C16.7614 2 19 4.23858 19 7V15"]) {
    display: none !important;
}

/* ===== PERSONNALISATION DU LOGO ===== */

/* Masquer le logo par défaut de Chainlit dans le header */
#app-header img[alt="logo"],
header img[alt="logo"],
.MuiAvatar-root img,
a[href="/"] img {
    content: url('/logo.svg') !important;
    width: 40px !important;
    height: 40px !important;
}

/* Alternative : remplacer le logo via le conteneur */
#app-header a[href="/"] {
    background-image: url('/logo.svg') !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
}

/* S'assurer que le logo personnalisé est bien visible */
#app-header a[href="/"] img {
    opacity: 1 !important;
}

/* ===== AMÉLIORATION DU STREAMING ===== */

/* Animation fluide pour les messages en cours de streaming */
.step-streaming .message-content,
.step-streaming p,
.step-streaming span {
    animation: smoothAppear 0.15s ease-out;
}

/* Effet de fade-in doux pour le texte streamé */
@keyframes smoothAppear {
    from {
        opacity: 0;
        transform: translateY(2px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Améliorer le rendu du texte pendant le streaming */
.step-streaming {
    will-change: contents;
}

/* Cursor clignotant pendant le streaming */
.step-streaming .message-content::after {
    content: '▊';
    animation: blink 1s step-end infinite;
    margin-left: 2px;
    color: var(--primary-main, #6366f1);
    opacity: 0.6;
}

@keyframes blink {
    0%, 50% { opacity: 0.6; }
    51%, 100% { opacity: 0; }
}

/* Désactiver le cursor après la fin du streaming */
.step:not(.step-streaming) .message-content::after {
    display: none;
}

/* Améliorer la lisibilité pendant le streaming */
.step-streaming .message-content {
    line-height: 1.6;
    letter-spacing: 0.01em;
}

/* Transition fluide pour les paragraphes */
.message-content p {
    transition: opacity 0.2s ease-in-out;
}

/* Accélération matérielle pour de meilleures performances */
.step-streaming .message-content,
.message-content {
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== RESPONSIVE MOBILE ===== */

/* Correction du responsive de la modale README (Lisez-moi) */
@media screen and (max-width: 768px) {
    /* S'assurer que la modale ne déborde pas sur mobile et reste sous la barre du navigateur */
    .MuiDialog-paper,
    [role="dialog"] {
        margin: 16px !important;
        margin-top: 80px !important; /* Espace pour la barre du navigateur */
        max-height: calc(100vh - 96px) !important; /* Ajusté pour le margin-top */
        width: calc(100vw - 32px) !important;
        max-width: calc(100vw - 32px) !important;
    }
    
    /* Ajuster le padding du contenu de la modale */
    .MuiDialogContent-root,
    [role="dialog"] > div {
        padding: 16px !important;
        padding-top: 48px !important; /* Espace pour le bouton de fermeture */
    }
    
    /* S'assurer que le bouton de fermeture est toujours visible */
    .MuiDialogTitle-root button,
    [role="dialog"] button[aria-label*="close"],
    [role="dialog"] button[aria-label*="Close"],
    [role="dialog"] .MuiIconButton-root {
        position: fixed !important;
        top: 8px !important;
        right: 8px !important;
        z-index: 9999 !important;
        background-color: rgba(255, 255, 255, 0.9) !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
        padding: 8px !important;
    }
    
    /* Améliorer la visibilité du titre sur mobile */
    .MuiDialogTitle-root,
    [role="dialog"] h2 {
        padding-right: 48px !important; /* Espace pour le bouton */
        font-size: 1.25rem !important;
    }
    
    /* Ajuster le contenu markdown sur mobile */
    .markdown-body,
    [role="dialog"] .markdown {
        font-size: 14px !important;
        line-height: 1.6 !important;
    }
    
    /* Ajuster les titres dans la modale sur mobile */
    [role="dialog"] h1 {
        font-size: 1.5rem !important;
    }
    
    [role="dialog"] h2 {
        font-size: 1.25rem !important;
    }
    
    [role="dialog"] h3 {
        font-size: 1.1rem !important;
    }
}

/* Pour les très petits écrans (moins de 400px) */
@media screen and (max-width: 400px) {
    .MuiDialog-paper,
    [role="dialog"] {
        margin: 8px !important;
        margin-top: 80px !important; /* Espace pour la barre du navigateur */
        max-height: calc(100vh - 88px) !important; /* Ajusté pour le margin-top */
        width: calc(100vw - 16px) !important;
        max-width: calc(100vw - 16px) !important;
    }
    
    .MuiDialogContent-root,
    [role="dialog"] > div {
        padding: 12px !important;
        padding-top: 44px !important;
    }
}

/* ===== FOOTER CGU PERMANENT ===== */

/* Footer fixe en bas de page qui s'adapte au thème */
.cgu-footer-permanent {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: hsl(var(--background)) !important;
    backdrop-filter: blur(10px);
    border-top: 1px solid hsl(var(--border));
    padding: 12px 20px !important;
    text-align: center !important;
    font-size: 0.85em;
    color: hsl(var(--muted-foreground));
    z-index: 10000 !important;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    line-height: 1.5;
    margin: 0 auto !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.cgu-footer-permanent p {
    margin: 0 !important;
    padding: 0 !important;
}

/* ===== MASQUER LE CURSEUR ANIMÉ APRÈS LE STREAMING ===== */

/* Masquer le curseur animé (rond qui pulse) une fois le streaming terminé */
.step:not(.step-streaming) .animate-pulse,
.step:not(.step-streaming) span.animate-pulse,
.step:not(.step-streaming) .inline-block.animate-pulse {
    display: none !important;
}

/* Alternative : masquer tous les curseurs animés dans les messages terminés */
.step:not(.step-streaming) span[class*="animate-pulse"] {
    display: none !important;
}

/* ===== RETIRER L'ARRONDI DE L'AVATAR DE L'ASSISTANT ===== */

/* Retirer rounded-full de l'avatar de l'assistant */
span[data-state] img[alt*="Assistant"],
span.rounded-full img[alt*="Assistant"],
span[class*="rounded-full"] img[alt*="Assistant"] {
    border-radius: 0 !important;
}

/* Retirer aussi rounded-full du conteneur span */
span[data-state] img[alt*="Assistant"] {
    border-radius: 0 !important;
}

span[class*="rounded-full"]:has(img[alt*="Assistant"]) {
    border-radius: 0 !important;
}

/* Cibler spécifiquement le span avec les classes mentionnées */
span.relative.flex.shrink-0.overflow-hidden.rounded-full:has(img[alt*="Assistant"]) {
    border-radius: 0 !important;
}

span.relative.flex.shrink-0.overflow-hidden.rounded-full img[alt*="Assistant"] {
    border-radius: 0 !important;
}

.cgu-footer-permanent a,
.cgu-footer-permanent a:link,
.cgu-footer-permanent a:visited,
.cgu-footer-permanent a:active {
    color: #6366f1 !important;
    text-decoration: underline !important;
    text-decoration-thickness: 1px !important;
    text-underline-offset: 2px !important;
    font-weight: 500 !important;
    transition: all 0.2s ease !important;
}

.cgu-footer-permanent a:hover,
.cgu-footer-permanent a:focus {
    color: #6366f1 !important;
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    opacity: 0.8 !important;
}

/* Ajouter un padding au conteneur principal pour éviter que le contenu soit caché par le footer */
#root,
.MuiContainer-root,
main {
    padding-bottom: 70px !important;
}

/* Responsive pour mobile */
@media screen and (max-width: 768px) {
    .cgu-footer-permanent {
        font-size: 0.7em !important;
        padding: 10px 12px !important;
        line-height: 1.3;
    }
    
    #root,
    .MuiContainer-root,
    main {
        padding-bottom: 65px !important;
    }
}

/* ===== MASQUER LE BOUTON LISEZ-MOI ===== */

/* Masquer le bouton avec l'icône d'information (Lisez-moi) */
button[aria-label*="readme" i],
button[aria-label*="Read me" i],
button[aria-label*="Lisez-moi" i],
button[title*="readme" i],
button[title*="Read me" i],
button[title*="Lisez-moi" i],
button[aria-label*="readme"],
button[aria-label*="Read me"],
button[aria-label*="Lisez-moi"],
button[title*="readme"],
button[title*="Read me"],
button[title*="Lisez-moi"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

/* Masquer aussi par le SVG d'information (icône ℹ) - avec :has() pour navigateurs modernes */
button:has(svg[data-testid="InfoIcon"]),
button:has(svg[data-testid*="info" i]),
button:has(svg path[d*="M12 2C6.48"]) {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

/* Alternative pour Firefox - cibler les boutons contenant un SVG avec data-testid */
button svg[data-testid="InfoIcon"],
button svg[data-testid*="info" i] {
    display: none !important;
}

/* Cibler les boutons dans la barre d'outils en haut à gauche (position typique du bouton readme) */
header button[aria-label*="readme" i],
header button[aria-label*="Read me" i],
header button[aria-label*="Lisez-moi" i],
header button[title*="readme" i],
header button[title*="Read me" i],
header button[title*="Lisez-moi" i],
nav button[aria-label*="readme" i],
nav button[aria-label*="Read me" i],
nav button[aria-label*="Lisez-moi" i],
nav button[title*="readme" i],
nav button[title*="Read me" i],
nav button[title*="Lisez-moi" i] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

/* ===== SCROLLBAR PERSONNALISÉE ===== */

/* Firefox - Scrollbar fine et élégante */
* {
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--muted-foreground) / 0.3) hsl(var(--background));
}

/* Chrome, Edge, Safari - Scrollbar personnalisée */
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: hsl(var(--background));
    border-radius: 10px;
}

*::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.3);
    border-radius: 10px;
    border: 2px solid hsl(var(--background));
    transition: background 0.2s ease;
}

*::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
}

*::-webkit-scrollbar-thumb:active {
    background: hsl(var(--primary) / 0.6);
}

/* Scrollbar pour les conteneurs avec bordure (plus visible) */
.scrollable-container::-webkit-scrollbar-thumb,
[class*="scroll"]::-webkit-scrollbar-thumb,
main::-webkit-scrollbar-thumb,
#root::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.4);
}

.scrollable-container::-webkit-scrollbar-thumb:hover,
[class*="scroll"]::-webkit-scrollbar-thumb:hover,
main::-webkit-scrollbar-thumb:hover,
#root::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--primary) / 0.5);
}

/* Scrollbar horizontale */
*::-webkit-scrollbar:horizontal {
    height: 10px;
}

/* Amélioration pour les zones de texte */
textarea::-webkit-scrollbar,
input::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

textarea::-webkit-scrollbar-thumb,
input::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.25);
    border-radius: 8px;
    border: 1px solid hsl(var(--background));
}

textarea::-webkit-scrollbar-thumb:hover,
input::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.4);
}

/* Adaptation automatique au thème sombre */
@media (prefers-color-scheme: dark) {
    * {
        scrollbar-color: hsl(var(--muted-foreground) / 0.4) hsl(var(--background));
    }
    
    *::-webkit-scrollbar-thumb {
        background: hsl(var(--muted-foreground) / 0.4);
    }
    
    *::-webkit-scrollbar-thumb:hover {
        background: hsl(var(--muted-foreground) / 0.6);
    }
    
    *::-webkit-scrollbar-thumb:active {
        background: hsl(var(--primary) / 0.7);
    }
}

/* Adaptation pour le light mode explicite */
[data-theme="light"],
.light-mode {
    scrollbar-color: hsl(var(--muted-foreground) / 0.3) hsl(var(--background));
}

[data-theme="light"] *::-webkit-scrollbar-thumb,
.light-mode *::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.3);
}

[data-theme="light"] *::-webkit-scrollbar-thumb:hover,
.light-mode *::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
}

/* Adaptation pour le dark mode explicite */
[data-theme="dark"],
.dark-mode {
    scrollbar-color: hsl(var(--muted-foreground) / 0.4) hsl(var(--background));
}

[data-theme="dark"] *::-webkit-scrollbar-thumb,
.dark-mode *::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.4);
}

[data-theme="dark"] *::-webkit-scrollbar-thumb:hover,
.dark-mode *::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.6);
}

[data-theme="dark"] *::-webkit-scrollbar-thumb:active,
.dark-mode *::-webkit-scrollbar-thumb:active {
    background: hsl(var(--primary) / 0.7);
}
