/* ==========================================================================
   1. VARIABLES & RESET
   ========================================================================== */
:root {
    --fond-principal: #fff;
    --fond-secondaire: #f8f9fa;
    --fond-tertiaire: #f1f3f4;
    --texte-principal: #202124;
    --texte-secondaire: #5f6368;
    --texte-tertiaire: #80868b;
    --bordure: #e0e0e0;
    --accent: #1a73e8;
    --accent-hover: #1765cc;
    --accent-leger: #e8f0fe;
    --ombre-legere: 0 1px 2px rgba(0,0,0,0.1);
    --ombre-moyenne: 0 2px 8px rgba(0,0,0,0.1);
    --rayon: 8px;
    --transition: all 0.2s ease;
    --code-fond: #f8f8f8;
    --code-bordure: #d1d5da;
    --code-texte: #1a1a1a;
    --diff-addition: #e6ffec;
    --diff-deletion: #ffebe9;
    --diff-addition-text: #055d20;
    --diff-deletion-text: #82071e;
}

body.theme-sombre {
    --fond-principal: #202124;
    --fond-secondaire: #292a2d;
    --fond-tertiaire: #35363a;
    --texte-principal: #e8eaed;
    --texte-secondaire: #9aa0a6;
    --texte-tertiaire: #80868b;
    --bordure: #3c4043;
    --accent: #8ab4f8;
    --accent-hover: #aecbfa;
    --accent-leger: #1e3a5f;
    --code-fond: #1e1e1e;
    --code-bordure: #3e3e3e;
    --code-texte: #f8f8f2;
    --diff-addition: #0e2f19;
    --diff-deletion: #3d1e1e;
    --diff-addition-text: #7ee83f;
    --diff-deletion-text: #ff6b6b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    min-height: 100%;
    background: var(--fond-principal);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--texte-principal);
    line-height: 1.5;
    font-size: 14px;
    overflow: auto;
}

/* ==========================================================================
   2. LAYOUT GÉNÉRAL & COMPOSANTS
   ========================================================================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    min-width: 0;
}

.content-layout {
    flex: 1;
    display: flex;
    min-height: 0;
    height: 100%;
}

.btn-primary {
    padding: 8px 16px;
    border: none;
    border-radius: var(--rayon);
    background: var(--accent);
    color: white;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}
.btn-primary[disabled] {
    background: var(--fond-tertiaire);
    color: var(--texte-tertiaire);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    padding: 8px 16px;
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    background: var(--fond-principal);
    color: var(--texte-principal);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--fond-tertiaire);
    border-color: var(--accent);
    transform: translateY(-1px);
}
.btn-secondary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--rayon);
    border: 1px solid var(--bordure);
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.btn-icon:hover {
    background: var(--fond-tertiaire);
    color: var(--texte-principal);
    border-color: var(--accent);
}

.btn-icon-small {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid var(--bordure);
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}
.btn-icon-small:hover {
    background: var(--fond-tertiaire);
    color: var(--accent);
}

/* NOUVEAU: Boutons mobiles */
.btn-nav-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--bordure);
    background: var(--fond-principal);
    color: var(--texte-secondaire);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 12px;
}
.btn-nav-icon:hover {
    background: var(--fond-tertiaire);
    color: var(--texte-principal);
    border-color: var(--accent);
}

/* Bouton hamburger mobile - caché par défaut sur desktop */
.btn-toggle-mobile {
    display: none;
}

/* ==========================================================================
   6. RESPONSIVE & ANIMATIONS
   ========================================================================== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes messageSlideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 1; } }
/* ===== SCROLLBARS VISIBLES (Phase 1 - Fix UI) ===== */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
    background: var(--fond-secondaire);
}
::-webkit-scrollbar-track {
    background: var(--fond-tertiaire);
    border-radius: 5px;
}
::-webkit-scrollbar-thumb {
    background: var(--bordure);
    border-radius: 5px;
    border: 2px solid var(--fond-tertiaire);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}
.notification { position: fixed; top: 20px; right: 20px; padding: 12px 18px; border-radius: var(--rayon); z-index: 10000; font-size: 13px; font-weight: 500; animation: slideIn 0.3s ease; }
.notification-success { background: #4caf50; color: white; }
.notification-error { background: #f44336; color: white; }
.notification-warning { background: #ff9800; color: white; }
.notification-info { background: var(--accent); color: white; }

@media (max-width: 1400px) { 
    .tool-panel { 
        width: 45%; 
        min-width: 350px;
    }
    .chat-panel.avec-panneau {
        flex: 0 0 55%;
    }
}

@media (max-width: 1200px) { 
    .tool-panel { 
        display: none !important; 
    } 
    .chat-panel.avec-panneau {
        flex: 1;
    }
    .form-row { 
        flex-wrap: wrap; 
    } 
}

@media (max-width: 768px) { 
    .sidebar { 
        width: 220px; 
    } 
    .chat-title-container { 
        margin-left: 0;
        max-width: 70%; 
    } 
    .config-header h2 { 
        margin-left: 12px; 
    } 
    .config-content { 
        padding: 16px; 
    } 
    .config-section { 
        padding: 12px; 
    } 
    .liste-groupes, .fournisseur-modeles {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* FORCER app-container à largeur viewport complète ET retirer flexbox */
    .app-container {
        display: block !important;
        width: 100vw !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        height: 100vh !important;
        overflow-y: hidden !important;
    }

    /* Bouton hamburger en position fixed pour ne pas décaler le contenu */
    .btn-toggle-mobile {
        position: fixed !important;
        top: 12px !important;
        left: 12px !important;
        z-index: 1001 !important;
        width: 40px !important;
        height: 40px !important;
        border-radius: 8px !important;
        border: 1px solid var(--bordure) !important;
        background: var(--fond-principal) !important;
        color: var(--texte-secondaire) !important;
        cursor: pointer !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: var(--ombre-moyenne) !important;
    }

    .btn-toggle-mobile:hover {
        background: var(--fond-tertiaire) !important;
        color: var(--texte-principal) !important;
    }

    /* Sidebar en position fixed = sortie du flux = ne prend pas d'espace */
    .sidebar {
        position: fixed;
        z-index: 1000;
        height: 100vh;
        width: 260px;
        left: 0;
        top: 0;
        transition: left 0.3s ease;
    }

    /* Sidebar repliée = complètement cachée hors écran */
    .sidebar.repliee {
        left: -260px !important;
        width: 260px !important;
    }

    /* FORCER tous les conteneurs à prendre 100% de largeur ET hauteur */
    .main-content {
        position: absolute !important;
        top: 0 !important;
        left: 260px !important;
        right: 0 !important;
        bottom: 0 !important;
        width: calc(100vw - 260px) !important;
        max-width: none !important;
        height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
        transition: left 0.3s ease, width 0.3s ease !important;
        margin: 0 !important;
    }

    /* Quand sidebar repliée, main-content prend toute la largeur */
    /* Utilise body.sidebar-repliee (ajouté par JS) pour compatibilité navigateurs sans :has() */
    body.sidebar-repliee .main-content {
        left: 0 !important;
        width: 100vw !important;
    }

    /* CRUCIAL : content-layout et chat-panel doivent s'étendre verticalement */
    .content-layout {
        width: 100% !important;
        max-width: none !important;
        flex: 1 !important;
        height: 100% !important;
        min-height: 0 !important;
    }

    .chat-panel {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        flex: 1 !important;
        height: 100% !important;
        min-height: 0 !important;
    }

    /* Chat-zone doit prendre toute la hauteur disponible */
    .chat-zone {
        height: 100% !important;
        min-height: 0 !important;
    }

    /* IMPORTANT : Surcharger les règles .avec-panneau sur mobile */
    .chat-panel.avec-panneau {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        flex: 1 !important;
    }

    /* ========================================
       BOUTON CONNEXION CLAIR
       ======================================== */
    .btn-connexion {
        display: flex !important;
        align-items: center;
        gap: 6px;
        background: var(--accent) !important;
        color: white !important;
        padding: 6px 12px !important;
        border-radius: 6px !important;
        font-weight: 500;
        text-decoration: none;
    }

    .btn-connexion:hover {
        background: var(--accent-hover) !important;
    }

    .btn-connexion-label {
        font-size: 12px;
    }

    /* ========================================
       PANNEAU OUTILS MOBILE (slide droite)
       ======================================== */
    .tool-panel {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 1002 !important;
        transform: translateX(100%);
        transition: transform 0.3s ease !important;
    }

    .tool-panel[style*="display: block"],
    .tool-panel[style*="display:block"],
    .tool-panel.visible {
        transform: translateX(0) !important;
    }

    .tool-panel-header {
        padding: 10px 12px !important;
        flex-wrap: wrap;
        gap: 8px;
    }

    .tool-panel-tabs {
        order: 2;
        width: 100%;
        display: flex;
        gap: 4px;
    }

    .tool-tab {
        flex: 1;
        font-size: 11px !important;
        padding: 6px 8px !important;
    }

    .tool-panel-title {
        order: 1;
        flex: 1;
    }

    .tool-panel-actions {
        order: 1;
    }

    /* ========================================
       OPTIMISATIONS MARGES MOBILE
       ======================================== */
    .chat-header {
        padding: 8px 12px !important;
    }

    .chat-actions {
        gap: 4px !important;
    }

    .chat-actions .btn-icon {
        width: 32px !important;
        height: 32px !important;
        font-size: 14px !important;
    }

    .messages-container {
        padding: 8px !important;
    }

    .message {
        padding: 10px 12px !important;
        margin-bottom: 8px !important;
    }

    .input-zone {
        padding: 8px !important;
    }
}

@media (max-width: 600px) {
    .chat-title-container {
        margin-left: 48px;
        max-width: 50%;
    }
    .config-header h2 {
        margin-left: 48px;
    }
    .input-group {
        flex-direction: column;
        gap: 6px;
    }
    .input-wrapper {
        width: 100%;
    }
    .input-controls { 
        width: 100%;
        justify-content: space-between;
    } 
    .groupe-selection-container { 
        flex: 1;
    } 
    .selecteur-groupe { 
        width: 100%; 
        max-width: none; 
    } 
    .chat-actions { 
        flex-wrap: wrap; 
        gap: 4px; 
    }
    .input-message {
        padding: 12px 12px 40px 12px;
    }
    .input-actions {
        bottom: 8px;
        right: 8px;
        left: 8px;
        justify-content: space-between;
    }
    .btn-input-action {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
}