/* ══════════════════════════════════════════════════════════
       LAYOUT
    ══════════════════════════════════════════════════════════ */
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--bg);
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-logo {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  color: var(--amber-d);
  white-space: nowrap;
}
.topbar-logo span {
  color: var(--ink);
}
.topbar-sep {
  width: 1.5px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}
.topbar-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink2);
}
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.role-chip {
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border: 1.5px solid transparent;
  white-space: nowrap;
}
.role-chip.patron {
  background: var(--amber-l);
  border-color: var(--border-d);
  color: var(--amber-dd);
}
.role-chip.manager {
  background: var(--blue-l);
  border-color: #bfdbfe;
  color: #1d4ed8;
}
.role-chip.caissiere {
  background: var(--green-l);
  border-color: #a7f3d0;
  color: #065f46;
}
.btn-nav {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--r-full);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink2);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}
.btn-nav:hover {
  border-color: var(--amber-d);
  color: var(--amber-d);
}
.btn-nav.deco:hover {
  border-color: var(--rust);
  color: var(--rust);
  background: var(--rust-l);
}

/* ── Contenu principal ──────────────────────────────────── */
.main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

/* ══════════════════════════════════════════════════════════
       CARTES STATISTIQUES
    ══════════════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: all var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.stat-card:hover {
  border-color: var(--border-d);
  box-shadow: var(--shadow-sm);
}
.stat-card.active {
  border-width: 2.5px;
}
.stat-card.active.all {
  border-color: var(--amber-d);
  background: var(--amber-ll);
}
.stat-card.active.ok {
  border-color: var(--green);
  background: var(--green-l);
}
.stat-card.active.bas {
  border-color: var(--amber-d);
  background: var(--amber-l);
}
.stat-card.active.zero {
  border-color: var(--rust);
  background: var(--rust-l);
}

.stat-card .sc-icon {
  font-size: 1.4rem;
}
.stat-card .sc-val {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
}
.stat-card.all .sc-val {
  color: var(--amber-d);
}
.stat-card.ok .sc-val {
  color: var(--green);
}
.stat-card.bas .sc-val {
  color: var(--amber-dd);
}
.stat-card.zero .sc-val {
  color: var(--rust);
}
.stat-card .sc-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink3);
}

/* ══════════════════════════════════════════════════════════
       BARRE DE CONTRÔLES
    ══════════════════════════════════════════════════════════ */
.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.search-box {
  flex: 1;
  min-width: 180px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 14px;
  transition: border-color var(--t-fast);
}
.search-box:focus-within {
  border-color: var(--amber);
}
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  min-width: 0;
}
.search-box input::placeholder {
  color: var(--ink4);
  font-weight: 600;
}

.select-cat {
  padding: 9px 14px;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink2);
  outline: none;
  cursor: pointer;
  transition: border-color var(--t-fast);
  max-width: 160px;
}
.select-cat:focus {
  border-color: var(--amber);
}

.select-tri {
  padding: 9px 14px;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink2);
  outline: none;
  cursor: pointer;
  transition: border-color var(--t-fast);
}
.select-tri:focus {
  border-color: var(--amber);
}

/* ══════════════════════════════════════════════════════════
       TABLEAU
    ══════════════════════════════════════════════════════════ */
.table-wrapper {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}
thead tr {
  background: var(--surface2);
  border-bottom: 2px solid var(--border);
}
thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
thead th.center {
  text-align: center;
}

tbody tr {
  border-bottom: 1.5px solid var(--border);
  transition: background var(--t-fast);
}
tbody tr:last-child {
  border-bottom: none;
}
tbody tr:hover {
  background: var(--bg);
}
tbody tr.rupture {
  background: #fff5f5;
}
tbody tr.bas {
  background: #fffbeb;
}
tbody tr.rupture:hover {
  background: #fee2e2;
}
tbody tr.bas:hover {
  background: var(--amber-ll);
}

tbody td {
  padding: 11px 14px;
  font-size: 0.83rem;
  font-weight: 700;
  color: var(--ink);
  vertical-align: middle;
}
tbody td.center {
  text-align: center;
}

/* Cellule produit */
.td-produit {
  display: flex;
  align-items: center;
  gap: 10px;
}
.td-ico {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.td-nom {
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--ink);
}
.td-cat {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink4);
  margin-top: 1px;
}

/* Badge stock */
.stock-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 900;
}
.stock-badge.ok {
  background: var(--green-l);
  color: #065f46;
}
.stock-badge.bas {
  background: var(--amber-l);
  color: var(--amber-dd);
}
.stock-badge.zero {
  background: var(--rust-l);
  color: var(--rust);
}

/* Barre progression stock */
.bar-wrap {
  width: 100%;
  min-width: 80px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}
.bar-fill.ok {
  background: var(--green);
}
.bar-fill.bas {
  background: var(--amber);
}
.bar-fill.zero {
  background: var(--rust);
  width: 100% !important;
  opacity: 0.3;
}

/* Seuil */
.td-seuil {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink3);
}

/* Boutons actions dans le tableau */
.td-actions {
  display: flex;
  gap: 5px;
  justify-content: center;
}
.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink2);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--t-fast);
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}
.action-btn.reappro {
  background: var(--green-l);
  border-color: #a7f3d0;
  color: #065f46;
}
.action-btn.reappro:hover {
  background: #a7f3d0;
  border-color: var(--green);
}
.action-btn.ajuster:hover {
  background: var(--amber-l);
  border-color: var(--amber);
  color: var(--amber-dd);
}

/* État vide */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.empty-state .es-ico {
  font-size: 3.5rem;
  opacity: 0.3;
}
.empty-state .es-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink2);
}
.empty-state .es-sub {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink3);
}

/* Skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    var(--surface2) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}
.skel-row td {
  padding: 14px;
}

/* ══════════════════════════════════════════════════════════
       MODALS
    ══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 18, 9, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  padding: 0;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 0 0 32px;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  transform: translateY(40px);
  transition: transform 0.25s cubic-bezier(0.34, 1, 0.64, 1);
  display: flex;
  flex-direction: column;
}
.modal-overlay.open .modal {
  transform: translateY(0);
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
  .modal {
    border-radius: var(--r-xl);
    max-height: 85dvh;
  }
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 14px auto 0;
  flex-shrink: 0;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px 0;
  flex-shrink: 0;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink);
}
.btn-close-modal {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}
.btn-close-modal:hover {
  border-color: var(--rust);
  color: var(--rust);
}

.modal-body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

/* Carte info produit dans modal */
.modal-produit-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.mp-ico {
  font-size: 1.6rem;
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mp-info {
}
.mp-nom {
  font-size: 0.92rem;
  font-weight: 900;
  color: var(--ink);
}
.mp-stock {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink3);
  margin-top: 2px;
}

/* Flèche résultat */
.resultat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--green-l);
  border: 1.5px solid #a7f3d0;
  border-radius: var(--r-md);
  padding: 12px 16px;
}
.rr-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #065f46;
}
.rr-val {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--green);
}
.resultat-row.ajust {
  background: var(--amber-l);
  border-color: var(--border-d);
}
.resultat-row.ajust .rr-label {
  color: var(--amber-dd);
}
.resultat-row.ajust .rr-val {
  color: var(--amber-d);
}

/* Champ numérique +/- */
.num-wrap {
  display: flex;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface);
  transition: border-color var(--t-fast);
}
.num-wrap:focus-within {
  border-color: var(--amber);
}
.num-btn {
  width: 48px;
  height: 50px;
  border: none;
  background: var(--surface2);
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--ink2);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--t-fast);
}
.num-btn:hover {
  background: var(--border);
}
.num-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
  padding: 12px 4px;
}

/* Motif (ajustement) */
.motif-select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  outline: none;
  cursor: pointer;
  transition: border-color var(--t-fast);
}
.motif-select:focus {
  border-color: var(--amber);
}

/* Boutons modal */
.modal-actions {
  display: flex;
  gap: 8px;
}
.btn-cancel {
  flex: 1;
  padding: 13px;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--ink2);
  cursor: pointer;
  transition: all var(--t-fast);
}
.btn-cancel:hover {
  border-color: var(--ink2);
}

.btn-confirm {
  flex: 2;
  padding: 13px;
  border: none;
  border-radius: var(--r-md);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 900;
  cursor: pointer;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all var(--t-fast);
}
.btn-confirm.green {
  background: var(--green);
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.3);
}
.btn-confirm.green:hover {
  background: #047857;
}
.btn-confirm.amber {
  background: var(--amber-d);
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.3);
}
.btn-confirm.amber:hover {
  background: var(--amber-dd);
}
.btn-confirm:disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ══════════════════════════════════════════════════════════
       RESPONSIVE
    ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .select-tri {
    display: none;
  }
  /* Colonnes masquées sur mobile */
  .col-barre {
    display: none;
  }
  .col-seuil {
    display: none;
  }
  .col-cat {
    display: none;
  }
}
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .stat-card {
    padding: 12px;
  }
  .stat-card .sc-val {
    font-size: 1.3rem;
  }
  .controls {
    gap: 6px;
  }
  .select-cat {
    display: none;
  }
  .main {
    padding: 12px;
    gap: 14px;
  }
  tbody td {
    padding: 10px 10px;
  }
  .action-btn span {
    display: none;
  }
}
