/* =============================================================================
   WIDGET FACTURES — POPOVERS + KPI SOBRE + RESPONSIVE
   =============================================================================
   À ajouter à widgets.css (ou en fichier dédié inclus après widgets.css).
   ============================================================================= */


/* -----------------------------------------------------------------------------
   ENCART "EN COURS TTC" — style sobre harmonisé avec le widget KPI
   ----------------------------------------------------------------------------- */

.toolbar-kpi {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 4px 12px;
    margin: 0 4px;
    border-left: 1px solid rgba(0, 0, 0, 0.10);
    border-right: 1px solid rgba(0, 0, 0, 0.10);
    line-height: 1.1;
}

.toolbar-kpi-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted, #6b7280);
    margin-bottom: 3px;
    white-space: nowrap;
}

.toolbar-kpi-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text, #1a1a1a);
    letter-spacing: -0.01em;
}


/* -----------------------------------------------------------------------------
   POPOVERS — wrapper + bouton + panneau
   ----------------------------------------------------------------------------- */

.toolbar-popover-wrap {
    position: relative;
    display: inline-block;
}

/* Le bouton .toolbar-filter est-dark existe déjà ; on ajoute juste
   un style "actif" quand son popover est ouvert */
.toolbar-popover-wrap > .toolbar-filter {
    cursor: pointer;
    user-select: none;
}

/* Panneau du popover */
.toolbar-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 180px;
    max-width: 320px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
    padding: 6px;
    z-index: 1000;
    max-height: 360px;
    overflow-y: auto;
    animation: popover-in 0.12s ease-out;
}

.toolbar-popover[hidden] {
    display: none;
}

.toolbar-popover.is-wide {
    min-width: 220px;
}

@keyframes popover-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Item simple cliquable (Année / Affichage) */
.toolbar-popover-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    color: var(--color-text, #1a1a1a);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s ease;
}

.toolbar-popover-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.toolbar-popover-item.is-active {
    background: rgba(59, 130, 246, 0.08);
    color: #2563eb;
    font-weight: 600;
}

/* Item avec case à cocher (Filtres / Commercial) */
.toolbar-popover-item.is-checkable {
    cursor: pointer;
}

.toolbar-popover-item.is-checkable input[type="checkbox"] {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    margin: 0;
    cursor: pointer;
    accent-color: #2563eb;
}

.toolbar-popover-item.is-checkable span {
    flex: 1;
    user-select: none;
}

/* Titre de section ("Émetteurs", "États") */
.toolbar-popover-section {
    padding: 10px 10px 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-light, #888);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    margin-top: 4px;
}

.toolbar-popover-section:first-child {
    border-top: none;
    margin-top: 0;
}

/* Séparateur après "Tout sélectionner" : la première section qui suit
   garde sa bordure du haut (déjà gérée ci-dessus) */


/* -----------------------------------------------------------------------------
   RESPONSIVE — toolbar wrap sur 2 lignes en dessous de 900px
   ----------------------------------------------------------------------------- */

@media (max-width: 900px) {

    .widget-toolbar.is-dark-toolbar {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    /* La recherche prend toute la largeur en mobile */
    .widget-toolbar.is-dark-toolbar .widget-search.is-dark {
        max-width: none !important;
        flex: 1 1 100%;
        order: 10;
    }

    /* Les filtres descendent en dessous */
    .toolbar-popover-wrap {
        order: 20;
    }

    .toolbar-kpi {
        order: 5;
    }

    /* Le bouton "Créer" reste à droite tout en bas */
    .widget-toolbar.is-dark-toolbar .btn-header.is-primary {
        order: 99;
    }

    /* Popovers s'alignent intelligemment pour ne pas déborder */
    .toolbar-popover {
        max-width: calc(100vw - 32px);
    }
}

@media (max-width: 600px) {

    /* Encart KPI reste visible mais sans bordures latérales pour gagner de la place */
    .toolbar-kpi {
        border-left: none;
        border-right: none;
        padding: 4px 8px;
    }

    /* Le toggle TTC peut passer en bas aussi */
    .widget-toolbar.is-dark-toolbar .toolbar-toggle.is-dark {
        order: 50;
    }
}
