:root {
  --ink: #16181D;
  --ink-2: #5B5F66;
  --ground: #F6F5F2;
  --white: #FFFFFF;
  --line: #E6E4DE;
  --line-2: #DEDCD6;
  --ok-bg: #E3F1E8;
  --ok: #0B5A2D;
  --err-bg: #FBE7E4;
  --err: #8F2116;
  --brand: #B23A2B;
  --radius: 16px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", var(--font);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; }
a { color: var(--ink); }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.3px; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
p { line-height: 1.5; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
#app.wide { max-width: 1180px; }

.screen { flex: 1; display: flex; flex-direction: column; gap: 20px; padding: calc(24px + env(safe-area-inset-top, 0px)) 20px calc(28px + var(--safe-b)); }
.screen.with-tabs { padding-bottom: calc(110px + var(--safe-b)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; }

/* Boutons */
.btn { appearance: none; border: 0; border-radius: 14px; min-height: 52px; padding: 0 20px; font: 600 16px var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; text-decoration: none; background: var(--ink); color: var(--white); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.outline { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
.btn.light { background: var(--white); color: var(--ink); border: 1px solid var(--line-2); }
.btn.brand { background: var(--brand); color: var(--white); }
.btn.block { width: 100%; }
.btn.small { min-height: 44px; font-size: 14px; padding: 0 14px; border-radius: 12px; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line-2); background: var(--white); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink); text-decoration: none; flex: none; }
.icon-btn.on-brand { background: rgba(255,255,255,.18); border: 0; color: #fff; }
.link { background: none; border: 0; font: 600 15px var(--font); color: var(--ink); text-decoration: underline; cursor: pointer; padding: 12px 0; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 14px; font-weight: 600; }
.input, select.input, textarea.input { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--white); padding: 0 14px; font: 16px var(--font); color: var(--ink); }
textarea.input { padding: 12px 14px; min-height: 96px; resize: vertical; }
.input:focus, .btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.code-input { font: 700 28px var(--display); letter-spacing: 10px; text-align: center; }
.choice { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--white); cursor: pointer; }
.choice:has(input:checked) { border: 2px solid var(--ink); }
.choice input { width: 20px; height: 20px; accent-color: var(--ink); }
.toggle-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--white); border: 1px solid var(--line); border-radius: 14px; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--ink); }
.swatches { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 18px; border: 0; cursor: pointer; }
.swatch[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 3px; }
input[type="color"].swatch { padding: 0; background: none; border: 1px solid var(--line-2); }

.panel { background: var(--white); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.notice { padding: 12px 14px; border-radius: 14px; font-size: 14px; font-weight: 600; line-height: 1.45; }
.notice > svg { display: inline-block; vertical-align: -5px; margin-right: 8px; }
.notice a { color: inherit; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.err { background: var(--err-bg); color: var(--err); }
.notice.warn { background: #FDF1DC; color: #7A4B00; }

/* Cartes de fidélité */
.loyalty { display: flex; flex-direction: column; gap: 16px; padding: 20px; border-radius: 20px; background: var(--brand); color: #fff; text-decoration: none; }
.loyalty .head { display: flex; align-items: center; gap: 12px; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: #fff; color: var(--brand); display: flex; align-items: center; justify-content: center; font: 700 16px var(--display); overflow: hidden; flex: none; }
.logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.logo-pick { display: flex; align-items: center; gap: 14px; }
.logo-thumb { width: 72px; height: 72px; flex: none; border-radius: 18px; border: 2px dashed var(--line-2); background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; font: 700 20px var(--display); color: var(--ink-2); }
.logo-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.logo-thumb:has(img) { border-style: solid; border-color: var(--line); }
.logo.lg { width: 56px; height: 56px; border-radius: 16px; font-size: 20px; }
.loyalty .name { font: 600 17px var(--display); }
.loyalty .sub { font-size: 13px; opacity: .9; }
.badge { padding: 6px 12px; border-radius: 999px; background: #fff; color: var(--brand); font-size: 13px; font-weight: 600; white-space: nowrap; }
.bar-seg { display: flex; gap: 6px; }
.bar-seg span { flex: 1; height: 8px; border-radius: 4px; background: rgba(255,255,255,.3); }
.bar-seg span.on { background: #fff; }
.bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: #fff; border-radius: 4px; }
.stamps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.stamp { aspect-ratio: 1; border-radius: 50%; border: 2px dashed rgba(255,255,255,.6); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.stamp.on { background: #fff; border: 0; color: var(--brand); }
.stamp.on img { width: 80%; height: 80%; object-fit: contain; }
.add-card { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; border-radius: 20px; border: 1.5px dashed #B9B6AE; color: var(--ink); font-weight: 600; text-decoration: none; background: none; cursor: pointer; font-size: 15px; }

.hero { margin: calc(-24px - env(safe-area-inset-top, 0px)) -20px 0; padding: calc(24px + env(safe-area-inset-top, 0px)) 20px 24px; background: var(--brand); color: #fff; display: flex; flex-direction: column; gap: 18px; }
.list-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.list-row:last-child { border-bottom: 0; }

/* Écran QR */
.qr-screen { flex: 1; background: var(--brand); color: #fff; display: flex; flex-direction: column; gap: 22px; padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(28px + var(--safe-b)); }
.qr-box { background: #fff; color: var(--ink); border-radius: 24px; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.qr-box canvas { width: 100%; max-width: 280px; height: auto; image-rendering: pixelated; }
.countdown { height: 4px; width: 100%; max-width: 280px; background: var(--line); border-radius: 2px; overflow: hidden; }
.countdown > span { display: block; height: 100%; background: var(--ink); transition: width 1s linear; }

/* Scanner */
.scanner { position: relative; border-radius: 20px; overflow: hidden; background: #000; aspect-ratio: 1; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 15%; border: 3px solid rgba(255,255,255,.9); border-radius: 20px; }

/* Barre d'onglets */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--white); border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: center; padding: 10px 24px calc(14px + var(--safe-b)); z-index: 10; }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); text-decoration: none; min-width: 64px; }
.tabbar a.active { color: var(--ink); font-weight: 600; }
.tabbar .fab { width: 58px; height: 58px; border-radius: 29px; background: var(--ink); color: #fff; margin-top: -30px; min-width: 0; justify-content: center; }

/* Pro */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--white); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font: 700 28px var(--display); }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; border-bottom: 1px solid var(--line); }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; font-size: 12px; font-weight: 600; }
.bars i { display: block; width: 100%; border-radius: 6px 6px 0 0; background: #D9D6CE; min-height: 2px; }
.bars div:last-child i { background: var(--brand); }
.pro-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stamp-pick { display: grid; gap: 10px; padding: 5px; }
.stamp-pick button { aspect-ratio: 1; min-width: 0; width: 100%; max-width: 72px; justify-self: center; padding: 0; border-radius: 50%; border: 2px dashed var(--line-2); background: #fff; color: var(--ink-2); font: 600 13px var(--font); display: flex; align-items: center; justify-content: center; cursor: pointer; touch-action: manipulation; }
.stamp-pick button.old { background: var(--brand); border: 0; color: #fff; opacity: .35; cursor: default; }
.stamp-pick button.new { background: var(--brand); border: 0; color: #fff; box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--brand); }
.stamp-pick button:disabled:not(.old) { opacity: .4; cursor: default; }
.stepper { display: flex; align-items: center; justify-content: space-between; padding: 8px; border-radius: 16px; background: var(--ground); }
.stepper button { width: 56px; height: 56px; border-radius: 14px; border: 0; font-size: 26px; cursor: pointer; background: #fff; color: var(--ink); }
.stepper button.plus { background: var(--ink); color: #fff; }
.stepper .val { font: 700 40px var(--display); line-height: 1; text-align: center; }

/* Affiche à imprimer */
.poster { background: var(--brand); color: #fff; border-radius: 24px; padding: 32px 24px; display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.poster .qr-wrap { background: #fff; border-radius: 18px; padding: 16px; }
.poster canvas { width: 240px; height: 240px; image-rendering: pixelated; }
.poster .title { font: 700 26px/1.2 var(--display); }

#toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: calc(100% - 40px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  body { background: #fff; }
  .no-print, .tabbar, #toast { display: none !important; }
  #app { max-width: none; }
  .screen { padding: 0; }
  .poster { -webkit-print-color-adjust: exact; print-color-adjust: exact; border-radius: 0; min-height: 100vh; justify-content: center; }
  .poster canvas { width: 9cm; height: 9cm; }
  .poster .title { font-size: 32pt; }
}
/* Aperçu d'une notification (écran Messages du commerçant) */
.notif-preview { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 18px; background: var(--ground); border: 1px solid var(--line); }
.notif-preview .grow { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
/* Plusieurs établissements */
.biz-switch { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; min-height: 40px; border-radius: 999px; background: var(--white); border: 1px solid var(--line-2); color: var(--ink); font-size: 13px; font-weight: 600; text-decoration: none; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.etab { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 16px; background: var(--white); border: 1px solid var(--line); color: var(--ink); font: inherit; cursor: pointer; }
.etab.current { border: 2px solid var(--brand); }
/* Onglets Créer un compte / Se connecter */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--white); border: 1px solid var(--line); }
.seg button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); font: 600 15px var(--font); cursor: pointer; }
.seg button.on { background: var(--ink); color: #fff; }
/* Champ mot de passe avec bouton Afficher */
.pw { position: relative; }
.pw .input { padding-right: 92px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); min-height: 40px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); font: 600 14px var(--font); cursor: pointer; }
/* Règles du mot de passe */
.pw-rules { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.pw-rules li::before { content: '○'; display: inline-block; width: 18px; }
.pw-rules li.ok { color: var(--ok); }
.pw-rules li.ok::before { content: '✓'; }

/* Carte cliquable (page d'ajout d'une carte) */
.loyalty.as-btn { width: 100%; border: 0; text-align: left; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .15s; }
.loyalty.as-btn:active { transform: scale(.98); }
.loyalty.as-btn svg { width: 16px; height: 16px; vertical-align: -3px; }

/* Infobulles du tableau de bord (une bulle fixe, placée par app.js dans les limites de l'écran) */
.tipbox { position: fixed; left: 0; top: 0; z-index: 100; width: max-content; max-width: min(260px, calc(100vw - 16px));
  background: var(--ink); color: #fff; font: 500 12.5px/1.45 var(--font); text-align: left; padding: 8px 11px; border-radius: 10px;
  box-shadow: 0 10px 24px -12px rgba(0,0,0,.5); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .15s; }
.tipbox.on { opacity: 1; visibility: visible; }
.kpi[data-tip], h2[data-tip] { cursor: help; outline: none; }
.tip-i { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 6px; border-radius: 50%; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink-2); font: 700 10px/1 var(--font); font-style: normal; vertical-align: 2px; }

/* Case « J'accepte les conditions » */
.check-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; background: var(--white); border: 1px solid var(--line); border-radius: 14px; font-size: 14px; line-height: 1.45; cursor: pointer; }
.check-row input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--ink); }
.check-row a { color: inherit; font-weight: 600; }
.check-row.need { border-color: var(--err, #B3261E); box-shadow: 0 0 0 3px rgba(179,38,30,.12); }

/* Connexion avec Google */
.or { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.gbtn { display: flex; justify-content: center; min-height: 44px; }
