:root {
  --brand: #6f4a8e;
  --brand-dark: #55366f;
  --brand-light: #f2ecf7;
  --brand-lighter: #faf8fc;
  --sidebar-width: 248px;
  --bg: #f6f5fa;
  --surface: #ffffff;
  --border: #e6e3ee;
  --text: #2f2b3a;
  --text-muted: #837e93;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(31, 15, 51, 0.06), 0 1px 2px rgba(31, 15, 51, 0.04);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.925rem;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 1030;
}

.sidebar-brand {
  padding: 1.15rem 1.25rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  gap: .6rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .bi { font-size: 1.3rem; color: var(--brand); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .6rem; }
.sidebar-section {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #ADA6BC;
  padding: 1rem .6rem .35rem;
}
.sidebar-nav .nav-link {
  color: #4a4553;
  border-radius: 8px;
  padding: .5rem .7rem;
  display: flex;
  align-items: center;
  gap: .65rem;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: 2px;
}
.sidebar-nav .nav-link .bi { font-size: 1rem; width: 1.1rem; text-align: center; color: #9791a8; }
.sidebar-nav .nav-link:hover { background: var(--brand-lighter); color: var(--brand-dark); }
.sidebar-nav .nav-link.active { background: var(--brand-light); color: var(--brand-dark); }
.sidebar-nav .nav-link.active .bi { color: var(--brand); }

.sidebar-footer { border-top: 1px solid var(--border); padding: .75rem; }

.main-content { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .7rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}
.topbar .boutique-pill {
  background: var(--brand-light);
  color: var(--brand-dark);
  border-radius: 999px;
  padding: .3rem .85rem;
  font-size: .82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}

.page { padding: 1.75rem; flex: 1; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.35rem; font-weight: 700; margin: 0 0 .2rem; }
.page-header .text-muted { font-size: .875rem; }

/* Cards */
.card-app {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-app .card-app-header {
  padding: 1rem 1.35rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .95rem;
}
.card-app .card-app-body { padding: 1.35rem; }

/* Stat cards */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.3rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform .12s ease, box-shadow .12s ease;
}
a.stat-card:hover, a.stat-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,.09);
}
.stat-card .stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-light);
  color: var(--brand);
  font-size: 1.25rem;
  flex-shrink: 0;
}
.stat-card .stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { font-size: .78rem; color: var(--text-muted); margin-top: .1rem; }
.stat-card.stat-warn .stat-icon { background: #fdeee0; color: #c96f1a; }
.stat-card.stat-warn .stat-value { color: #c96f1a; }

/* Buttons */
.btn { border-radius: 8px; font-size: .875rem; font-weight: 600; }
.btn-primary, .btn-brand {
  background: var(--brand);
  border-color: var(--brand);
}
.btn-primary:hover, .btn-brand:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}
.btn-outline-secondary { border-color: var(--border); color: var(--text); }
.btn-outline-secondary:hover { background: var(--brand-lighter); border-color: var(--border); color: var(--text); }
.btn-link { color: var(--brand); font-weight: 600; }
.btn-whatsapp { background: #25D366; border-color: #25D366; color: #fff; }
.btn-whatsapp:hover { background: #1ea952; border-color: #1ea952; color: #fff; }
.btn-loading { display: inline-flex; align-items: center; gap: .4rem; cursor: progress !important; }

/* Forms */
.form-label { font-weight: 600; font-size: .82rem; color: #514c5f; margin-bottom: .3rem; }
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--border);
  font-size: .9rem;
  padding: .5rem .75rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 .18rem var(--brand-light);
}

/* Tables */
.table-app { background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); }
.table-app table { margin-bottom: 0; }
.table-app thead th {
  text-transform: uppercase;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--brand-lighter);
  padding: .8rem 1.1rem;
  white-space: nowrap;
}
.table-app tbody td { padding: .75rem 1.1rem; vertical-align: middle; border-bottom: 1px solid var(--border); font-size: .875rem; }
.table-app tbody tr:last-child td { border-bottom: none; }
.table-app tbody tr:hover { background: var(--brand-lighter); }
.table-app tbody tr.row-danger { background: #fdf1ef; }
.table-app tbody tr.row-danger:hover { background: #fbe6e2; }

/* Badges */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  border-radius: 999px;
  padding: .3rem .7rem;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-gray { background: #eeecf2; color: #625d70; }
.badge-purple { background: var(--brand-light); color: var(--brand-dark); }
.badge-green { background: #e4f5ea; color: #1e8a4c; }
.badge-orange { background: #fdeee0; color: #c96f1a; }
.badge-red { background: #fbe6e2; color: #c23c26; }

/* Auth pages */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 100%);
  padding: 2rem 1rem;
}
.auth-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 20px 45px rgba(41, 20, 66, .25);
  padding: 2.25rem 2.25rem;
  width: 100%;
  max-width: 440px;
}
.auth-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; color: var(--brand-dark); margin-bottom: 1.5rem; }
.auth-brand .bi { color: var(--brand); font-size: 1.5rem; }

/* Tiroir de navigation mobile : masqué par défaut, sans effet sur le
   rendu ordinateur (l'élément n'existait pas avant, aucune règle
   existante n'est modifiée). Rendu visible uniquement dans le media
   query téléphone/tablette ci-dessous. */
.sidebar-backdrop { display: none; }
.sidebar-user-email { display: none; }

/* =========================================================================
   TÉLÉPHONE & TABLETTE UNIQUEMENT (< 992px, seuil Bootstrap "lg" déjà
   utilisé par les grilles col-lg-* des templates). Rien ici ne s'applique
   à l'affichage ordinateur — voir contrainte : ne pas toucher au desktop.
   ========================================================================= */
@media (max-width: 991.98px) {
  /* --- Tiroir de navigation --- */
  .sidebar {
    width: 84vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(31, 15, 51, .18);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }

  .sidebar-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 10, 35, .45);
    z-index: 1025;
    animation: sidebar-fade-in .15s ease;
  }
  @keyframes sidebar-fade-in { from { opacity: 0; } to { opacity: 1; } }

  /* Cibles tactiles plus généreuses dans le menu */
  .sidebar-nav { padding: 1rem .75rem; }
  .sidebar-nav .nav-link { padding: .8rem .85rem; font-size: .95rem; }
  .sidebar-nav .nav-link .bi { font-size: 1.15rem; }
  .sidebar-footer .nav-link { padding: .8rem .85rem; }
  .sidebar-user-email {
    display: block;
    padding: .3rem .85rem .6rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* --- Barre du haut : évite tout débordement sur petit écran --- */
  .topbar { padding: .6rem .9rem; gap: .5rem; }
  .sidebar-toggle {
    min-width: 44px; min-height: 44px;
    padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .topbar .boutique-pill {
    font-size: .78rem;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-email { display: none; } /* déjà visible dans le tiroir (email en bas) — évite l'encombrement */

  /* --- Contenu : on récupère de la largeur --- */
  .page { padding: 1rem; }
  .card-app .card-app-body { padding: 1rem; }
  .card-app .card-app-header { padding: .85rem 1rem; }
  .page-header { margin-bottom: 1.1rem; }
  .page-header h1 { font-size: 1.15rem; }

  /* --- Cibles tactiles : boutons et champs --- */
  .btn { min-height: 44px; padding-top: .55rem; padding-bottom: .55rem; }
  .btn-link { min-height: auto; } /* liens texte type "Modifier" : pas de gros bloc tactile */
  .form-control, .form-select {
    font-size: 16px; /* empêche le zoom auto iOS au focus */
    padding: .6rem .75rem;
  }

  /* --- Tuiles du tableau de bord : plus compactes --- */
  .stat-card { padding: .85rem 1rem; gap: .75rem; }
  .stat-card .stat-icon { width: 38px; height: 38px; font-size: 1.05rem; }
  .stat-card .stat-value { font-size: 1.15rem; }

  /* --- Tableaux : défilement horizontal plutôt qu'un rendu cassé --- */
  .table-app {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-app table { min-width: 100%; }
  .table-app thead th, .table-app tbody td { padding: .65rem .75rem; }

  /* --- Écran de vente (POS) : resserré pour les petits écrans --- */
  .pos-thumb { width: 36px; height: 36px; }
  .pos-item, .pos-cart-line { padding: .55rem .4rem; gap: .55rem; }
  .pos-item-name { font-size: .82rem; }
  .pos-qty { width: 56px; }
  .pos-line-total { width: 68px; font-size: .8rem; }

  /* --- Formulaire d'inscription/connexion --- */
  .auth-card { padding: 1.75rem 1.5rem; }
}

/* POS (écran de vente) */
.pos-pane .card-app-body { padding: 1rem; }
.pos-search-icon {
  position: absolute;
  left: 1rem; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.pos-results, .pos-cart {
  max-height: 480px;
  overflow-y: auto;
}
.pos-thumb {
  width: 42px; height: 42px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.pos-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-light);
  color: var(--brand-dark);
  font-weight: 700;
  font-size: .95rem;
}
.pos-item, .pos-cart-line {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .5rem;
  border-radius: 8px;
  border-bottom: 1px solid var(--border);
}
.pos-item:last-child, .pos-cart-line:last-child { border-bottom: none; }
.pos-item { cursor: pointer; }
.pos-item:hover { background: var(--brand-lighter); }
.pos-item-info { flex: 1; min-width: 0; }
.pos-item-name { font-weight: 600; font-size: .875rem; }
.product-picker { position: relative; min-width: 190px; }
.product-thumb-wrap {
  width: 34px; height: 34px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--brand-lighter);
  color: #c3bcd1;
}
.product-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }
.product-selected { display: flex; align-items: center; gap: .5rem; }
.product-selected-info { flex: 1; min-width: 0; }
.product-selected-name { font-weight: 600; font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-selected-meta { white-space: nowrap; }
.product-search-floating {
  display: none;
  position: fixed;
  z-index: 1060;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  max-height: 300px;
  overflow-y: auto;
}
.pos-item-price { font-weight: 700; font-size: .875rem; white-space: nowrap; }
.pos-item-qty {
  width: 60px;
  text-align: center;
  padding: .3rem;
  flex-shrink: 0;
}
.pos-qty {
  width: 72px;
  text-align: center;
  padding: .35rem .3rem;
  flex-shrink: 0;
}
.pos-line-total {
  width: 90px;
  text-align: right;
  font-weight: 700;
  font-size: .875rem;
  flex-shrink: 0;
}
.pos-remove { flex-shrink: 0; padding: 0 .25rem; }

.client-suggestions {
  display: none;
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
