/* ============================================================
   Liste de courses — feuille de style
   Mobile-first, sobre, grandes zones tactiles, mode clair/sombre.
   ============================================================ */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e4e7eb;
  --text: #1a1f26;
  --text-soft: #5b6470;
  --text-faint: #8a929c;
  --primary: #16a34a;
  --primary-strong: #15803d;
  --primary-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --accent: #2563eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 30px rgba(16, 24, 40, .16);
  --radius: 14px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1f2831;
    --border: #2a343f;
    --text: #eef2f6;
    --text-soft: #a8b2bd;
    --text-faint: #6c7783;
    --primary: #22c55e;
    --primary-strong: #16a34a;
    --primary-soft: #14321f;
    --danger: #f87171;
    --danger-soft: #3a1d1d;
    --accent: #60a5fa;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 34px rgba(0, 0, 0, .5);
  }
}

/* Forçage manuel du thème (bouton lune/soleil) */
:root[data-theme="light"] {
  --bg: #f6f7f9; --surface: #fff; --surface-2: #f1f3f5; --border: #e4e7eb;
  --text: #1a1f26; --text-soft: #5b6470; --text-faint: #8a929c;
  --primary: #16a34a; --primary-strong: #15803d; --primary-soft: #dcfce7;
  --danger: #dc2626; --danger-soft: #fee2e2; --accent: #2563eb;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --shadow-lg: 0 8px 30px rgba(16,24,40,.16);
}
:root[data-theme="dark"] {
  --bg: #0f141a; --surface: #171e26; --surface-2: #1f2831; --border: #2a343f;
  --text: #eef2f6; --text-soft: #a8b2bd; --text-faint: #6c7783;
  --primary: #22c55e; --primary-strong: #16a34a; --primary-soft: #14321f;
  --danger: #f87171; --danger-soft: #3a1d1d; --accent: #60a5fa;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 34px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font-family: inherit; font-size: 1rem; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 1rem; }
a { color: var(--accent); }

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

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 48px; padding: 0 1.1rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-weight: 600; transition: transform .06s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-strong); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.subtle { background: var(--surface-2); border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 0 .8rem; font-size: .92rem; }
.btn:disabled { opacity: .5; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 50%;
  border: none; background: transparent; color: var(--text); font-size: 1.3rem;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.92); }

/* ---------- Champs ---------- */
.field { width: 100%; min-height: 50px; padding: .7rem .9rem;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); }
.field:focus { border-color: var(--primary); outline: none; }
label.lbl { display: block; font-size: .85rem; font-weight: 600; color: var(--text-soft); margin: .8rem 0 .3rem; }

/* ---------- Mise en page ---------- */
.screen { max-width: 720px; margin: 0 auto; padding: 0 1rem calc(120px + var(--safe-bottom)); }
.stack > * + * { margin-top: .75rem; }
.muted { color: var(--text-soft); }
.faint { color: var(--text-faint); font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: .6rem; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ============================================================
   ACCUEIL
   ============================================================ */
.home-hero { padding: calc(2rem + var(--safe-top)) 0 1rem; text-align: center; }
.home-hero .logo { font-size: 3rem; }
.home-hero h1 { margin: .4rem 0 .2rem; font-size: 1.6rem; }
.home-hero p { margin: 0; color: var(--text-soft); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 .8rem; font-size: 1.1rem; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 700; margin: 1.6rem .3rem .6rem; }

/* Sélecteur d'icône (emoji) */
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: .4rem; }
.emoji-opt { font-size: 1.4rem; height: 48px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); line-height: 1; }
.emoji-opt.active { background: var(--primary-soft); border-color: var(--primary); }
.emoji-custom { width: 96px; text-align: center; }
.title-icon { flex: 0 0 auto; }

.join-row { display: flex; gap: .5rem; }
.join-row .field { flex: 1; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }

.recent-item {
  display: flex; align-items: center; gap: .9rem; width: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: .6rem;
  text-align: left; box-shadow: var(--shadow); color: var(--text);
}
.recent-item:active { transform: scale(.99); }
.recent-item.pinned { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b33, var(--shadow); }
.icon-btn.star { color: #f59e0b; }
.recent-item .r-emoji { font-size: 1.5rem; flex: 0 0 auto; }
.recent-item .r-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item .r-sub { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: .15rem; }
.recent-badge { display: inline-flex; align-items: center; gap: .35rem;
  background: var(--primary-soft); color: var(--primary-strong); font-weight: 700;
  padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; white-space: nowrap; }
.owner-tag { font-size: .72rem; background: var(--surface-2); color: var(--text-soft);
  padding: .1rem .45rem; border-radius: 6px; font-weight: 700; }

/* ============================================================
   BARRE D'APPLICATION (écran liste)
   ============================================================ */
.appbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: calc(.6rem + var(--safe-top)) .6rem .6rem;
}
.appbar-main { display: flex; align-items: center; gap: .3rem; }
.appbar-title { flex: 1; min-width: 0; }
.appbar-title h1 { margin: 0; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title .sub { font-size: .82rem; color: var(--text-soft); }
.appbar .count-pill { background: var(--primary-soft); color: var(--primary-strong); font-weight: 700; }

/* Barre d'outils : recherche + filtres */
.toolbar { display: flex; gap: .5rem; align-items: center; margin-top: .55rem; }
.search-wrap { position: relative; flex: 1; }
.search-wrap input { padding-left: 2.3rem; min-height: 44px; }
.search-wrap .s-icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search-wrap .s-clear { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding: .55rem .2rem .2rem; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: .35rem;
  min-height: 38px; padding: 0 .8rem; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: .9rem; white-space: nowrap;
}
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }

/* ============================================================
   LISTE DE PRODUITS
   ============================================================ */
.cat-group { margin-top: 1.1rem; }
.cat-head { display: flex; align-items: center; gap: .5rem; padding: 0 .3rem .4rem; }
.cat-head .c-icon { font-size: 1.15rem; }
.cat-head .c-name { font-weight: 700; }
.cat-head .c-count { color: var(--text-faint); font-size: .85rem; font-weight: 600; }
.cat-bar { width: 4px; align-self: stretch; border-radius: 4px; }

.item {
  display: flex; align-items: center; gap: .2rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: .5rem; box-shadow: var(--shadow);
  overflow: hidden;
}
.item .check {
  flex: 0 0 auto; width: 60px; align-self: stretch; min-height: 62px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text-faint);
}
.item .check .box {
  width: 28px; height: 28px; border-radius: 8px; border: 2.5px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: #fff;
  transition: background .12s, border-color .12s;
}
.item.bought .check .box { background: var(--primary); border-color: var(--primary); }
.item .body { flex: 1; min-width: 0; padding: .55rem .2rem; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { font-size: .82rem; color: var(--text-soft); display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .1rem; }
.item .qty-badge { background: var(--surface-2); border-radius: 6px; padding: 0 .4rem; font-weight: 600; color: var(--text); }
.item .note-badge { font-style: italic; }
.item .edit { flex: 0 0 auto; width: 52px; align-self: stretch; }
.item.bought .name { text-decoration: line-through; color: var(--text-faint); }
.item .star { color: #f59e0b; }

.bought-section-head {
  display: flex; align-items: center; gap: .5rem; margin: 1.4rem .3rem .5rem;
  color: var(--text-soft); font-weight: 700; font-size: .95rem;
}
.bought-section-head .line { flex: 1; height: 1px; background: var(--border); }

/* Vide / états */
.empty { text-align: center; padding: 3rem 1rem; color: var(--text-soft); }
.empty .e-emoji { font-size: 3rem; }
.empty h3 { margin: .6rem 0 .3rem; color: var(--text); }

/* ============================================================
   BARRE D'AJOUT + FAB
   ============================================================ */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: .6rem .7rem calc(.6rem + var(--safe-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}
.addbar form { display: flex; gap: .5rem; max-width: 720px; margin: 0 auto; align-items: center; }
.addbar input { flex: 1; min-height: 50px; }
.addbar .add-go { flex: 0 0 auto; width: 52px; height: 50px; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; border: none; font-size: 1.5rem; }
.addbar .add-more { flex: 0 0 auto; }
.add-opts-btn { flex: 0 0 auto; font-size: 1.15rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); width: 50px; height: 50px; background: var(--surface); }
.add-opts-btn.active { background: var(--primary-soft); border-color: var(--primary); }
.add-options { max-width: 720px; margin: 0 auto .5rem; display: flex; flex-direction: column; gap: .5rem; }
.add-options .qa-row { display: flex; gap: .5rem; }
.add-options .field { min-height: 46px; }
.add-options .qa-qty { width: 90px; flex: 0 0 auto; text-align: center; }
.suggestions { max-width: 720px; margin: 0 auto .5rem; display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; }
.suggestions::-webkit-scrollbar { display: none; }
.sugg {
  flex: 0 0 auto; min-height: 38px; padding: 0 .7rem; border-radius: 999px;
  border: 1.5px dashed var(--border); background: var(--surface); color: var(--text-soft);
  font-weight: 600; font-size: .88rem; white-space: nowrap;
}
.sugg .s-plus { color: var(--primary); font-weight: 800; }

/* ============================================================
   MODALES
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(4, 8, 14, .5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg);
  max-height: 92vh; overflow-y: auto; animation: slideup .2s ease;
  padding: 0 0 calc(1rem + var(--safe-bottom));
}
@media (min-width: 620px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } }
.sheet-head {
  position: sticky; top: 0; background: var(--surface); z-index: 2;
  display: flex; align-items: center; gap: .5rem; padding: 1rem 1rem .6rem;
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.sheet-body { padding: 1rem; }
.sheet .grabber { width: 40px; height: 4px; background: var(--border); border-radius: 3px; margin: .5rem auto -.2rem; }

/* Partage */
.share-code { text-align: center; font-size: 2rem; font-weight: 800; letter-spacing: .3em;
  background: var(--surface-2); border-radius: var(--radius); padding: 1rem; margin: .3rem 0;
  user-select: all; }
.qr-box { display: flex; justify-content: center; padding: 1rem; background: #fff; border-radius: var(--radius); }
.qr-box svg { width: 220px; height: 220px; }
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }

/* Historique */
.hist-item { display: flex; gap: .6rem; padding: .6rem .2rem; border-bottom: 1px solid var(--border); }
.hist-item .h-emoji { font-size: 1.1rem; }
.hist-item .h-time { color: var(--text-faint); font-size: .78rem; }

/* Catégories admin */
.cat-admin { display: flex; align-items: center; gap: .6rem; padding: .55rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: .5rem; background: var(--surface); }
.cat-admin .drag { cursor: grab; color: var(--text-faint); touch-action: none; }
.cat-admin.dragging { opacity: .5; }
.color-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); padding: 0; }

/* Bannière hors-ligne / connexion */
.conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  background: #b45309; color: #fff; text-align: center; font-weight: 600; font-size: .88rem;
  padding: calc(.4rem + var(--safe-top)) .5rem .4rem; transform: translateY(-120%); transition: transform .25s;
}
.conn-banner.show { transform: translateY(0); }
.conn-banner.reconnected { background: var(--primary-strong); }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(80px + var(--safe-bottom)); z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none; padding: 0 1rem; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--surface);
  border-radius: 12px; padding: .7rem .9rem; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: .8rem; max-width: 480px; width: 100%;
  animation: toastin .2s ease; font-size: .92rem;
}
@keyframes toastin { from { transform: translateY(20px); opacity: 0; } }
.toast .t-undo { background: transparent; border: none; color: var(--primary); font-weight: 800; padding: .2rem .4rem; }
.toast.error { background: var(--danger); color: #fff; }

/* Divers */
.badge-pill { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .6rem;
  border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--surface-2); color: var(--text-soft); }
.danger-zone { border: 1px solid var(--danger); border-radius: var(--radius); padding: 1rem; margin-top: 1rem; }
.danger-zone h3 { margin: 0 0 .3rem; color: var(--danger); font-size: 1rem; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.list-inline { display: flex; flex-direction: column; gap: .1rem; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 .35rem; font-size: .8rem; }
