:root{
  --bg:#f5f6fa;
  --card:#fff;
  --text:#1d2433;
  --muted:#7d8697;
  --line:#e6e9ef;
  --accent:#ff7a1a;
  --accent-soft:#fff0e5;
  --green:#1fa66a;
  --header-h:58px;
  --footer-h:50px;
  --summary-h:40px;
  --radius:10px;
}

*{box-sizing:border-box}
html,body{margin:0;min-height:100%;background:var(--bg);color:var(--text);font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif}
body{padding-bottom:calc(var(--footer-h) + env(safe-area-inset-bottom)); overflow: hidden}
button,input{font:inherit}
button{-webkit-tap-highlight-color:transparent}

/* ===== Structure générale ===== */
.app-header{
  position:fixed;
  left:0;
  right:0;
  top:0;
  z-index:30;
  height:calc(var(--header-h) + env(safe-area-inset-top));
  padding:env(safe-area-inset-top) 16px 0;
  background:#fff;
  border-bottom:1px solid var(--line);
}

.header-inner{
  width:min(100%,760px);
  height:var(--header-h);
  margin-inline:auto;
  display:flex;
  align-items:center;
}

.normal-header{
  width:100%;
  display:flex;
  align-items:center;
  gap:10px;
}

.header-logo{
  width:44px;
  height:44px;
  flex:0 0 44px;
  border-radius:12px;
  object-fit:cover;
}

.header-brand{min-width:0}
.header-brand h1{
  margin:0;
  font-size:1.3rem;
  line-height:1;
  font-weight:800;
}

.normal-header[hidden],
.add-header[hidden]{display:none!important}

.add-header{width:100%}

.app-main{
  width:min(100%,760px);
  margin-inline:auto;
  padding:calc(var(--header-h) + env(safe-area-inset-top) + 0px) 5px calc(env(safe-area-inset-bottom) + 10px);
    overflow-Y: auto;
    height: calc(100svh - 50px);
}

.view{display:none}
.view.active{display:block}

/* ===== Barre résumé Accueil : toujours fixe ===== */
.summary{
  position:fixed;
  top:calc(var(--header-h) + env(safe-area-inset-top));
  left:50%;
  transform:translateX(-50%);
  z-index:25;
  width:min(100%,760px);
  height:var(--summary-h);
  display:grid;
  grid-template-columns:100px 1fr;
  align-items:center;
  padding:0 20px;
  background:#fff;
  border-bottom:1px solid var(--line);
  color:var(--muted);
  font-size:.9rem;
}
.summary strong{color:var(--text)}
.summary-right{display:flex;align-items:center;gap:8px}
.icon-button{width:34px;height:34px;border:0;border-radius:11px;color:#939baa;display:grid;place-items:center; margin-left: auto; background-color: transparent;}
.icon-button:disabled{opacity:.32}
.icon-button svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:2}

.shopping-list{display:block;margin-top:calc(var(--summary-h) + 10px)}
.shopping-active{display:grid;gap:2px}
.shopping-bought{display:grid;gap:0;margin:0;padding:0}
.shopping-item{
  display:grid;grid-template-columns:44px 1fr auto;align-items:center;
  min-height:55px;padding:5px 12px 5px 7px;
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:0 3px 12px rgba(29,36,51,.03);
  transition:opacity .22s ease,transform .38s cubic-bezier(.2,.8,.2,1),box-shadow .22s ease
}
.shopping-item.moving{position:relative;z-index:3;box-shadow:0 10px 26px rgba(29,36,51,.12)}
.check-button{width:28px;height:28px;border:2px solid #d7dce5;border-radius:12px;background:#fff;color:#fff;display:grid;place-items:center;font-weight:900;padding:0}
.shopping-item.bought{opacity:.56}
.shopping-item.bought .check-button{background:var(--green);border-color:var(--green)}
.shopping-item.bought .item-name{text-decoration:line-through}
.item-name{font-weight:760}
.item-amount{font-weight:850;color:#555e6f;white-space:nowrap}

/* Les achetés : volontairement très compacts, sans espace entre les lignes. */
.shopping-bought .shopping-item{
  min-height:38px;
  padding:2px 8px 2px 4px;
  grid-template-columns:34px 1fr auto;
  border:0;
  border-bottom:1px solid var(--line);
  border-radius:0;
  box-shadow:none;
  background:transparent;
}
.shopping-bought .check-button{width:26px;height:26px;border-radius:9px;font-size:.75rem}
.shopping-bought .item-name{font-size:.84rem;font-weight:680}
.shopping-bought .item-amount{font-size:.78rem;font-weight:740}

.empty-state{padding:58px 24px;text-align:center;color:var(--muted)}
.empty-state .emoji{font-size:3rem}
.empty-state strong{display:block;margin:8px 0 3px;color:var(--text)}

/* Ajouter : l'input devient le contenu du header. */
.search-box{
  width:100%;
  height:46px;
  display:grid;
  grid-template-columns:26px 1fr 34px;
  align-items:center;
  gap:8px;
  padding:0 8px 0 14px;
  background:#f7f8fa;
  border:1px solid var(--line);
  border-radius:14px;
}
.search-box>svg{width:21px;height:21px;fill:none;stroke:#8991a1;stroke-width:2}
.search-box input{width:100%;height:44px;border:0;outline:0;background:transparent;color:var(--text);font-size:1rem}
.clear-search{border:0;background:transparent;color:#a2a9b5;font-size:1.35rem;padding:0}

.suggestions{display:grid;gap:0;margin:0;padding:0}
.suggestion{
  min-height:50px;
  display:grid;
  grid-template-columns:40px minmax(0,1fr) auto 40px;
  align-items:center;
  gap:2px;
  padding:0 4px;
  border-bottom:1px solid var(--line);
  background:transparent;
}
.suggestion.selected{background:var(--accent-soft)}
.suggestion-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:720}
.suggestion.selected .suggestion-name{color:#c85b0b}
.suggestion-plus,.suggestion-remove{
  width:36px;height:36px;border:0;border-radius:12px;background:transparent;
  display:grid;place-items:center;font-size:1.35rem;line-height:1;color:var(--accent);padding:0
}
.suggestion-remove{color:#8f97a5}
.suggestion-count{min-width:34px;text-align:center;font-weight:850;color:#c85b0b;white-space:nowrap}
.suggestion-spacer{width:36px;height:36px}
.suggestion-plus.is-pending{
  background:var(--line);
}

/* Cartes */
.letters{display:grid;gap:19px}
.letter-section h2{margin:0 0 8px 4px;color:#60697a;font-size:.88rem;letter-spacing:.09em}
.card-list{display:grid;gap:8px}
.loyalty-card{width:100%;min-height:65px;display:grid;grid-template-columns:46px 1fr auto;align-items:center;gap:12px;padding:9px 12px;border:1px solid var(--line);border-radius:17px;background:#fff;box-shadow:0 3px 12px rgba(29,36,51,.03);text-align:left;color:var(--text)}
.card-logo{width:44px;height:44px;display:grid;place-items:center;border-radius:14px;background:#f0f2f6;font-weight:900;font-size:1.15rem}
.card-list-name{display:block;font-weight:800}
.card-list-type{display:block;margin-top:2px;color:var(--muted);font-size:.77rem}
.chevron{color:#a4abb8;font-size:1.4rem}

/* ===== Footer compact ===== */
.app-footer{
  position:fixed;
  left:0;
  right:0;
  bottom:0;
  z-index:30;
  height:calc(var(--footer-h) + env(safe-area-inset-bottom));
  padding:0 12px env(safe-area-inset-bottom);
  background:rgba(255,255,255,.97);
  backdrop-filter:blur(16px);
  border-top:1px solid var(--line);
}
.footer-inner{
  width:min(100%,760px);
  height:var(--footer-h);
  margin-inline:auto;
  display:grid;
  grid-template-columns:repeat(3,1fr);
  align-items:center;
}
.nav-button{
  height:100%;
  border:0;
  background:transparent;
  color:#8b93a3;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:1px;
  font-size:.65rem;
  font-weight:760;
}
.nav-button>svg{width:21px;height:21px;fill:none;stroke:currentColor;stroke-width:2}
.nav-button.active{color:var(--accent)}
.plus-circle{width:40px;height:27px;display:grid;place-items:center}
.plus-circle svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:2.4}

.card-screen{position:fixed;inset:0;z-index:100;display:none;flex-direction:column;padding:calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));background:#fff}
.card-screen.open{display:flex}
.card-screen-top{display:flex;justify-content:space-between;align-items:flex-start;gap:14px}
.card-screen-top small{color:var(--muted);font-size:.7rem;font-weight:800;letter-spacing:.07em}
.card-screen-top h2{margin:2px 0 0}
.close-card{width:42px;height:42px;border:0;border-radius:14px;background:#f1f3f6;color:#666f7f;font-size:1.35rem}
.card-code-zone{flex:1;display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center}
.card-number{margin-bottom:28px;color:var(--muted);font-size:.88rem;word-break:break-all}
.fake-barcode{width:min(92vw,520px);height:170px;border-radius:8px;background:repeating-linear-gradient(90deg,#050505 0 3px,transparent 3px 6px,#050505 6px 8px,transparent 8px 12px,#050505 12px 17px,transparent 17px 20px)}
.fake-qr{width:225px;height:225px;border:17px solid #fff;box-shadow:0 0 0 1px #ddd;background:linear-gradient(90deg,#000 12%,transparent 12% 24%,#000 24% 36%,transparent 36% 48%,#000 48% 62%,transparent 62% 72%,#000 72% 84%,transparent 84%),linear-gradient(#000 12%,transparent 12% 24%,#000 24% 36%,transparent 36% 48%,#000 48% 62%,transparent 62% 72%,#000 72% 84%,transparent 84%);background-size:45px 45px}
.card-code-zone p{margin-top:20px;color:var(--muted);font-size:.82rem}



/* Le + tourne pendant l'enregistrement.
   On l'arrête seulement après le retour de la BDD,
   avec au minimum un tour complet. */
.suggestion-plus{
  display:inline-grid;
  place-items:center;
  transform-origin:center;
}

.suggestion-plus.is-spinning{
  animation:plusLoadingSpin .55s linear infinite;
}

@keyframes plusLoadingSpin{
  from{transform:rotate(0deg)}
  to{transform:rotate(360deg)}
}


/* Nouvel article reçu d'un autre appareil */
.shopping-item.remote-added{
  animation:remoteItemArrival 1.6s ease-out;
}

@keyframes remoteItemArrival{
  0%{
    transform:translateX(10px) scale(.985);
    background:var(--accent-soft);
    border-color:rgba(255,122,26,.55);
    box-shadow:0 0 0 3px rgba(255,122,26,.13);
  }
  28%{
    transform:translateX(0) scale(1);
    background:var(--accent-soft);
    border-color:rgba(255,122,26,.42);
    box-shadow:0 5px 18px rgba(255,122,26,.16);
  }
  100%{
    transform:translateX(0) scale(1);
    background:var(--card);
    border-color:var(--line);
    box-shadow:0 3px 12px rgba(29,36,51,.03);
  }
}


/* Quantité produit — long clic dans Ajouter */
body.quantity-sheet-open{overflow:hidden}
.quantity-sheet-backdrop{
  position:fixed;inset:0;z-index:70;background:rgba(20,25,36,.34);
  opacity:0;transition:opacity .2s ease
}
.quantity-sheet-backdrop.open{opacity:1}
.quantity-sheet{
  position:fixed;left:0;right:0;bottom:0;z-index:71;
  max-height:min(78vh,620px);overflow:auto;
  padding:0 14px calc(14px + env(safe-area-inset-bottom));
  background:#fff;border-radius:24px 24px 0 0;
  box-shadow:0 -12px 40px rgba(29,36,51,.18);
  transform:translateY(102%);transition:transform .22s cubic-bezier(.2,.8,.2,1)
}
.quantity-sheet.open{transform:translateY(0)}
.quantity-sheet-grab{height:30px;display:grid;place-items:center;touch-action:none;cursor:grab}
.quantity-sheet-grab span{width:42px;height:5px;border-radius:999px;background:#d8dce4}
.quantity-sheet-content{max-width:560px;margin:0 auto}
.quantity-sheet-content>small{display:block;color:var(--muted);font-size:.7rem;font-weight:800;letter-spacing:.1em}
.quantity-sheet-content h2{margin:3px 0 16px;font-size:1.2rem}
.quantity-mode-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.quantity-mode-grid button,.quantity-presets button{
  min-height:42px;border:1px solid var(--line);border-radius:13px;background:#f8f9fb;
  color:var(--text);font-weight:780
}
.quantity-mode-grid button.selected,.quantity-presets button.selected{
  border-color:var(--accent);background:var(--accent-soft);color:#c85b0b
}
.quantity-options{margin-top:14px}
.quantity-presets{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:7px}
#quantity-pack-options .quantity-presets{grid-template-columns:repeat(4,minmax(0,1fr))}
.quantity-custom{
  margin-top:10px;min-height:48px;display:grid;grid-template-columns:1fr 90px auto;
  align-items:center;gap:8px;padding:0 12px;border:1px solid var(--line);border-radius:13px
}
.quantity-custom span{font-weight:730}
.quantity-custom input{width:100%;height:38px;border:0;outline:0;text-align:right;font-size:1rem;background:transparent}
.quantity-custom b{color:var(--muted);font-size:.85rem}
.quantity-save{
  width:100%;height:48px;margin-top:16px;border:0;border-radius:14px;
  background:var(--accent);color:#fff;font-weight:850;font-size:.96rem
}
@media(max-width:390px){
  .quantity-presets{grid-template-columns:repeat(3,minmax(0,1fr))}
}
.quantity-actions{
  display:grid;
  grid-template-columns:auto 1fr;
  gap:9px;
  margin-top:16px;
}

.quantity-save{
  width:100%;
  height:48px;
  margin:0;
}

.quantity-delete{
  height:48px;
  padding:0 16px;

  border:1px solid #f3c5c5;
  border-radius:14px;

  background:#fff5f5;
  color:#b42318;

  font-weight:800;
}
.quantity-delete[hidden]{
  display:none;
}

.quantity-actions:has(.quantity-delete[hidden]){
  grid-template-columns:1fr;
}
/* Cartes de fidélité — gestion */
.cards-view{position:relative;min-height:100%}
.cards-empty{margin:28px 10px;padding:26px 20px;border:1px dashed var(--line);border-radius:18px;text-align:center;color:var(--muted);display:grid;gap:5px}
.cards-empty strong{color:var(--text);font-size:.95rem}
.cards-empty span{font-size:.8rem;line-height:1.4}
.add-card-fab{position:fixed;right:20px;bottom:calc(var(--footer-h) + 18px + env(safe-area-inset-bottom));z-index:18;width:52px;height:52px;border:0;border-radius:50%;background:var(--accent);color:#fff;font-size:2rem;font-weight:300;line-height:1;box-shadow:0 8px 22px rgba(255,122,26,.28)}
.loyalty-card{touch-action:pan-y}

.card-edit-backdrop{position:fixed;inset:0;z-index:119;background:rgba(19,25,46,.28);opacity:0;transition:opacity .18s ease}
.card-edit-backdrop.open{opacity:1}
.card-edit-sheet{position:fixed;left:0;right:0;bottom:0;z-index:120;background:#fff;border-radius:24px 24px 0 0;box-shadow:0 -15px 45px rgba(17,24,39,.16);transform:translateY(105%);transition:transform .18s ease;padding-bottom:calc(18px + env(safe-area-inset-bottom))}
.card-edit-sheet.open{transform:translateY(0)}
.card-edit-grab{height:28px;display:grid;place-items:center}
.card-edit-grab span{width:42px;height:4px;border-radius:999px;background:#d7dae2}
.card-edit-content{padding:0 18px 6px;display:grid;gap:14px}
.card-edit-content>small{font-size:.68rem;font-weight:800;letter-spacing:.08em;color:var(--muted)}
.card-edit-content h2{margin:-8px 0 0;font-size:1.2rem}
.card-field{display:grid;gap:6px}
.card-field span{font-size:.75rem;font-weight:750;color:var(--muted)}
.card-field input{width:100%;height:46px;border:1px solid var(--line);border-radius:13px;background:#f8f9fc;padding:0 13px;font:inherit;color:var(--text);outline:none}
.card-field input:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(255,122,26,.1);background:#fff}
.card-type-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.card-type-grid button{height:42px;border:1px solid var(--line);border-radius:13px;background:#fff;color:var(--text);font-weight:750}
.card-type-grid button.active{border-color:var(--accent);background:var(--accent-soft);color:var(--accent)}
.card-edit-actions{display:grid;grid-template-columns:auto 1fr;gap:9px;margin-top:3px}
.card-edit-actions button{height:46px;border-radius:13px;font-weight:800}
.card-save{border:0;background:var(--accent);color:#fff}
.card-delete{border:1px solid #f3c5c5;background:#fff5f5;color:#b42318;padding:0 16px}
.card-delete[hidden]{display:none}
.card-edit-actions:has(.card-delete[hidden]){grid-template-columns:1fr}

#card-code{width:min(92vw,620px);display:flex;justify-content:center;align-items:center;overflow:hidden}
#card-code svg{display:block;max-width:100%;height:auto}
#card-code.qr-code-render svg{width:min(76vw,330px);height:auto}
#card-code.barcode-render svg{width:min(92vw,600px);max-height:180px}
.code-error{padding:18px;border:1px dashed var(--line);border-radius:14px;color:var(--muted)}
.card-number{max-width:92vw;overflow-wrap:anywhere}


/* Scanner de carte */
.card-value-row{
  display:grid;
  grid-template-columns:minmax(0,1fr) 46px;
  gap:8px;
  align-items:center;
}
.card-value-row input{
  min-width:0;
}
.card-scan{
  width:46px;
  height:46px;
  display:grid;
  place-items:center;
  border:1px solid var(--line);
  border-radius:13px;
  background:#fff;
  color:var(--accent);
  padding:0;
  transition:transform .15s ease, background .15s ease, border-color .15s ease;
}
.card-scan svg{
  width:22px;
  height:22px;
  fill:none;
  stroke:currentColor;
  stroke-width:1.8;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.card-scan:active{
  transform:scale(.94);
}
.card-scan.scanning svg{
  animation:cardScanPulse .75s ease-in-out infinite alternate;
}
.card-scan.scanned{
  background:var(--accent-soft);
  border-color:var(--accent);
}
.card-scan-status{
  min-height:16px;
  font-size:.7rem;
  font-weight:700;
  color:var(--muted);
}
@keyframes cardScanPulse{
  from{opacity:.35;transform:scale(.88)}
  to{opacity:1;transform:scale(1.06)}
}


/* Logos d'enseignes — Brandfetch */
.card-logo{
  overflow:hidden;
  flex:none;
}
.card-logo.has-brand-logo{
  background:#fff;
  border:1px solid var(--line);
  padding:5px;
}
.card-logo.has-brand-logo img{
  display:block;
  width:100%;
  height:100%;
  object-fit:contain;
  border-radius:8px;
}


/* Choix explicite de l'enseigne / logo */
.card-brand-box{
  display:grid;
  gap:8px;
  padding:10px 0 2px;
}
.card-brand-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.card-brand-head > span{
  font-size:.75rem;
  font-weight:800;
  color:var(--text);
}
.card-brand-head button{
  border:0;
  background:transparent;
  color:var(--accent);
  font-size:.75rem;
  font-weight:800;
  padding:3px 0;
}
.card-brand-status{
  min-height:17px;
  color:var(--muted);
  font-size:.7rem;
  font-weight:650;
}
.card-brand-selected{
  display:grid;
  grid-template-columns:42px minmax(0,1fr);
  gap:10px;
  align-items:center;
  padding:9px 10px;
  border:1px solid var(--line);
  border-radius:13px;
  background:#fff;
}
.card-brand-selected strong,
.brand-result strong{
  display:block;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:.82rem;
}
.card-brand-selected small,
.brand-result small{
  display:block;
  margin-top:2px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  color:var(--muted);
  font-size:.67rem;
}
.brand-choice-logo,
.brand-result-logo{
  width:42px;
  height:42px;
  border:1px solid var(--line);
  border-radius:11px;
  background:#fff;
  display:grid;
  place-items:center;
  overflow:hidden;
  font-weight:900;
}
.brand-choice-logo img,
.brand-result-logo img{
  display:block;
  width:100%;
  height:100%;
  object-fit:contain;
  padding:5px;
  box-sizing:border-box;
}
.card-brand-results{
  display:grid;
  gap:6px;
  max-height:230px;
  overflow:auto;
}
.brand-result{
  width:100%;
  display:grid;
  grid-template-columns:42px minmax(0,1fr) 24px;
  gap:10px;
  align-items:center;
  text-align:left;
  padding:8px 9px;
  border:1px solid var(--line);
  border-radius:13px;
  background:#fff;
  color:var(--text);
}
.brand-result:active{
  transform:scale(.985);
}
.brand-result-check{
  display:grid;
  place-items:center;
  width:22px;
  height:22px;
  border-radius:50%;
  background:var(--accent-soft);
  color:var(--accent);
  font-size:.72rem;
  font-weight:900;
}
