:root {
    --bg: #0b0f14;
    --card: #141b24;
    --card-2: #1b2430;
    --line: #263140;
    --text: #e8edf3;
    --muted: #8b99aa;
    --accent: #fbbf24;
    --primary: #3b82f6;
    --danger: #ef4444;
    --ok: #22c55e;
    --radius: 14px;
    color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
    font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar form { margin: 0; }
.logo { color: var(--text); font-weight: 800; font-size: 20px; letter-spacing: .5px; text-decoration: none; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 15px; padding: 8px 0 8px 12px; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

h1, h2, h3 { margin: 0; }
h2 { font-size: 22px; }
h3.section { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stack > * + * { margin-top: 12px; }

/* Boutons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 52px; padding: 0 18px;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--card-2); color: var(--text);
    font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { filter: brightness(1.2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--danger); border-color: #4a2227; background: transparent; }
.btn.big { width: 100%; min-height: 64px; font-size: 19px; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 15px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Champs */
input, select, textarea {
    width: 100%; min-height: 52px; padding: 0 14px;
    background: var(--card-2); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius);
    font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; }
label { display: block; font-size: 14px; color: var(--muted); }
label > input, label > select { margin-top: 6px; color: var(--text); font-size: 17px; }
.field + .field { margin-top: 14px; }
.search { display: grid; gap: 10px; margin-top: 14px; }

/* Liste de résultats */
.list { display: grid; gap: 8px; }
.item {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    width: 100%; padding: 12px 14px; text-align: left;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    color: var(--text); font: inherit; cursor: pointer;
}
.item:active { background: var(--card-2); }
.item .meta { min-width: 0; display: grid; }
.item .meta b { font-weight: 700; }
.item .meta small { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addr {
    flex: none; padding: 6px 10px; border-radius: 10px;
    background: #2a2208; color: var(--accent);
    font: 700 17px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: .5px;
}
.empty { color: var(--muted); text-align: center; padding: 28px 0; }

/* Fiche produit */
.back { background: none; border: 0; color: var(--muted); font: inherit; padding: 4px 0 12px; }
.detail { text-align: center; }
.addr-big {
    margin: 4px auto 18px; padding: 18px 12px; border-radius: var(--radius);
    background: #2a2208; color: var(--accent);
    font: 800 clamp(34px, 11vw, 56px)/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: 1px; word-break: break-word;
}
.detail .brand { margin: 2px 0 0; color: var(--muted); }
.detail .desc { margin: 10px 0 0; }
.codes { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 14px 0 0; padding: 0; list-style: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    background: var(--card-2); border: 1px solid var(--line);
    font: 14px ui-monospace, Consolas, monospace; color: var(--muted);
}
.chip button { background: none; border: 0; color: var(--danger); font-size: 18px; line-height: 1; padding: 6px; margin: -6px -8px -6px 0; }
.actions { margin-top: 18px; }
.inline-edit { margin-top: 14px; text-align: left; }

.banner {
    margin-top: 14px; padding: 12px 14px; border-radius: var(--radius);
    background: #10233f; border: 1px solid var(--primary); display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.banner button { flex: none; }
.notice { color: var(--muted); font-size: 15px; }
.code-big { font: 700 22px ui-monospace, Consolas, monospace; word-break: break-all; color: var(--accent); }

.fab {
    position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
    width: 60px; height: 60px; border-radius: 50%; border: 0;
    background: var(--primary); color: #fff; font-size: 34px; line-height: 1;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}

/* Scanner */
.scan { position: fixed; inset: 0; z-index: 20; background: #000; display: grid; grid-template-rows: 1fr auto; }
.scan video { width: 100%; height: 100%; object-fit: cover; }
.scan .frame {
    position: absolute; left: 8%; right: 8%; top: 28%; height: 24%;
    border: 3px solid var(--accent); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
    pointer-events: none;
}
.scan .hint { position: absolute; left: 0; right: 0; top: calc(56% + 16px); text-align: center; margin: 0; padding: 0 16px; text-shadow: 0 1px 4px #000; }
.scan .panel { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--bg); display: grid; gap: 10px; }
.scan .manual { display: flex; gap: 8px; }
.scan .manual .btn { flex: none; }

.toast {
    position: fixed; left: 16px; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 30;
    margin: 0 auto; max-width: 480px; padding: 12px 16px; border-radius: var(--radius);
    background: #1f2937; border: 1px solid var(--line); text-align: center;
    opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-color: var(--danger); color: #fecaca; }
.toast.ok { border-color: var(--ok); }

/* Connexion */
.login-page { display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login h1 { text-align: center; margin-bottom: 18px; font-size: 32px; letter-spacing: .5px; }
.login .btn { margin-top: 18px; }
.login label + label { margin-top: 14px; }
.error { color: #fecaca; background: #3b1218; border: 1px solid #5c1f27; border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; }

/* Utilitaires (pas de style en ligne : CSP) */
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt14 { margin-top: 14px; } .mt20 { margin-top: 20px; }
.mb14 { margin-bottom: 14px; }
.codes.start { justify-content: flex-start; }
.row > .grow { flex: 2; }
.row > .noflex { flex: none; }
.lnk { color: var(--primary); }

/* Hors ligne : consultation seule */
.badge {
    flex: 0 1 auto; margin: 0 auto 0 12px; padding: 3px 10px; border-radius: 999px;
    background: #3b2a06; color: var(--accent); font-size: 12px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.only-offline { display: none; }
.offline .only-offline { display: block; }
.offline .fab, .offline .banner, .offline .topbar form, .offline #addrForm,
.offline #assoc, .offline #create, .offline a[href="#/new"], .offline .admin-link { display: none !important; }
.offline .row.actions:has(#fav), .offline .row.actions:has(#edit) { display: none !important; }

/* Scanner : lampe, zoom, changement de caméra */
.scan .tools { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: calc(100% - 24px); }
.scan .tools .btn { background: rgba(0, 0, 0, .6); border-color: rgba(255, 255, 255, .25); }

/* Import / export (administrateur) */
.admin-link { margin: 28px 0 90px; text-align: center; font-size: 15px; }
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.tbl { border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.tbl th, .tbl td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.tbl th { background: var(--card-2); color: var(--accent); }
.check { display: flex; align-items: center; gap: 12px; color: var(--text); font-size: 16px; }
.check input, .upd input { width: 22px; min-height: 22px; height: 22px; flex: none; accent-color: var(--primary); }
.counts { display: flex; flex-wrap: wrap; gap: 8px; }
.counts .chip { font: 600 14px system-ui, sans-serif; padding: 6px 12px; }
.chip.ok { color: var(--ok); border-color: var(--ok); }
.chip.warn { color: var(--accent); border-color: var(--accent); }
.chip.bad { color: #fca5a5; border-color: #7f1d1d; }
.item.static { cursor: default; justify-content: flex-start; align-items: flex-start; }
.item.static .addr { margin-left: auto; }
.item.upd { gap: 12px; align-items: flex-start; }
.item.upd .meta small, .item.err .meta small { white-space: normal; }
.item.err { border-color: #5c1f27; }
.chg { color: var(--muted); }
.chg b { color: var(--text); }

.about-ver { font-size: clamp(30px, 10vw, 44px); }
