:root {
  --bg: #f6f6f4; --card: #ffffff; --soft: #efefec; --line: #e2e1dc; --text: #1c1c1a; --muted: #6d6c66;
  --accent: #2f4fd8; --accent-bg: #e8ecfd;
  --pos: #16794a; --pos-bg: #e3f4ea; --neg: #b3261e; --neg-bg: #fbe6e4; --neu: #6d6c66; --neu-bg: #ecece8;
  --warn: #8a5a00; --warn-bg: #fbefd3;
  --pub: #6b3fc4; --pub-bg: #efe8fb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --card: #1f1f1d; --soft: #2a2a27; --line: #34342f; --text: #ededea; --muted: #a09f97;
    --accent: #8fa2ff; --accent-bg: #252c4d;
    --pos: #5fd39a; --pos-bg: #173326; --neg: #ff8a80; --neg-bg: #3f1c19; --neu: #a09f97; --neu-bg: #2e2e2b;
    --warn: #f0c060; --warn-bg: #3a2e12;
    --pub: #b79cf5; --pub-bg: #2e2350;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
#app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }

/* Navigation */
.side { background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 17px; padding: 0 8px 12px; }
.spaces { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--soft); padding: 4px; border-radius: 10px; margin-bottom: 12px; }
.spaces button { border: 0; background: none; padding: 7px 4px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
.spaces button.on { background: var(--card); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.nav { border: 0; background: none; text-align: left; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.nav:hover { background: var(--soft); }
.nav.on { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.nav[disabled] { cursor: default; opacity: .55; }
.nav[disabled]:hover { background: none; }
.soon { font-size: 11px; background: var(--soft); padding: 1px 6px; border-radius: 6px; }
.side .foot { margin-top: auto; display: grid; gap: 4px; }
.side .foot button { font-size: 13px; }

/* Contenu */
main { padding: 22px 26px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.head h1 { font-size: 22px; margin: 0; flex: 1; min-width: 160px; }
.btn { border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10131f; } }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.danger { color: var(--neg); }
select, input[type=text], input[type=password], input[type=number], input[type=date], input[type=search] { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 9px; min-width: 0; }
.banner { background: var(--warn-bg); color: var(--warn); padding: 9px 14px; border-radius: 10px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.banner span { flex: 1; min-width: 200px; }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .s { font-size: 12px; color: var(--muted); }
.pos { color: var(--pos); } .neg { color: var(--neg); } .neu { color: var(--neu); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }

.chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; align-items: end; height: 170px; }
.chart .m { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; }
.chart .bars { display: flex; gap: 3px; align-items: flex-end; height: 140px; width: 100%; justify-content: center; }
.chart .bar { width: 38%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bar.ca { background: var(--line); } .bar.p { background: var(--pos); } .bar.n { background: var(--neg); }
.chart .x { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Lots */
.lot { cursor: pointer; }
.lot .top { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.lot .id { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--soft); padding: 2px 7px; border-radius: 6px; }
.lot .title { font-weight: 650; font-size: 16px; }
.lot .info { flex: 1; min-width: 200px; }
.lot .res { text-align: right; font-weight: 700; }
.prog { height: 7px; background: var(--soft); border-radius: 4px; margin: 12px 0 6px; overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--pos); }
.lotbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 6px; }

/* Tableaux */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
td.ref { font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
tr.t-pos td:first-child { box-shadow: inset 4px 0 0 var(--pos); }
tr.t-neg td:first-child { box-shadow: inset 4px 0 0 var(--neg); }
tr.t-neu td:first-child { box-shadow: inset 4px 0 0 var(--neu); }
tr.t-pos { background: color-mix(in srgb, var(--pos-bg) 55%, transparent); }
tr.t-neg { background: color-mix(in srgb, var(--neg-bg) 55%, transparent); }
tr.t-neu { background: color-mix(in srgb, var(--neu-bg) 55%, transparent); }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
input.cell { border-color: transparent; background: transparent; padding: 4px 6px; width: 100%; min-width: 150px; }
input.cell.sm { min-width: 60px; width: 76px; }
input.cell:hover, input.cell:focus { border-color: var(--line); background: var(--card); }
select.cell { padding: 4px 6px; font-size: 13px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12.5px; font-weight: 600; }
.pill.pos { background: var(--pos-bg); } .pill.neg { background: var(--neg-bg); } .pill.neu { background: var(--neu-bg); }
.pill.info { background: var(--accent-bg); color: var(--accent); } .pill.warn { background: var(--warn-bg); color: var(--warn); }

/* Filtres */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
.srt { opacity: .45; }
tr.flt td { padding: 4px 4px 8px; border-bottom: 1px solid var(--line); }
tr.flt input, tr.flt select { width: 100%; min-width: 54px; padding: 4px 5px; font-size: 13px; }

/* Factures */
.drop { border: 2px dashed var(--line); background: transparent; text-align: center; color: var(--muted); padding: 22px 14px; border-radius: 12px; }
.drop.over { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.flist { display: grid; gap: 4px; }
.frow { display: flex; gap: 10px; align-items: center; border: 1px solid transparent; background: none; padding: 7px 9px; border-radius: 8px; cursor: pointer; text-align: left; }
.frow:hover { background: var(--soft); }
.frow.on { border-color: var(--accent); background: var(--accent-bg); }
.frow .ref { font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
.frow .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.verify { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.verify form { display: grid; gap: 12px; }
.verify h3 { margin: 0; font-size: 17px; }
.verify label, .verify .two { font-size: 13px; color: var(--muted); }
.verify label { display: grid; gap: 4px; }
.verify label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.verify .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.verify .acts { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.verify .hint, .hint { font-size: 13px; color: var(--muted); background: var(--soft); padding: 8px 10px; border-radius: 8px; }
.doc { background: var(--soft); border-radius: 10px; overflow: auto; min-height: 200px; max-height: 640px; }
.doc iframe { width: 100%; height: 620px; border: 0; display: block; }
.doc img { width: 100%; display: block; }
.doc.mini { min-height: 0; max-height: 300px; margin-top: 12px; }
.doc.mini iframe { height: 300px; }
dialog.wide { width: min(860px, calc(100vw - 24px)); }
.cols { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.side2 { padding: 20px; border-left: 1px solid var(--line); }
.side2 h3 { margin: 0 0 12px; font-size: 18px; }
@media (max-width: 760px) { .verify, .cols { grid-template-columns: minmax(0, 1fr); } .side2 { border-left: 0; border-top: 1px solid var(--line); } }

/* Historique */
.tl { display: grid; gap: 2px; }
.ev { display: grid; grid-template-columns: 48px 84px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: 0; }
.ev .pill { text-align: center; }
.ev details { margin-top: 4px; color: var(--muted); }
.ev summary { cursor: pointer; font-size: 13px; }

/* Annonces */
.anngrid { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 14px; align-items: start; }
.adlist { display: grid; gap: 4px; max-height: 78vh; overflow-y: auto; padding: 10px; }
.adform { display: grid; gap: 12px; }
.adform h2 { margin: 0; }
.adform label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.adform label.check { display: flex; gap: 6px; align-items: center; color: var(--text); font-size: 14px; }
.adform .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.withbtn { display: flex; gap: 6px; }
.withbtn input { flex: 1; }
textarea { font: inherit; color: inherit; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 10px; resize: vertical; width: 100%; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { width: 92px; height: 92px; border-radius: 10px; background: var(--soft) center/cover no-repeat; position: relative; border: 1px solid var(--line); }
.thumb .btn { position: absolute; top: 4px; right: 4px; padding: 0 7px; line-height: 20px; }
.thumb.add { border-style: dashed; cursor: pointer; color: var(--muted); }
.sites { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.site { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 8px; justify-items: start; }
a.btn { text-decoration: none; color: inherit; display: inline-block; }
@media (max-width: 760px) { .anngrid { grid-template-columns: minmax(0, 1fr); } .adlist { max-height: 240px; } .sites { grid-template-columns: minmax(0, 1fr); } .ev { grid-template-columns: 44px minmax(0, 1fr); } }

/* Étiquettes */
.labels { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.label { background: #fff; color: #000; border: 1px solid #bbb; border-radius: 3px; padding: 1.5mm 2mm; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
.label .lr { font-family: ui-monospace, Menlo, monospace; font-weight: 800; line-height: 1; white-space: nowrap; text-align: center; }
.label .ln { text-align: center; }
.label .ln { font-size: 8.5pt; line-height: 1.1; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.label .lb { display: flex; justify-content: space-between; align-items: baseline; gap: 2mm; font-size: 6.5pt; white-space: nowrap; }
.label .lb b { font-size: 9pt; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* Fenêtres */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--card); color: var(--text); width: min(460px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h3 { margin: 0 0 4px; font-size: 18px; }
dialog label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
dialog .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
dialog .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
dialog .hint { font-size: 13px; color: var(--muted); background: var(--soft); padding: 8px 10px; border-radius: 8px; }

#print { display: none; }
@media print {
  #app, dialog { display: none !important; }
  #print { display: block; }
  body { background: #fff; }
  html, body { margin: 0; padding: 0; }
  #print .label { border: 0; border-radius: 0; page-break-after: always; break-after: page; page-break-inside: avoid; }
  #print .label:last-child { page-break-after: auto; break-after: auto; }
}

@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; align-items: center; }
  .brand, .side .foot { display: none; }
  .spaces { margin: 0 6px 0 0; min-width: 190px; }
  .nav { white-space: nowrap; }
  .soon { display: none; }
  main { padding: 16px 16px 60px; }
}

/* Onglets du stock, vignettes, cases */
.seg { display: inline-flex; gap: 4px; background: var(--soft); padding: 4px; border-radius: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.thumb.mini { width: 56px; height: 56px; flex: none; }
.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--text); }

/* Téléphone */
@media (max-width: 760px) {
  .side { position: sticky; top: 0; z-index: 5; }
  input, select, textarea { font-size: 16px !important; } /* évite le zoom automatique de Safari sur iPhone */
  .head h1 { flex-basis: 100%; }
  .btn { padding: 9px 12px; }
  .btn.small { padding: 7px 10px; }
  table.items thead { display: none; }
  table.items, table.items tbody { display: block; }
  table.items tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 10px 8px; border-bottom: 1px solid var(--line); }
  table.items td { border: 0; padding: 0; white-space: normal; }
  table.items td:nth-child(2) { flex: 1 1 60%; }
  table.items td:nth-child(8) { flex: 1 1 100%; text-align: left; display: flex; gap: 6px; flex-wrap: wrap; }
  table.items input.cell { border-color: var(--line); background: var(--card); min-width: 0; }
  tr.t-pos td:first-child, tr.t-neg td:first-child, tr.t-neu td:first-child { box-shadow: none; }
  .lot .res { text-align: left; flex-basis: 100%; }
  dialog form, .side2 { padding: 16px; }
  dialog .two, .verify .two, .adform .two { grid-template-columns: minmax(0, 1fr); }
}

/* Statuts des pièces non vendues */
tr.s-stock td:first-child { box-shadow: inset 4px 0 0 var(--pub); }
tr.s-online td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
tr.s-consign td:first-child { box-shadow: inset 4px 0 0 var(--warn); }
select.cell.st-stock { color: var(--pub); background: var(--pub-bg); border-color: transparent; font-weight: 600; }
select.cell.st-online { color: var(--accent); background: var(--accent-bg); border-color: transparent; font-weight: 600; }
select.cell.st-consign { color: var(--warn); background: var(--warn-bg); border-color: transparent; font-weight: 600; }
.pill.pub { background: var(--pub-bg); color: var(--pub); }
.thumbs.big .thumb { width: 150px; height: 150px; }

/* Vue générale */
.genbtn { border: 0; background: none; color: var(--muted); font-size: 12.5px; text-align: left; padding: 2px 8px 6px; cursor: pointer; }
.genbtn:hover { color: var(--text); }
.genbtn.on { color: var(--accent); font-weight: 600; }
@media (max-width: 760px) { .genbtn { white-space: nowrap; padding: 6px 8px; } }

.choice { display: grid; gap: 3px; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.choice:hover { border-color: var(--accent); background: var(--accent-bg); }
.choice span { font-size: 13px; color: var(--muted); }

/* Prix du marché */
.market { background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 10px; padding: 12px 14px; }
.market .mt { color: var(--warn); font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.market .btn { background: var(--card); }

/* Recherche des prix du marché */
.market #mktQ { width: 100%; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }

/* iPhone : barre d'onglets en bas, comme une application */
.tabbar { display: none; }
.more { padding: 18px; display: grid; gap: 12px; }
.more h3 { margin: 0; }
.morelist { display: grid; gap: 8px; }
.seg.full { display: flex; margin: 0; }
.seg.full button { flex: 1; }
@media (max-width: 760px) {
  .side { display: none; }
  main { padding: 12px 14px calc(84px + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .tabbar button { flex: 1; display: grid; justify-items: center; gap: 2px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 0; min-height: 50px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .tabbar button .ic { font-size: 20px; line-height: 1; }
  .tabbar button.on { color: var(--accent); }
  .head { gap: 8px; }
  .head h1 { font-size: 21px; }
  .head > select, .head > input[type=search] { flex: 1 1 45%; min-width: 0; }
  .head > .btn { flex: 1 1 auto; }
  .btn, .chip, .seg button, .choice { min-height: 44px; } /* taille confortable pour le doigt */
  .btn.small { min-height: 38px; }
  .seg { display: flex; overflow-x: auto; flex-wrap: nowrap; max-width: 100%; }
  .seg button { white-space: nowrap; }
  dialog, dialog.wide { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .kpi .v { font-size: 20px; }
}

/* Connexion en ligne */
#login { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: var(--bg); }
#login form { width: min(380px, 100%); display: grid; gap: 12px; padding: 24px; }
#login h1 { margin: 0 0 4px; font-size: 22px; }
#login .err { color: var(--neg); }
.cloudst { display: flex; gap: 6px; align-items: flex-start; font-size: 12.5px; color: var(--muted); margin: 6px 0; }
.cloudst .dot { flex: none; margin-top: 4px; background: var(--neu); }
.cloudst.ok .dot { background: var(--pos); }
.cloudst.offline .dot { background: var(--warn); }
.cloudst.saving .dot, .cloudst.sync .dot { background: var(--accent); }
.cloudbox:empty { display: none; }
#login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
#login input { width: 100%; font-size: 16px; padding: 10px 12px; }
#login .btn { min-height: 44px; }
