:root {
  --bg: #f4f1ec;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e2ddd5;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181c;
    --card: #1d2329;
    --ink: #eef1f3;
    --muted: #9aa5b1;
    --line: #2d353d;
    --accent: #2dd4bf;
    --accent-ink: #062c28;
    --warn: #fbbf24;
    --danger: #f87171;
    --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.4rem; margin: 8px 0 14px; }
h2 { font-size: 1.1rem; margin: 22px 0 8px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); font-size: .9rem; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: var(--accent-ink);
}
.top a, .top .who { color: var(--accent-ink); }
.brand { font-weight: 700; letter-spacing: .2px; }
.who { font-size: .85rem; opacity: .85; }

main { max-width: 900px; margin: 0 auto; padding: 12px 16px 24px; }
.back { display: inline-block; margin-bottom: 4px; font-size: .95rem; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around; align-items: center;
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a, .tabs .linklike {
  flex: 1; text-align: center; padding: 10px 2px; font-size: .85rem;
  color: var(--ink); border-radius: 10px;
}
.linklike { background: none; border: 0; font: inherit; cursor: pointer; color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.item { display: block; color: inherit; }
.item .t { font-weight: 600; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 0 0 auto; }
.grow { flex: 1 1 auto !important; }

.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }

label { display: block; margin: 10px 0; font-weight: 600; font-size: .92rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit; font-weight: 400;
}
input[type=checkbox] { display: inline-block; width: auto; margin: 0 8px 0 0; }
.card > input[type=search], #q { margin: 0 0 10px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700;
  border: 1px solid var(--line);
}
.badge.en_cours { color: var(--warn); }
.badge.terminee { color: var(--ok); }
.badge.attente_pieces { color: var(--danger); }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }

video { width: 100%; max-height: 60vh; border-radius: 12px; background: #000; object-fit: cover; }
dl { margin: 0; display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; }
dt { color: var(--muted); }
dd { margin: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: 92vw; padding: 12px 16px; border-radius: 12px; font-weight: 600;
  background: var(--ink); color: var(--bg); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }

.login { max-width: 420px; margin: 8vh auto; padding: 0 16px; }

/* Impression : fiche à poser sur la machine, et planche d'étiquettes */
.printonly, #printzone { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .noprint { display: none !important; }
  main { max-width: none; padding: 0; }
  .printonly { display: block; }
  #printzone { display: grid; grid-template-columns: repeat(auto-fill, 40mm); gap: 2mm; }
  .label { width: 40mm; height: 40mm; padding: 2mm; text-align: center; border: .2mm dashed #999; page-break-inside: avoid; }
  .label svg { width: 30mm; height: 30mm; display: block; margin: 0 auto; }
  .label .n { font: 700 4.5mm/1 system-ui, sans-serif; margin-top: 1mm; }
  .fiche { font-family: system-ui, sans-serif; color: #000; }
  .fiche h1 { font-size: 20pt; margin: 0 0 4mm; }
  .fiche .head { display: flex; justify-content: space-between; gap: 8mm; border-bottom: .4mm solid #000; padding-bottom: 4mm; margin-bottom: 4mm; }
  .fiche .head svg { width: 32mm; height: 32mm; }
  .fiche .big { font-size: 26pt; font-weight: 800; }
  .fiche table { width: 100%; border-collapse: collapse; font-size: 10pt; }
  .fiche td, .fiche th { border-bottom: .2mm solid #999; padding: 2mm 1mm; text-align: left; vertical-align: top; }
}
