/* Mobile d'abord (360 px), zones tactiles >= 44 px, contraste élevé, lisible en plein soleil (NFR-01, NFR-08). */
:root {
  color-scheme: light;
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --text: #0b1220;
  --muted: #4a5565;
  --border: #c9cfd6;
  --primary: #0f766e;
  --primary-strong: #0b5e58;
  --primary-ink: #ffffff;
  --primary-soft: #e3f2f0;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #067647;
  --ok-soft: #e6f4ec;
  --warn: #9a5b00;
  --warn-soft: #fff4de;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
  --nav-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}
img, svg { max-width: 100%; }
a { color: var(--primary-strong); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Structure ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; min-height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; font-weight: 700; }
.topbar .brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; }
.topbar .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary-strong); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

main#view {
  flex: 1; width: 100%; max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 24px);
}
body.no-nav main#view { padding-bottom: 32px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: var(--nav-h); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 44px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a[aria-current="page"] { color: var(--primary-strong); }
.bottomnav a[aria-current="page"] svg { stroke-width: 2.4; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0 10px; }
.section-title h2 { margin: 0; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--primary-soft); color: var(--text); margin-bottom: 16px; font-size: 15px; }
.notice.warn { background: var(--warn-soft); }
.notice.danger { background: var(--danger-soft); }
.notice.ok { background: var(--ok-soft); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 600 16px/1.2 var(--font); text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-strong); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.whatsapp { background: #128c4a; border-color: #128c4a; color: #fff; }
.btn.block { width: 100%; }
.btn.small { min-height: 44px; padding: 8px 12px; font-size: 15px; }
.btn.link { border: 0; background: none; color: var(--primary-strong); padding: 8px 4px; min-height: 44px; text-decoration: underline; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row > .btn { flex: 1 1 140px; }
.stack { display: grid; gap: 10px; }

/* ---------- Formulaires ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-weight: 600; font-size: 15px; }
.field .hint { font-size: 14px; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font: 16px/1.3 var(--font); color: var(--text); background: var(--surface);
}
textarea { min-height: 88px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, a:focus-visible {
  outline: 3px solid #f59e0b; outline-offset: 2px;
}
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }
input[type="color"] { padding: 4px; width: 72px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; }
.code-input { font-size: 28px; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-error { color: var(--danger); font-weight: 600; margin: 0 16px 8px; }

.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented label {
  flex: 1 1 90px; display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 8px; border: 1px solid var(--border); border-radius: 10px;
  font-weight: 600; cursor: pointer; background: var(--surface);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:checked + span { color: var(--primary-ink); }
.segmented label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.segmented label:has(input:focus-visible) { outline: 3px solid #f59e0b; outline-offset: 2px; }

.choice-cards { display: grid; gap: 10px; }
.choice-cards label {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px;
  border: 2px solid var(--border); border-radius: 12px; cursor: pointer; background: var(--surface);
}
.choice-cards label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice-cards strong { display: block; font-size: 17px; }

/* ---------- Caisse (mode Simple) ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.product-btn {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  min-height: 92px; padding: 12px 10px; text-align: left;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  font: 600 15px/1.25 var(--font); color: var(--text); cursor: pointer; box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent; overflow-wrap: anywhere;
}
.product-btn .price { font-weight: 700; color: var(--primary-strong); font-size: 15px; }
.product-btn .qty-badge {
  position: absolute; top: -8px; right: -8px; min-width: 28px; height: 28px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--primary); color: #fff; font-size: 14px; font-weight: 700;
}
.product-btn.flash { animation: flash .35s ease; }
@keyframes flash { 50% { background: var(--primary-soft); } }
.product-btn.free { border-style: dashed; color: var(--primary-strong); justify-content: center; align-items: center; text-align: center; }

.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cart-line:last-child { border-bottom: 0; }
.cart-line .name { background: none; border: 0; padding: 0; text-align: left; font: 600 16px/1.3 var(--font); color: var(--text); cursor: pointer; min-height: 32px; overflow-wrap: anywhere; }
.cart-line .name small { display: block; font-weight: 400; color: var(--muted); font-size: 14px; }
.cart-line .amount { font-weight: 700; text-align: right; white-space: nowrap; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper output { min-width: 40px; text-align: center; font-weight: 700; font-size: 17px; }

.checkout-bar {
  position: sticky; bottom: calc(var(--nav-h) + 8px); z-index: 10;
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--text); color: #fff; border-radius: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.checkout-bar .total { flex: 1; }
.checkout-bar .total small { display: block; font-size: 13px; opacity: .8; }
.checkout-bar .total strong { font-size: 22px; }
.checkout-bar .btn.primary { background: #2dd4bf; border-color: #2dd4bf; color: #04201d; min-width: 130px; }

.quota { margin-bottom: 14px; font-size: 14px; color: var(--muted); }
.quota .bar { height: 8px; background: #e4e7ea; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.quota .bar span { display: block; height: 100%; background: var(--primary); }
.quota.warn .bar span { background: var(--warn); }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px;
  color: var(--text); text-decoration: none; width: 100%; text-align: left; font: inherit; cursor: pointer;
}
.list-item .main { flex: 1; min-width: 0; }
.list-item .main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .main span { display: block; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .side { text-align: right; white-space: nowrap; font-weight: 700; }
.list-item .side .badge { margin-top: 4px; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .btn { margin-top: 12px; }
.searchbar { position: relative; margin-bottom: 12px; }

/* ---------- Reçu ---------- */
.receipt {
  --accent: #0f766e;
  background: #fff; color: #111; border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 16px; margin-bottom: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.receipt::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--accent); }
.r-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.r-head img { width: 56px; height: 56px; object-fit: contain; }
.r-head .who strong { display: block; font-size: 18px; }
.r-head .who span { display: block; font-size: 14px; color: #444; }
.r-title { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px; border-top: 1px dashed #bbb; border-bottom: 1px dashed #bbb; padding: 8px 0; margin-bottom: 10px; }
.r-title strong { font-size: 18px; letter-spacing: 1px; color: var(--accent); }
.r-meta { font-size: 14px; color: #333; margin-bottom: 10px; }
.r-lines { width: 100%; border-collapse: collapse; font-size: 15px; }
.r-lines th { text-align: left; font-size: 13px; color: #555; font-weight: 600; border-bottom: 1px solid #ddd; padding: 4px 0; }
.r-lines td { padding: 6px 0; border-bottom: 1px solid #eee; vertical-align: top; }
.r-lines .num { text-align: right; white-space: nowrap; padding-left: 8px; }
.r-lines small { display: block; color: #555; font-size: 12px; }
.r-totals { margin-top: 10px; display: grid; gap: 4px; font-size: 15px; }
.r-totals div { display: flex; justify-content: space-between; }
.r-totals .grand { font-size: 20px; font-weight: 800; border-top: 2px solid #111; padding-top: 6px; margin-top: 4px; }
.r-foot { display: flex; gap: 12px; align-items: center; margin-top: 14px; padding-top: 12px; border-top: 1px dashed #bbb; font-size: 13px; color: #333; }
.r-foot svg { flex: none; width: 104px; height: 104px; }
.r-mention { margin-top: 10px; font-size: 12px; color: #555; text-align: center; }
.stamp {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg);
  border: 4px solid #b42318; color: #b42318; padding: 4px 16px; font-size: 32px; font-weight: 900;
  letter-spacing: 4px; opacity: .8; background: rgba(255,255,255,.7); pointer-events: none;
}

/* ---------- Vérification publique ---------- */
.verify-status { display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 12px; margin-bottom: 16px; font-size: 18px; font-weight: 800; }
.verify-status.valid { background: var(--ok-soft); color: var(--ok); }
.verify-status.cancelled { background: var(--danger-soft); color: var(--danger); }
.verify-status svg { width: 32px; height: 32px; flex: none; }

/* ---------- Boîtes de dialogue ---------- */
.dialog { border: 0; padding: 0; border-radius: 16px; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); color: var(--text); background: var(--surface); }
.dialog::backdrop { background: rgba(11, 18, 32, .55); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-body { padding: 16px; overflow: auto; }
.dialog-actions { display: flex; gap: 10px; padding: 12px 16px 16px; flex-wrap: wrap; }
.dialog-actions .btn { flex: 1 1 120px; }
details.more { margin: 4px 0 12px; }
details.more summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; color: var(--primary-strong); }

/* ---------- Divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 10px;
  background: #111827; color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.secret { font: 600 18px/1.4 ui-monospace, Consolas, monospace; letter-spacing: 1px; word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 8px; border: 1px solid var(--border); }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font: 600 16px ui-monospace, Consolas, monospace; }
.codes span { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; text-align: center; }
.qr-box { display: flex; justify-content: center; margin: 12px 0; }
.qr-box svg { width: 200px; height: 200px; }
.mail { white-space: pre-wrap; }
.mail-code { font: 800 32px ui-monospace, Consolas, monospace; letter-spacing: 6px; }
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.logo-preview { width: 72px; height: 72px; object-fit: contain; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.env-ribbon { background: #fde68a; color: #4a3500; text-align: center; font-size: 13px; font-weight: 700; padding: 4px 8px; }

#print-root { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  body.printing { background: #fff; }
  #print-root .receipt { box-shadow: none; border: 0; max-width: 150mm; margin: 0 auto; }
}

@media (min-width: 720px) {
  .bottomnav { left: 50%; transform: translateX(-50%); max-width: 640px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); border-radius: 14px 14px 0 0; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
