:root {
  --main-bg-color: #343a40;  /* Sidebar Dark Background */
  --main-text-color: #ffffff; /* Sidebar Text */
  --second-text-color: #b0bec5; /* Sidebar Secondary Text */
  --second-bg-color: #f8f9fa;   /* Main Content Background */
  --active-link-bg: #e9ecef;    /* Active Link Background (Light) */
  --active-link-text: #000;     /* Active Link Text (Dark) */
  --primary-color: #4e73df;     /* Primary Blue */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow-x: hidden;
    background-color: var(--second-bg-color);
    margin: 0; /* Ajout pour supprimer la marge par défaut du navigateur */
}

/* --- WRAPPER & SIDEBAR LAYOUT --- */
#wrapper {
    overflow-x: hidden;
    display: flex;
    width: 100%;
    align-items: stretch;
}

#sidebar-wrapper {
    min-height: 100vh;
    margin-left: -15rem;
    transition: margin 0.25s ease-out;
    background-color: var(--main-bg-color);
    color: var(--main-text-color);
    border-right: 1px solid #dee2e6;
    width: 15rem;
    /* FIX: Ensure strict positioning to remove gaps */
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    height: 100%;
    overflow-y: auto;
}

#sidebar-wrapper .sidebar-heading {
    padding: 0.875rem 1.25rem;
    font-size: 1.2rem;
    color: var(--main-text-color);
}

#sidebar-wrapper .list-group {
    width: 15rem;
}

#page-content-wrapper {
    min-width: 0;
    width: 100%;
    background-color: var(--second-bg-color);
    transition: all 0.25s ease-out;
}

/* --- SIDEBAR LINKS STYLING (SCOPED to #sidebar-wrapper) --- */
/* IMPORTANT: We scope these to #sidebar-wrapper so they don't affect other lists (like search results) */
#sidebar-wrapper .list-group-item {
    border: none;
    padding: 15px 30px;
    font-size: 0.95rem;
    color: var(--second-text-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background-color: transparent; /* Ensure transparent bg for sidebar items */
}

#sidebar-wrapper .list-group-item:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
}

#sidebar-wrapper .list-group-item.active {
    background-color: transparent;
    color: var(--main-text-color);
    font-weight: bold;
    border-left: 4px solid var(--primary-color);
}

/* Sidebar Dropdown on Hover Logic REMOVED */
/* Default Bootstrap collapse behavior will apply (click to toggle) */

/* User Account Dropdown Styling */
.dropdown-menu[aria-labelledby="userDropdown"] .dropdown-item {
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

/* --- GLOBAL BUTTON NORMALIZATION ---
   Garantit que tous les boutons affichent icône + texte sur une seule ligne,
   quelle que soit la taille de l'écran. */
.btn {
    display: inline-flex !important;
    align-items: center;
    gap: .35rem;
    white-space: nowrap !important;
}

.btn i, .btn .fas, .btn .far, .btn .fab {
    flex: 0 0 auto;
}

/* Conteneur d'actions de formulaire (Enregistrer / Annuler, etc.) */
.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: .5rem;
    margin-top: 1.5rem;
}

/* Petits et moyens écrans : réduction adaptative sans cacher le texte */
@media (max-width: 575.98px) {
    .form-actions .btn,
    .form-actions .btn-lg {
        font-size: .8rem !important;
        padding: .42rem .75rem !important;
    }
}

/* --- AUTOCOMPLETE SEARCH BOX STYLING --- */
.autocomplete-container {
    position: relative; /* Indispensable pour positionner les résultats */
}

/* Styles spécifiques pour la recherche de produits (ID) */
#product_search_results {
    background-color: #fff;
    border: 1px solid #e3e6f0;
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    /* Note: width, max-height, z-index gérés en inline dans le PHP */
}

#product_search_results .list-group-item {
    text-transform: none;
    color: #4e4e4e;
    background-color: #fff;
    border: none;
    border-bottom: 1px solid #f8f9fc;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    font-size: 0.9rem;
    font-weight: 500;
}

#product_search_results .list-group-item:last-child {
    border-bottom: none;
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

#product_search_results .list-group-item:hover,
#product_search_results .list-group-item.active {
    background-color: #f8f9fc !important;
    color: #4e73df !important;
    border-left: 4px solid #4e73df;
    padding-left: calc(1.25rem - 4px);
}

/* Ancienne classe conservée au cas où */
.autocomplete-results-list {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    z-index: 2000;
    max-height: 280px;
    overflow-y: auto;
    background-color: #fff;
    border: 1px solid #e3e6f0;
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
    display: none;
    pointer-events: auto;
}

.autocomplete-results-list .list-group-item {
    text-transform: none;
    color: #4e4e4e;
    background-color: #fff;
    border: none;
    border-bottom: 1px solid #f8f9fc;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    transform: none !important;
    min-height: 45px;
    box-sizing: border-box;
    font-size: 0.9rem;
    font-weight: 500;
}

.autocomplete-results-list .list-group-item:last-child {
    border-bottom: none;
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

.autocomplete-results-list .list-group-item:hover,
.autocomplete-results-list .list-group-item.active {
    background-color: #f8f9fc !important;
    color: #4e73df !important;
    border-left: 4px solid #4e73df;
    padding-left: calc(1.25rem - 4px); /* Compensate for border */
    transform: none !important;
}

/* --- TOGGLE STATE (DESKTOP vs MOBILE) --- */

/* MOBILE (Default): Sidebar is hidden */
#sidebar-wrapper {
    margin-left: -15rem;
}
#wrapper.toggled #sidebar-wrapper {
    margin-left: 0;
}

/* DESKTOP (min-width: 768px): Sidebar is visible by default */
@media (min-width: 768px) {
    #sidebar-wrapper {
        margin-left: 0;
    }
    
    #page-content-wrapper {
        margin-left: 15rem;
    }

    #wrapper.toggled #sidebar-wrapper {
        margin-left: -15rem;
    }

    #wrapper.toggled #page-content-wrapper {
        margin-left: 0;
    }
    
    #sidebar-close {
        display: none;
    }
}

/* --- WATERMARK BACKGROUND --- */
#watermark-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
}

/* --- NAVBAR STYLING --- */
.navbar {
    background-color: #fff !important;
    box-shadow: 0 2px 4px rgba(0,0,0,.08);
}

#menu-toggle {
    cursor: pointer;
    color: var(--primary-color);
}

/* Alignement à droite des menus navbar sur mobile */
@media (max-width: 991.98px) {
    #navbarSupportedContent .navbar-nav {
        text-align: right;
        align-items: flex-end;
    }
}

/* --- CARDS & WIDGETS --- */
.card {
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.1);
    transition: transform 0.2s;
    overflow: visible; /* CRITIQUE: Permet aux listes déroulantes de dépasser de la carte */
    z-index: 1; /* Stack context de base */
}

/* FIX: Inversion de l'ordre d'empilement pour les cartes du formulaire de vente
   Cela permet aux menus déroulants des cartes supérieures (Clients, Produits)
   de s'afficher PAR-DESSUS les cartes inférieures (Paiement). */
#vente-form .card {
    position: relative;
}
#vente-form .card:nth-of-type(1) { z-index: 20 !important; }
#vente-form .card:nth-of-type(2) { z-index: 15 !important; }
#vente-form .card:nth-of-type(3) { z-index: 10 !important; }
#vente-form .card:nth-of-type(4) { z-index: 5 !important; }

.card:hover {
    transform: translateY(-3px);
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid #e3e6f0;
    font-weight: bold;
}

/* --- PROFESSIONAL TABLES ---
   Harmonise les tableaux avec l'esthetique des filtres: bleu net,
   contours doux, lignes lisibles et actions propres. */
body:not(.page-facture):not(.page-mini_facture) .table-responsive {
    border: 1px solid #dbe3f0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 .45rem 1.1rem rgba(15, 23, 42, .06);
    overflow: auto;
}

body:not(.page-facture):not(.page-mini_facture) .table {
    margin-bottom: 0;
    color: #1f2937;
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
}

.table,
.table th,
.table td,
.table th *,
.table td * {
    white-space: nowrap !important;
}

body:not(.page-facture):not(.page-mini_facture) .table-bordered,
body:not(.page-facture):not(.page-mini_facture) .table-bordered th,
body:not(.page-facture):not(.page-mini_facture) .table-bordered td {
    border-color: #e3e9f4 !important;
}

body:not(.page-facture):not(.page-mini_facture) .table thead th {
    position: relative;
    background: linear-gradient(135deg, #2563eb, #4f46e5) !important;
    color: #fff !important;
    border: 0 !important;
    padding: .78rem .85rem;
    font-size: .82rem !important;
    font-weight: 800;
    letter-spacing: .035em;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;
}

body:not(.page-facture):not(.page-mini_facture) .table thead th:first-child {
    border-top-left-radius: 11px;
}

body:not(.page-facture):not(.page-mini_facture) .table thead th:last-child {
    border-top-right-radius: 11px;
}

body:not(.page-facture):not(.page-mini_facture) .table tbody td,
body:not(.page-facture):not(.page-mini_facture) .table tbody th {
    padding: .72rem .85rem;
    border-top: 1px solid #edf2f7;
    vertical-align: middle;
    font-size: .95rem !important;
}

body:not(.page-facture):not(.page-mini_facture) .table-striped tbody tr:nth-of-type(odd) {
    background-color: #f8fbff;
}

body:not(.page-facture):not(.page-mini_facture) .table-hover tbody tr:hover,
body:not(.page-facture):not(.page-mini_facture) .table tbody tr:hover {
    background-color: #eef5ff;
}

body:not(.page-facture):not(.page-mini_facture) .table tbody tr {
    transition: background-color .16s ease, box-shadow .16s ease;
}

body:not(.page-facture):not(.page-mini_facture) .table tbody tr:last-child td:first-child {
    border-bottom-left-radius: 11px;
}

body:not(.page-facture):not(.page-mini_facture) .table tbody tr:last-child td:last-child {
    border-bottom-right-radius: 11px;
}

body:not(.page-facture):not(.page-mini_facture) .table td .btn,
body:not(.page-facture):not(.page-mini_facture) .table th .btn {
    min-height: 32px;
    padding: .34rem .58rem;
    border-radius: 9px;
    font-size: .78rem;
    font-weight: 750;
    box-shadow: 0 .25rem .65rem rgba(15, 23, 42, .08);
}

body:not(.page-facture):not(.page-mini_facture) .table td .badge {
    border-radius: 999px;
    padding: .38rem .58rem;
    font-size: .84rem;
    font-weight: 750;
}

body:not(.page-facture):not(.page-mini_facture) .card > .table-responsive,
body:not(.page-facture):not(.page-mini_facture) .card-body > .table-responsive {
    margin: 0;
}

body:not(.page-facture):not(.page-mini_facture) .card .card-header.bg-primary,
body:not(.page-facture):not(.page-mini_facture) .card .card-header.bg-info,
body:not(.page-facture):not(.page-mini_facture) .card .card-header.bg-success {
    background: linear-gradient(135deg, #2563eb, #4f46e5) !important;
    border: 0;
    color: #fff !important;
    padding: .9rem 1.1rem;
}

@media (max-width: 575.98px) {
    body:not(.page-facture):not(.page-mini_facture) .table thead th,
    body:not(.page-facture):not(.page-mini_facture) .table tbody td,
    body:not(.page-facture):not(.page-mini_facture) .table tbody th {
        padding: .62rem .7rem;
        font-size: .88rem !important;
    }
}

/* --- GENERAL UTILS --- */
.shadow-sm {
    box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important;
}

.shadow-lg {
    box-shadow: 0 1rem 3rem rgba(0,0,0,.175)!important;
}

.bg-dark {
    background-color: #2c3e50 !important;
}

.text-uppercase {
    letter-spacing: 1px;
}

/* --- PAGE LOADER --- */
#page-loader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(248, 249, 250, 0.92);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 1;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

#page-loader.loader-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Spinner principal */
.loader-spinner {
    width: 54px;
    height: 54px;
    border: 5px solid #e3e6f0;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: loader-spin 0.75s linear infinite;
}

@keyframes loader-spin {
    to { transform: rotate(360deg); }
}

/* Texte sous le spinner */
.loader-text {
    margin-top: 18px;
    font-size: 0.88rem;
    font-weight: 600;
    color: #6c757d;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Barre de progression en haut de l'écran */
.loader-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), #6610f2);
    z-index: 100000;
    transition: width 0.4s ease;
    border-radius: 0 2px 2px 0;
}

/* Cacher le loader sur les pages d'impression */
@media print {
    #page-loader { display: none !important; }
}

/* --- PRINT STYLES --- */
@media print {
    #sidebar-wrapper, #menu-toggle, .navbar {
        display: none !important;
    }
    #page-content-wrapper {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}

 . c o l - d a t e   { 
         w i d t h :   1 0 0 p x ; 
         m i n - w i d t h :   1 0 0 p x ; 
         m a x - w i d t h :   1 0 0 p x ; 
         w h i t e - s p a c e :   n o w r a p ; 
 } 
 
 . c o l - t o t a l   { 
         w i d t h :   1 5 0 p x ; 
         m i n - w i d t h :   1 5 0 p x ; 
         m a x - w i d t h :   1 5 0 p x ; 
         w h i t e - s p a c e :   n o w r a p ; 
 } 
  
 
