/* ===== Jetons de design ===== */
:root {
  --brand: #145A3A;
  --brand-dark: #0C3D27;
  --accent: #E0642B;
  --accent-text: #B4441A;
  --ground: #F4F5F1;
  --surface: #FFFFFF;
  --ink: #1B1F1C;
  --muted: #5A615C;
  --line: #E4E6E0;
  --tint-green: #E7EFE9;
  --tint-orange: #F6E6DC;
  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font-display: 'Bricolage Grotesque', 'Segoe UI', sans-serif;
  --font-body: 'Figtree', 'Segoe UI', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: #D9DDD6;
  display: flex;
  align-items: center;
  justify-content: center;
}

button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

/* ===== Cadre téléphone ===== */
.phone {
  position: relative;
  width: 390px;
  height: 844px;
  max-height: 100vh;
  background: var(--ground);
  border-radius: 40px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 60px rgba(20, 40, 30, 0.25);
}

@media (max-width: 480px) {
  body { background: var(--ground); }
  .phone {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }
}

/* ===== Écrans ===== */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: env(safe-area-inset-top, 0px);
}
.screen[hidden] { display: none; }
.screen-brand { background: var(--brand); }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.display { font-family: var(--font-display); font-weight: 800; }
.muted { color: var(--muted); }
.muted-light { font-size: 13px; opacity: 0.85; }
.small { font-size: 13px; }
.strong { font-weight: 600; font-size: 13px; }

/* ===== En-têtes ===== */
.topbar {
  padding: 48px 20px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row.small-gap { gap: 10px; }
.greeting { display: flex; flex-direction: column; }
.greeting span { font-size: 13px; color: var(--muted); }
.greeting h1 { font-size: 20px; }

.logo {
  position: relative;
  width: 44px; height: 44px;
  border-radius: 14px;
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.logo span { font-family: var(--font-display); font-weight: 800; font-size: 24px; color: #fff; }
.logo i {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.logo-sm { width: 36px; height: 36px; border-radius: 11px; }
.logo-sm span { font-size: 19px; }
.logo-sm i { top: 6px; right: 6px; width: 6px; height: 6px; }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid #DADDD6;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 20px; height: 20px; }

.page-head {
  padding: 48px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.page-title { font-size: 30px; }
.page-head.on-brand { color: #fff; gap: 6px; }
.page-head.on-brand p { font-size: 14px; opacity: 0.9; }

/* ===== Carte de fidélité (accueil) ===== */
.loyalty-card {
  text-align: left;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--brand);
  color: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.loyalty-head { display: flex; justify-content: space-between; align-items: flex-start; }
.loyalty-head > div { display: flex; flex-direction: column; gap: 4px; }
.points { font-size: 26px; }
.qr-icon { width: 28px; height: 28px; }
.progress {
  height: 8px; border-radius: 4px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.6s ease;
}
.progress-text { font-size: 13px; }
.pill-white {
  align-self: flex-start;
  padding: 10px 16px;
  border-radius: 999px;
  background: #fff;
  color: var(--brand);
  font-weight: 700;
  font-size: 14px;
}

.section-head { display: flex; justify-content: space-between; align-items: baseline; }
h2.display { font-size: 20px; }
.link-btn {
  border: none; background: none;
  color: var(--brand); font-weight: 600; font-size: 14px;
  min-height: 44px; padding: 0 4px;
}

/* ===== Coupons ===== */
.coupon-preview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.coupon-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.coupon-tile .thumb { height: 72px; }
.coupon-value { font-family: var(--font-display); font-weight: 800; font-size: 22px; color: var(--accent-text); }

.thumb {
  border-radius: var(--radius-sm);
  background: var(--tint-green);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #4C5650; text-align: center;
}
.thumb.orange { background: var(--tint-orange); }

.btn-activate {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 700; font-size: 14px;
  transition: background 0.2s, color 0.2s;
}
.btn-activate.is-on { background: #fff; color: var(--brand); }

.tabs { display: flex; gap: 8px; }
.tab {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid #DADDD6;
  background: var(--surface);
  font-weight: 600; font-size: 14px;
}
.tab.is-active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }

.coupon-list { display: flex; flex-direction: column; gap: 12px; }
.coupon-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: flex; align-items: stretch;
  overflow: hidden;
}
.coupon-stub {
  width: 96px;
  display: flex; align-items: center; justify-content: center;
  background: var(--tint-green);
  border-right: 2px dashed #fff;
  text-align: center;
}
.coupon-stub.orange { background: var(--tint-orange); }
.coupon-info { flex: 1; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.coupon-info strong { font-size: 15px; }
.coupon-info span { font-size: 12px; color: var(--muted); }
.coupon-action { display: flex; align-items: center; padding-right: 12px; }

.empty { text-align: center; color: var(--muted); padding: 32px 12px; font-size: 14px; }

/* ===== Offre ===== */
.offer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex; align-items: center; gap: 14px;
}
.offer .thumb { width: 72px; height: 72px; flex-shrink: 0; }
.offer-body { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.offer-body strong { font-size: 15px; }
.offer-body span { font-size: 13px; }

/* ===== Écran carte ===== */
.card-panel {
  background: #fff;
  border-radius: 24px;
  padding: 24px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.card-panel-head { align-self: stretch; display: flex; justify-content: space-between; align-items: center; }
.card-panel-head strong { font-size: 18px; }

.barcode { display: flex; align-items: stretch; height: 120px; justify-content: center; }
.barcode span { background: var(--ink); display: block; }

.card-number { letter-spacing: 3px; font-size: 16px; font-weight: 600; }
.card-panel hr { align-self: stretch; border: none; height: 1px; background: var(--line); margin: 0; }
.card-stats { align-self: stretch; display: flex; justify-content: space-between; }
.card-stats > div { display: flex; flex-direction: column; gap: 2px; }
.card-stats .right { align-items: flex-end; }
.card-stats strong { font-size: 22px; }

.ghost-btn {
  min-height: 52px;
  border-radius: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  background: transparent;
  color: #fff;
  font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.ghost-btn svg { width: 20px; height: 20px; }
.ghost-btn[aria-pressed="true"] { background: #fff; color: var(--brand); }

/* Mode luminosité max : on blanchit tout l'écran autour du code */
.screen-brand.bright { background: #fff; }
.screen-brand.bright .page-head.on-brand { color: var(--ink); }
.screen-brand.bright .ghost-btn { border-color: var(--brand); }

/* ===== Achats ===== */
.savings {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex; justify-content: space-between; align-items: center;
}
.savings > div { display: flex; flex-direction: column; gap: 2px; }
.savings-amount { font-size: 26px; color: var(--brand); }
.savings svg { width: 36px; height: 36px; color: var(--brand); }

.list-label { font-size: 14px; font-weight: 700; color: #4C5650; }

.ticket-list { display: flex; flex-direction: column; gap: 10px; }
.ticket {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.ticket-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  background: var(--tint-green);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.ticket-icon svg { width: 22px; height: 22px; }
.ticket-main { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.ticket-main strong { font-size: 15px; }
.ticket-main span { font-size: 12px; color: var(--muted); }
.ticket-amount { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.ticket-amount strong { font-size: 15px; }
.ticket-amount span { font-size: 12px; font-weight: 600; color: var(--accent-text); }

/* ===== Détail ticket (feuille) ===== */
.sheet {
  position: absolute;
  inset: auto 0 0 0;
  width: 100%;
  max-width: none;
  max-height: 75%;
  margin: 0;
  border: none;
  border-radius: 24px 24px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  color: var(--ink);
  overflow-y: auto;
  z-index: 20;
  display: flex; flex-direction: column; gap: 12px;
  animation: sheet-up 0.25s ease-out;
}
.sheet[hidden], .sheet-backdrop[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 30, 25, 0.45); z-index: 10; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #DADDD6; align-self: center; }
.sheet-lines li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sheet-lines li.discount { color: var(--accent-text); font-weight: 600; }
.sheet-total { display: flex; justify-content: space-between; font-size: 17px; font-weight: 700; padding: 6px 0; }
.primary-btn {
  min-height: 48px;
  border: none;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 700; font-size: 15px;
}

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== Barre de navigation ===== */
.tabbar {
  display: flex;
  justify-content: space-around;
  padding: 10px 8px calc(20px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid var(--line);
}
.nav-item {
  min-width: 64px; min-height: 44px;
  border: none; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500;
  color: var(--muted);
}
.nav-item.is-active { color: var(--brand); font-weight: 700; }

/* ===== Notification ===== */
.toast {
  position: absolute;
  left: 50%;
  bottom: 100px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  width: max-content;
  max-width: calc(100% - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* =========================================================
   Fonctionnalités ajoutées
   ========================================================= */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.center { text-align: center; }
.screen { position: relative; }

/* Bouton retour */
.back-btn {
  align-self: flex-start;
  display: flex; align-items: center; gap: 4px;
  min-height: 44px; padding: 0 8px 0 0;
  border: none; background: none;
  color: var(--brand); font-weight: 600; font-size: 15px;
}
.back-btn svg { width: 20px; height: 20px; }
.page-head:has(.back-btn) { padding-top: 32px; }

/* Raccourcis accueil */
.shortcuts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.shortcut {
  position: relative;
  border: none; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; text-align: center;
  min-height: 44px; padding: 4px 0;
}
.shortcut-icon {
  width: 56px; height: 56px; border-radius: 18px;
  background: var(--tint-green); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.shortcut-icon.orange { background: var(--tint-orange); color: var(--accent-text); }
.badge {
  position: absolute; top: 0; right: 10px;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent-text); color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.reward-strip, .store-strip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-md); padding: 14px 16px;
  text-align: left;
}
.reward-strip { display: flex; flex-direction: column; gap: 10px; }
.reward-strip-text { display: flex; flex-direction: column; gap: 2px; }
.store-strip { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.store-strip > svg:first-child { color: var(--brand); }
.store-strip-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.progress.dark { background: var(--tint-green); }

.h-scroll { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x mandatory; }
.h-scroll .product { min-width: 150px; scroll-snap-align: start; }

/* Boutons */
.secondary-btn {
  min-height: 48px; border-radius: 14px;
  border: 1.5px solid var(--brand); background: var(--surface);
  color: var(--brand); font-weight: 700; font-size: 15px;
}
.secondary-btn.danger { border-color: var(--accent-text); color: var(--accent-text); }
.secondary-btn:disabled { opacity: 0.5; cursor: default; }

/* Navigation : bouton carte central */
.nav-item { min-width: 56px; }
.nav-card { position: relative; }
.nav-card-btn {
  width: 52px; height: 52px; margin-top: -26px;
  border-radius: 18px; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: 4px solid #fff;
}
.nav-card-btn svg { width: 22px; height: 22px; }

/* Circulaire */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex-shrink: 0; min-height: 40px; padding: 0 14px;
  border-radius: 999px; border: 1px solid #DADDD6; background: var(--surface);
  font-size: 13px; font-weight: 600;
}
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }
.product-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.product {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.product .thumb { height: 90px; position: relative; }
.product .tag {
  position: absolute; top: 8px; left: 8px;
  background: var(--accent-text); color: #fff;
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 8px;
}
.product strong { font-size: 14px; }
.price-row { display: flex; align-items: baseline; gap: 6px; }
.price { font-family: var(--font-display); font-weight: 800; font-size: 20px; }
.old-price { font-size: 12px; color: var(--muted); text-decoration: line-through; }
.add-btn {
  min-height: 40px; border-radius: 10px;
  border: 1.5px solid var(--brand); background: var(--surface);
  color: var(--brand); font-weight: 700; font-size: 13px;
}
.add-btn.is-on { background: var(--brand); color: #fff; }

/* Menu Plus */
.menu { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.menu li + li { border-top: 1px solid var(--line); }
.menu button {
  width: 100%; min-height: 56px; padding: 0 16px;
  border: none; background: none; text-align: left;
  display: flex; align-items: center; gap: 14px;
  font-size: 15px; font-weight: 600;
}
.menu button svg:first-child { color: var(--brand); }
.menu .chev { margin-left: auto; color: var(--muted); width: 20px; height: 20px; }

/* Carte à gratter */
.scratch-wrap {
  position: relative; align-self: center;
  width: 320px; max-width: 100%; aspect-ratio: 16 / 10;
  border-radius: var(--radius-lg); overflow: hidden;
  background: var(--tint-orange);
}
.scratch-prize {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-align: center; padding: 16px;
}
.scratch-prize .big { font-family: var(--font-display); font-weight: 800; font-size: 34px; color: var(--accent-text); }
#scratch-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }

/* Récompenses */
.spent-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.spent-box strong { font-size: 28px; color: var(--brand); }
.tier-list { display: flex; flex-direction: column; gap: 10px; }
.tier {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.tier-dot {
  width: 54px; height: 54px; border-radius: 50%; flex-shrink: 0; white-space: nowrap;
  border: 2px dashed #B9BFB8; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12px;
}
.tier.reached .tier-dot { border: none; background: var(--brand); color: #fff; }
.tier-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.tier-info strong { font-size: 15px; }
.tier-info span { font-size: 12px; color: var(--muted); }
.tier .btn-activate { font-size: 13px; }

/* Liste de courses */
.add-form { display: flex; gap: 8px; }
.add-form input, .search, .field input {
  flex: 1; min-height: 48px; padding: 0 14px;
  border: 1px solid #C9CEC6; border-radius: 14px;
  font: inherit; font-size: 15px; background: #fff; color: var(--ink);
}
.add-form .primary-btn { padding: 0 16px; }
.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px 6px 4px 14px;
  display: flex; align-items: center; gap: 12px;
}
.shop-item label { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 15px; cursor: pointer; }
.shop-item input { width: 22px; height: 22px; accent-color: var(--brand); }
.shop-item.done label span { text-decoration: line-through; color: var(--muted); }
.shop-item .from { font-size: 11px; font-weight: 700; color: var(--accent-text); }
.del-btn {
  width: 44px; height: 44px; border: none; background: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.del-btn svg { width: 18px; height: 18px; }

/* Magasins */
.map-placeholder {
  height: 140px; border-radius: var(--radius-md);
  background: var(--tint-green); color: #4C5650; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.store-list { display: flex; flex-direction: column; gap: 10px; }
.store {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.store-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.store-top strong { font-size: 15px; }
.store .status { font-size: 12px; font-weight: 700; }
.store .status.open { color: var(--brand); }
.store .status.closed { color: var(--accent-text); }
.store-hours { font-size: 12px; color: var(--muted); }
.fav-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  border: none; background: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.fav-btn[aria-pressed="true"] { color: var(--accent); }
.fav-btn[aria-pressed="true"] svg { fill: currentColor; }

/* Profil */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.toggles { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); }
.toggles li + li { border-top: 1px solid var(--line); }
.toggles label { display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding: 0 16px; font-size: 15px; cursor: pointer; }
.toggles input {
  appearance: none; width: 46px; height: 28px; border-radius: 14px;
  background: #C9CEC6; position: relative; cursor: pointer; transition: background 0.2s;
}
.toggles input::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform 0.2s;
}
.toggles input:checked { background: var(--brand); }
.toggles input:checked::after { transform: translateX(18px); }
