/* =========================================================================
   Caisse CMCC — système de design
   - Grosses cibles tactiles (≥ 64×64), contrastes AAA, focus visibles
   - Pensé pour la basse vision : typo grasse, chiffres tabulaires
   ========================================================================= */

:root {
  --bg:        #FFF9F5;
  --surface:   #FFFFFF;
  --surface-2: #F4ECE3;
  --ink:       #141414;
  --ink-soft:  #4B4B4B;
  --muted:     #6B6B6B;
  --line:      #E2D7C9;

  --accent:        #D7263D;   /* rouge CMCC */
  --accent-ink:    #FFFFFF;
  --accent-soft:   #FBE6E9;

  --ok:        #14803C;
  --ok-soft:   #DDF1E2;
  --warn:      #B23A0E;
  --warn-soft: #FBE2D2;

  --radius-s:  10px;
  --radius:    16px;
  --radius-l:  22px;

  --shadow-1:  0 1px 0 rgba(20, 20, 20, .04), 0 6px 18px rgba(20, 20, 20, .06);
  --shadow-2:  0 2px 0 rgba(20, 20, 20, .06), 0 14px 40px rgba(20, 20, 20, .12);

  --tap:       64px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

/* Mode haut contraste : fond noir, texte blanc, accent jaune */
:root[data-hc="1"] {
  --bg:        #000000;
  --surface:   #0A0A0A;
  --surface-2: #1A1A1A;
  --ink:       #FFFFFF;
  --ink-soft:  #EAEAEA;
  --muted:     #C9C9C9;
  --line:      #4A4A4A;
  --accent:        #FFE600;
  --accent-ink:    #000000;
  --accent-soft:   #2A2700;
  --ok:        #6CFF8B;
  --ok-soft:   #052B11;
  --warn:      #FF7A4D;
  --warn-soft: #2A0E03;
  --shadow-1: none;
  --shadow-2: 0 0 0 2px #FFFFFF inset;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 20px;
  line-height: 1.35;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--tap) + 80px + var(--safe-bottom));
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  /* Désactive le double-tap-to-zoom et le pinch-zoom (iOS ignore parfois user-scalable=no). */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
}

button, input, select { font: inherit; color: inherit; }

/* Focus universellement visible */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.skip-link {
  position: absolute; left: -9999px; top: -9999px;
  background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 0 0 var(--radius-s) 0;
  z-index: 1000;
}
.skip-link:focus { left: 0; top: 0; }

/* ==================== TOPBAR ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + var(--safe-top)) 16px 10px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--line);
}
.topbar__logo { width: 44px; height: 44px; flex: 0 0 auto; }
.topbar__title {
  margin: 0; flex: 1; min-width: 0;
  display: flex; flex-direction: column; line-height: 1.05;
}
.topbar__title-strong { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.topbar__title-soft   { font-size: 14px; color: var(--muted); font-weight: 500; }

.iconbtn {
  width: var(--tap); height: var(--tap);
  border: 2px solid var(--line);
  background: var(--surface-2); color: var(--ink);
  border-radius: var(--radius);
  font-size: 28px;
  cursor: pointer;
  display: inline-grid; place-items: center;
}
.iconbtn:active { transform: translateY(1px); }

/* ==================== VUES ==================== */
.view { padding: 14px 14px 0 14px; }

/* ==================== CATEGORIES ==================== */
.cats {
  display: flex; gap: 10px; overflow-x: auto;
  padding: 6px 2px 12px 2px;
  scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 0 22px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700; font-size: 18px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.cat[aria-pressed="true"] {
  background: var(--ink); color: var(--bg);
  border-color: var(--ink);
}

/* ==================== GRILLE PRODUITS ==================== */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; } }
@media (min-width: 1200px){ .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.product {
  position: relative;
  display: flex; flex-direction: column; align-items: stretch;
  gap: 2px;
  padding: 10px 10px 12px 10px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  text-align: center;
  transition: transform .08s ease, box-shadow .12s ease, border-color .12s ease;
}
.product:active { transform: translateY(2px); box-shadow: var(--shadow-1); }
.product:focus-visible { border-color: var(--accent); }

.product__emoji {
  font-size: 42px;
  line-height: 1;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.05));
  margin: 2px 0 0 0;
  /* Décoratif : ne doit jamais intercepter les clics, sinon il bloque le stepper. */
  pointer-events: none;
}
.product--active .product__emoji {
  /* Quand un stepper est affiché, on réduit l'emoji pour limiter le chevauchement. */
  font-size: 34px;
}
.product__name {
  font-size: 14px; font-weight: 700;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.5em;
  line-height: 1.2;
  pointer-events: none;
}
.product__price {
  font-variant-numeric: tabular-nums;
  font-size: 22px; font-weight: 800;
  color: var(--ink);
  letter-spacing: -.01em;
  margin-top: 2px;
  pointer-events: none;
}

.product__badge {
  position: absolute; top: 8px; right: 8px;
  min-width: 36px; height: 36px;
  padding: 0 10px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px;
  font-weight: 800; font-size: 18px;
  display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(215,38,61,.4);
}

/* Stepper visible sur la carte quand qty > 0 — permet d'ajuster sans ouvrir le tiroir. */
.product--active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-1);
}
.product__stepper {
  position: absolute; top: 8px; right: 8px;
  z-index: 2;
  display: inline-flex; align-items: center; gap: 0;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px;
  padding: 4px;
  box-shadow: 0 4px 12px rgba(215,38,61,.35);
}
.product__stepper-qty {
  pointer-events: none;
}
.product__stepper button {
  width: 40px; height: 40px;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font-size: 22px; font-weight: 800;
  cursor: pointer;
  border-radius: 999px;
  display: grid; place-items: center;
  line-height: 1;
}
.product__stepper button:active { background: rgba(255,255,255,.18); }
.product__stepper-qty {
  min-width: 28px; text-align: center;
  font-weight: 800; font-size: 18px;
  font-variant-numeric: tabular-nums;
}

/* ==================== BARRE PANIER STICKY ==================== */
.cartbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 4;
  display: flex;
  background: var(--surface);
  border-top: 2px solid var(--line);
  padding: 8px 8px calc(8px + var(--safe-bottom)) 8px;
  gap: 8px;
  box-shadow: var(--shadow-2);
}

.cartbar__clear {
  flex: 0 0 auto;
  width: var(--tap); height: var(--tap);
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius);
  font-size: 26px;
  cursor: pointer;
  display: grid; place-items: center;
}
.cartbar__clear[disabled] {
  opacity: .35; cursor: not-allowed;
}

.cartbar__toggle {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  background: var(--surface-2);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}
.cartbar__count {
  display: inline-grid; place-items: center;
  min-width: 36px; height: 36px;
  padding: 0 10px;
  background: var(--ink); color: var(--bg);
  border-radius: 999px;
  font-weight: 800;
}
.cartbar__label { font-weight: 700; }
.cartbar__total {
  font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 22px;
  text-align: right;
}
.cartbar__chevron {
  font-size: 18px; color: var(--muted);
  transition: transform .15s ease;
}
.cartbar__toggle[aria-expanded="true"] .cartbar__chevron { transform: rotate(180deg); }

.cartbar__pay {
  min-height: var(--tap);
  padding: 0 22px;
  background: var(--accent); color: var(--accent-ink);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  font-weight: 800; font-size: 20px;
  cursor: pointer;
}
.cartbar__pay[disabled] {
  background: var(--surface-2); color: var(--muted);
  border-color: var(--line);
  cursor: not-allowed;
}

/* ==================== TIROIR PANIER ==================== */
.cartdrawer {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--tap) + 16px + var(--safe-bottom));
  z-index: 3;
  background: var(--surface);
  border-top: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  max-height: 60vh;
  overflow-y: auto;
  padding: 8px 12px 16px 12px;
  box-shadow: 0 -10px 30px rgba(0,0,0,.08);
}

.cartlines { list-style: none; margin: 0; padding: 0; }
.cartline {
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.cartline__emoji { font-size: 30px; line-height: 1; text-align: center; }
.cartline__name  {
  font-weight: 700; font-size: 17px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cartline__name small { display: block; color: var(--muted); font-weight: 500; }
.cartline__qty {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); border: 2px solid var(--line);
  border-radius: 999px; padding: 4px;
}
.cartline__qty button {
  width: 40px; height: 40px;
  border: 0;
  background: var(--surface);
  border-radius: 999px;
  font-size: 22px; font-weight: 800;
  cursor: pointer;
}
.cartline__qty span {
  min-width: 28px; text-align: center;
  font-weight: 800; font-variant-numeric: tabular-nums;
}
.cartline__total {
  font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 20px;
}

/* ==================== BUTTONS ==================== */
.btn {
  min-height: var(--tap);
  padding: 0 22px;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  background: var(--ink); color: var(--bg);
  font-weight: 800; font-size: 18px;
  cursor: pointer;
}
.btn--primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.btn--ghost {
  background: var(--surface); color: var(--ink); border-color: var(--line);
}
.btn--full { width: 100%; margin-top: 12px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.back {
  appearance: none;
  border: 0; background: transparent; color: var(--ink);
  font-size: 18px; font-weight: 700;
  padding: 8px 8px 8px 0;
  cursor: pointer;
  margin: 4px 0 8px 0;
}

/* ==================== CHECKOUT ==================== */
/* Layout compact "no-scroll" : total (haut), reçu+rendu (2 colonnes), clavier (actions intégrées) */
.checkout {
  display: flex; flex-direction: column; gap: 10px;
  max-width: 540px; margin: 0 auto;
  padding-bottom: var(--safe-bottom);
}

/* Total à payer — seul, très visible mais moins haut qu'avant */
.checkout__total {
  background: var(--ink); color: var(--bg);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.checkout__total .checkout__label { color: var(--bg); opacity: .85; }
.checkout__label { font-weight: 700; font-size: 13px; letter-spacing: .02em; text-transform: uppercase; }
.checkout__amount {
  font-variant-numeric: tabular-nums;
  font-size: 32px; font-weight: 800; letter-spacing: -.01em;
}

/* Zone 2 colonnes : Montant reçu | À rendre */
.checkout__row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.checkout__field,
.checkout__change {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
}
.checkout__field { text-align: center; }
.checkout__received {
  font-variant-numeric: tabular-nums;
  font-size: 26px; font-weight: 800;
  color: var(--ink);
}
.checkout__amount--ok   { color: var(--ok); }
.checkout__amount--warn { color: var(--warn); }
.checkout__change--ok   { background: var(--ok-soft);   border-color: var(--ok); }
.checkout__change--warn { background: var(--warn-soft); border-color: var(--warn); }

/* Clavier avec boutons d'action intégrés en dernière ligne */
.numpad {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
/* Premières lignes : chiffres 1-9 */
.numpad .numkey:nth-child(-n+9) {
  grid-column: span 2;
}
/* Dernière ligne : C | 0 | ⌫ | Annuler | Valider */
.numpad .numkey[data-key="clear"]   { grid-column: 1 / 3; }
.numpad .numkey[data-key="0"]       { grid-column: 3 / 5; }
.numpad .numkey[data-key="back"]    { grid-column: 5 / 7; }
.numpad .btn--checkout-cancel { grid-column: 1 / 4; }
.numpad .btn--checkout-valid  { grid-column: 4 / 7; }

.numkey, .btn--checkout {
  min-height: 64px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  font-size: 26px; font-weight: 800;
  cursor: pointer;
  display: grid; place-items: center;
}
.numkey:active, .btn--checkout:active { transform: translateY(1px); }
.numkey--soft { background: var(--surface-2); font-size: 20px; }

.btn--checkout {
  font-size: 15px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
  min-height: 64px;
}
/* Masquer la barre d'actions desktop sur mobile (on utilise les boutons intégrés au clavier) */
.checkout__actions { display: none; }
.btn--checkout-cancel {
  background: var(--surface-2); color: var(--ink); border-color: var(--line);
}
.btn--checkout-valid {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.btn--checkout-valid[disabled] {
  background: var(--surface-2); color: var(--muted); border-color: var(--line);
  cursor: not-allowed;
}

/* Sur tablette/desktop : clavier 3 colonnes classique avec actions dessous */
@media (min-width: 600px) {
  .checkout { max-width: 720px; gap: 14px; }
  .checkout__total { padding: 14px 18px; }
  .checkout__amount { font-size: 38px; }
  .checkout__received { font-size: 32px; }
  .numpad {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  .numpad .numkey:nth-child(-n+9) { grid-column: auto; }
  .numpad .numkey[data-key="clear"]   { grid-column: auto; }
  .numpad .numkey[data-key="0"]       { grid-column: auto; }
  .numpad .numkey[data-key="back"]    { grid-column: auto; }
  .numkey { min-height: 72px; font-size: 30px; }
  .checkout__actions {
    display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 4px;
  }
  .btn--checkout-cancel,
  .btn--checkout-valid { display: none; }
}

/* ==================== ADMIN ==================== */
.admin {
  max-width: 720px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 14px;
}
.admin h2 {
  margin: 12px 0 4px;
  font-size: 22px;
}
.muted { color: var(--muted); }
.muted.small { font-size: 14px; }

.adminlist { display: flex; flex-direction: column; gap: 8px; }
.adminitem {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px; align-items: center;
  padding: 10px 12px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}
.adminitem__emoji { font-size: 28px; text-align: center; }
.adminitem__name { font-weight: 700; }
.adminitem__name small { display: block; color: var(--muted); font-weight: 500; }
.adminitem__price {
  font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 22px;
}

.field {
  display: flex; flex-direction: column; gap: 6px;
  font-weight: 700;
}
.field input, .field select {
  min-height: 56px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-size: 20px;
}

.switch {
  display: flex; align-items: center; gap: 14px;
  font-weight: 700; cursor: pointer;
  padding: 10px 0;
}
.switch input { width: 28px; height: 28px; accent-color: var(--accent); }

.pinput {
  display: flex; gap: 14px; justify-content: center;
  margin: 18px 0 8px 0;
}
.pindot {
  width: 22px; height: 22px;
  border-radius: 999px;
  border: 3px solid var(--line);
  background: transparent;
}
.pindot[data-on="1"] { background: var(--ink); border-color: var(--ink); }
.numpad--admin { max-width: 360px; margin: 8px auto; }
.pinerror { min-height: 1.4em; color: var(--warn); font-weight: 700; text-align: center; }

/* ==================== DIALOG ==================== */
.dialog {
  border: 0;
  border-radius: var(--radius-l);
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  max-width: 92vw;
  width: 480px;
  box-shadow: var(--shadow-2);
}
.dialog::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.dialog__form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dialog__form h2 { margin: 0; font-size: 22px; }
.dialog__actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 6px;
}
.spacer { flex: 1; }

/* ==================== ARIA STATUS (visually hidden) ==================== */
.ariastatus {
  position: absolute;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ==================== REDUCED MOTION ==================== */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
