/* === FEUILLE DE STYLE GLOBALE === */

/* ----- Base ----- */
body {
    background-color: #f8f9fa;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #212529;
    min-height: 100vh;
}

main {
    background-color: #ffffff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: #343a40;
}

/* Pour les pages qui n'ont pas besoin de gros padding sur mobile */
@media (max-width: 575.98px) {
    main {
        padding: 16px;
        border-radius: 0;
        box-shadow: none;
    }
}

/* ----- Tables ----- */
.table thead th {
    background-color: #f0f2f5;
    font-weight: bold;
}
.table tbody td {
    vertical-align: middle;
}
table tbody {
    font-size: 0.95rem;
}
table thead th {
    position: sticky;
    top: 0;
    background-color: #f8f9fa;
    z-index: 1;
}

/* Table responsive "horizontale" */
.table-responsive {
    border-radius: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Comportement commun des tableaux, y compris ceux injectes en AJAX. */
.app-table-responsive {
    width: 100%;
    max-width: 100%;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
}

.app-table-responsive:focus-visible {
    outline: 3px solid rgba(13, 110, 253, .3);
    outline-offset: 2px;
}

.app-table-scroll-hint {
    display: none;
    margin: 0 0 .4rem;
    color: #6c757d;
    font-size: .78rem;
}

@media (max-width: 767.98px) {
    .app-table-scroll-hint {
        display: flex;
        align-items: center;
        gap: .35rem;
    }

    .app-table-scroll-hint::before {
        content: '\2194';
        font-size: 1rem;
        line-height: 1;
    }

    .app-responsive-table.app-table-medium {
        min-width: 680px;
    }

    .app-responsive-table.app-table-wide {
        min-width: 780px;
    }

    .app-responsive-table.app-table-xwide {
        min-width: 980px;
    }

    /* Les tableaux de saisie doivent defiler, pas ecraser leurs champs. */
    .app-responsive-table.app-table-form {
        min-width: 740px !important;
        table-layout: auto !important;
    }

    .app-responsive-table.app-table-form th,
    .app-responsive-table.app-table-form td {
        width: auto !important;
    }

    .app-responsive-table.app-table-form th:first-child,
    .app-responsive-table.app-table-form td:first-child {
        min-width: 230px;
    }

    .app-responsive-table.app-table-form .form-control,
    .app-responsive-table.app-table-form .form-select,
    .app-responsive-table.app-table-form .select2-container {
        min-width: 105px;
    }

    .app-responsive-table th,
    .app-responsive-table td {
        padding: .55rem .6rem;
    }
}

/* Utilitaires pour les zones qui doivent s'empiler sur telephone. */
@media (max-width: 575.98px) {
    .app-mobile-stack {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100%;
    }

    .app-mobile-actions {
        display: flex;
        flex-wrap: wrap;
        width: 100%;
        gap: .5rem;
    }

    .app-mobile-actions > .btn,
    .app-mobile-actions > form,
    .app-mobile-stack > .btn {
        flex: 1 1 auto;
    }

    .app-mobile-actions > form > .btn {
        width: 100%;
    }

    .app-mobile-form-row {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100%;
    }

    .app-mobile-form-row > .form-control,
    .app-mobile-form-row > .form-select,
    .app-mobile-form-row > .select2-container,
    .app-mobile-form-row > .btn {
        width: 100% !important;
        max-width: none !important;
    }

    .app-mobile-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .app-mobile-tabs .nav-item {
        flex: 0 0 auto;
    }

    .app-preview-frame {
        min-height: 60vh;
    }
}

/* Empêche les tableaux, graphiques et formulaires larges d'élargir la page. */
main,
.app-content {
    min-width: 0;
}

canvas,
svg,
img {
    max-width: 100%;
}

@media (min-width: 768px) and (max-width: 1199.98px) {
    main {
        padding: 20px;
    }
}

/* ----- Formulaires ----- */
.form-control,
.form-select {
    border: 1px solid #ced4da;
    background-color: #fefefe;
    border-radius: 6px;
    min-height: 38px;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(13, 110, 253, 0.6);
    box-shadow: 0 0 0 .15rem rgba(13, 110, 253, 0.1);
}

/* Alignement label + aide */
.form-label {
    font-weight: 500;
}

/* ----- Boutons ----- */
.btn {
    border-radius: 6px;
    font-weight: 500;
}
.btn-light {
    border: 1px solid #e9ecef;
}

/* ----- Modales ----- */
.modal-content {
    border-radius: 10px;
}

/* ----- Iframes ----- */
iframe {
    border: 1px solid #dee2e6;
    background-color: #fafafa;
}

/* ----- Sidebar ----- */
.sidebar {
    min-height: 100vh;
    background-color: #343a40;
    color: #fff;
}
.sidebar a {
    color: #adb5bd;
    text-decoration: none;
    display: block;
    padding: 10px 20px;
    font-weight: 500;
}
.sidebar a:hover,
.sidebar a.active {
    background-color: #495057;
    color: #fff;
}

/* Sur mobile, on laisse la sidebar passer en haut (si tu l'inclus avant main) */
@media (max-width: 767.98px) {
    .sidebar {
        min-height: auto;
        width: 100%;
    }
}

/* ----- Navbar (déjà présente dans ton header) ----- */
/* on peut ajuster un peu les paddings en mobile */
@media (max-width: 575.98px) {
    .navbar .navbar-brand {
        font-size: 1rem;
    }
    .navbar .nav-link {
        padding: .35rem .5rem;
    }
}

/* =========================
   SECTION : APP / LAYOUT
   ========================= */

/* Conteneur page sans "saut" sous navbar fixe */
.app-wrapper {
    min-height: calc(100vh - 56px);
    display: flex;
}

/* Zone de contenu scrollable à côté de la sidebar */
.app-content {
    flex: 1;
    min-height: 100vh;
    background: #f8f9fa;
}

/* Petites cards dashboard */
.app-card {
    background: #fff;
    border: 1px solid #edf0f4;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.02);
}

/* ----- Barre d'action collante (mobile) ----- */
.sticky-action-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    background: #111827;
    color: #fff;
    display: flex;
    align-items: center;
    gap: .75rem;
    justify-content: space-between;
    padding: .5rem .75rem;
    z-index: 999;
}

@media (min-width: 576px) {
    .sticky-action-bar {
        display: none;
    }
}

/* =========================
   SELECT2 (intégration Bootstrap-ish)
   ========================= */

/* conteneur prend la largeur du parent */
.select2-container {
    width: 100% !important;
}

/* style du champ */
.select2-container .select2-selection--single {
    height: 38px !important;
    border: 1px solid #ced4da !important;
    border-radius: 6px !important;
    background: #fefefe;
    display: flex;
    align-items: center;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
    padding-left: .5rem !important;
    line-height: 1.4 !important;
    color: #212529;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px !important;
    right: 6px !important;
}

/* focus */
.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: rgba(13, 110, 253, 0.6) !important;
    box-shadow: 0 0 0 .15rem rgba(13, 110, 253, 0.1);
}

/* dropdown */
.select2-container .select2-dropdown {
    border-color: #ced4da;
    border-radius: 6px;
}
.select2-results__option {
    padding: .4rem .6rem;
    font-size: .9rem;
}
.select2-results__option--highlighted {
    background: #0d6efd !important;
}

/* sur mobile : champ un poil plus haut */
@media (max-width: 575.98px) {
    .select2-container .select2-selection--single {
        height: 40px !important;
    }
}

/* =========================
   TABLE DES PRODUITS (ton patch)
   ========================= */

/* La table ne compresse pas n'importe comment */
#table-produits { table-layout: fixed; }

/* Colonnes lisibles sur mobile : on donne + de place au Prix */
@media (max-width: 575.98px) {
  /* Rééquilibrage des largeurs */
  #table-produits th:nth-child(1),
  #table-produits td:nth-child(1) { width: 38%; } /* Produit (Select2) */
  #table-produits th:nth-child(2),
  #table-produits td:nth-child(2) { width: 30%; } /* Prix ↑ pour 6–8 chiffres */
  #table-produits th:nth-child(3),
  #table-produits td:nth-child(3) { width: 14%; } /* Qté */
  #table-produits th:nth-child(4),
  #table-produits td:nth-child(4) { width: 14%; } /* Total */
  #table-produits th:nth-child(5),
  #table-produits td:nth-child(5) { width: 4%; }  /* Poubelle */

  /* Empêche la coupure des nombres */
  #table-produits th:nth-child(2),
  #table-produits td:nth-child(2),
  #table-produits th:nth-child(3),
  #table-produits td:nth-child(3),
  #table-produits th:nth-child(4),
  #table-produits td:nth-child(4) {
    white-space: nowrap;
  }

  /* Champs compacts, bien lisibles, et assez larges pour les grands montants */
  #table-produits .prix-unitaire {
    min-width: 9ch;
    font-size: 1rem;
    padding: .35rem .5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
  #table-produits .quantite,
  #table-produits .total-produit {
    min-width: 6ch;
    font-size: .95rem;
    padding: .35rem .5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  /* Sélecteur produit (Select2) prend toute la largeur de sa cellule */
  #table-produits .select2-container { width: 100% !important; }
  #table-produits .select2-selection--single {
    height: 34px !important;
    min-height: 34px !important;
    line-height: 32px !important;
    font-size: .9rem;
    padding: 0 .45rem;
    border-radius: .5rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Légère compaction de la table sur très petits écrans */
  #table-produits th,
  #table-produits td { padding: .35rem .4rem; }
}

/* Sur ≥ 576px, on garde une répartition stable et confortable */
@media (min-width: 576px) {
  #table-produits th:nth-child(1),
  #table-produits td:nth-child(1) { width: 42%; } /* Produit */
  #table-produits th:nth-child(2),
  #table-produits td:nth-child(2) { width: 22%; } /* Prix */
  #table-produits th:nth-child(3),
  #table-produits td:nth-child(3) { width: 16%; } /* Qté */
  #table-produits th:nth-child(4),
  #table-produits td:nth-child(4) { width: 16%; } /* Total */
  #table-produits th:nth-child(5),
  #table-produits td:nth-child(5) { width: 4%;  } /* Poubelle */
}

/* =========================
   UTILITAIRES
   ========================= */

.badge-soft {
    background: rgba(13, 110, 253, 0.08);
    color: #0d6efd;
    border-radius: 999px;
    padding: .25rem .6rem;
    font-size: .7rem;
    font-weight: 500;
}

.text-muted-sm {
    font-size: .8rem;
    color: #6c757d;
}

.gap-6 { gap: 3.5rem; }

/* conteneur scrollable dans une carte */
.scroll-y {
    max-height: 420px;
    overflow-y: auto;
}

/* zone de totaux fixée en bas d'une carte */
.card-totals {
    background: #fff;
    border-top: 1px solid #edf0f4;
    padding: .75rem 1rem;
}

/* Total vente déjà présent */
#total-vente {
    font-weight: 700;
    color: #0d6efd;
}
