/* pos.css — l'écran de caisse.

   Les jetons viennent de `.ctx-pos` (contexts.css) : fond sombre, cibles de 52 px,
   typographie plus grande. Ce fichier ne redéfinit pas de couleurs, il dessine la
   disposition et les composants propres à la caisse.

   Trois règles tiennent tout le reste :

   — Rien ne défile sauf le rayon et le ticket. Sur une tablette posée sur un comptoir, une
     page qui glisse sous le doigt déplace le bouton qu'on visait.
   — Aucune cible n'est plus petite que 48 px. Un doigt n'est pas un curseur, et une erreur
     de caisse se répare devant le client.
   — Le total est le plus gros caractère de l'écran. C'est ce que le vendeur annonce et ce
     que le client vérifie. */

html.pos-html, body.pos-body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body.pos-body { background: var(--c-bg); color: var(--c-text); }

.pos {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.pos.is-busy { cursor: progress; }
.pos.is-busy .pos-grid, .pos.is-busy .pos-lines { opacity: .55; pointer-events: none; }

/* ------------------------------------------------------------------ barre du haut */

.pos-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.pos-bar-mid { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.pos-bar-mid .pos-muted { font-size: .8125rem; }
.pos-muted { color: var(--c-text-muted); }

.pos-id {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: 48px; padding: 0 var(--sp-3);
  border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm);
  background: var(--c-surface-2); color: var(--c-text);
  font: inherit; font-weight: 600; cursor: pointer;
}
/* Tant que personne n'est identifié, le bouton se voit : aucune vente ne partira sans lui. */
.pos-id.is-empty { border-color: var(--c-warning, #b7791f); color: var(--c-warning, #e0a33a); }
.pos-id.is-set   { border-color: var(--c-success, #1a8f4a); }

.pos-icon {
  display: inline-grid; place-items: center;
  width: 48px; height: 48px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--c-text-muted);
  font-size: 1.25rem; cursor: pointer;
}
.pos-icon:hover { background: var(--c-surface-2); color: var(--c-text); }

.pos.is-offline .pos-bar { background: #4a1d1d; }

/* ------------------------------------------------------------------ corps */

.pos-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24rem;
  min-height: 0;
}
.pos-catalog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  padding: var(--sp-3);
  gap: var(--sp-3);
}

.pos-search {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm);
}
.pos-search i { color: var(--c-text-muted); font-size: 1.25rem; }
.pos-search input {
  min-height: 56px;
  border: 0; background: transparent; color: var(--c-text);
  font: inherit; font-size: 1.125rem;
  outline: none;
}
.pos-search input::-webkit-search-cancel-button { display: none; }

.pos-chips { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.pos-chip {
  flex: 0 0 auto;
  min-height: 44px; padding: 0 var(--sp-3);
  border: 1px solid var(--c-border-strong); border-radius: 999px;
  background: var(--c-surface); color: var(--c-text-muted);
  font: inherit; font-size: .9375rem; cursor: pointer; white-space: nowrap;
}
.pos-chip.is-on { background: var(--c-primary); border-color: var(--c-primary); color: #fff; font-weight: 600; }
.pos-chip-brand { font-style: italic; }

.pos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: var(--sp-3);
  overflow-y: auto;
  align-content: start;
  padding-right: 2px;
}

.pos-tile {
  display: grid; gap: 2px; align-content: start;
  min-height: 7.5rem; padding: var(--sp-3);
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  background: var(--c-surface); color: var(--c-text);
  font: inherit; text-align: left; cursor: pointer;
}
.pos-tile:active { transform: scale(.97); border-color: var(--c-primary); }
.pos-tile-name { font-weight: 600; line-height: 1.25; }
.pos-tile-sub  { color: var(--c-text-muted); font-size: .875rem; }
.pos-tile-foot { display: flex; justify-content: space-between; align-items: baseline; margin-top: auto; padding-top: var(--sp-2); }
.pos-tile-price { font-size: 1.125rem; font-weight: 700; }
.pos-tile-qty {
  min-width: 2rem; padding: 2px 8px; border-radius: 999px;
  background: var(--c-surface-2); color: var(--c-text-muted);
  font-size: .8125rem; text-align: center;
}
/* Deux paires ou moins : le vendeur doit le savoir avant de promettre la pointure. */
.pos-tile-qty.is-low { background: #4a3a12; color: #f0c674; }

.pos-empty { grid-column: 1 / -1; padding: var(--sp-5); color: var(--c-text-muted); text-align: center; }

/* ------------------------------------------------------------------ ticket */

.pos-ticket {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  background: var(--c-surface);
  border-left: 1px solid var(--c-border);
}
.pos-ticket-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3); border-bottom: 1px solid var(--c-border);
}
.pos-ticket-head h2 { margin: 0; font-size: 1.125rem; }

.pos-lines { margin: 0; padding: 0; list-style: none; overflow-y: auto; }
.pos-line { padding: var(--sp-3); border-bottom: 1px solid var(--c-border); }
.pos-line-top { display: flex; justify-content: space-between; gap: var(--sp-2); }
.pos-line-name { font-weight: 600; }
.pos-line-total { font-weight: 700; white-space: nowrap; }
.pos-line-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: var(--sp-2); }
.pos-line-unit { color: var(--c-text-muted); font-size: .875rem; }
.pos-line-disc { color: var(--c-success, #5cc98a); }

.pos-qty { display: flex; align-items: center; gap: 2px; }
.pos-qty-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px;
  border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm);
  background: var(--c-surface-2); color: var(--c-text);
  cursor: pointer;
}
.pos-qty-btn:active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.pos-qty-n { min-width: 2.25rem; text-align: center; font-size: 1.125rem; font-weight: 700; }
.pos-qty-del { margin-left: var(--sp-2); color: var(--c-danger, #e07070); }

.pos-ticket-foot { padding: var(--sp-3); border-top: 1px solid var(--c-border); display: grid; gap: var(--sp-2); }
.pos-sum { display: flex; justify-content: space-between; color: var(--c-text-muted); font-size: .9375rem; }
.pos-sum-disc { color: var(--c-success, #5cc98a); }
.pos-sum-total { align-items: baseline; color: var(--c-text); font-size: 1rem; }
.pos-sum-total strong { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -.02em; }
.pos-cash-btn { min-height: 72px; font-size: 1.25rem; font-weight: 700; }

/* Un bouton désactivé doit se voir désactivé. Sur un ticket vide, « Encaisser » restait
   bleu vif : le vendeur appuyait, rien ne se passait, et il recommençait. */
.pos-body .btn:disabled,
.pos-body .btn[disabled] {
  background: var(--c-surface-2) !important;
  border-color: var(--c-border) !important;
  color: var(--c-text-muted) !important;
  opacity: 1;
  cursor: not-allowed;
}
.pos-danger { color: var(--c-danger, #e07070); }

/* ------------------------------------------------------------------ superpositions */

.pos-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: var(--sp-4);
  background: rgba(8, 10, 14, .72);
  backdrop-filter: blur(2px);
}
.pos-overlay[hidden] { display: none; }
.pos-sheet {
  position: relative;
  width: min(34rem, 100%);
  max-height: 92dvh; overflow-y: auto;
  padding: var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-lg, 14px);
  display: grid; gap: var(--sp-3);
}
.pos-sheet h2 { margin: 0; font-size: 1.375rem; }
.pos-sheet-pay { width: min(40rem, 100%); }
.pos-sheet-foot { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.pos-close { position: absolute; top: var(--sp-2); right: var(--sp-2); width: 44px; height: 44px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--c-text-muted); cursor: pointer; }

.pos-error { margin: 0; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); background: #4a1d1d; color: #ffb4b4; }
.pos-ok    { margin: 0; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); background: #14351f; color: #8fe0ab; }
.pos-warn  { margin: 0; padding: var(--sp-3); border-radius: var(--radius-sm); background: #3d3112; color: #f0c674; }

/* --- vendeurs et PIN --- */
.pos-sellers { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: var(--sp-3); }
.pos-tile-seller { justify-items: center; text-align: center; min-height: 8rem; }
.pos-avatar {
  display: grid; place-items: center;
  width: 3.5rem; height: 3.5rem; margin-bottom: var(--sp-2);
  border-radius: 50%; background: var(--c-primary-soft); color: var(--c-text);
  font-size: 1.25rem; font-weight: 700;
}
.pos-pin { display: grid; gap: var(--sp-3); justify-items: center; }
.pos-pin-who { margin: 0; font-size: 1.125rem; font-weight: 600; }
.pos-pin-dots { display: flex; gap: var(--sp-2); }
.pos-pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--c-border-strong); }
.pos-pin-dots span.is-on { background: var(--c-primary); border-color: var(--c-primary); }

.pos-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); width: min(18rem, 100%); }
.pos-keypad-wide { width: min(22rem, 100%); margin: 0 auto; }
.pos-keypad button {
  min-height: 64px;
  border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm);
  background: var(--c-surface-2); color: var(--c-text);
  font: inherit; font-size: 1.5rem; font-weight: 600; cursor: pointer;
}
.pos-keypad button:active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.pos-key-ok { background: var(--c-primary) !important; border-color: var(--c-primary) !important; color: #fff; }

/* --- encaissement --- */
.pos-pay-head, .pos-pay-rest { display: flex; justify-content: space-between; align-items: baseline; }
.pos-pay-head strong { font-size: var(--fs-2xl); font-weight: 800; }
.pos-pay-rest strong { font-size: 1.5rem; font-weight: 700; }
.pos-pay-rest strong.is-change { color: var(--c-success, #5cc98a); }
.pos-pay-list { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--sp-2); }
.pos-pay-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface-2); border-radius: var(--radius-sm);
}
.pos-pay-methods { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: var(--sp-2); }
.pos-pay-btn { min-height: 64px; background: var(--c-surface-2); border: 1px solid var(--c-border-strong); color: var(--c-text); }
.pos-pay-btn:active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.pos-pay-voucher { grid-column: 1 / -1; }

.pos-sheet-done { text-align: center; justify-items: center; }
.pos-done-icon { font-size: 4rem; color: var(--c-success, #5cc98a); }
.pos-done-change { margin: 0; font-size: 1.5rem; font-weight: 700; }

.pos-menu { display: grid; gap: var(--sp-2); }
.pos-menu-foot { margin: 0; text-align: center; font-size: .875rem; }
.pos-chips-mv { flex-wrap: wrap; overflow: visible; }

/* ------------------------------------------------------------------ pages simples */

.pos-center { display: grid; place-items: center; min-height: 100dvh; padding: var(--sp-4); }
.pos-card {
  width: min(30rem, 100%);
  padding: var(--sp-5);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-lg, 14px);
  display: grid; gap: var(--sp-3);
}
.pos-card h1 { margin: 0; font-size: 1.5rem; }
.pos-card-foot { display: flex; justify-content: space-between; gap: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--c-border); }
.pos-form { display: grid; gap: var(--sp-2); }
.pos-form label { font-weight: 600; }
.pos-form input, .pos-amount {
  width: 100%; min-height: 56px; padding: 0 var(--sp-3);
  border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm);
  background: var(--c-surface-2); color: var(--c-text);
  font: inherit; font-size: 1.25rem;
}
.pos-amount { text-align: center; font-size: 1.75rem; font-weight: 700; letter-spacing: .02em; }
.pos-wide { width: 100%; }
.pos-inline { display: inline; }
.pos-link { border: 0; background: none; color: var(--c-text-muted); font: inherit; text-decoration: underline; cursor: pointer; padding: var(--sp-2); }
.pos-link:hover { color: var(--c-text); }
.pos-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--sp-3); }
.pos-tile-shop { min-height: 6rem; }

/* ------------------------------------------------------------------ messages */

/* Sous la barre, jamais dessus : un message qui recouvre le nom de la boutique cache
   précisément ce qu'on vérifie quand quelque chose vient de changer. */
.pos-flash {
  position: fixed; left: 50%; top: 5rem; z-index: 90;
  transform: translateX(-50%);
  max-width: min(28rem, 90vw);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  background: #14351f; color: #d6f5e2;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
  animation: pos-flash-in .18s ease-out;
}
.pos-flash-error { background: #4a1d1d; color: #ffd4d4; }
.pos-flash-info  { background: var(--c-surface-2); color: var(--c-text); }
@keyframes pos-flash-in { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ------------------------------------------------------------------ tablette portrait */

@media (max-width: 900px) {
  /* Le ticket passe sous le rayon : en portrait, deux colonnes donnent deux moitiés
     inutilisables plutôt qu'un écran partagé. */
  .pos-main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .pos-ticket { border-left: 0; border-top: 1px solid var(--c-border); max-height: 55dvh; }
  .pos-grid { grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); }
  .pos-bar-mid strong { font-size: .9375rem; }
}
@media (max-width: 560px) {
  .pos-sheet-foot { grid-template-columns: 1fr; }
  .pos-pay-methods { grid-template-columns: 1fr 1fr; }
}

/* ------------------------------------------------------------------ le Z */

.pos-close-card { width: min(36rem, 100%); }
.pos-z { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.pos-z th, .pos-z td { padding: var(--sp-2) var(--sp-2); text-align: right; border-bottom: 1px solid var(--c-border); }
.pos-z th { text-align: left; font-weight: 600; }
.pos-z tfoot th, .pos-z tfoot td { border-bottom: 0; border-top: 2px solid var(--c-border-strong); padding-top: var(--sp-3); }
.pos-z thead th { color: var(--c-text-muted); font-size: .8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; text-align: right; }
.pos-z thead th:first-child { text-align: left; }
