*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #0f130b;
    --surface:  #171d11;
    --border:   #2b3521;
    --accent:   #84cc16;
    --accent-h: #a3e635;
    --on-accent:#111a03;
    --green:    #22c55e;
    --orange:   #f59e0b;
    --red:      #ef4444;
    --text:     #eef5e6;
    --muted:    #95a386;
    --radius:   12px;
    --shadow:   0 4px 32px rgba(0,0,0,.4);
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
}

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

/* ── Layout ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.5rem;
    width: 100%;
    max-width: 480px;
    margin: auto;
}
.card-wide { max-width: 980px; }
.card-mid { max-width: 640px; }

.logo { display: flex; align-items: center; gap: .6rem; margin-bottom: 2rem; }
.logo svg { flex-shrink: 0; }
.logo-text { font-size: 1.35rem; font-weight: 700; letter-spacing: -.5px; }
.logo-text span { color: var(--accent); }

h1 { font-size: 1.15rem; font-weight: 600; margin-bottom: .35rem; }
h2 { font-size: 1rem; font-weight: 700; margin-bottom: .75rem; }
h3 { font-size: .9rem; font-weight: 700; margin-bottom: .5rem; }
.subtitle { font-size: .875rem; color: var(--muted); margin-bottom: 1.75rem; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

.back-link {
    display: inline-flex; align-items: center; gap: .4rem;
    font-size: .8rem; color: var(--muted); text-decoration: none; margin-bottom: 1.25rem;
}
.back-link:hover { color: var(--text); }

section { margin-bottom: 2rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.75rem 0; }

/* ── Formulaires ── */
.field { margin-bottom: 1.1rem; }
label, .label {
    display: block; font-size: .78rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .45rem;
}
input[type=text], input[type=search], input[type=number], input[type=url], textarea, select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    padding: .75rem 1rem;
    outline: none;
    font-family: inherit;
    transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
select option { background: var(--surface); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.inline-form { display: flex; gap: .5rem; align-items: stretch; }
.inline-form > input, .inline-form > select { flex: 1; min-width: 0; }
.inline-form .btn { width: auto; white-space: nowrap; }

.code-input {
    font-family: 'Courier New', monospace;
    font-size: 1.4rem;
    letter-spacing: .14em;
    text-align: center;
    text-transform: uppercase;
}
.qty-input { font-size: 1.6rem !important; font-weight: 700; text-align: center; padding: .6rem 1rem !important; }

.hint { font-size: .78rem; color: var(--muted); margin-top: .4rem; line-height: 1.5; }

.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .4rem .75rem; }
.check {
    display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--text);
    text-transform: none; letter-spacing: 0; font-weight: 500; margin: 0; cursor: pointer;
    padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.check input { accent-color: var(--accent); width: 1rem; height: 1rem; }

/* ── Boutons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    background: var(--accent); color: var(--on-accent); border: none; border-radius: 8px;
    font-size: .95rem; font-weight: 700; padding: .8rem 1.4rem; cursor: pointer;
    transition: background .15s, transform .1s; text-decoration: none; width: 100%; font-family: inherit;
}
.btn:hover { background: var(--accent-h); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: transparent; border: 1px solid rgba(239,68,68,.5); color: #fca5a5; }
.btn-danger:hover { background: rgba(239,68,68,.15); }
.btn-sm { font-size: .82rem; padding: .5rem .9rem; width: auto; }
.btn-xs { font-size: .75rem; padding: .3rem .6rem; width: auto; border-radius: 6px; }
.btn-auto { width: auto; }
.btn-scan { font-size: 1.05rem; padding: 1rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-row form { margin: 0; }

/* ── Alertes ── */
.alert {
    border-radius: 8px; padding: .85rem 1rem; font-size: .875rem; margin-bottom: 1.25rem;
    display: flex; align-items: flex-start; gap: .6rem; line-height: 1.5;
}
.alert svg { flex-shrink: 0; margin-top: 2px; }
.alert-error   { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.3);  color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.12);  border: 1px solid rgba(34,197,94,.3);  color: #86efac; }
.alert-info    { background: rgba(132,204,22,.1);  border: 1px solid rgba(132,204,22,.3); color: #bef264; }
.alert-warn    { background: rgba(245,158,11,.1);  border: 1px solid rgba(245,158,11,.35); color: #fcd34d; }

/* ── En-têtes de page ── */
.dash-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.75rem; flex-wrap: wrap; }
.dash-header .logo { margin-bottom: 0; }
.dash-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.page-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-title h1 { font-size: 1.35rem; margin-bottom: .2rem; }

/* ── Pastilles ── */
.pill {
    display: inline-flex; align-items: center; gap: .3rem; font-size: .7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em; padding: .25rem .6rem; border-radius: 999px;
    background: rgba(132,204,22,.15); color: var(--accent); white-space: nowrap;
}
.pill-saisie   { background: rgba(132,204,22,.15); color: var(--accent); }
.pill-controle { background: rgba(245,158,11,.15); color: var(--orange); }
.pill-cloture  { background: rgba(149,163,134,.15); color: var(--muted); }
.pill-ok       { background: rgba(34,197,94,.15); color: var(--green); }
.pill-ko       { background: rgba(239,68,68,.15); color: #fca5a5; }
.pill-danger   { background: rgba(239,68,68,.15); color: #fca5a5; text-transform: none; letter-spacing: 0; }

/* ── Cartes de liste ── */
.list { display: flex; flex-direction: column; gap: .6rem; }
.row-card {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .85rem 1rem;
    text-decoration: none; color: var(--text); flex-wrap: wrap;
}
a.row-card:hover { border-color: var(--accent); }
.row-title { font-weight: 600; font-size: .95rem; }
.row-meta { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.row-card form { margin: 0; }

.empty-state {
    text-align: center; padding: 2rem 1rem; color: var(--muted); font-size: .9rem;
    border: 1px dashed var(--border); border-radius: var(--radius);
}

/* ── Chiffres clés ── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-bottom: 1.75rem; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem; }
.stat-value { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: .1rem; }

.plan-box {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .9rem 1rem; margin-bottom: 1.75rem;
    font-size: .85rem;
}
.meter { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: .45rem; min-width: 160px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter.full > span { background: var(--red); }

/* ── Code inventaire ── */
.code-box {
    background: var(--bg); border: 1px solid var(--accent); border-radius: 10px;
    padding: 1.1rem 1.25rem; margin-bottom: 1.75rem; display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.code-value { font-family: 'Courier New', monospace; font-size: 1.7rem; font-weight: 700; letter-spacing: .14em; user-select: all; }
.code-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: .2rem; }
.copied-feedback { font-size: .78rem; color: var(--green); display: none; align-items: center; gap: .3rem; }
.copied-feedback.show { display: inline-flex; }

/* ── Tableaux ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline; }
tr.doublon td { background: rgba(245,158,11,.07); }
tr.ecart td { background: rgba(239,68,68,.07); }
.thumb { width: 38px; height: 38px; border-radius: 6px; background: #fff; object-fit: contain; border: 1px solid var(--border); display: block; }
.thumb-empty { width: 38px; height: 38px; border-radius: 6px; background: var(--bg); border: 1px dashed var(--border); }
.cell-name { font-weight: 600; }
.cell-sub { font-size: .74rem; color: var(--muted); }

details.zone { border: 1px solid var(--border); border-radius: 10px; margin-bottom: .6rem; overflow: hidden; }
details.zone > summary {
    cursor: pointer; padding: .8rem 1rem; font-weight: 600; background: var(--bg);
    display: flex; justify-content: space-between; gap: 1rem; list-style: none;
}
details.zone > summary::-webkit-details-marker { display: none; }
details.zone > summary::before { content: '▸'; color: var(--accent); margin-right: .5rem; }
details.zone[open] > summary::before { content: '▾'; }
details.zone .table-wrap { border: none; border-top: 1px solid var(--border); border-radius: 0; }

.search-wrap { position: relative; margin-bottom: 1rem; }
.search-wrap svg { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-wrap input[type=search] { padding-left: 2.6rem; }

/* ── Saisie ── */
.saisie-head {
    display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; flex-wrap: wrap;
    margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.saisie-head .who { font-size: .8rem; color: var(--muted); }
.zone-picker { margin-bottom: 1.25rem; }
.zone-picker select { font-weight: 700; font-size: 1.05rem; border-color: var(--accent); }
.zone-missing select { border-color: var(--orange); }

.scan-form { display: flex; gap: .5rem; margin-bottom: .6rem; }
.scan-form input { flex: 1; min-width: 0; font-size: 1.1rem; }
.scan-form .btn { width: auto; }

.product {
    display: flex; gap: 1rem; margin: 1.25rem 0; padding: 1rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
}
.product-image {
    position: relative; width: 96px; height: 96px; flex-shrink: 0; border-radius: 8px; background: #fff;
    display: flex; align-items: center; justify-content: center; overflow: hidden; border: 1px solid var(--border);
}
.product-image img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.product-image-fallback { color: #c4c4c4; }
.product-info { min-width: 0; flex: 1; }
.product-name { font-size: 1.05rem; font-weight: 700; line-height: 1.35; margin-bottom: .25rem; }
.product-brand { font-size: .82rem; color: var(--accent); font-weight: 600; margin-bottom: .25rem; }
.product-meta { font-size: .76rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; margin-top: .35rem; }

.candidates { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1.25rem; }
.candidate {
    display: flex; gap: .75rem; align-items: center; padding: .7rem .8rem; cursor: pointer;
    background: var(--bg); border: 2px solid var(--border); border-radius: 10px;
    text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); margin: 0;
}
.candidate:has(input:checked) { border-color: var(--accent); background: rgba(132,204,22,.06); }
.candidate input { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; flex-shrink: 0; }
.candidate .product-image { width: 56px; height: 56px; }
.candidate-name { font-weight: 600; font-size: .9rem; }
.candidate-meta { font-size: .74rem; color: var(--muted); }

.deja { background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.3); border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1rem; font-size: .85rem; }
.deja ul { list-style: none; margin-top: .4rem; }
.deja li { display: flex; justify-content: space-between; gap: .5rem; padding: .25rem 0; color: var(--muted); }

.recent { margin-top: 2rem; }
.recent-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.recent-row:last-child { border-bottom: none; }
.recent-qty { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 3rem; text-align: right; }

details.more { margin-bottom: 1rem; }
details.more > summary { cursor: pointer; font-size: .85rem; color: var(--accent); margin-bottom: .75rem; }

/* ── Scanner ── */
.scanner-overlay { display: none; position: fixed; inset: 0; background: #000; z-index: 1000; align-items: center; justify-content: center; }
.scanner-overlay.open { display: flex; }
.scanner-frame { position: relative; width: 100%; height: 100%; max-width: 520px; max-height: 100dvh; margin: 0 auto; }
.scanner-frame video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.scanner-viewfinder {
    position: absolute; left: 8%; right: 8%; top: 36%; height: 26%;
    border: 3px solid var(--accent); border-radius: 14px; box-shadow: 0 0 0 2000px rgba(0,0,0,.45); pointer-events: none;
}
.scanner-close {
    position: absolute; top: 1rem; right: 1rem; width: 42px; height: 42px; border-radius: 999px;
    background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.25); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.scanner-status { position: absolute; bottom: 2rem; left: 1rem; right: 1rem; text-align: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 4px rgba(0,0,0,.9); }

footer { margin-top: 2rem; font-size: .78rem; color: var(--muted); text-align: center; max-width: 900px; line-height: 1.6; }

/* ── Petits écrans (mobile) ── */
@media (max-width: 560px) {
    body { padding: .75rem; }
    .card { padding: 1.25rem; }
    .field-row { grid-template-columns: 1fr; gap: 0; }
    .code-value { font-size: 1.35rem; }
    .hide-mobile { display: none; }
    th, td { padding: .5rem .5rem; }
}
