/* ========================================
   1. ÉLÉMENTS GLOBAUX & HEADER
   ======================================== */

/* Masquer le bouton plug (non utilisé) */
button:has(svg.lucide-plug) {
    display: none;
}

/* Header principal */
#header {
    background: hsl(var(--header-bg));
    height: 47px;
}

#header > div.flex.items-center {
    position: relative;
}

/* Logo dans le header */
#header > div:last-child::before {
    content: "";
    display: block;
    width: 158px;
    height: 21px;
    background-image: url('/public/logo_dark.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin-right: 6px;
}

/* Sidebar header */
[data-sidebar="header"] {
    background: hsl(var(--header-bg));
    height: 47px;
    padding-top: 6px !important;
    padding-bottom: 0 !important;
}

/* Boutons du header */
#theme-toggle, #search-chats-button, #sidebar-trigger-button {
    color: hsl(var(--header-muted));
}
/* Bouton fermeture sidebar masqué sur desktop */
#sidebar-trigger-button {
    display: none;
}

/* Hover et focus des éléments du header */
#theme-toggle:hover, #search-chats-button:hover, #sidebar-trigger-button:hover, #chat-profiles:hover, #user-nav-button:hover {
    background-color: hsl(var(--header-hover-bg));
}

#theme-toggle:focus-visible, #new-chat-button:focus-visible, #search-chats-button:focus-visible, #sidebar-trigger-button:focus-visible, #chat-profiles:focus-visible, #user-nav-button:focus-visible {
    --tw-ring-offset-shadow: 1px 0px 15px 5px #00000029;
}

#theme-toggle::focus, #new-chat-button::focus, #search-chats-button::focus, #sidebar-trigger-button::focus, #chat-profiles::focus, #user-nav-button::focus {
    --tw-ring-offset-shadow: 1px 0px 15px 5px #00000029;
}

/* ========================================
   2. SÉLECTION DE PROFIL
   ======================================== */

/* Masquer le sélecteur natif (remplacé par les cartes custom) */
#chat-profiles {
    opacity: 0;
    pointer-events: none;
}

/* Masquer le sous-menu déroulant */
[data-radix-popper-content-wrapper]:has([role="option"]) {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Conteneur des cartes de profil */
#profile-cards-container {
    position: relative;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-top: 5px;
}

/* Cartes de sélection de profil */
.profile-card {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 240px;
    height: 96px;
    border-radius: 20px;
    border: 2px solid hsl(var(--border));
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    cursor: pointer;
    gap: 14px;
    padding: 20px;
    font-family: inherit;
}

.profile-card:hover {
    border: 2px solid hsl(var(--primary));
}

.profile-card img {
    width: 36px !important;
    height: 36px !important;
    margin-bottom: 0 !important;
    border-radius: 20% !important;
    object-fit: cover;
}

.profile-card span {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
}

/* ========================================
   3. WELCOME SCREEN & MESSAGES DE BIENVENUE
   ======================================== */

/* Message de bienvenue principal pour mmulti-profils (avec cartes) */
#welcome-screen .prose {
    font-size: 15px;
    color: hsl(var(--welcome-msg));
    position: relative;
}

#welcome-screen .prose::before {
    content: "Comment puis-je vous aider aujourd'hui ?";
    display: block;
    text-align: center;
    position: absolute;
    top: -41px;
    left: 50%;
    transform: translateX(-50%);
    color: hsl(var(--card-foreground));
    font-family: 'Roboto', sans-serif;
    font-size: 26px;
    font-weight: 500;
    width: max-content;
}

/** 1 profil only **/
/* Messages de bienvenue pour profil unique (body sans classe) */
body:not([class]) #welcome-screen #message-composer {
    position: relative;
}

/** 1 profil only **/
body:not([class]) #welcome-screen #message-composer::before {
    content: "Comment puis-je vous aider aujourd'hui ?";
    display: block;
    text-align: center;
    position: absolute;
    top: -134px;
    left: 0;
    font-family: 'Roboto', sans-serif;
    font-size: 26px;
    font-weight: 500;
    width: 100%;
}

/** 1 profil only **/
body:not([class]) #welcome-screen #message-composer::after {
    content: "Inutile de me solliciter pour un sketch'o : je ne suis pas très \"court et drôle\"";
    display: block;
    text-align: center;
    position: absolute;
    top: -87px;
    left: 0;
    font-family: 'Roboto', sans-serif;
    font-size: 16px;
    color: hsl(var(--welcome-msg));
    font-weight: 400;
    width: 100%;
}

body:has(#profile-cards-container) #welcome-screen .prose::before {
    content: "Bienvenue sur l'assistant IA interne de Cospirit";
}

/* Avatar du welcome screen */
.welcome-screen img {
    margin-bottom: 50px;
    border-radius: 20% !important;
    width: 50px;
    height: 50px;
}

body:not([class]) .welcome-screen img {
    margin-bottom: 127px;
}

/* Masquer l'envoi de message quand les cartes sont présentes */
#welcome-screen:has(#profile-cards-container) #message-composer {
    display: none;
}

/* ========================================
   4. BOUTON NOUVELLE CONVERSATION
   ======================================== */

#new-chat-button {
    position: absolute;
    left: 22px;
    top: 70px;
    width: auto !important;
    padding: 0 28px;
    z-index: 1000;
    background: hsl(var(--primary));
    color: white;
}

#new-chat-button:hover {
    background-color: #3333ffb0;
}

#new-chat-button svg {
    display: none;
}

#new-chat-button::after {
    content: "Nouvelle conversation";
    font-size: 14px;
    font-weight: 500;
    color: white;
    margin-left: 8px;
}

#new-chat-button::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 4v16m8-8H4' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

/* ========================================
   5. LAYOUT & POSITIONNEMENT
   ======================================== */

#thread-history {
    margin-top: 58px;
}

/* User nav button */
#user-nav-button {
    .bg-primary {
        background: #ecebeb5c;
    }
}

/* Avatar messages IA */
.ai-message .relative.flex {
    width: 25px !important;
    height: 25px !important;
}

/* ========================================
   10. RESPONSIVE - MOBILE & TABLETTE
   ======================================== */

@media (max-width: 1024px) {
    #new-chat-button {
        position: static;
        left: auto;
        top: auto;
        width: 36px !important;
        padding: 0;
    }
    
    #new-chat-button svg {
        display: block;
    }
    
    #new-chat-button::after {
        content: none;
    }
    
    #new-chat-button::before {
        display: none;
    }
    
    #sidebar-trigger-button {
        display: block;
    }
    body:not([class]) #welcome-screen #message-composer::after {
        display: none;
    }
    #welcome-screen .prose::before {
        width: 90vw;
        flex-wrap: wrap;
        top: -78px;
        font-size: 23px;
    }
    #welcome-screen .prose {
        margin-top: 35px;
    }

    #header > div:last-child::before {
        display: none;
    }
    
    #profile-cards-container::after {
        display: none;
    }
}

@media (max-width: 768px) {
    .profile-badge .badge-content {
        font-size: 0 !important;
        padding: 5px !important;
        padding-right: 0 !important;
    }

    .profile-badge .badge-icon {
        font-size: 12px;
    }
}

/* ========================================
   7. STYLES SPÉCIFIQUES PAR PROFIL
   ======================================== */

/* Profil META - boutons et avatar */
.profile-meta #chat-submit, .profile-meta #stop-button {
    background-color: var(--meta-purple-solid) !important;
}

/* Avatar personnalisé pour le profil META */
.profile-meta .ai-message img[alt*="Avatar"] {
    content: url('/public/avatars/meta.png') !important;
    src: '/public/avatars/meta.png' !important;
}

/* ========================================
   8. LOADING & INDICATEURS
   ======================================== */

/* Animation de chargement */
@keyframes shimmer {
    0%   { background-position:  200% center; }
    100% { background-position: -200% center; }
}

/* Indicateur de chargement au-dessus du message-composer */
body:has(#message-composer .stop-icon) *:has(> [data-step-type="user_message"])::after {
    content: "Chargement...";
    display: block;
    margin-top: 12px;
    padding-left: 16px;
    font-size: 1em;
    white-space: nowrap;
    background: linear-gradient(
        90deg,
        hsl(var(--muted-foreground, 0 0% 25%)) 25%,
        hsl(var(--foreground, 0 0% 95%)) 50%,
        hsl(var(--muted-foreground, 0 0% 25%)) 75%
    );
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 1.6s linear infinite;
}

/* Cacher le curseur de chargement par défaut */
.loading-cursor {
    display: none !important;
}

/* ========================================
   9. ÉLÉMENTS MASQUÉS
   ======================================== */

/* Masquer le bouton readme */
#readme-button {
    display: none;
}

/* Désactiver le bouton rail de la sidebar */
[data-sidebar="rail"] {
    pointer-events: none;
}

[data-sidebar="rail"]:hover::after {
    background: transparent !important;
}

/* Masquer le watermark */
.watermark {
    height: 17px;
}

.watermark .prose {
    display: none;
}

/* Masquer les étapes tool et llm */
[data-step-type="tool"],
[data-step-type="llm"] {
    display: none;
}

/* ========================================
   9. PASTILLE DE PROFIL (MESSAGE COMPOSER)
   ======================================== */

/* Pastille de profil dans le message composer */
.profile-badge {
    margin-right: 8px;
    white-space: nowrap;
    width: fit-content;
}

.profile-badge .badge-content {
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 9999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
    border-width: 1px;
    border-style: solid;
}

.profile-badge .badge-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.profile-badge .badge-icon svg {
    width: 12px;
    height: 12px;
}

/* Style pour profil META (violet) */
.profile-meta .profile-badge .badge-content {
    background: var(--meta-purple-bg);
    color: var(--meta-purple);
    border-color: var(--meta-purple-border);
}

.profile-meta .profile-badge .badge-icon {
    background-color: var(--meta-purple-solid);
}

.profile-meta .profile-badge .badge-icon svg {
    color: white;
}

/* Style pour profil DEFAULT (bleu) */
.profile-default .profile-badge .badge-content {
    background: rgba(59, 130, 246, 0.125);
    color: #3B82F6;
    border-color: rgba(59, 130, 246, 0.25);
}

.profile-default .profile-badge .badge-icon {
    background-color: #3333ffb0;
}

.profile-default .profile-badge .badge-icon svg {
    color: white;
}

/** Style pour les boutons du chatbot */
.meta-oauth-btn {
    border: 1px solid #d7d7d7;
    font-size: 17px !important;
}

/* ========================================
   11. META UI — SOUS-HEADER, SIDEBAR & WELCOME
   ======================================== */

@keyframes metaFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

:root {
    --meta-purple: rgb(var(--meta-purple-rgb));
    --meta-purple-solid: rgb(153, 0, 255);
    --meta-purple-light: rgba(var(--meta-purple-rgb), 0.063);
    --meta-purple-border: rgba(var(--meta-purple-rgb), 0.25);
    --meta-purple-bg: rgba(var(--meta-purple-rgb), 0.082);
    --meta-purple-badge: rgba(var(--meta-purple-rgb), 0.19);
    --meta-purple-btn-icon: rgba(var(--meta-purple-rgb), 0.145);
}

/* ---- Sous-header bonnes pratiques ---- */

#meta-subheader {
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid hsl(var(--border));
    flex-shrink: 0;
    background: transparent;
}

.meta-practices-btn {
    margin-left: auto;
    height: 28px;
    padding: 0 6px 0 10px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    background: var(--meta-purple-bg);
    color: var(--meta-purple);
    border: 1px solid var(--meta-purple-border);
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
}

.meta-practices-btn:hover {
    background: var(--meta-purple-bg);
}

.meta-practices-btn-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--meta-purple-btn-icon);
}

/* ---- Overlay & panneau latéral ---- */

#meta-sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 49;
    background: rgba(0, 0, 0, 0.35);
    display: none;
    animation: metaFadeIn 0.2s ease;
}

#meta-sidebar-overlay.is-open {
    display: block;
}

#meta-sidebar-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 100%;
    max-width: 448px;
    background: hsl(var(--card));
    border-left: 1px solid hsl(var(--border));
    z-index: 50;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

#meta-sidebar-panel.is-open {
    transform: translateX(0);
}

.meta-sidebar-header {
    padding: 24px;
    border-bottom: 1px solid hsl(var(--border));
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.meta-sidebar-header-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--meta-purple-solid);
    color: white;
}

.meta-sidebar-title {
    font-size: 18px;
    font-weight: 600;
    color: hsl(var(--foreground));
    margin: 0;
}

.meta-sidebar-subtitle {
    font-size: 14px;
    color: hsl(var(--muted-foreground));
    margin: 4px 0 0;
}

.meta-sidebar-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    flex: 1;
}

.meta-intro-box {
    border-radius: 8px;
    padding: 12px;
    font-size: 12px;
    line-height: 1.6;
    background: var(--meta-purple-light);
    border: 1px solid var(--meta-purple-border);
    color: hsl(var(--foreground));
}

.meta-section-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.meta-section-head-label {
    display: flex;
    align-items: center;
    gap: 6px;
}

.meta-badge {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
    background: var(--meta-purple-bg);
    color: var(--meta-purple);
    border: 1px solid var(--meta-purple-badge);
}

.meta-section-icon {
    color: var(--meta-purple-solid);
    display: flex;
    align-items: center;
}

.meta-section-title {
    font-size: 14px;
    font-weight: 600;
    color: hsl(var(--foreground));
    margin: 0;
}

.meta-quote {
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
    background: hsl(var(--accent));
    border: 1px solid hsl(var(--border));
}

.meta-quote p {
    font-size: 12px;
    line-height: 1.6;
    font-style: italic;
    color: hsl(var(--foreground));
    margin: 0;
}

.meta-hint {
    font-size: 12px;
    margin: 12px 0 6px;
    color: hsl(var(--foreground));
}

.meta-hint-list {
    font-size: 12px;
    list-style-type: disc;
    padding-left: 16px;
    margin: 0;
    color: hsl(var(--foreground));
}

.meta-hint-muted {
    font-size: 12px;
    margin: 12px 0 0;
    color: hsl(var(--muted-foreground));
}

.meta-error-box {
    border-radius: 8px;
    padding: 12px;
    display: flex;
    gap: 8px;
    margin-top: 12px;
    background: rgba(201, 29, 29, 0.08);
    border: 1px solid rgba(201, 29, 29, 0.28);
}

.meta-error-icon {
    color: rgb(201, 29, 29);
    flex-shrink: 0;
    margin-top: 2px;
    display: flex;
}

.meta-error-text {
    font-size: 12px;
    color: rgb(115, 38, 38);
}

.dark .meta-error-box {
    background: rgba(240, 80, 80, 0.12);
    border-color: rgba(240, 80, 80, 0.3);
}

.dark .meta-error-icon,
.dark .meta-error-text {
    color: rgb(240, 120, 120);
}

#meta-sidebar-close {
    position: absolute;
    right: 16px;
    top: 16px;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.6;
    padding: 4px;
    border-radius: 4px;
    color: hsl(var(--foreground));
    display: flex;
    align-items: center;
    justify-content: center;
}

#meta-sidebar-close:hover {
    opacity: 1;
    background: hsl(var(--accent));
}

/* ---- Welcome cards bonnes pratiques ---- */

#meta-welcome-cards {
    width: 100%;
    max-width: 768px;
    margin: 20px auto 0;
    box-sizing: border-box;
}

.meta-welcome-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.meta-welcome-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: hsl(var(--meta-advices-link));
    text-transform: uppercase;
}

.meta-welcome-title-icon {
    color: var(--meta-purple);
    display: flex;
    align-items: center;
}

.meta-guide-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: var(--meta-purple);
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 0;
    font-family: inherit;
}

.meta-cards-row {
    display: flex;
    gap: 12px;
}

.meta-welcome-card {
    flex: 1;
    min-width: 0;
    border-radius: 12px;
    padding: 12px;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
}

.meta-welcome-card-icon {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--meta-purple-light);
    color: var(--meta-purple);
    margin-bottom: 8px;
    flex-shrink: 0;
}

.meta-welcome-card-title {
    font-size: 13px;
    font-weight: 600;
    color: hsl(var(--foreground));
    margin: 0 0 6px;
}

.meta-welcome-card-desc {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    line-height: 1.5;
    margin: 0;
}

@media (max-width: 640px) {
    .meta-cards-row {
        flex-direction: column;
    }

    #meta-welcome-cards .meta-welcome-title { display: none; }
    #meta-welcome-cards .meta-cards-row     { display: none; }
    #meta-welcome-cards                     { margin-top: 8px; }
    #meta-welcome-cards .meta-welcome-header { justify-content: flex-end; }

    #meta-guide-btn     { font-size: 0; }
    #meta-guide-btn svg { display: none; }
    #meta-guide-btn::before {
        content: "Voir les bonnes pratiques >";
        font-size: 12px;
        font-weight: 500;
    }

    #meta-sidebar-close { top: 8px; right: 12px; }
}
