:root {
  --bg: #faf6f0; --card: #ffffff; --ink: #2a1a12; --muted: #7a6a5f; --line: #eadfd3;
  --choc: #3b2418; --gold: #f4c27a; --accent: #b4541c;
  --labo: #8a5a2b; --cond: #0f766e; --mag: #7c3aed;
  --ok: #15803d; --warn: #c2410c; --bad: #b91c1c;
  --r: 14px; --shadow: 0 1px 2px rgba(60,30,10,.06), 0 4px 14px rgba(60,30,10,.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* En-tête */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--choc); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 170px; }
.brand small { display: block; color: #d9c3b0; font-size: .8rem; }
.logo { width: 38px; height: 38px; border-radius: 10px; background: var(--gold); color: var(--choc); display: grid; place-items: center; font: 700 22px Georgia, serif; }
#tabs { display: flex; gap: 6px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#tabs button { border: 0; background: transparent; color: #e9d9cb; padding: 10px 14px; border-radius: 10px; font-weight: 600; white-space: nowrap; min-height: 46px; }
#tabs button.on { background: var(--gold); color: var(--choc); }
.conn { border: 0; background: rgba(255,255,255,.08); color: #e9d9cb; padding: 8px 12px; border-radius: 10px; display: flex; align-items: center; gap: 8px; font-size: .85rem; min-height: 42px; }
.conn i { width: 10px; height: 10px; border-radius: 50%; background: #999; }
.conn.ok i { background: #4ade80; } .conn.ko i { background: #f87171; }

main { padding: 16px; padding-bottom: 60px; max-width: 1500px; margin: 0 auto; }

/* Blocs */
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); }
.section { margin: 22px 0 10px; display: flex; align-items: baseline; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.section h2 small { font-weight: 400; font-size: .9rem; margin-left: 6px; }
.empty { padding: 22px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--r); background: #fffdf9; }
.banner { padding: 12px 14px; border-radius: var(--r); background: #fff7ed; border: 1px solid #fed7aa; color: #7c2d12; margin-bottom: 14px; }
.banner.info { background: #f0f9ff; border-color: #bae6fd; color: #0c4a6e; }

/* Boutons */
.btn { border: 1px solid var(--line); background: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; min-height: 46px; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn.primary { background: var(--choc); border-color: var(--choc); color: #fff; }
.btn.gold { background: var(--gold); border-color: #e9ad5a; color: var(--choc); }
.btn.green { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.btn.big { min-height: 58px; font-size: 1.05rem; padding: 12px 22px; }
.btn:disabled { opacity: .45; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; min-height: 42px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--choc); color: #fff; border-color: var(--choc); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* Étiquettes d'étape */
.tag { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.t-prevu { background: #f5efe7; color: var(--labo); }
.t-fab { background: #fde68a; color: #78350f; }
.t-acond { background: #ccfbf1; color: #115e59; }
.t-cond { background: #99f6e4; color: #134e4a; }
.t-pret { background: #dcfce7; color: #166534; }
.t-recu { background: #ede9fe; color: #5b21b6; }
.t-retard { background: #fee2e2; color: #991b1b; }

/* Agenda */
.week-nav { display: flex; gap: 8px; align-items: center; }
.week { display: grid; grid-template-columns: 140px repeat(var(--days), minmax(150px, 1fr)); gap: 8px; overflow-x: auto; }
.week .lane-h { font-weight: 700; padding: 10px 6px; overflow-wrap: anywhere; hyphens: auto; display: flex; align-items: flex-start; gap: 6px; font-size: .95rem; }
.week .day-h { text-align: center; padding: 8px 4px; border-radius: 10px; background: #fff; border: 1px solid var(--line); }
.week .day-h b { display: block; font-size: 1.05rem; }
.week .day-h.today { background: var(--choc); color: #fff; border-color: var(--choc); }
.week .day-h.today small { color: #e9d9cb; }
.cell { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px; min-height: 80px; display: flex; flex-direction: column; gap: 6px; }
.cell.add { cursor: pointer; }
.cell.past { opacity: .75; }
.lotchip { text-align: left; border: 0; border-left: 4px solid var(--labo); background: #fbf7f2; border-radius: 8px; padding: 6px 8px; font-size: .85rem; line-height: 1.25; width: 100%; }
.lotchip b { display: block; font-size: .86rem; }
.lotchip.c { border-left-color: var(--cond); background: #f0fdfa; }
.lotchip.m { border-left-color: var(--mag); background: #f5f3ff; }
.gauge { height: 12px; border-radius: 6px; background: #eee6dc; overflow: hidden; position: relative; }
.gauge > i { position: absolute; inset: 0 auto 0 0; background: var(--ok); border-radius: 6px; }
.gauge.warn > i { background: #f59e0b; } .gauge.bad > i { background: var(--bad); }
.gauge-l { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.gauge-l b { color: var(--ink); }

/* Lots (listes) */
.lot { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; }
.thumb { width: 64px; height: 64px; border-radius: 12px; background: #f3ebe1 center/cover no-repeat; display: grid; place-items: center; color: var(--labo); font-weight: 700; font-size: 1.3rem; flex: none; }
.thumb.lg { width: 100%; height: 170px; border-radius: 12px 12px 0 0; font-size: 2.4rem; }
.lot h3 { margin-bottom: 3px; }
.lot .meta { font-size: .88rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.progress { height: 8px; border-radius: 4px; background: #eee6dc; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--cond); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Personnes */
.person { display: flex; gap: 10px; align-items: center; }
.avatar { width: 42px; height: 42px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.stars { color: #d97706; letter-spacing: 1px; font-size: .85rem; }
.working { font-size: .85rem; color: var(--cond); font-weight: 600; }
.away { font-size: .85rem; color: var(--mag); font-weight: 600; }

/* Catalogue */
.prod { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.prod .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.price { font-size: 1.25rem; font-weight: 800; color: var(--choc); }
.stock { font-weight: 700; }

/* Tableaux */
table { border-collapse: collapse; width: 100%; background: #fff; border-radius: var(--r); overflow: hidden; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: .92rem; }
th { background: #f7f1ea; font-size: .82rem; color: var(--muted); font-weight: 700; position: sticky; top: 0; }
.scroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); }
td.c, th.c { text-align: center; }
.cad { border: 0; background: transparent; width: 100%; padding: 6px; border-radius: 8px; text-align: center; }
.cad b { display: block; font-size: 1rem; }
.cad small { font-size: .72rem; }
.src-m b { color: var(--ok); } .src-s b { color: var(--choc); } .src-e b { color: #a8a29e; }
.hcell { border: 1px solid var(--line); background: #fff; border-radius: 8px; min-width: 52px; min-height: 40px; font-weight: 700; }
.hcell.off { color: #c4b5a5; background: #faf7f3; }
.hcell.ovr { border-color: var(--accent); color: var(--accent); }

/* Feuilles (fenêtres) */
.sheet { position: fixed; inset: 0; background: rgba(30,15,5,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card { background: var(--bg); width: min(760px, 100%); max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px 18px calc(22px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0,0,0,.2); }
@media (min-width: 800px) { .sheet { align-items: center; } .sheet-card { border-radius: 20px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.x { border: 0; background: #efe6dc; width: 44px; height: 44px; border-radius: 50%; font-size: 1.3rem; flex: none; }
label.f { display: block; margin: 12px 0 6px; font-weight: 600; font-size: .92rem; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; border: 1px solid #d9cbbd; background: #fff; border-radius: 12px; padding: 12px; min-height: 48px; font-size: 1rem; }
textarea { min-height: 80px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { text-align: center; font-size: 1.3rem; font-weight: 700; max-width: 140px; }
.stepper .btn { min-width: 56px; font-size: 1.2rem; }
.pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; }
.pick button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 0; overflow: hidden; text-align: left; }
.pick button.on { border-color: var(--choc); box-shadow: 0 0 0 2px var(--gold); }
.pick .thumb { width: 100%; height: 70px; border-radius: 0; }
.pick span { display: block; padding: 6px 8px; font-size: .82rem; font-weight: 600; }
.impact { margin-top: 14px; padding: 12px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .95rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.step { border-radius: 12px; padding: 10px; background: #fff; border: 1px solid var(--line); }
.step.done { background: #f0fdf4; border-color: #bbf7d0; }
.step.now { background: #fffbeb; border-color: #fcd34d; }
.step h4 { margin: 0 0 4px; font-size: .9rem; }
.journal li { padding: 8px 0; border-bottom: 1px solid var(--line); list-style: none; font-size: .92rem; }
.journal { padding: 0; margin: 0; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--choc); color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 80; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--bad); }

/* Connexion */
.login { max-width: 420px; margin: 10vh auto; text-align: center; }
.login .logo { width: 72px; height: 72px; font-size: 42px; margin: 0 auto 14px; border-radius: 18px; }
.login input { text-align: center; font-size: 1.3rem; margin: 16px 0; }
.services { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 16px; }
.services button { min-height: 90px; font-size: 1.05rem; }

/* Pavé de code */
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 18px 0; }
.pin-dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--choc); }
.pin-dots i.on { background: var(--choc); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 320px; margin: 0 auto; }
.keypad .btn { min-height: 68px; font-size: 1.5rem; }
.keypad [data-key=back], .keypad [data-key=del] { font-size: 1rem; }
[hidden] { display: none !important; }

/* Synthèse imprimable : gros caractères, lisible de loin */
.pdoc { background: #fff; color: #000; border: 1px solid var(--line); border-radius: var(--r); padding: 28px; font-size: 18px; line-height: 1.35; }
.phead { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #000; padding-bottom: 12px; margin-bottom: 10px; }
.pbrand { font-size: 15px; letter-spacing: .04em; text-transform: uppercase; }
.pdoc h1 { font-size: 34px; margin: 4px 0; }
.pper { font-size: 22px; font-weight: 700; }
.pstamp { text-align: right; font-size: 15px; }
.pstamp b { font-size: 18px; }
.psec { margin-top: 26px !important; border-bottom: 2px solid #000; }
.pblock { margin: 18px 0 8px; break-inside: avoid-page; }
.pday { font-size: 24px; margin: 0 0 8px; }
.pday::first-letter { text-transform: uppercase; }
.pday small { font-size: 18px; font-weight: 400; }
.pdoc h3 { font-size: 20px; margin: 12px 0 6px; }
.ptab { width: 100%; border-collapse: collapse; border-radius: 0; font-size: 18px; }
.ptab th { background: #eee; color: #000; font-size: 15px; position: static; border: 1.5px solid #000; padding: 6px 8px; }
.ptab td { border: 1.5px solid #000; padding: 8px; font-size: 18px; vertical-align: middle; }
.ptab tr { break-inside: avoid; }
.ptab td.c { text-align: center; width: 1%; white-space: nowrap; }
.pbox { display: inline-block; width: 24px; height: 24px; border: 2.5px solid #000; border-radius: 4px; }
.pline { display: inline-block; min-width: 110px; border-bottom: 1.5px dotted #000; height: 1em; }
.pnote { font-size: 15px; font-style: italic; margin-top: 2px; }
.pimg { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; display: block; }
.pcharge { font-size: 18px; margin: 8px 0; padding: 8px 10px; border: 1.5px solid #000; }
.pcharge.over { border-width: 3px; font-weight: 700; }
.pteam { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0; }
.pnone { font-style: italic; }
.palert { border: 3px solid #000; padding: 10px 14px; }
.palert ul { margin: 0; padding-left: 22px; }
.pfoot { margin-top: 22px; border-top: 1.5px solid #000; padding-top: 8px; font-size: 14px; }

@media print {
  @page { size: A4; margin: 12mm; }
  .top, .noprint, .sheet, .toast { display: none !important; }
  html, body { background: #fff; }
  main { padding: 0; max-width: none; }
  .pdoc { border: 0; padding: 0; border-radius: 0; }
  .pbreak { break-before: page; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 1250px) {
  .top { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .brand { min-width: 0; }
  .brand > div { display: none; }
  #tabs button { padding: 10px 10px; }
  .conn { padding: 8px 10px; }
  .wide { display: none; }
}
