:root {
    --sp-primary: #186d3c;
    --sp-primary-dark: #0f4627;
    --sp-accent: #68a080;
    --sp-bg: #f4f6f9;
    --sp-sidebar-width: 250px;
    --sp-sidebar-collapsed-width: 68px;
}

body {
    background-color: var(--sp-bg);
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

/* ---------- Page de connexion ---------- */
.login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--sp-primary) 0%, var(--sp-accent) 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    border-radius: 16px;
}

.login-logo {
    width: 64px;
    height: 64px;
    line-height: 64px;
    border-radius: 50%;
    background: var(--sp-primary);
    color: #fff;
    font-size: 1.75rem;
    margin: 0 auto;
}

/* ---------- Layout général ---------- */
.sp-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sp-sidebar-width);
    background: var(--sp-primary);
    color: #fff;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1030;
    transition: transform .2s ease, width .2s ease;
}

.sp-sidebar .brand {
    padding: 1.1rem 1.25rem;
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
    display: flex;
    align-items: center;
    gap: .5rem;
}

.sp-sidebar .nav-section-title {
    text-transform: uppercase;
    font-size: .7rem;
    letter-spacing: .06em;
    color: rgba(255,255,255,.5);
    padding: .9rem 1.25rem .3rem;
}

.sp-sidebar .nav-link {
    color: rgba(255,255,255,.85);
    padding: .55rem 1.25rem;
    font-size: .92rem;
    border-left: 3px solid transparent;
}

.sp-sidebar .nav-link i {
    width: 20px;
    display: inline-block;
    text-align: center;
    margin-right: .4rem;
}

.sp-sidebar .nav-link:hover {
    background: rgba(255,255,255,.06);
    color: #fff;
}

.sp-sidebar .nav-link.active {
    background: rgba(255,255,255,.12);
    color: #fff;
    border-left-color: var(--sp-accent);
    font-weight: 600;
}

.sp-content {
    margin-left: var(--sp-sidebar-width);
    min-height: 100vh;
    transition: margin-left .2s ease;
}

/* Réduction du menu en mode « icônes seules » (option activée depuis la barre
   du haut, mémorisée par navigateur via localStorage) — desktop uniquement :
   sur mobile le menu est déjà masqué par défaut et s'ouvre via le bouton
   « hamburger » (voir la règle .sp-sidebar.show ci-dessous). Les icônes des
   liens restent visibles ; seuls les libellés textuels sont masqués, et le
   survol d'un lien affiche son nom en infobulle (attribut title). */
@media (min-width: 992px) {
    html.sidebar-collapsed .sp-sidebar {
        width: var(--sp-sidebar-collapsed-width);
    }
    html.sidebar-collapsed .sp-content {
        margin-left: var(--sp-sidebar-collapsed-width);
    }
    html.sidebar-collapsed .sp-sidebar .brand {
        justify-content: center;
        padding-left: .5rem;
        padding-right: .5rem;
    }
    html.sidebar-collapsed .sp-sidebar .brand-label,
    html.sidebar-collapsed .sp-sidebar .nav-label,
    html.sidebar-collapsed .sp-sidebar .nav-section-title {
        display: none;
    }
    html.sidebar-collapsed .sp-sidebar .nav-link {
        text-align: center;
        padding-left: 0;
        padding-right: 0;
    }
    html.sidebar-collapsed .sp-sidebar .nav-link i {
        margin-right: 0;
        font-size: 1.15rem;
    }
}

.sp-topbar {
    background: #fff;
    border-bottom: 1px solid #e3e6ec;
    padding: .75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.sp-main {
    padding: 1.5rem;
}

@media (max-width: 991.98px) {
    .sp-sidebar {
        transform: translateX(-100%);
    }
    .sp-sidebar.show {
        transform: translateX(0);
    }
    .sp-content {
        margin-left: 0;
    }
}

/* ---------- Cartes KPI ---------- */
.kpi-card {
    border: none;
    border-radius: 14px;
    color: #fff;
    box-shadow: 0 4px 14px rgba(0,0,0,.08);
}

.kpi-card .kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.kpi-card.bg-blue { background: linear-gradient(135deg,#2f80ed,#1e3a5f); }
.kpi-card.bg-green { background: linear-gradient(135deg,#27ae60,#145a32); }
.kpi-card.bg-orange { background: linear-gradient(135deg,#f2994a,#b9560b); }
.kpi-card.bg-red { background: linear-gradient(135deg,#eb5757,#8e1f1f); }
.kpi-card.bg-purple { background: linear-gradient(135deg,#9b51e0,#5b2c8a); }
.kpi-card.bg-teal { background: linear-gradient(135deg,#17a2b8,#0d5661); }

/* ---------- Cartes et tableaux ---------- */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,.05);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #eef0f4;
    font-weight: 600;
}

.table thead th {
    background: #f8f9fb;
    border-bottom: 2px solid #eef0f4;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #6b7280;
    white-space: nowrap;
}

.stock-faible {
    color: #b9560b;
    font-weight: 600;
}

.stock-rupture {
    color: #8e1f1f;
    font-weight: 700;
}

.peremption-proche {
    color: #b9560b;
    font-weight: 600;
}

.peremption-depassee {
    color: #8e1f1f;
    font-weight: 700;
}

/* ---------- Récapitulatif imprimable (tableau de bord) ---------- */
.print-recap-row {
    display: flex;
    gap: 1rem;
}
.print-recap-row + .print-recap-row {
    margin-top: .75rem;
}
.print-recap-row .print-recap-item {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    padding: .5rem .9rem;
}
.print-recap-row .print-recap-item .label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #6c757d;
}
.print-recap-row .print-recap-item .value {
    font-size: 1.15rem;
    font-weight: 700;
}

/* ---------- Liste déroulante de sélection de produit (Choices.js) ---------- */
/* La liste de choix doit toujours s'afficher au premier plan, y compris
   lorsqu'elle est ouverte dans une ligne de tableau défilable (.table-responsive),
   dont le débordement masquerait sinon les produits proposés. */
.choices {
    position: relative;
    z-index: 1;
}
.choices.is-open {
    z-index: 1050;
}
.choices__list--dropdown {
    z-index: 1050;
}
.table-responsive.contient-liste-ouverte {
    overflow: visible;
}

/* ---------- Impression facture ---------- */
@media print {
    .no-print { display: none !important; }
    .sp-sidebar, .sp-topbar { display: none !important; }
    .sp-content { margin-left: 0 !important; }
    body { background: #fff !important; }
    .print-full { flex: 0 0 100% !important; max-width: 100% !important; width: 100% !important; }
    /* Cartes de synthèse (ex : Ventes au comptant / à crédit / Total général) : la mise en
       page d'impression du navigateur peut réduire la largeur utile sous le seuil "md" de
       Bootstrap, ce qui ferait repasser les cartes en pleine largeur (empilées) au lieu de
       rester sur une seule ligne comme à l'écran. On force donc ici 3 colonnes égales,
       indépendamment de la largeur de page effective à l'impression. */
    .row-kpi-print3 > [class*="col-"] { flex: 0 0 33.3333% !important; max-width: 33.3333% !important; width: 33.3333% !important; }
    body.print-mode-liste #carteProduitsLies { display: none !important; }
    body.print-mode-regul #carteListeRegul { display: none !important; }
    body.print-sans-solde .col-solde { display: none !important; }

    /* Centre / Clinique : impression du dossier d'un animal (fiche + chronologie uniquement). */
    body.print-mode-dossier .tab-content > .tab-pane:not(#ongletChrono) { display: none !important; }
    body.print-mode-dossier .tab-content > #ongletChrono { display: block !important; opacity: 1 !important; }

    /* Tableau de bord : impression d'une seule section (ex : produits périmés)
       sans le reste de la page — masque tous les autres blocs de premier niveau
       et force l'affichage de celui visé, même s'il est normalement en no-print. */
    body.print-mode-peremption .sp-main > *:not(#lignePeremptionDashboard) { display: none !important; }
    body.print-mode-peremption #lignePeremptionDashboard { display: block !important; }

    /* Un fond d'estompage de fenêtre modale ne doit jamais apparaître à l'impression. */
    .modal-backdrop { display: none !important; }

    /* Déconditionnement : impression du contenu de la fenêtre « Liste des
       déconditionnements » seule, sans le reste de la page. La fenêtre modale est en
       position fixe à l'écran (ce qui tronquerait l'impression à une seule page) : on la
       repasse donc en flux normal, on masque les champs de filtre, le bouton de fermeture
       et le pied de fenêtre, et on affiche à la place la période choisie en texte. */
    body.print-mode-decond-rapport .sp-main > *:not(#modalListeDeconditionnements) { display: none !important; }
    body.print-mode-decond-rapport #modalListeDeconditionnements {
        position: static !important;
        display: block !important;
        overflow: visible !important;
    }
    body.print-mode-decond-rapport #modalListeDeconditionnements .modal-dialog {
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        margin: 0 !important;
    }
    body.print-mode-decond-rapport #modalListeDeconditionnements .modal-content {
        border: none !important;
        box-shadow: none !important;
    }
    body.print-mode-decond-rapport #modalListeDeconditionnements .modal-header .btn-close,
    body.print-mode-decond-rapport #modalListeDeconditionnements .filtre-periode-rapport,
    body.print-mode-decond-rapport #modalListeDeconditionnements .modal-footer {
        display: none !important;
    }
    body.print-mode-decond-rapport #modalListeDeconditionnements .print-only-periode {
        display: block !important;
    }

    /* Inventaire physique : impression d'un document généré (Fiche inventaire,
       Fiche écart ou Résultat inventaire) à partir de la saisie en cours, sans le
       reste de la page. Le contenu est injecté en JS dans #zoneImpressionInventaire,
       masquée à l'écran et seule affichée à l'impression. */
    body.print-mode-inventaire-doc .sp-main > *:not(#zoneImpressionInventaire) { display: none !important; }
    body.print-mode-inventaire-doc #zoneImpressionInventaire { display: block !important; }

    /* Liste des liaisons : impression de la seule carte "Historique des
       déconditionnements", sans le reste de la page. La colonne Actions (bouton
       Délier) reste masquée via sa propre classe no-print déjà en place. */
    body.print-mode-historique-decond .sp-main > *:not(#carteHistoriqueDeconditionnements) { display: none !important; }

    /* Inventaire physique : impression du détail (par catégorie) d'une session
       d'inventaire, ouvert depuis la fenêtre "Produits de l'inventaire". Le contenu
       est injecté en JS dans #zoneImpressionSessionProduits, masquée à l'écran et
       seule affichée à l'impression. */
    body.print-mode-session-produits .sp-main > *:not(#zoneImpressionSessionProduits) { display: none !important; }
    body.print-mode-session-produits #zoneImpressionSessionProduits { display: block !important; }

    /* Inventaire physique : impression d'un document généré à partir des inventaires
       déjà validés sur la période sélectionnée (Fiche inventaire, Fiche écart,
       Résultat inventaire ou Rapport inventaire), sans le reste de la page. */
    body.print-mode-historique-inventaire-doc .sp-main > *:not(#zoneImpressionHistoriqueInventaire) { display: none !important; }
    body.print-mode-historique-inventaire-doc #zoneImpressionHistoriqueInventaire { display: block !important; }
}

/* ---------- Reçu de vente — format ticket (imprimante thermique 58/80 mm) ---------- */
/* Mise en page dédiée façon « ticket de caisse » : colonne étroite, police
   monospace condensée, séparateurs en pointillés — pensée pour l'impression
   thermique mais aussi lisible telle quelle à l'écran (aperçu avant impression). */
.ticket-recu {
    width: 80mm;
    max-width: 100%;
    margin: 0 auto;
    background: #fff;
    padding: 4mm 5mm 6mm;
    font-family: "Courier New", Consolas, monospace;
    font-size: 11.5px;
    line-height: 1.4;
    color: #212529;
}

.ticket-recu.largeur-58mm {
    width: 58mm;
    font-size: 10.3px;
    padding: 3mm 3.5mm 5mm;
}

.ticket-annulee {
    text-align: center;
    color: #a11d1d;
    font-weight: 700;
    border: 1px dashed #a11d1d;
    padding: 3px 0;
    margin-bottom: 6px;
}

.ticket-entreprise {
    font-size: 1.35em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.ticket-souligne {
    font-size: .92em;
    color: #555;
}

.ticket-titre {
    margin-top: 5px;
    font-weight: 700;
    letter-spacing: .08em;
    font-size: .95em;
}

.ticket-sep {
    border-top: 1px dashed #999;
    margin: 7px 0;
}

.ticket-meta > div,
.ticket-totaux .ticket-ligne-total,
.ticket-paiement > div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.ticket-meta > div span:first-child {
    color: #555;
}

.ticket-meta > div span:last-child,
.ticket-paiement > div span:last-child {
    text-align: right;
    font-weight: 600;
}

.ticket-lignes {
    width: 100%;
    border-collapse: collapse;
}

.ticket-lignes .ticket-designation {
    padding-top: 5px;
    font-weight: 600;
}

.ticket-lignes tr:first-child .ticket-designation {
    padding-top: 0;
}

.ticket-lignes .ticket-qte {
    color: #555;
    font-size: .95em;
}

.ticket-lignes .ticket-remise {
    color: #8a5a00;
}

.ticket-lignes .ticket-montant {
    font-weight: 600;
    white-space: nowrap;
    vertical-align: bottom;
}

.ticket-total-general {
    font-size: 1.15em;
    font-weight: 700;
    border-top: 1px solid #333;
    margin-top: 4px;
    padding-top: 4px;
}

.ticket-solde-du {
    color: #a11d1d;
    font-weight: 700;
}

.ticket-statut-badge {
    display: inline-block;
    margin: 2px 0 4px;
    padding: 2px 12px;
    border-radius: 3px;
    font-size: .85em;
    font-weight: 700;
    letter-spacing: .03em;
}

.ticket-statut-payee { background: #dff5e6; color: #177245; }
.ticket-statut-partielle { background: #fff3d6; color: #8a5a00; }
.ticket-statut-impayee { background: #fde3e3; color: #a11d1d; }

.ticket-observation {
    font-size: .92em;
}

.ticket-versements-titre {
    font-weight: 700;
    font-size: .92em;
    margin-bottom: 3px;
}

.ticket-versement + .ticket-versement {
    margin-top: 4px;
}

.ticket-versement-date {
    color: #555;
    font-size: .9em;
}

.ticket-versement-detail {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-weight: 600;
}

.ticket-footer {
    margin-top: 6px;
    font-style: italic;
    color: #444;
}

@media screen {
    .ticket-recu {
        box-shadow: 0 2px 14px rgba(0,0,0,.12);
        border-radius: 6px;
        margin-top: 1rem;
        margin-bottom: 1.5rem;
    }
}

@media print {
    body.ticket-print { margin: 0; }
    .ticket-recu {
        box-shadow: none;
        border-radius: 0;
        margin: 0 auto;
    }
}

/* Lignes de saisie (vente, achat, régularisation de stock) : les champs de quantité,
   prix et montants sont centrés pour une lecture plus claire ; les champs de texte libre
   (produit, observation/motif) restent alignés à gauche. */
#tableLignes .input-quantite,
#tableLignes .input-servie,
#tableLignes .input-prix,
#tableLignes .input-remise,
#tableLignes .champ-quantite,
#tableLignes .champ-prix-achat,
#tableLignes .champ-prix-vente,
#tableLignes .champ-val-achat,
#tableLignes .champ-val-vente {
    text-align: center;
}
