:root {
  --frost: #E4EEF0;
  --enamel: #FAFDFD;
  --ink: #0F2B33;
  --ink-2: #4A656C;
  --line: #C5D8DC;
  --fresh: #17734A;
  --fresh-bg: #D6EFE2;
  --soon: #8A4B00;
  --soon-bg: #FFE6B8;
  --late: #A81C3A;
  --late-bg: #FAD3DB;
  --focus: #1D6FE0;
  font-family: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--frost);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; background: var(--frost); line-height: 1.4; }
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: 720px; margin: 0 auto; padding: 20px 16px calc(112px + env(safe-area-inset-bottom)); }

/* ---------- En-tête ---------- */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 2.1rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.top .actions { display: flex; gap: 6px; }
.summary { margin-top: 6px; color: var(--ink-2); font-size: 1.02rem; }
.summary strong { color: var(--ink); font-weight: 700; }

.search { margin: 18px 0 8px; }
.search input { width: 100%; }

/* ---------- Champs & boutons ---------- */
input[type="text"], input[type="search"], input[type="password"], input[type="url"],
input[type="number"], input[type="date"] {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px;
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
}
input:focus { border-color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border: 1.5px solid var(--ink); border-radius: 12px;
  background: var(--ink); color: var(--enamel); font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: transparent; color: var(--ink); }
.btn.danger { background: transparent; color: var(--late); border-color: var(--late); }
.btn.block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer; color: var(--ink);
}
.icon-btn:hover { background: rgba(15, 43, 51, .08); }
.ico { display: inline-grid; place-items: center; width: 22px; height: 22px; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(18px + env(safe-area-inset-bottom));
  min-height: 56px; padding: 0 22px 0 18px; border-radius: 18px; font-size: 1.05rem;
  box-shadow: 0 8px 22px rgba(15, 43, 51, .28);
}

/* ---------- Liste ---------- */
.group { margin-top: 22px; }
.group h2 { display: flex; align-items: baseline; gap: 8px; font-size: 1.15rem; font-weight: 700; margin-bottom: 10px; }
.group h2 small { color: var(--ink-2); font-size: .95rem; font-weight: 500; }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.item {
  display: grid; grid-template-columns: 68px 1fr; gap: 14px; padding: 12px;
  background: var(--enamel); border: 1px solid var(--line); border-radius: 14px;
}
.stamp {
  display: grid; align-content: center; justify-items: center; align-self: start;
  min-height: 68px; padding: 6px 4px; border-radius: 10px; border: 2px solid currentColor;
  font-variant-numeric: tabular-nums; text-align: center;
}
.stamp b { font-size: 1.9rem; font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.stamp span { margin-top: 3px; font-size: .78rem; font-weight: 600; line-height: 1.1; }
.state-ok .stamp { color: var(--fresh); background: var(--fresh-bg); }
.state-soon .stamp { color: var(--soon); background: var(--soon-bg); }
.state-expired .stamp { color: var(--late); background: var(--late-bg); }

.body { min-width: 0; }
.title-row { display: flex; align-items: center; gap: 10px; }
.thumb { flex: none; width: 40px; height: 40px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.name { font-weight: 700; font-size: 1.08rem; line-height: 1.2; overflow-wrap: anywhere; }
.sub { color: var(--ink-2); font-size: .95rem; margin-top: 2px; }
.state-expired .when { color: var(--late); font-weight: 600; }
.state-soon .when { color: var(--soon); font-weight: 600; }
.row-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }

.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; }
.stepper button { width: 44px; height: 40px; border: 0; background: transparent; border-radius: 999px; cursor: pointer; }
.stepper button:hover { background: rgba(15, 43, 51, .08); }
.stepper output { min-width: 30px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.empty { margin-top: 40px; padding: 28px 20px; text-align: center; color: var(--ink-2); border: 1.5px dashed var(--line); border-radius: 16px; }
.empty strong { display: block; color: var(--ink); font-size: 1.15rem; margin-bottom: 4px; }

/* ---------- Connexion ---------- */
.login { max-width: 400px; margin: 0 auto; padding: 14vh 20px 40px; }
.login h1 { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; }
.login .lede { margin: 8px 0 26px; color: var(--ink-2); }

/* ---------- Formulaires & feuilles ---------- */
.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: .95rem; }
.hint { color: var(--ink-2); font-size: .9rem; }
.error { color: var(--late); font-weight: 600; min-height: 1.2em; }
.inline { display: flex; gap: 8px; }
.inline > input { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 6px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; font-weight: 500; }
.chip:hover { border-color: var(--ink); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row .btn { flex: 1 1 auto; }

dialog.sheet { width: min(560px, 100%); max-width: 100%; max-height: 92dvh; padding: 0; border: 0; border-radius: 20px; background: var(--enamel); color: var(--ink); overflow: auto; }
dialog.sheet::backdrop { background: rgba(15, 43, 51, .5); }
.sheet-body { padding: 8px 18px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--enamel); padding: 10px 0 6px; z-index: 1; }
.sheet-head h2 { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; }
.sheet section + section { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.sheet section > h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.sheet section > p { color: var(--ink-2); margin-bottom: 12px; font-size: .95rem; }

.scan-box { display: grid; gap: 10px; }
#reader { width: 100%; border-radius: 12px; overflow: hidden; background: #000; min-height: 120px; }
.preview { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--frost); }
.preview img { width: 52px; height: 52px; object-fit: contain; background: #fff; border-radius: 8px; }
.preview .sub { margin: 0; }

.qty-line { display: flex; align-items: center; gap: 12px; }

.users { display: grid; gap: 8px; margin: 12px 0 16px; }
.user-row { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.user-row .who { font-weight: 700; }
.user-row .sub { margin: 0; }
.user-row .btn-row .btn { min-height: 38px; padding: 4px 12px; font-size: .92rem; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 100;
  max-width: min(92vw, 460px); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--enamel); font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none; transform: translate(-50%, 8px);
}
.toast.error { background: var(--late); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: no-preference) {
  .toast { transition: opacity .18s ease, transform .18s ease; }
}

@media (max-width: 640px) {
  dialog.sheet { margin: auto 0 0; border-radius: 20px 20px 0 0; }
}

/* ---------- Foyer, scanner, administration ---------- */
.top .who { margin-top: 4px; color: var(--ink-2); font-size: .95rem; overflow-wrap: anywhere; }

select {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px;
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
}
select:focus { border-color: var(--ink); }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--ink); }

.scan-view {
  position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 55dvh;
  overflow: hidden; border-radius: 12px; background: #000;
}
.cam-video { display: block; width: 100%; height: 100%; object-fit: cover; }
.scan-guide {
  position: absolute; z-index: 1; left: 7%; right: 7%; top: 50%; height: 36%;
  transform: translateY(-50%); pointer-events: none;
  border: 2px solid rgba(255, 255, 255, .92); border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .32);
}
.scan-guide::after {
  content: ""; position: absolute; left: 5%; right: 5%; top: 50%; height: 2px; background: #FF4D6A;
}

.hh-list { display: grid; gap: 12px; }
.hh-card { padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fff; display: grid; gap: 10px; }
.hh-head h4 { margin: 0; font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.hh-head .sub { margin-top: 2px; }
.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.member { display: grid; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.who-line { display: flex; align-items: center; gap: 8px; }
.tag { padding: 1px 8px; border-radius: 999px; background: var(--frost); color: var(--ink-2); font-size: .8rem; font-weight: 600; }
.member .btn-row { gap: 8px; }
.member .btn { min-height: 38px; padding: 4px 12px; font-size: .92rem; }
.member select { width: auto; flex: 1 1 170px; min-height: 38px; padding: 4px 10px; font-size: .92rem; }
.hh-card > .btn-row .btn { min-height: 38px; padding: 4px 14px; font-size: .92rem; }

/* ---------- Dernière livraison ---------- */
.delivery {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 16px; padding: 12px 14px;
  background: var(--enamel); border: 1px solid var(--line); border-radius: 14px;
}
.delivery-main { min-width: 0; }
.delivery h2 { font-size: 1rem; font-weight: 700; }
.delivery-date { margin-top: 2px; font-weight: 600; overflow-wrap: anywhere; }
.delivery-date .sub { font-weight: 400; }
.delivery .sub { margin-top: 1px; }
.delivery .btn { flex: none; min-height: 40px; padding: 6px 16px; }
