:root {
  --navy: #1f3a5f; --navy-2: #2c5282; --accent: #c8102e; --bg: #f5f3ef; --card: #fff;
  --ink: #1d2433; --muted: #6b7280; --line: #e5e1da; --ok: #1f7a4d; --warn: #b45309; --err: #b91c1c;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--navy-2); }
h1 { font-size: 1.5rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; }
h2:first-child { margin-top: 0; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .02em; }
.muted { color: var(--muted); } .small, small { font-size: .85em; }
.center { text-align: center; } .r { text-align: right; } .pre { white-space: pre-line; }
.inline { display: inline; }

/* Barre du haut */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 1rem; padding: .55rem 1.2rem; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 700; }
.brand small { display: block; font-weight: 400; opacity: .75; font-size: .75rem; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-size: 1.2rem; }
.topbar nav { display: flex; align-items: center; gap: .15rem; margin-left: auto; flex-wrap: wrap; }
.topbar nav a, .linkbtn.nav { color: #dbe4f0; text-decoration: none; padding: .45rem .65rem; border-radius: 6px; font-size: .92rem; }
.topbar nav a:hover, .topbar nav a.on { background: rgba(255, 255, 255, .14); color: #fff; }
.topbar nav .lang { font-weight: 700; border: 1px solid rgba(255,255,255,.35); }
.topbar .linkbtn { color: #dbe4f0; }
.nav-sep { width: 1px; height: 22px; background: rgba(255,255,255,.25); margin: 0 .4rem; }
.menu-btn { display: none; margin-left: auto; background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; font-size: 1.2rem; border-radius: 6px; padding: .2rem .6rem; }
.scanbar { display: flex; gap: .5rem; padding: .5rem 1.2rem; background: #e9eef5; border-bottom: 1px solid var(--line); }
.scanbar input { flex: 1; max-width: 420px; }

main { max-width: 1240px; margin: 0 auto; padding: 1.2rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 0 1rem; }

/* Cartes et grilles */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.narrow { max-width: 420px; margin: 3rem auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 1rem; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.stat b { display: block; font-size: 1.7rem; color: var(--navy); }
.stat span { color: var(--muted); font-size: .85rem; }

/* Formulaires */
label { display: block; font-size: .85rem; color: #374151; font-weight: 600; margin-bottom: .7rem; }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; font: inherit; font-weight: 400; padding: .55rem .65rem; border: 1px solid #cfd6df; border-radius: 7px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ea; border-color: var(--navy-2); }
input[type=checkbox] { display: inline; width: auto; margin: 0 .35rem 0 0; transform: scale(1.2); }
label.check { font-weight: 400; display: flex; align-items: center; font-size: .95rem; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 0 1 180px; } .row > label.grow { flex: 1 1 220px; } .row > label.grow2 { flex: 2 1 300px; } .row > label.sm { flex: 0 1 130px; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.filters input, .filters select { width: auto; min-width: 200px; margin: 0; }
.filters label { margin: 0; display: flex; gap: .5rem; align-items: center; }

.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .55rem 1rem; border-radius: 7px; border: 1px solid #c3ccd8; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f1f4f8; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--err); border-color: #f0b4b4; }
.btn.big { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn.wide { width: 100%; justify-content: center; }
.linkbtn { background: none; border: 0; color: var(--navy-2); font: inherit; cursor: pointer; padding: .2rem .3rem; text-decoration: underline; }
.linkbtn.danger { color: var(--err); }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #ecf8f1; border-color: #a7dcc0; color: #14532d; }
.flash.err { background: #fdf0f0; border-color: #f3b7b7; color: #7f1d1d; }

/* Tableaux */
.tbl { width: 100%; border-collapse: collapse; }
table.tbl.card { padding: 0; display: table; overflow: hidden; }
.tbl th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: .6rem .7rem; border-bottom: 2px solid var(--line); background: #faf9f7; }
.tbl td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl tfoot th, .tbl tfoot td { border-top: 2px solid var(--line); }
.tbl tr.urgent td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.tbl tr.inactive { opacity: .5; }
.tbl tr.picked { background: #ecf8f1; }
.thumbcell { width: 64px; }
.thumbcell img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; display: block; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 99px; background: #eef1f5; color: #334155; white-space: nowrap; }
.st-in_stock, .st-shipped { background: #e3f4ea; color: #166534; }
.st-reserved, .st-preparing { background: #fff2d9; color: #92400e; }
.st-submitted { background: #e3edfb; color: #1e40af; }
.st-ready { background: #ede4fb; color: #5b21b6; }
.st-cancelled { background: #f3f4f6; color: #6b7280; text-decoration: line-through; }

.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a.on { color: var(--navy); border-color: var(--navy); }

/* Articles (cartes avec photo) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .9rem; }
.itemcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; transition: box-shadow .15s; }
.itemcard:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.itemcard img, .itemcard .nophoto { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #eceae6; }
.nophoto { display: grid; place-items: center; color: var(--muted); font-size: .9rem; }
.nophoto.sm { width: 64px; height: 64px; aspect-ratio: auto; border-radius: 6px; flex: none; background: #eceae6; }
.ic-body { padding: .7rem .8rem; display: flex; flex-direction: column; gap: .2rem; }
.ic-body .badge { align-self: flex-start; margin-top: .3rem; }

.gallery { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.gallery figure { margin: 0; position: relative; }
.gallery img { width: 140px; height: 140px; object-fit: cover; border-radius: 8px; display: block; }
.gallery.big img { width: 220px; height: 220px; }
.gallery figure form { position: absolute; top: 4px; right: 4px; background: rgba(255,255,255,.9); border-radius: 6px; }

.photo-in { border: 2px dashed #c3ccd8; border-radius: 8px; padding: .8rem; text-align: center; background: #fafbfc; cursor: pointer; }
.photo-in input { margin-top: .4rem; }
.previews { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .6rem; }
.previews img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; }
.itemrow { border: 1px solid var(--line); border-radius: 8px; padding: .9rem; margin-bottom: .8rem; background: #fcfcfb; }

.picklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .5rem; max-height: 60vh; overflow: auto; padding: .2rem; }
.pick { display: flex; gap: .7rem; align-items: center; font-weight: 400; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; margin: 0; cursor: pointer; background: #fff; }
.pick:has(input:checked) { border-color: var(--navy-2); background: #eef4fc; }
.pick img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; flex: none; }
.pick[hidden] { display: none; }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.dl dt { color: var(--muted); font-size: .88rem; } .dl dd { margin: 0; }
.steps { padding-left: 0; list-style: none; display: grid; gap: .7rem; }
.steps li { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.status { list-style: none; padding: 0; display: grid; gap: .5rem; }
.scancheck { display: flex; gap: .6rem; align-items: center; }
.scancheck input { min-width: 280px; margin: 0; }
.ship { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* Facture */
.invoice { max-width: 860px; margin: 0 auto; position: relative; padding: 2rem; }
.inv-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 3px solid var(--navy); padding-bottom: 1rem; margin-bottom: 1rem; }
.inv-head h1 { margin: 0; color: var(--navy); letter-spacing: .08em; }
.inv-company { font-size: 1.3rem; font-weight: 800; color: var(--navy); }
.inv-to { margin-bottom: 1.2rem; }
.inv-lines tfoot td { border: 0; padding: .3rem .7rem; }
.inv-lines tr.grand td { font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--ink); }
.draft-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%,-50%) rotate(-18deg); font-size: 5rem; font-weight: 900; color: rgba(200,16,46,.09); pointer-events: none; }

@media (max-width: 820px) {
  .menu-btn { display: block; }
  .topbar nav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  .topbar nav.open { display: flex; }
  .nav-sep { display: none; }
  main { padding: .8rem; }
  .grid2 { grid-template-columns: 1fr; }
  table.tbl.card { display: block; overflow-x: auto; }
  .filters input, .filters select { min-width: 0; flex: 1; }
}
@media print {
  .topbar, .scanbar, .noprint, .foot, .flash { display: none !important; }
  body { background: #fff; } main { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; }
  .draft-stamp { color: rgba(0,0,0,.12); }
}

.perms { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center; margin: .4rem 0 .6rem; }
.perms label.check { margin: 0; font-size: .88rem; }

.prodgrid { display: grid; grid-template-columns: 110px minmax(160px,2fr) 100px 100px 90px 90px 44px 44px 60px auto; gap: .4rem; align-items: center; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.prodgrid input, .prodgrid select { margin: 0; padding: .4rem .5rem; }
.prodgrid input[type=checkbox] { justify-self: center; }
.prodhead { font-size: .75rem; text-transform: uppercase; color: var(--muted); font-weight: 700; border-bottom: 2px solid var(--line); }
.prodgrid.inactive { opacity: .5; }
.prodgrid.newprod { background: #f7f9fc; padding: .5rem; border-radius: 8px; border: 1px dashed #c3ccd8; margin-top: .6rem; }
@media (max-width: 1000px) { .prodgrid { grid-template-columns: 1fr 1fr; } .prodhead { display: none; } }
