:root {
    --bg: #f1f7f1;
    --surface: #ffffff;
    --ink: #17261c;
    --muted: #576a5c;
    --line: #d3e3d5;
    --accent: #1c7c3f;
    --accent-ink: #ffffff;
    --accent-soft: #dff0e3;
    --error: #b3261e;
    --error-soft: #fdeceb;
    --ok: #1d7a4d;
    --ok-soft: #e4f5ec;
    --radius: 14px;
    --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1a12;
        --surface: #16271c;
        --ink: #e6f2e8;
        --muted: #9db8a3;
        --line: #27402d;
        --accent: #6fd08e;
        --accent-ink: #0e1a12;
        --accent-soft: #1f3a27;
        --error: #ff8f87;
        --error-soft: #3a1c28;
        --ok: #62d49a;
        --ok-soft: #173a2b;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.55;
}

a { color: var(--accent); }

/* En-tête */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; max-width: 960px; margin: 0 auto; padding: 16px 20px; }
.brand { font-weight: 800; font-size: 1.4rem; color: var(--accent); text-decoration: none; letter-spacing: .02em; }
.nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.nav a:not(.btn) { color: var(--ink); text-decoration: none; font-weight: 600; }
.nav a:not(.btn):hover { color: var(--accent); }

.page { max-width: 640px; margin: 0 auto; padding: 8px 16px 48px; display: grid; gap: 16px; }
.page:has(.hero) { max-width: 960px; }

/* Boutons */
.btn {
    display: inline-block;
    font: inherit;
    font-weight: 700;
    padding: 12px 22px;
    border: 2px solid var(--accent);
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-ink);
    text-decoration: none;
    text-align: center;
    cursor: pointer;
}
.btn-small { padding: 7px 16px; font-size: .95rem; }
.btn-ghost { background: transparent; color: var(--accent); }
button.btn { width: 100%; }
.hero-actions .btn { width: auto; }

/* Messages */
.flash { margin: 0; padding: 12px 16px; border-radius: 10px; }
ul.flash { padding-left: 32px; }
.flash-error { background: var(--error-soft); color: var(--error); }
.flash-success { background: var(--ok-soft); color: var(--ok); }

/* Cartes et formulaires */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card h1 { margin: 0 0 14px; font-size: 1.5rem; line-height: 1.25; }
.card h2 { margin: 0 0 10px; font-size: 1.1rem; }

.form { display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 600; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select {
    width: 100%;
    font: inherit;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
    color: var(--ink);
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.check-line { display: flex !important; align-items: center; gap: 10px; font-weight: 400 !important; }
.check-line input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.hint { color: var(--muted); font-weight: 400; font-size: .85rem; }
.muted { color: var(--muted); font-size: .9rem; }
.fine { color: var(--muted); font-size: .85rem; margin: 0; }

/* Champ mot de passe avec bouton œil */
.password-field { position: relative; display: block; }
.password-field input { padding-right: 2.9rem; }
.pw-toggle {
    position: absolute; top: 50%; right: .35rem; transform: translateY(-50%);
    display: grid; place-items: center; width: 2.25rem; height: 2.25rem; padding: 0;
    border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--ink); }
.pw-toggle .eye-off { display: none; }
.pw-toggle[aria-pressed="true"] .eye-on { display: none; }
.pw-toggle[aria-pressed="true"] .eye-off { display: block; }

/* Connexion et inscription */
.auth { max-width: 24rem; width: 100%; margin: 1.5rem auto 0; display: grid; gap: 1rem; }
.auth h1 { margin: 0; text-align: center; font-size: 1.6rem; }
.auth-lead, .auth-switch { margin: 0; text-align: center; color: var(--muted); }
.auth-switch { font-size: .95rem; }

/* Accueil public */
.hero { padding: 24px 0 8px; }
.hero-text h1 { margin: 0 0 14px; font-size: clamp(1.9rem, 5vw, 2.8rem); line-height: 1.15; text-wrap: balance; }
.hero-lead { margin: 0 0 22px; font-size: 1.15rem; color: var(--muted); max-width: 34rem; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin: 0; }

/* Bandeau d'installation */
.install { background: var(--accent); color: var(--accent-ink); }
.install-row { display: flex; align-items: center; gap: 12px; max-width: 960px; margin: 0 auto; padding: 10px 16px; }
.install-text { flex: 1; font-weight: 700; }
.install .btn { width: auto; background: var(--accent-ink); color: var(--accent); border-color: var(--accent-ink); }
.install-close { width: 2.25rem; height: 2.25rem; padding: 0; border: 0; border-radius: 8px; background: transparent; color: inherit; font-size: 1.6rem; line-height: 1; cursor: pointer; }
.install-hint { margin: 0; padding: 0 16px 12px; max-width: 960px; margin-inline: auto; font-size: .95rem; }

/* Accueil : explications */
.explain { display: grid; gap: 16px; margin-top: 24px; }
.explain h2 { margin: 0; font-size: 1.5rem; }
.explain h3 { margin: 0 0 6px; font-size: 1.05rem; }
.explain p { margin: 0; color: var(--muted); }
.explain-steps, .explain-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.explain-steps { counter-reset: step; }
.explain-steps li, .explain-points li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.explain-steps li { counter-increment: step; position: relative; padding-left: 64px; }
.explain-steps li::before {
    content: counter(step);
    position: absolute; left: 16px; top: 16px;
    display: grid; place-items: center; width: 34px; height: 34px;
    border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800;
}
@media (min-width: 640px) {
    .explain-points { grid-template-columns: 1fr 1fr; }
}

/* Scanner et fiche produit */
.scan-zone { display: grid; gap: 10px; margin-bottom: 16px; justify-items: start; }
.scan-video { width: 100%; max-height: 320px; border-radius: 12px; background: #000; object-fit: cover; }
.scan-form { margin-top: 16px; }
.fiche-tete { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.fiche-img { width: 110px; height: 110px; object-fit: contain; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.fiche-tete > div { min-width: 0; flex: 1 1 200px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-size: .85rem; font-weight: 700; }
.ns { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .85rem; font-weight: 800; color: #fff; }
.ns-a { background: #1e8e3e; }
.ns-b { background: #6aa51f; }
.ns-c { background: #b08a00; }
.ns-d { background: #d9731a; }
.ns-e { background: #c8372d; }
.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 16px 0 4px; }
.chiffres div { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.chiffres dt { color: var(--muted); font-size: .85rem; }
.chiffres dd { margin: 2px 0 0; font-weight: 800; font-size: 1.15rem; }
.alts { display: grid; gap: 12px; }
.alt { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; color: inherit; text-decoration: none; background: var(--bg); }
.alt:hover { border-color: var(--accent); }
.alt-img { width: 72px; height: 72px; flex: none; object-fit: contain; border-radius: 8px; background: #fff; }
.alt-vide { background: var(--accent-soft); }
.alt-corps { display: grid; gap: 4px; min-width: 0; }
.compare { margin: 4px 0 0; padding-left: 18px; font-size: .9rem; }
.cmp-gain { color: var(--ok); }
.cmp-perte { color: var(--error); }
.cmp-info { color: var(--muted); }
details summary { cursor: pointer; font-weight: 700; }

/* Liste : boutons du bas */
.liste-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Mode magasin */
.magasin-message { position: sticky; top: 8px; z-index: 5; margin-bottom: 12px; font-weight: 700; }
.card .magasin-titre { margin-top: 22px; }
.courses { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.course { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.course-case { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; cursor: pointer; }
.course-case input { width: 1.6rem; height: 1.6rem; flex: none; accent-color: var(--accent); }
.course-texte { display: grid; min-width: 0; }
.course-qte { flex: none; font-weight: 800; color: var(--muted); }
.course-ok { background: var(--ok-soft); border-color: var(--ok); }
.course-ok .course-texte strong { text-decoration: line-through; }
.course .course-retirer { width: auto; flex: none; }
.course:not(.course-ok) .course-retirer { display: none; }
.magasin-actions { display: grid; gap: 10px; }

/* Mode magasin : fenêtre après un scan */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .55); }
.modal-boite { width: 100%; max-width: 420px; display: grid; gap: 12px; justify-items: center; text-align: center; padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.modal-img { width: 150px; height: 150px; object-fit: contain; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.modal-titre { font-size: 1.2rem; }
.modal-actions { width: 100%; display: grid; gap: 8px; margin-top: 4px; }