:root {
  --bg: #fcf7f8;
  --surface: #ffffff;
  --surface-2: #f6edf1;
  --ink: #2b2326;
  --muted: #7d6d72;
  --line: #ecdfe5;
  --rose: #a8577e;
  --rose-dark: #84405f;
  --rose-soft: #f6e2ec;
  --lilac: #7e5a9b;
  --lilac-soft: #ece3f3;
  --sage: #6e8b6f;
  --sage-soft: #e3ece0;
  --honey: #c98a1b;
  --honey-soft: #fbedd0;
  --sky: #4f7ea8;
  --sky-soft: #dfeaf4;
  --danger: #b93a32;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 30, 40, .06), 0 4px 14px rgba(60, 30, 40, .06);
  --font: 'Nunito Sans', system-ui, sans-serif;
  --serif: 'Fraunces', Georgia, serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--rose-dark); }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Mise en page */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex: none; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--serif); font-weight: 700; font-size: 17px; padding: 4px 8px 18px; }
.brand img { width: 44px; height: 44px; object-fit: contain; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); font-weight: 600; }
#nav a:hover { background: var(--surface-2); }
#nav a.on { background: var(--rose-soft); color: var(--rose-dark); }
.logout-form { margin-top: auto; }
.logout { padding: 8px 12px; color: var(--muted); font: 13px var(--font); background: none; border: 0; cursor: pointer; text-decoration: underline; }
main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1200px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.head h1 { margin-right: auto; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-size: 14px; }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 600 14px var(--font); padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 40px; }
.btn:hover { border-color: #d8c6be; background: var(--surface-2); }
.btn.primary { background: var(--rose); border-color: var(--rose); color: #fff; }
.btn.primary:hover { background: var(--rose-dark); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { padding: 13px 20px; font-size: 16px; width: 100%; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.stat { padding: 16px 18px; }
.stat .v { font-family: var(--serif); font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

.hello { background: linear-gradient(120deg, var(--rose-soft), var(--lilac-soft)); border: 0; padding: 22px 24px; margin-bottom: 16px; }
.hello h1 { font-size: 26px; }

/* Listes en vignettes */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .15s ease, box-shadow .15s ease; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(60, 30, 40, .1); }
.tile .ph { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; font-size: 40px; overflow: hidden; position: relative; }
.tile .ph img { width: 100%; height: 100%; object-fit: cover; }
.tile .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.tile .t { font-weight: 700; line-height: 1.3; }
.tile .s { color: var(--muted); font-size: 13px; }
.tile .foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 6px; gap: 6px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); display: inline-block; vertical-align: middle; flex: none; }
.ph .swatch-big { position: absolute; bottom: 8px; right: 8px; width: 26px; height: 26px; }

/* Puces */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.rose { background: var(--rose-soft); color: var(--rose-dark); }
.chip.sage { background: var(--sage-soft); color: #4a6a4b; }
.chip.honey { background: var(--honey-soft); color: #8a5c08; }
.chip.sky { background: var(--sky-soft); color: #36618a; }
.chip.red { background: #f8dcd9; color: var(--danger); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filters .chip { cursor: pointer; padding: 6px 12px; font-size: 13px; border: 1px solid transparent; }
.filters .chip.on { background: var(--ink); color: #fff; }
.search { flex: 1; min-width: 180px; max-width: 340px; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr.link { cursor: pointer; }
table.t tr.link:hover td { background: var(--surface-2); }
.r { text-align: right; white-space: nowrap; }
.list { display: flex; flex-direction: column; }
.list .row { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.list .row:last-child { border-bottom: 0; }
.list .row .grow { flex: 1; min-width: 0; }
.list .row .thumb { width: 40px; height: 40px; border-radius: 9px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; flex: none; font-size: 18px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Formulaires */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
input, select, textarea { font: 15px var(--font); color: var(--ink); padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--rose-soft); border-color: var(--rose); }
textarea { min-height: 80px; resize: vertical; }
input[type=color] { padding: 3px; height: 40px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form h3 { grid-column: 1 / -1; margin-top: 6px; color: var(--rose-dark); }
.upload { display: flex; gap: 10px; align-items: center; }
.upload img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; min-height: 0; }

/* Fenêtre modale */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(43, 35, 38, .45); }
dialog form.m { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
dialog .m-head { padding: 18px 20px 6px; display: flex; align-items: center; }
dialog .m-head h2 { margin-right: auto; }
dialog .m-body { padding: 12px 20px; overflow-y: auto; }
dialog .m-foot { padding: 12px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); flex-wrap: wrap; }
dialog .m-foot .left { margin-right: auto; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

.alert { background: #f8dcd9; color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.notice { background: var(--honey-soft); color: #6d4a07; padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }

/* Détail */
.detail-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 60px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; }
dl.kv dd { margin: 0; font-weight: 600; }
.qty-big { font-family: var(--serif); font-size: 40px; font-weight: 700; line-height: 1; }
.pre { white-space: pre-line; }

/* Compteur de rangs */
.counter { text-align: center; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.counter .lab { font-weight: 700; display: flex; justify-content: center; gap: 6px; align-items: center; }
.counter .val { font-family: var(--serif); font-size: 64px; font-weight: 700; line-height: 1.05; color: var(--rose-dark); font-variant-numeric: tabular-nums; }
.counter .ctl { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.counter .ctl button { width: 64px; height: 64px; border-radius: 50%; font-size: 30px; border: 0; cursor: pointer; background: #fff; box-shadow: var(--shadow); color: var(--ink); touch-action: manipulation; }
.counter .ctl button.plus { width: 84px; height: 84px; background: var(--rose); color: #fff; font-size: 40px; }
.counter .ctl button:active { transform: scale(.94); }
.progress { height: 6px; background: #fff; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress span { display: block; height: 100%; background: var(--sage); transition: width .2s ease; }

/* Éditeur de devis / facture */
.lines-edit { width: 100%; border-collapse: collapse; }
.lines-edit th { font-size: 12px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 4px; }
.lines-edit td { padding: 4px; vertical-align: top; }
.lines-edit td.desc { width: 55%; }
.lines-edit textarea { min-height: 40px; height: 40px; }
.lines-edit input.n { text-align: right; }
.totals-box { margin-left: auto; width: min(320px, 100%); }
.totals-box div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-box .grand { border-top: 2px solid var(--ink); font-weight: 800; font-size: 18px; margin-top: 4px; padding-top: 8px; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .bar span { width: 100%; max-width: 28px; background: var(--rose); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bars .bar.now span { background: var(--honey); }
.bars .bar small { font-size: 11px; color: var(--muted); }

/* Connexion */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(140deg, var(--rose-soft), var(--bg) 50%, var(--lilac-soft)); }
.login-card { background: #fff; padding: 32px 28px; border-radius: 22px; box-shadow: 0 20px 60px rgba(90, 40, 50, .15); width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card label { text-align: left; }
.login-logo { width: 120px; height: 120px; object-fit: contain; margin: 0 auto; }

/* Mobile */
@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .layout { flex-direction: column; }
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; width: 100%; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 20; }
  .brand, .logout-form { display: none; }
  #nav { flex-direction: row; overflow-x: auto; gap: 0; width: 100%; scrollbar-width: none; }
  #nav a { flex-direction: column; gap: 0; font-size: 18px; padding: 6px 10px; min-width: 64px; text-align: center; }
  #nav a span { font-size: 10.5px; }
  main { padding: 18px 16px 100px; }
  h1 { font-size: 24px; }
  .grid.g4 { gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .v { font-size: 19px; white-space: nowrap; }
  .g2, .form { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .ph { font-size: 32px; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100%; border-radius: 0; margin: 0; }
  dialog form.m { max-height: 100vh; height: 100%; }
  dialog .m-body { flex: 1; }
  .lines-edit thead { display: none; }
  .lines-edit tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 4px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .lines-edit td { padding: 0; }
  .lines-edit td.desc { grid-column: 1 / -1; width: auto; }
  .hide-m { display: none; }
}

.check-ok { color: #4a6a4b; }
.check-bad { color: var(--danger); font-weight: 700; }
.qrbox { background: #fff; padding: 10px; border-radius: 12px; width: 200px; height: 200px; border: 1px solid var(--line); }
.qrbox svg { width: 100%; height: 100%; display: block; }
.mono { font-family: ui-monospace, Consolas, monospace; letter-spacing: .08em; word-break: break-all; }

/* Prise de commande */
.order-page { align-items: start; }
.order-card { width: min(560px, 100%); text-align: left; margin: 16px 0; }
.order-card h1, .order-card > p, .order-card > .login-logo { text-align: center; }
.order-card .check span { font-weight: 400; color: var(--ink); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.badge { background: var(--rose); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 800; padding: 1px 7px; margin-left: auto; }
.qr-big { background: #fff; padding: 14px; border-radius: 18px; width: min(320px, 80vw); margin: 0 auto; }
.qr-big svg { width: 100%; height: auto; display: block; }
.req-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
@media (max-width: 760px) {
  #nav a { position: relative; }
  .badge { position: absolute; top: 2px; right: 8px; margin: 0; padding: 0 5px; font-size: 10px; }
  .order-card { padding: 22px 16px; }
}
