/* Précommandes — feuille de style unique, mobile d'abord. */
:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --ink: #1f1d1a;
  --muted: #6b665e;
  --line: #e4dfd7;
  --brand: #8c2f2b;
  --brand-dark: #6f2421;
  --brand-soft: #f6e9e7;
  --ok: #24724a;
  --ok-soft: #e4f3ea;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --info: #255d99;
  --info-soft: #e5eef8;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { overflow-x: clip; margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45; }
img { max-width: 100%; height: auto; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card h2 { margin-bottom: .75rem; }
.grid { display: grid; gap: 1rem; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stat .value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: .9rem; }
@media (max-width: 719px) { .stats { grid-template-columns: repeat(3, 1fr); gap: .5rem; } .stats .stat { padding: .75rem .6rem; } .stats .value { font-size: 1.6rem; } .stats .label { font-size: .78rem; } }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: #cfc8bd; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; border-radius: 8px; }
.btn-lg { min-height: 56px; font-size: 1.1rem; padding: .8rem 1.25rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-link { background: none; border: 0; color: var(--brand); padding: 0; min-height: auto; font-weight: 500; text-decoration: underline; cursor: pointer; font: inherit; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.inline { display: inline; }

/* Formulaires */
label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; min-height: 48px; padding: .6rem .75rem; font: inherit; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid #d3ccc1; border-radius: 10px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(140,47,43,.2); border-color: var(--brand); }
.help { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.error-text { color: var(--danger); font-size: .9rem; margin-top: .3rem; font-weight: 600; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.check { display: flex; gap: .65rem; align-items: flex-start; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex-shrink: 0; accent-color: var(--brand); }
.row { display: grid; gap: .75rem; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.row-3 { display: grid; gap: .75rem; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 480px) { .row-3 { grid-template-columns: 1fr 1fr; } .row-3 > :first-child { grid-column: 1 / -1; } }

/* Alertes */
.alert { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 500; }
.alert-success { background: var(--ok-soft); color: var(--ok); }
.alert-error { background: #fdecea; color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-credentials { background: #fff8e1; color: #6d4c00; border: 1px dashed #d4a72c; font-family: ui-monospace, monospace; word-break: break-all; }

/* Badges statut */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; background: #eee; color: #444; }
.badge-new { background: var(--info-soft); color: var(--info); }
.badge-preparing { background: var(--warn-soft); color: var(--warn); }
.badge-ready { background: var(--ok-soft); color: var(--ok); }
.badge-collected { background: #ececec; color: #555; }
.badge-cancelled { background: #fdecea; color: var(--danger); text-decoration: line-through; }
.badge-on { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: #ececec; color: #666; }

/* ===================== Page publique ===================== */
.shop-header { background: var(--surface); border-bottom: 1px solid var(--line); padding: 1rem 0 1.1rem; text-align: center; }
.shop-header .logo { max-height: 64px; max-width: 180px; display: block; margin: 0 auto .5rem; }
.shop-name { font-size: 1rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0; }
.campaign-title { font-size: 1.55rem; margin: .35rem 0 .35rem; }
.campaign-intro { color: var(--muted); margin: 0; white-space: pre-line; }
.campaign-image { width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius); margin: 1rem 0 0; display: block; }

.step-title { display: flex; align-items: center; gap: .6rem; margin: 1.5rem 0 .75rem; font-size: 1.15rem; }
.step-title .num { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .95rem; flex-shrink: 0; }

.product { display: flex; gap: .75rem; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem .9rem; margin-bottom: .6rem; transition: border-color .15s, box-shadow .15s; }
.product.selected { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.product-info { min-width: 0; flex: 1; }
.product-name { font-weight: 700; font-size: 1.02rem; }
.product-desc { color: var(--muted); font-size: .88rem; margin-top: .1rem; }
.product-price { font-weight: 700; color: var(--brand); margin-top: .2rem; }
.product-price .weight-note { font-weight: 500; color: var(--muted); font-size: .8rem; display: block; }

.stepper { display: flex; align-items: center; gap: .15rem; flex-shrink: 0; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid #d3ccc1; background: #fff; font-size: 1.4rem; line-height: 1; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; touch-action: manipulation; }
.stepper button:active { transform: scale(.94); }
.stepper .plus { background: var(--brand); border-color: var(--brand); color: #fff; }
.stepper input { width: 42px; min-height: 44px; text-align: center; font-weight: 700; font-size: 1.1rem; border: 0; background: transparent; padding: 0; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.slot-day { margin-bottom: 1rem; }
.slot-day h3 { font-size: 1rem; margin-bottom: .5rem; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.slot-option { position: relative; }
.slot-option input { position: absolute; opacity: 0; pointer-events: none; }
.slot-option span { display: flex; align-items: center; justify-content: center; min-height: 54px; padding: .5rem; border: 1px solid #d3ccc1; border-radius: 12px; background: #fff; font-weight: 700; cursor: pointer; text-align: center; }
.slot-option input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); box-shadow: 0 0 0 2px var(--brand); }
.slot-option input:focus-visible + span { outline: 3px solid rgba(140,47,43,.35); }

.cart-bar { position: sticky; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(0,0,0,.07); padding: .7rem 0 calc(.7rem + env(safe-area-inset-bottom)); }
.cart-bar .container { display: flex; align-items: center; justify-content: space-between; gap: .75rem; max-width: 640px; }
.cart-summary { line-height: 1.2; }
.cart-summary strong { font-size: 1.2rem; display: block; }
.cart-summary .small { color: var(--muted); }

.summary-list { list-style: none; padding: 0; margin: 0; }
.summary-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.summary-list li:last-child { border-bottom: 0; }
.total-line { display: flex; justify-content: space-between; font-weight: 800; font-size: 1.15rem; padding-top: .6rem; }

.confirm-hero { text-align: center; padding: 1.5rem 0 .5rem; }
.confirm-hero .check-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 2rem; display: inline-flex; align-items: center; justify-content: center; margin-bottom: .75rem; }
.ref { font-size: 1.6rem; font-weight: 800; letter-spacing: .03em; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.empty-state { text-align: center; padding: 3rem 1rem; }
.empty-state .icon { font-size: 2.6rem; margin-bottom: .5rem; }

.site-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 16px 2.5rem; }
.site-footer a { color: var(--muted); }

/* ===================== Back-office ===================== */
.topbar { background: var(--ink); color: #fff; }
.topbar .container { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 56px; }
.topbar a { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 800; letter-spacing: .01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand small { font-weight: 500; opacity: .7; }
.topbar .user { font-size: .85rem; opacity: .85; white-space: nowrap; }
.nav { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.nav ul { list-style: none; margin: 0 auto; padding: 0 8px; display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; max-width: 1100px; }
.nav ul::-webkit-scrollbar { display: none; }
.nav a { display: block; padding: .85rem .75rem; font-weight: 600; font-size: .92rem; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a.active { color: var(--brand); border-bottom-color: var(--brand); }
.demo-banner { background: #1f1d1a; color: #fff; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem 1rem; padding: .5rem 16px; font-size: .9rem; text-align: center; }
.demo-banner a:not(.btn) { color: #fff; }
.impersonate { background: #ffe8a3; color: #5b4300; text-align: center; padding: .45rem 16px; font-size: .9rem; font-weight: 600; }
.impersonate a { color: inherit; }
main.page { padding: 1.25rem 0 3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters > * { flex: 1 1 160px; }
.filters .btn { flex: 0 0 auto; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { padding: .4rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); font-size: .9rem; font-weight: 600; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Tableau responsive : lignes en cartes sur mobile */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: .7rem .75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #faf8f5; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fcfbf9; }
.table tr.inactive td { opacity: .55; }
@media (max-width: 760px) {
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive thead { display: none; }
  .table.responsive { background: none; border: 0; }
  .table.responsive tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .6rem; padding: .5rem .25rem; }
  .table.responsive td { border: 0; padding: .25rem .75rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; font-weight: 500; }
  .table.responsive td.td-main { font-weight: 700; font-size: 1.05rem; }
  .table.responsive td.td-main::before { content: none; }
  .table.responsive td.td-actions { justify-content: flex-start; flex-wrap: wrap; }
  .table.responsive td.td-actions::before { content: none; }
}

.list-item { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }

.status-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; }
.status-buttons .btn.current { background: var(--ink); color: #fff; border-color: var(--ink); }

.qr-box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; display: inline-block; }
.qr-box svg { display: block; width: 220px; height: 220px; }
.url-box { font-family: ui-monospace, monospace; background: #faf8f5; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; word-break: break-all; }

.integration-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; border-style: dashed; box-shadow: none; }

.file-list { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; gap: .5rem; }
.file-list li { display: flex; align-items: center; gap: .6rem; background: #faf8f5; border: 1px solid var(--line); border-radius: 10px; padding: .4rem .5rem; }
.file-list img, .file-list .file-icon { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; background: #fff; }
.file-list .file-name { flex: 1; min-width: 0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem; }
.thumbs a { display: block; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #faf8f5; text-decoration: none; color: inherit; font-size: .8rem; }
.thumbs img { width: 100%; height: 120px; object-fit: cover; display: block; }
.thumbs span { display: block; padding: .3rem .4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Photo produit */
.product-thumb { flex-shrink: 0; width: 64px; height: 64px; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: #eee; cursor: zoom-in; }
.product-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (max-width: 380px) { .product-thumb { width: 52px; height: 52px; } }
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(20,18,16,.88); display: flex; align-items: center; justify-content: center; padding: 20px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 85vh; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.lightbox p { position: absolute; bottom: calc(20px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #fff; font-weight: 600; margin: 0; padding: 0 20px; }

/* Lieux de retrait (commerces ambulants) */
.place-picker { margin-bottom: 1rem; }
.place-question { font-weight: 700; margin-bottom: .5rem; }
.place-options { display: flex; flex-wrap: wrap; gap: .5rem; }
.place-option { min-height: 48px; padding: .55rem 1rem; border-radius: 999px; border: 1px solid #d3ccc1; background: #fff; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; }
.place-option.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.place-single { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; margin-bottom: 1rem; }
.slot-option span { flex-direction: column; line-height: 1.2; }
.slot-place { display: block; font-weight: 500; font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.slot-option input:checked + span .slot-place { color: var(--brand-dark); }

/* Préparation */
.prep-group { break-inside: avoid; }
.prep-slot-title { background: var(--ink); color: #fff; padding: .55rem .9rem; border-radius: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; margin: 1.25rem 0 .6rem; }
.prep-order { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .75rem .9rem; margin-bottom: .55rem; break-inside: avoid; }
.prep-order-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; font-weight: 700; margin-bottom: .35rem; }
.prep-order ul { margin: 0; padding-left: 1.1rem; }
.prep-order li { margin: .1rem 0; }
.prep-total td.qty { font-size: 1.35rem; font-weight: 800; text-align: right; width: 1%; white-space: nowrap; }
.print-only { display: none; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; }

/* ===================== Impression ===================== */
@media print {
  @page { margin: 12mm; }
  body { background: #fff; font-size: 12pt; }
  .no-print, .topbar, .nav, .impersonate, .site-footer, .alert, .filters, .chips, .btn { display: none !important; }
  .print-only { display: block; }
  main.page { padding: 0; }
  .container { max-width: none; padding: 0; }
  .card, .prep-order, .table { box-shadow: none; border-color: #999; }
  .prep-slot-title { background: #fff; color: #000; border: 2px solid #000; }
  .prep-order { page-break-inside: avoid; }
  a { color: #000; text-decoration: none; }
}

/* Marque */
.auth-logo { display: block; text-align: center; margin-bottom: 1.2rem; }
.auth-logo img { height: 34px; width: auto; }
.topbar .brand img { height: 22px; width: auto; vertical-align: middle; }
.powered a { display: inline-flex; align-items: center; gap: .3rem; text-decoration: none; }
.powered img { border-radius: 3px; }

/* PWA */
.pwa-card { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; border-color: var(--brand); }
.pwa-card img { border-radius: 12px; flex-shrink: 0; }
.pwa-card .pwa-text { flex: 1; min-width: 200px; }
.pwa-card .pwa-text p { margin: .2rem 0 0; }
@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }

/* Petits écrans / grande taille de texte : rien ne doit élargir la page */
input, select, textarea { min-width: 0; max-width: 100%; }
.grid > *, .actions > * { min-width: 0; }
.btn { white-space: normal; text-align: center; }
.list-item > div:first-child { min-width: 0; }
