/* ====================================
   Layout principal - Aligne sur le design system myCFiA
   Sources : _app-layout.css, _sidebar.css, _header.css, _content.css
   ==================================== */

/* ==========================================================================
   APP CONTAINER (from _app-layout.css)
   ========================================================================== */
.app {
    display: flex;
    min-height: 100vh;
}

/* ==========================================================================
   MAIN CONTENT AREA (from _app-layout.css)
   ========================================================================== */
.main {
    margin-left: 260px;
    flex: 1;
    transition: margin-left 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.sidebar.collapsed ~ .main {
    margin-left: 70px;
}

/* ==========================================================================
   SIDEBAR CONTAINER (from _sidebar.css)
   ========================================================================== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 260px;
    height: 100vh;
    background: var(--theme-sidebar-bg, #001f3f);
    color: #ffffff;
    padding: 0;
    z-index: 200;
    transition: width 0.3s ease, transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ==========================================================================
   SIDEBAR COLLAPSED STATE (from _sidebar.css)
   ========================================================================== */
.sidebar.collapsed {
    width: 70px !important;
}

.sidebar.collapsed span:not(.sidebar-header span),
.sidebar.collapsed .bi-chevron-down,
.sidebar.collapsed .bi-arrow-left-circle {
    display: none !important;
}

/* UX-005 §1.3 : masquer le message "Aucune conversation favorite/recente"
   en mode sidebar repliee, sinon le texte s'enroule caractere par caractere
   sur 3 lignes dans les 70px de large. */
.sidebar.collapsed .empty-state-message {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center !important;
}

.sidebar.collapsed .nav-section-title-pill {
    padding: 0.75rem;
    justify-content: center;
    background: transparent !important;
    border: none !important;
    cursor: default;
}

.sidebar.collapsed .sidebar-link {
    padding: 0.75rem;
    justify-content: center;
}

/* ==========================================================================
   SIDEBAR HEADER (from _sidebar.css)
   ========================================================================== */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .btn-link,
.sidebar-header .btn-link:hover,
.sidebar-header .btn-link:focus,
.sidebar-header .btn-link:active {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    text-decoration: none !important;
    outline: none !important;
    padding: 0 !important;
}

/* ==========================================================================
   SIDEBAR NAVIGATION SECTIONS (from _sidebar.css)
   ========================================================================== */
.nav-section {
    margin-bottom: 20px;
}

.nav-section-title-pill {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 12px;
}

.nav-section-title-pill:hover {
    background: rgba(255, 255, 255, 0.15);
}

.nav-section-title-pill i.bi-chevron-down {
    font-size: 0.875rem;
    transition: transform 0.2s ease;
}

/* BUG-020 : aligner la taille de l'icone principale de l'en-tete de section
   (megaphone, etoile, horloge) sur la taille des icones des sidebar-link
   (20px). Le pill a un font-size: 12px (pour le label texte uppercase),
   du coup sans regle dediee l'icone bi heritait de cette petite taille
   et apparaissait deux fois plus petite que les icones du footer. */
.nav-section-title-pill i:not(.bi-chevron-down) {
    font-size: 20px;
    line-height: 1;
}

.nav-section-title-pill[aria-expanded='true'] i.bi-chevron-down {
    transform: rotate(180deg);
}

/* R-06 : variantes Lucide (SVG) de l'en-tete de section (icone + chevron).
   La sidebar est sombre dans tous les themes (--theme-sidebar-bg) :
   le filtre force l'icone en blanc, comme .sidebar-link-ico. */
.nav-section-title-pill .section-ico {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1);
}

.nav-section-title-pill .section-chevron {
    width: 0.875rem;
    height: 0.875rem;
    filter: brightness(0) invert(1);
    transition: transform 0.2s ease;
}

.nav-section-title-pill[aria-expanded='true'] .section-chevron {
    transform: rotate(180deg);
}

.nav-section-content {
    padding: 0;
}

/* ==========================================================================
   SIDEBAR LINKS (from _sidebar.css)
   ========================================================================== */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: all 0.3s ease;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #ffffff;
    padding-left: 16px;
}

.sidebar-link.active {
    background: #003080;
    color: #ffffff;
}

.sidebar-link i {
    font-size: 20px;
    min-width: 24px;
    text-align: center;
    transition: transform 0.3s ease;
}

.sidebar-link:hover i {
    transform: scale(1.1);
}

/* Icone Lucide (SVG) dans un lien de sidebar — aligne sur la taille des icones bi */
.sidebar-link-ico {
    width: 20px;
    min-width: 24px;
    height: 20px;
    filter: brightness(0) invert(1);
    opacity: 0.75;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.sidebar-link:hover .sidebar-link-ico {
    transform: scale(1.1);
    opacity: 1;
}

.sidebar-link.active .sidebar-link-ico {
    opacity: 1;
}

/* ==========================================================================
   SIDEBAR — sections groupees (en-tete repliable + socle MES AGENTS)
   ========================================================================== */

/* Zone haute epinglee : socle MES AGENTS, ne scrolle jamais (la zone contextuelle
   au milieu, en flex-grow + overflow-auto, absorbe seule le defilement). */
.sidebar-pinned-top {
    flex-shrink: 0;
    padding-top: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.sidebar-section {
    margin-bottom: 18px;
}

/* ==========================================================================
   SIDEBAR — flyouts contextuels (sous-menu lateral au clic)
   Evite l'empilement vertical / le scroll de la sidebar : le contenu vit dans
   un panneau flottant (position: fixed) ouvert a droite.
   ========================================================================== */
.sidebar-flyout {
    margin-bottom: 10px;
}

.sidebar-flyout-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sidebar-flyout-trigger:hover {
    background: rgba(255, 255, 255, 0.12);
}

.sidebar-flyout-trigger > span {
    flex: 1;
    text-align: left;
}

.sidebar-flyout-icon {
    font-size: 1rem;
    min-width: 20px;
    text-align: center;
}

.sidebar-flyout-caret {
    font-size: 0.85rem;
    opacity: 0.8;
    transition: transform 0.2s ease;
}

.sidebar-flyout-trigger[aria-expanded='true'] .sidebar-flyout-caret {
    transform: translateX(3px);
}

.sidebar-flyout-panel {
    position: fixed;
    z-index: 1080;
    min-width: 240px;
    max-width: 340px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 10px;
    border-radius: 12px;
    /* meme fond que la sidebar, suit le theme actif */
    background: var(--theme-sidebar-bg, #001f3f);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    /* scrollbar stylee (Firefox) */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

/* scrollbar stylee (WebKit/Blink) — discrete, aux couleurs de la sidebar */
.sidebar-flyout-panel::-webkit-scrollbar {
    width: 8px;
}
.sidebar-flyout-panel::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-flyout-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 8px;
}
.sidebar-flyout-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

.sidebar-flyout-panel[hidden] {
    display: none;
}

.sidebar-flyout-panel-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.6);
    padding: 4px 10px 8px;
}

/* ==========================================================================
   MODALE DE CONFIRMATION PARTAGEE (#appConfirmModal) — suit les 3 themes
   ========================================================================== */
#appConfirmModal .modal-content {
    background: var(--theme-bg-primary, #f5f5f7);
    color: var(--theme-text-primary, #1a1a1a);
    border: 1px solid var(--theme-border-color, #e3e4e9);
    border-radius: 14px;
}
#appConfirmModal .modal-title {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 600;
}
#appConfirmModal .modal-header,
#appConfirmModal .modal-footer {
    border-color: var(--theme-border-color, #e3e4e9);
}
/* btn-close Bootstrap est sombre par defaut → l'inverser sur fonds sombres */
body.theme-dark-blue #appConfirmModal .btn-close,
body.theme-dark-red #appConfirmModal .btn-close {
    filter: invert(1) grayscale(1) brightness(1.6);
}

/* ==========================================================================
   SIDEBAR — menu contextuel d'une conversation (renommer / favori / supprimer)
   ========================================================================== */
.conv-title {
    max-width: 150px;
}
.conv-badge {
    font-size: 0.65rem;
}

.conv-menu-trigger {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.55);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.conv-item:hover .conv-menu-trigger,
.conv-menu-trigger[aria-expanded='true'] {
    color: #ffffff;
}
.conv-menu-trigger:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

.conv-rename-input {
    flex-grow: 1;
    min-width: 0;
    margin: 0 4px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 0.85rem;
}
.conv-rename-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.6);
}

.conv-menu-dropdown {
    position: fixed;
    z-index: 1090;
    min-width: 170px;
    padding: 6px;
    border-radius: 10px;
    background: var(--theme-sidebar-bg, #001f3f);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}
.conv-menu-dropdown[hidden] {
    display: none;
}
.conv-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 0.82rem;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
}
.conv-menu-item:hover {
    background: rgba(255, 255, 255, 0.12);
}
.conv-menu-item i {
    width: 16px;
    text-align: center;
}
/* R-06 : icones Lucide du menu conversation. Renommer/Favori = SVG <img> blanc
   (fond sombre du dropdown). Supprimer = SVG inline (currentColor) pour suivre
   la teinte rouge #ff8a8a de .conv-menu-item--danger. */
.conv-menu-ico {
    width: 16px;
    height: 16px;
    filter: brightness(0) invert(1);
}
.conv-menu-ico-inline {
    display: inline-flex;
    line-height: 0;
}
.conv-menu-ico-inline svg {
    width: 16px;
    height: 16px;
}
.conv-menu-item--danger {
    color: #ff8a8a;
}
.conv-menu-item--danger:hover {
    background: rgba(220, 53, 69, 0.2);
}

/* Contenu reutilise dans un flyout (ex. ConversationSidebar) : le trigger fait office
   d'en-tete → on masque la pilule de titre interne et on force l'affichage de la liste. */
.sidebar-flyout-panel .nav-section-title-pill {
    display: none;
}
.sidebar-flyout-panel .nav-section {
    margin: 0;
}
.sidebar-flyout-panel .collapse {
    display: block !important;
}

/* en-tete de groupe (MES AGENTS) : meme rendu que les pilules de flyout
   (FAVORIS/HISTORIQUE) → titres homogenes (background, taille, casse, typo) */
.sidebar-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sidebar-group-header:hover {
    background: rgba(255, 255, 255, 0.12);
}


/* R-06 : chevron Lucide (SVG <img>) du groupe MES AGENTS — blanc sur fond sombre.
   La rotation reste pilotee par la classe (.sidebar-group-header.collapsed). */
.sidebar-group-chevron {
    width: 0.9rem;
    height: 0.9rem;
    filter: brightness(0) invert(1);
    opacity: 0.85;
    transition: transform 0.3s ease;
}

/* chevron pointe vers le bas quand ouvert, vers la droite quand replie */
.sidebar-group-header.collapsed .sidebar-group-chevron {
    transform: rotate(-90deg);
}

/* en mode sidebar repliee, masquer les en-tetes de groupe (icones seules restent) */
.sidebar.collapsed .sidebar-group-header {
    display: none;
}

/* en mode rail (sidebar repliee), l'etat de repli d'un groupe ne s'applique pas :
   les icones des liens restent toujours visibles, quel que soit le collapse Bootstrap */
.sidebar.collapsed .sidebar-section .collapse,
.sidebar.collapsed .sidebar-section .collapsing {
    display: block !important;
    height: auto !important;
}

/* en mode rail, le panneau flyout flottant n'est PAS concerne par le masquage
   des libelles (il s'affiche hors de la sidebar) : on restaure ses textes.
   Cible par classe pour depasser la specificite de la regle de masquage
   `.sidebar.collapsed span:not(.sidebar-header span)` (0,3,2). */
.sidebar.collapsed .sidebar-flyout-panel .conv-title,
.sidebar.collapsed .sidebar-flyout-panel .conv-badge {
    display: inline-block !important;
}

/* en mode rail, les triggers de flyout deviennent de simples icones (pas de pilule) */
.sidebar.collapsed .sidebar-flyout-trigger {
    background: transparent;
    justify-content: center;
    padding: 10px 0;
}
.sidebar.collapsed .sidebar-flyout-trigger:hover {
    background: rgba(255, 255, 255, 0.08);
}
.sidebar.collapsed .sidebar-flyout-caret {
    display: none;
}

/* ==========================================================================
   SIDEBAR FOOTER (from _sidebar.css)
   ========================================================================== */
.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ==========================================================================
   STICKY TOP CONTAINER
   ========================================================================== */
.sticky-top-container {
    position: sticky;
    top: 0;
    flex-shrink: 0;
    z-index: 100;
}

/* ==========================================================================
   HEADER (from _header.css)
   ========================================================================== */
.header {
    background: var(--theme-card-bg, #ffffff);
    padding: 20px 30px;
    border-bottom: 1px solid var(--theme-border-color, #e3e4e9);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-logo-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.header-actions {
    display: flex;
    gap: 16px;
    align-items: center;
}

/* ==========================================================================
   HEADER LOGOS
   ========================================================================== */
.header-logo-picto {
    display: inline-block;
    /* Picto volontairement plus haut que le wordmark (55px) : il deborde
       legerement en haut et en bas, centre via .header-logo-link (align-items:center).
       Ratio natif du SVG conserve (viewBox 46.418x50.5 ~0.92) -> pas de deformation.
       Regle non scopee : s'applique aux 3 themes (light / dark-blue / dark-red). */
    width: 54px;
    height: 58px;
}

.header-logo {
    display: inline-block;
    width: auto;
    max-width: 180px;
    height: 55px;
}

/* BUG-041 : logos desormais inlines en <svg> dans des wrappers span — on contraint
   le SVG enfant a la taille du wrapper (preserve la mise en page, supprime le FOUC). */
.header-logo-picto svg {
    display: block;
    width: 100%;
    height: 100%;
}
.header-logo svg {
    display: block;
    width: auto;
    height: 100%;
}

/* BUG-010 : recoloration retiree au profit de variantes pre-colorees du SVG
   (logo-light.svg pour le theme clair, logo.svg blanc pour les themes sombres).
   Eliminait un FOUC de 100-300 ms visible au chargement (le logo s'affichait
   dans sa couleur SVG d'origine avant que ce CSS soit charge via app.js). */

/* ==========================================================================
   HEADER BUTTONS (from _buttons.css)
   ========================================================================== */
.header-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    transition: all 0.3s ease;
    text-decoration: none !important;
}

.header-btn-text {
    display: inline;
}

/* btn-glass : bouton outline (Ma Division, Retour CFI) */
.btn-glass {
    background: rgba(255, 255, 255, 0.6) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 48, 128, 0.2) !important;
    color: #003080 !important;
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.8) !important;
    border-color: rgba(0, 48, 128, 0.3) !important;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 48, 128, 0.15);
    color: #003080 !important;
}

.btn-glass:active {
    transform: translateY(0);
    box-shadow: 0 4px 8px rgba(0, 48, 128, 0.1);
}

/* btn-glass-primary : bouton rempli bleu (Theme selector) */
.btn-glass-primary {
    background: rgba(0, 48, 128, 0.85) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(57, 191, 239, 0.3) !important;
    color: #ffffff !important;
}

.btn-glass-primary:hover {
    background: rgba(0, 48, 128, 0.95) !important;
    border-color: rgba(57, 191, 239, 0.5) !important;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 48, 128, 0.3);
    color: #ffffff !important;
}

/* Supprimer le caret Bootstrap sur les header-btn dropdowns */
.header-btn.dropdown-toggle::after {
    display: none;
}

.header-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==========================================================================
   CONTENT AREA (from _content.css)
   ========================================================================== */
.home-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Page variants */
.home-content.chat-page {
    justify-content: flex-start;
}

.home-content.profile-page {
    justify-content: flex-start;
    padding: 0;
}

.home-content.campaign-page {
    justify-content: flex-start;
    align-items: stretch;
    padding: 0;
}

.home-content.settings-page {
    justify-content: flex-start;
    padding: 0;
}

.home-content.marketing-page {
    justify-content: flex-start;
    padding-top: 1rem;
}

/* ==========================================================================
   RESPONSIVE (from _app-layout.css + _header.css)
   ========================================================================== */

/* Mobile : sidebar cachee, burger pour ouvrir */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 260px;
    }

    .main {
        margin-left: 0;
    }

    .sidebar.collapsed ~ .main {
        margin-left: 0;
    }

    .header-logo {
        max-width: 150px;
        height: 40px;
    }

    .home-content {
        padding: 1rem;
    }
}

/* Tablet : header buttons compacts */
@media (max-width: 991px) {
    .header-logo {
        display: none;
    }

    .header-btn {
        padding: 8px;
        gap: 0;
        min-width: 40px;
        justify-content: center;
    }

    .header-btn-text {
        display: none;
    }

    .header-content {
        gap: 8px;
    }

    .header-actions {
        gap: 8px;
    }
}

/* Mobile burger button */
.sidebar-mobile-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 250;
    background: var(--theme-card-bg, #ffffff);
    border: 1px solid var(--theme-border-color, #e3e4e9);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sidebar-mobile-toggle i {
    font-size: 1.5rem;
    color: #003080;
}

/* R-06 : burgers Lucide inline (SVG currentColor). Le SVG herite de la couleur
   du parent : bleu (#003080) sur le toggle mobile a fond clair, blanc translucide
   sur le bouton du header a fond sombre. Une seule classe, deux contextes. */
.sidebar-burger-ico {
    display: inline-flex;
    line-height: 0;
}

.sidebar-burger-ico svg {
    width: 1.5rem;
    height: 1.5rem;
}

.sidebar-mobile-toggle .sidebar-burger-ico {
    color: #003080;
}

@media (max-width: 768px) {
    .sidebar-mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Overlay mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 190;
}

.sidebar-overlay.active {
    display: block;
}
