:root {
  --paper: #F5F8F6;
  --card: #FFFFFF;
  --ink: #10231F;
  --muted: #5A6B66;
  --line: #DCE5E1;
  --brand: #0F2E2A;
  --halal: #15803D;
  --halal-bg: #E4F4EA;
  --douteux: #B45F00;
  --douteux-bg: #FFF1D6;
  --haram: #B42318;
  --haram-bg: #FDE7E4;
  --inconnu: #475569;
  --inconnu-bg: #E8ECF0;
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0C1513; --card: #15211E; --ink: #EAF2EF; --muted: #9DB0AA; --line: #263632;
    --brand: #0F2E2A;
    --halal: #4ADE80; --halal-bg: #123222;
    --douteux: #FBBF24; --douteux-bg: #3A2A09;
    --haram: #FF8A7E; --haram-bg: #3F1612;
    --inconnu: #B6C2CC; --inconnu-bg: #222E37;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 17px/1.5 var(--font);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #2F80ED; outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#app { max-width: 640px; margin: 0 auto; padding: 0 16px 48px; }
.view { padding-top: 20px; }

/* En-tête */
.top { position: relative; }
/* motif décoratif : étoile à huit branches (deux carrés superposés), très discret */
.top::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 108px; height: 108px; z-index: -1;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' fill='none' stroke='%230F2E2A' stroke-width='1.6'%3E%3Crect x='20' y='20' width='60' height='60'/%3E%3Crect x='20' y='20' width='60' height='60' transform='rotate(45 50 50)'/%3E%3Ccircle cx='50' cy='50' r='13'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: .13; pointer-events: none;
}
@media (prefers-color-scheme: dark) { .top::after { filter: invert(1); opacity: .16; } }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { flex: none; width: 52px; height: 52px; border-radius: 14px; box-shadow: 0 6px 14px -8px rgba(15, 46, 42, .8); }
.top h1 { margin: 0; font-size: 2rem; line-height: 1.1; font-weight: 800; letter-spacing: -0.02em; }
.lead { margin: 12px 0 22px; color: var(--muted); }

/* Bouton scanner : l'élément principal */
.scan {
  display: flex; align-items: center; gap: 18px; width: 100%;
  background: var(--brand); color: #fff; border: 0; border-radius: 24px;
  padding: 22px 22px; text-align: left; min-height: 104px;
  box-shadow: 0 10px 24px -12px rgba(15, 46, 42, .7);
  transition: transform .12s ease;
}
.scan:active { transform: scale(.985); }
.scan-label { font-size: 1.4rem; font-weight: 800; line-height: 1.15; }
.viewfinder { position: relative; flex: none; width: 64px; height: 64px; }
.viewfinder i { position: absolute; width: 20px; height: 20px; border: 4px solid #fff; }
.viewfinder i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.viewfinder i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.viewfinder i:nth-child(3) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }
.viewfinder i:nth-child(4) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.viewfinder b { position: absolute; left: 8px; right: 8px; top: 50%; height: 3px; margin-top: -1.5px; background: #3DDC84; border-radius: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .viewfinder b { animation: sweep 2.4s ease-in-out infinite alternate; }
  @keyframes sweep { from { top: 22%; } to { top: 78%; } }
}

/* Recherche */
.search { margin-top: 14px; }
.search input {
  width: 100%; height: 54px; padding: 0 18px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--card);
}
.search input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 4px rgba(47,128,237,.25); }

/* Filtres */
.chips { display: flex; gap: 8px; margin: 14px 0 6px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex: none; height: 44px; padding: 0 18px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--card); font-weight: 700;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip[data-f="halal"].on { background: var(--halal); border-color: var(--halal); color: #fff; }
.chip[data-f="douteux"].on { background: var(--douteux); border-color: var(--douteux); color: #fff; }
.chip[data-f="haram"].on { background: var(--haram); border-color: var(--haram); color: #fff; }
@media (prefers-color-scheme: dark) {
  .chip[data-f="halal"].on, .chip[data-f="douteux"].on, .chip[data-f="haram"].on { color: #10231F; }
}
.count { margin: 10px 2px 8px; color: var(--muted); font-size: .95rem; }

/* Liste */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; text-align: left; min-height: 64px;
}
.row .code { flex: none; min-width: 58px; font-weight: 800; font-size: 1rem; }
.row .name { flex: 1; min-width: 0; line-height: 1.25; }
.row .name small { display: block; color: var(--muted); font-size: .85rem; }
.pill {
  flex: none; padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: .88rem;
}
.pill.halal { background: var(--halal-bg); color: var(--halal); }
.pill.douteux { background: var(--douteux-bg); color: var(--douteux); }
.pill.haram { background: var(--haram-bg); color: var(--haram); }
.pill.inconnu { background: var(--inconnu-bg); color: var(--inconnu); }
.info {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--line); font-weight: 800; font-size: .9rem; color: var(--muted);
}
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.foot { margin-top: 28px; color: var(--muted); font-size: .9rem; }

/* Résultat produit */
.back { background: none; border: 0; padding: 10px 0; font-weight: 700; color: var(--muted); min-height: 44px; }
.product { display: flex; gap: 14px; align-items: center; margin: 4px 0 16px; }
.product img { width: 72px; height: 72px; object-fit: contain; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.product h2 { margin: 0; font-size: 1.25rem; line-height: 1.2; }
.product p { margin: 2px 0 0; color: var(--muted); }
.verdict { border-radius: var(--radius); padding: 22px 20px; margin-bottom: 16px; }
.verdict.halal { background: var(--halal-bg); color: var(--halal); }
.verdict.douteux { background: var(--douteux-bg); color: var(--douteux); }
.verdict.haram { background: var(--haram-bg); color: var(--haram); }
.verdict.inconnu { background: var(--inconnu-bg); color: var(--inconnu); }
.verdict .big { font-size: 2.6rem; line-height: 1; font-weight: 900; letter-spacing: -0.03em; }
.verdict p { margin: 8px 0 0; color: var(--ink); }
.note {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin: 0 0 12px; font-size: .95rem;
}
.sec { margin: 22px 2px 8px; font-size: 1.05rem; font-weight: 800; }
.raw { color: var(--muted); font-size: .92rem; margin-top: 18px; }
.raw summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }

/* Fiche détail */
.sheet {
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 640px;
  max-height: 92dvh; background: var(--paper); color: var(--ink);
  border-radius: 24px 24px 0 0; overflow: auto; left: 50%; transform: translateX(-50%);
  position: fixed; bottom: 0; top: auto;
}
.sheet::backdrop { background: rgba(8, 20, 17, .55); }
@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: rise .22s ease-out; }
  @keyframes rise { from { transform: translate(-50%, 24px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
}
.sheet-head { padding: 22px 20px 18px; }
.sheet-head.halal { background: var(--halal-bg); }
.sheet-head.douteux { background: var(--douteux-bg); }
.sheet-head.haram { background: var(--haram-bg); }
.sheet-head.inconnu { background: var(--inconnu-bg); }
.sheet-head .kicker { font-weight: 800; font-size: 1.1rem; }
.sheet-head.halal .kicker { color: var(--halal); }
.sheet-head.douteux .kicker { color: var(--douteux); }
.sheet-head.haram .kicker { color: var(--haram); }
.sheet-head h2 { margin: 2px 0 6px; font-size: 1.5rem; line-height: 1.2; }
.sheet-head p { margin: 0; }
.sheet-body { padding: 8px 20px 28px; }
.sheet-body h3 { margin: 20px 0 6px; font-size: 1.05rem; }
.sheet-body ul { margin: 0; padding-left: 20px; }
.sheet-body li { margin: 6px 0; }
.sheet-body .none { color: var(--muted); }
.warn { background: var(--douteux-bg); color: var(--ink); border-radius: 12px; padding: 10px 14px; margin: 16px 0 0; font-size: .95rem; }
.sources a { color: inherit; text-underline-offset: 3px; word-break: break-word; }
.close {
  display: block; width: calc(100% - 40px); margin: 0 20px 22px; height: 52px; border-radius: 14px;
  border: 0; background: var(--brand); color: #fff; font-weight: 800;
}
.disc { color: var(--muted); font-size: .88rem; margin-top: 18px; }

/* Scanner plein écran */
.scanner {
  position: fixed; inset: 0; z-index: 20; background: #050B0A; color: #fff;
  display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.scanner-bar { display: flex; justify-content: flex-end; padding: 12px 16px; }
.light { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 12px; padding: 0 18px; height: 44px; font-weight: 700; }
.scanner-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; }
.scanner-stage video, .scanner-stage #reader { width: 100%; height: 100%; object-fit: cover; }
.scanner-stage #reader video { object-fit: cover; }
.frame {
  position: absolute; left: 50%; top: 50%; width: min(78vw, 360px); height: 170px;
  transform: translate(-50%, -50%); border: 3px solid #3DDC84; border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); pointer-events: none;
}
.scanner-msg { margin: 0; padding: 14px 20px 6px; text-align: center; }
.manual { padding: 6px 16px 18px; }
.manual label { display: block; font-size: .92rem; color: #B9C7C2; margin-bottom: 6px; }
.manual div { display: flex; gap: 8px; }
.manual input { flex: 1; min-width: 0; height: 50px; border-radius: 12px; border: 0; padding: 0 14px; background: #fff; color: #10231F; }
.manual button { height: 50px; padding: 0 18px; border: 0; border-radius: 12px; background: #3DDC84; color: #05281A; font-weight: 800; }

.loading { padding: 40px 8px; text-align: center; color: var(--muted); }
