/* ===== Stock Camion – Pobrun =====
   Style « outil de chantier » : plat, bordures franches, pas d'ombres ni de dégradés.
   Bleu nuit + cyan du logo Pobrun (#009DE0). Barlow (signalétique routière) pour le texte,
   Barlow Condensed pour les titres, étiquettes et quantités. */
:root {
  --night: #0b1e33;
  --night-2: #13304f;
  --cyan: #009de0;
  --blue: #0a6fc2;
  --blue-soft: #e3f1fb;

  --bg: #eef1f4;
  --card: #ffffff;
  --card-2: #f4f6f8;
  --text: #0d1824;
  --muted: #56657a;
  --line: #d8dee6;
  --input: #ffffff;
  --input-line: #b9c4d1;
  --primary: var(--blue);
  --primary-text: #ffffff;
  --low: #f59e0b;
  --low-soft: #fff4e0;
  --low-text: #8a4f00;
  --ok: #14a35a;
  --ok-soft: #e4f6ec;
  --ok-text: #0c6b3a;
  --danger: #d0342c;
  --danger-soft: #fdecea;
  --shadow: none;
  --shadow-lg: 0 8px 28px rgb(11 30 51 / .25);
  --radius: 6px;
  --r-sm: 6px;
  --cond: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --head-h: 60px;
  --tabbar-h: 68px;
  color-scheme: light;
}
/* thème sombre : réglage du téléphone (Auto) ou choix forcé dans Plus › Apparence */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09121d;
    --card: #101b28;
    --card-2: #162333;
    --text: #e6edf4;
    --muted: #8d9db1;
    --line: #22324a;
    --input: #0b1520;
    --input-line: #33465f;
    --primary: #2b9be6;
    --primary-text: #ffffff;
    --blue-soft: #10314d;
    --low-soft: #3a2a0d;
    --low-text: #fbc56a;
    --ok-soft: #0f3221;
    --ok-text: #6fdc9e;
    --danger: #ff6b61;
    --danger-soft: #3a1714;
    --shadow: none;
    --shadow-lg: 0 12px 40px rgb(0 0 0 / .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #09121d;
    --card: #101b28;
    --card-2: #162333;
    --text: #e6edf4;
    --muted: #8d9db1;
    --line: #22324a;
    --input: #0b1520;
    --input-line: #33465f;
    --primary: #2b9be6;
    --primary-text: #ffffff;
    --blue-soft: #10314d;
    --low-soft: #3a2a0d;
    --low-text: #fbc56a;
    --ok-soft: #0f3221;
    --ok-text: #6fdc9e;
    --danger: #ff6b61;
    --danger-soft: #3a1714;
    --shadow: none;
    --shadow-lg: 0 12px 40px rgb(0 0 0 / .6);
    color-scheme: dark;
  }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Pas de zoom au double toucher (appli plein écran sur téléphone) */
html { touch-action: manipulation; }
html, body { margin: 0; }
/* iPhone (appli installée, contenu sous la barre d'état) : sans ça, une page plus courte que l'écran
   laisse une bande vide sous la barre d'onglets, de la hauteur de la barre d'état. */
html { background: var(--bg); min-height: calc(100% + env(safe-area-inset-top)); }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 Barlow, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ----- En-tête bleu nuit ----- */
header#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  height: calc(var(--head-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--night); color: #fff;
  border-bottom: 3px solid var(--cyan);
}
header .brand { height: 32px; width: auto; flex: 0 0 auto; display: block; }
header .brand.dark { display: none; }
header h1 {
  font-family: var(--cond); font-size: 20px; font-weight: 700; line-height: 1.1; margin: 0; flex: 1; min-width: 0;
  text-transform: uppercase; letter-spacing: .02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
header h1::before {
  content: "Pobrun · Stock"; display: block; font-size: 12px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--cyan);
}
header select {
  margin-left: auto; max-width: 62%; width: auto; min-height: 40px; padding: 6px 34px 6px 12px;
  background: var(--night-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23ffffff' stroke-width='2'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: #fff; border: 1px solid #2a4a6e; font-weight: 600; min-height: 38px; appearance: none; -webkit-appearance: none;
}
header select:focus { border-color: var(--cyan); box-shadow: none; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
h2 {
  font-family: var(--cond); font-size: 28px; font-weight: 700; line-height: 1.05;
  text-transform: uppercase; letter-spacing: .01em; margin: 8px 0 16px;
}
h2 small { font-weight: 600; color: var(--muted); font-size: .65em; text-transform: none; letter-spacing: 0; }
h3 {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--cond); font-size: 14px; font-weight: 700; margin: 28px 0 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .1em;
}
h3::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
p.muted, .muted { color: var(--muted); }
small { color: var(--muted); }
a { color: var(--primary); }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .9em; }

/* ----- Champs ----- */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--input-line); background: var(--input);
  min-height: 50px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary);
}
input[type="search"] { -webkit-appearance: none; appearance: none; }
/* Safari impose une largeur mini aux champs date : ils débordaient de l'écran */
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; text-align: left; padding-left: 12px; padding-right: 8px; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="file"] { padding: 10px; font-size: 14px; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
label { display: block; font-family: var(--cond); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }

/* ----- Boutons ----- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 50px; padding: 10px 18px; border-radius: var(--r-sm);
  border: 1px solid var(--input-line); background: var(--card); color: var(--text);
  font-family: var(--cond); font-weight: 600; font-size: 17px; line-height: 1.1;
  text-transform: uppercase; letter-spacing: .04em; cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s, filter .12s;
}
button:active { background: var(--card-2); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.primary:active { filter: brightness(.88); }
button.danger { color: var(--danger); border-color: currentColor; background: transparent; }
button.danger:active { background: var(--danger-soft); }
button.small { min-height: 40px; padding: 6px 12px; font-size: 15px; }
button.block { width: 100%; }
button:disabled { opacity: .45; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row > .shrink { flex: 0 0 auto; }
.row > * { min-width: 0; }
.stack > * + * { margin-top: 10px; }
.stack > label + * { margin-top: 0; }

/* ----- Cartes et listes ----- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--line);
}
.list {
  list-style: none; margin: 0; padding: 0; background: var(--card);
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line);
}
.list > li {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; min-height: 68px;
}
.list > li + li::after {
  content: ""; position: absolute; top: 0; right: 0; left: 0; border-top: 1px solid var(--line);
}
.list > li.group + li::after, .list > li.group::after { display: none; }
.list > li.tap { cursor: pointer; transition: background .12s; }
.list > li.tap:active { background: var(--card-2); }
.list > li .grow { flex: 1; min-width: 0; text-wrap: pretty; }
.list > li .name { overflow-wrap: anywhere; font-weight: 600; }
.list > li.group {
  min-height: 0; gap: 10px; padding: 10px 14px; background: var(--card-2);
  font-family: var(--cond); font-size: 17px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.list > li.group .gi {
  flex: 0 0 32px; width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 4px; background: var(--primary); color: #fff;
}
.list > li.group .gi svg { width: 19px; height: 19px; }
.list > li.group .gname { flex: 1; min-width: 0; overflow-wrap: anywhere; }
/* Bandeau repliable : chevron qui pivote */
.list > li.group.fold { cursor: pointer; user-select: none; }
.list > li.group.fold:active { filter: brightness(.97); }
.list > li.group .chev {
  flex: 0 0 auto; width: 10px; height: 10px; margin: 0 4px 0 6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px); transition: transform .15s;
}
.list > li.group[aria-expanded="false"] .chev { transform: rotate(-45deg); }
.list > li.group[aria-expanded="false"] { border-bottom-color: transparent; }
.list > li[hidden] { display: none; }
.list > li.group .gmore { font-size: 22px; color: var(--muted); font-family: Barlow, sans-serif; margin-left: 4px; }
.list > li.more { min-height: 50px; color: var(--primary); font-weight: 600; }
.list > li.more > :last-child { font-size: 22px; }
.back { display: inline-flex; align-items: center; min-height: 44px; margin: -6px 0 2px; padding: 0 12px 0 0; font-weight: 600; text-decoration: none; }
.cat-title { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.cat-title .gi { flex: 0 0 40px; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 4px; background: var(--primary); color: #fff; }
.warn-text { color: var(--low-text); }
main[data-page="cat"] .search { margin-top: 0; }
.list > li.group .gn {
  font-size: 14px; font-weight: 600; letter-spacing: .02em; color: var(--muted);
  font-family: Barlow, system-ui, sans-serif; text-transform: none;
}
.list > li.group:first-child { border-top: 0; }
.list > li.low { background: var(--low-soft); }
.list > li.low::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--low); }
/* « ›» en bout de ligne (historique, menu) */
.list > li.tap > :last-child:not(.qty):not(.grow):not(.pill):not(.mv-delta):not(.in-truck):not(.add-truck) { color: var(--muted); font-size: 22px; }
.list > li[data-go] { color: var(--muted); font-size: 22px; }
.list > li[data-go] .grow { color: var(--text); font-size: 16px; font-weight: 600; }

.qty {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; line-height: 1;
  font-family: var(--cond); font-weight: 700; font-size: 28px; font-variant-numeric: tabular-nums; white-space: nowrap;
  min-width: 52px; color: var(--ok-text);
}
.qty small { font-weight: 600; font-size: 14px; margin-top: 2px; color: var(--muted); }
.list > li.low .qty { color: var(--low-text); }
.pill {
  display: inline-block; font-family: var(--cond); font-size: 13px; font-weight: 700; line-height: 1.4; padding: 0 6px;
  border-radius: 3px; background: var(--low); color: #2e1a00; white-space: nowrap;
  text-transform: uppercase; letter-spacing: .05em; vertical-align: 1px; margin-left: 4px;
}
/* Jauge de remplissage sous le nom */
.bar { display: block; height: 4px; background: var(--line); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.low .bar > i { background: var(--low); }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.list > li.empty { justify-content: center; }

/* Vignettes photo des articles */
.thumb {
  flex: 0 0 48px; width: 48px; height: 48px; border-radius: 4px; overflow: hidden;
  background: #fff; display: grid; place-items: center; border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; padding: 3px; }
.thumb.empty {
  background: var(--blue-soft); color: var(--primary); font-family: var(--cond); font-weight: 700; font-size: 20px; padding: 0; border: 0;
}
.photo {
  display: block; width: 100%; max-height: 220px; object-fit: contain; background: #fff;
  border-radius: var(--r-sm); margin: 4px 0 6px; padding: 8px; border: 1px solid var(--line);
}

/* Puces de catégories */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 14px 0; margin: 0 -16px 0 0;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 40px; padding: 6px 12px; border-radius: 4px;
  font-size: 15px; white-space: nowrap; background: var(--card); border: 1px solid var(--input-line);
}
.chip small { margin-left: 2px; color: inherit; opacity: .6; font-weight: 700; }
.chip.on { background: var(--night); border-color: var(--night); color: #fff; }
/* thème sombre : réglage du téléphone (Auto) ou choix forcé dans Plus › Apparence */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip.on { background: var(--primary); border-color: var(--primary); }
}
:root[data-theme="dark"] .chip.on { background: var(--primary); border-color: var(--primary); }

/* Choix à boutons collés (thème) */
.segmented { display: flex; border: 1px solid var(--input-line); border-radius: var(--r-sm); overflow: hidden; background: var(--card); }
.segmented button { flex: 1; min-width: 0; border: 0; border-radius: 0; background: transparent; padding: 10px 6px; }
.segmented button + button { border-left: 1px solid var(--input-line); }
.segmented button[aria-checked="true"] { background: var(--primary); color: var(--primary-text); }

.segmented a {
  flex: 1; min-width: 0; display: grid; place-items: center; min-height: 44px; padding: 6px; text-align: center; text-decoration: none;
  font-family: var(--cond); font-size: 16px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text);
}
.segmented a + a { border-left: 1px solid var(--input-line); }
.segmented a[aria-current="page"] { background: var(--primary); color: var(--primary-text); }
.hist-tabs { margin: -4px 0 16px; }

/* Aperçu du message (fin de chantier, PC) : titre + petit bouton Copier */
.preview-head { display: flex; align-items: center; gap: 10px; }
.preview-head h3 { flex: 1; }
.copy-btn { flex: 0 0 auto; gap: 6px; min-height: 32px; padding: 4px 10px; font-size: 14px; }
@media (min-width: 1024px) { .preview-head { margin: 18px 0 8px; } .preview-head h3 { margin: 0; } }

/* Catalogue */
.catalog .in-truck {
  flex: 0 0 auto; min-width: 52px; text-align: right; line-height: 1;
  font-family: var(--cond); font-size: 22px; font-weight: 700; color: var(--ok-text);
}
.catalog .in-truck small { display: block; margin-top: 2px; font-family: Barlow, sans-serif; font-size: 12px; font-weight: 500; color: var(--muted); }
.catalog .add-truck {
  flex: 0 0 36px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 4px;
  border: 1px solid var(--input-line); color: var(--primary); font-size: 22px;
}
.catalog .where { display: block; margin-top: 2px; font-weight: 500; color: var(--muted); }
.catalog .in-truck small { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.where-line { margin: 6px 0 0; font-size: 15px; }
.cat-line { display: flex; align-items: center; gap: 8px; margin: 4px 0 0; font-weight: 600; }
.cat-line .gi { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 4px; background: var(--primary); color: #fff; }
.cat-line .gi svg { width: 17px; height: 17px; }

/* Mouvements de stock */
.moves > li { min-height: 60px; }
.moves > li.group.day { text-transform: none; letter-spacing: .02em; font-size: 16px; padding: 8px 14px; }
.moves > li.group.day::first-letter { text-transform: uppercase; }
.moves .name { display: block; font-weight: 600; }
.moves small { display: block; }
.mv-delta {
  flex: 0 0 auto; min-width: 56px; text-align: right; line-height: 1;
  font-family: var(--cond); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.mv-delta small { margin-top: 3px; font-family: Barlow, sans-serif; font-size: 12px; font-weight: 500; color: var(--muted); }
.mv-delta.plus { color: var(--ok-text); }
.mv-delta.minus { color: var(--danger); }
.mv-delta.zero { color: var(--muted); font-size: 18px; }
.mv-ico {
  flex: 0 0 36px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 4px;
  font-family: var(--cond); font-size: 22px; font-weight: 700; background: var(--card-2); color: var(--muted);
}
.mv-ico.plus { background: var(--ok-soft); color: var(--ok-text); }
.mv-ico.minus { background: var(--danger-soft); color: var(--danger); }
.item-filter { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.item-filter .btn { flex: 0 0 auto; }
.item-filter .grow { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 380px) { .item-filter { flex-wrap: wrap; } .item-filter .btn { flex: 1 0 100%; } }
.hist-link { display: inline-block; margin: 2px 0 4px; font-weight: 600; text-decoration: none; }
main[data-page="historique"] .search { margin-top: 0; position: static; padding: 0 0 12px; margin-left: 0; margin-right: 0; background: none; }

.order {
  flex: 0 0 auto; min-width: 34px; text-align: center; font-family: var(--cond); font-weight: 700; font-size: 15px;
  padding: 4px 6px; border-radius: 3px; background: var(--card-2); color: var(--muted);
}

.search {
  position: sticky; top: calc(var(--head-h) + env(safe-area-inset-top)); z-index: 4;
  background: var(--bg); margin: -16px -16px 0; padding: 14px 16px 12px;
}
.search input {
  padding-left: 44px;
  background: var(--input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%235b6b7e' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='9' cy='9' r='6'/%3E%3Cpath d='M14 14l4 4'/%3E%3C/svg%3E") no-repeat 14px center;
}
.search input:focus { border-color: var(--primary); }
.search button.primary { width: 50px; padding: 0; font-size: 28px; font-weight: 500; }
.suggest { margin-top: 8px; }
.suggest li { cursor: pointer; min-height: 60px; }
.suggest li:first-child:not(.group) { background: var(--blue-soft); }

/* ----- Fin de chantier : deux origines (camion / apporté) ----- */
.source { margin-top: 8px; padding-left: 12px; border-left: 4px solid var(--primary); }
.source.other { border-left-color: var(--ok); }
.source h3 { margin-top: 22px; margin-bottom: 2px; color: var(--text); }
.source h3 .count {
  order: 2; font-size: 14px; min-width: 24px; padding: 1px 6px; border-radius: 3px; text-align: center; letter-spacing: 0;
  background: var(--primary); color: var(--primary-text);
}
.source.other h3 .count { background: var(--ok); color: #fff; }
.source h3::after { order: 1; }
.source .hint { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.source .lines { margin-top: 10px; }
.lines > li { min-height: 64px; padding: 8px 10px; gap: 10px; }
.lines .thumb { flex-basis: 40px; width: 40px; height: 40px; }
.lines .name { display: block; font-weight: 600; line-height: 1.25; }
.lines .info { display: block; margin-top: 2px; }
.lines > li.over { background: var(--low-soft); }
.lines > li.over::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--low); }
.over-msg { color: var(--low-text); font-weight: 700; }
.stepper { flex: 0 0 auto; display: flex; align-items: stretch; height: 44px; border: 1px solid var(--input-line); border-radius: var(--r-sm); overflow: hidden; }
.stepper button {
  min-height: 0; width: 38px; padding: 0; border: 0; border-radius: 0; background: var(--card-2);
  font-family: inherit; font-size: 22px; font-weight: 500; color: var(--primary);
}
.stepper input {
  width: 42px; min-height: 0; padding: 0; border: 0; border-radius: 0; text-align: center;
  border-left: 1px solid var(--input-line); border-right: 1px solid var(--input-line);
  font-family: var(--cond); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.stepper input:focus { box-shadow: inset 0 0 0 2px var(--primary); }
@media (max-width: 359px) { .lines .thumb { display: none; } }
.suggest li.off { opacity: .5; }
.suggest li.free .grow { font-weight: 600; }
.source .suggest { margin-top: 6px; max-height: 320px; overflow-y: auto; }
.source .suggest li:first-child:not(.group) { background: none; }

pre.message {
  white-space: pre-wrap; background: var(--card); border-radius: var(--radius);
  padding: 16px 16px 16px 20px; margin: 0 0 16px; border: 1px solid var(--line);
  border-left: 4px solid var(--cyan);
  font: 500 15px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
}

/* ----- Barre d'onglets ----- */
nav#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 6px 4px env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
/* prolonge la barre sous le bord de l'écran : pas de bande de fond si iOS décale la page */
nav#tabbar::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 120px; background: inherit; }
nav#tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-family: var(--cond); font-size: 13px; font-weight: 600; line-height: 1.1;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-decoration: none;
}
nav#tabbar a svg { width: 26px; height: 26px; }
/* 6 onglets sur téléphone : libellés un peu plus serrés pour tenir dès 320 px */
@media (max-width: 1023px) {
  nav#tabbar { padding-left: 0; padding-right: 0; }
  nav#tabbar a { font-size: 12px; letter-spacing: 0; min-width: 0; white-space: nowrap; }
}
@media (max-width: 359px) { nav#tabbar a { font-size: 11px; } nav#tabbar a svg { width: 24px; height: 24px; } }
nav#tabbar a.active { color: var(--primary); }
nav#tabbar a.active::before {
  content: ""; position: absolute; top: -7px; left: 22%; right: 22%; height: 3px; background: var(--cyan);
}
#badge {
  position: absolute; top: 0; left: 50%; margin-left: 8px;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 3px;
  background: var(--low); color: #2e1a00; font-size: 14px; font-weight: 700; line-height: 20px; text-align: center;
  letter-spacing: 0;
}

/* ----- Toast ----- */
#toast {
  position: fixed; left: 16px; right: 16px; top: calc(var(--head-h) + 10px + env(safe-area-inset-top));
  z-index: 20; max-width: 480px; margin: 0 auto;
  background: var(--night); color: #fff; padding: 13px 16px; border-radius: var(--r-sm);
  border-left: 4px solid var(--cyan); font-weight: 600; box-shadow: var(--shadow-lg);
}
#toast.error { background: var(--danger); border-left-color: #fff; }

/* ----- Connexion ----- */
body:has(.login) {
  background: var(--night);
  min-height: 100dvh; padding-top: env(safe-area-inset-top);
}
.login {
  max-width: 400px; margin: max(5vh, 24px) auto 0; padding: 28px 22px 24px; border: 0; border-top: 4px solid var(--cyan);
}
.login .logo { display: block; height: 72px; width: auto; margin: 0 auto 14px; }
.login .logo.light { display: none; }
/* thème sombre : réglage du téléphone (Auto) ou choix forcé dans Plus › Apparence */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .login .logo.dark { display: none; }
  :root:not([data-theme="light"]) .login .logo.light { display: block; }
}
:root[data-theme="dark"] .login .logo.dark { display: none; }
:root[data-theme="dark"] .login .logo.light { display: block; }
.login-help { font-size: 14px; line-height: 1.45; margin: 12px 0 0; padding: 10px 12px; border-left: 4px solid var(--low); background: var(--low-soft); color: var(--text); }
.login h1 { text-align: center; margin: 0; font-family: var(--cond); font-size: 30px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }

/* ----- Dialogues (feuille qui monte du bas sur téléphone) -----
   Le contenu (.dlg-body) défile ; la barre de boutons (.actions) reste toujours visible en bas. */
dialog {
  border: 0; border-radius: 8px; padding: 0; width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px); overflow: hidden;
  background: var(--card); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog[open] { display: flex; flex-direction: column; animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
dialog::backdrop { background: rgb(8 17 29 / .6); }
/* le défilement de la fenêtre ne se propage jamais à la page */
dialog { overscroll-behavior: contain; }
dialog:focus { outline: none; }
dialog > form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.dlg-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 22px 20px 18px; }
dialog h2 { margin-top: 0; font-size: 24px; overflow-wrap: anywhere; }
dialog .actions {
  flex: 0 0 auto; display: flex; gap: 10px; flex-wrap: wrap; margin: 0;
  padding: 12px 20px 16px; border-top: 1px solid var(--line); background: var(--card);
}
dialog .actions > * { flex: 1 1 0; min-width: 0; }
@media (max-width: 520px) {
  dialog {
    margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 10px 10px 0 0; border-top: 3px solid var(--cyan);
    /* la feuille ne monte jamais sous la barre d'état de l'iPhone */
    max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
  }
  dialog::before {
    content: ""; flex: 0 0 auto; display: block; width: 36px; height: 4px; border-radius: 2px;
    background: var(--input-line); margin: 8px auto 0;
  }
  .dlg-body { padding: 14px 16px 16px; }
  dialog .actions { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); gap: 8px; }
  /* trois boutons (Annuler / Supprimer / Enregistrer) : texte sur deux lignes plutôt que coupé */
  dialog .actions button { padding-left: 6px; padding-right: 6px; white-space: normal; letter-spacing: .01em; font-size: 16px; }
}

/* Fenêtre « Ajouter au camion » : seule la liste défile, recherche et puces restent en haut */
dialog.picker { height: min(720px, calc(100dvh - 32px)); }
@media (max-width: 520px) { dialog.picker { height: calc(100dvh - env(safe-area-inset-top) - 12px); } }
.picker-body { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
dialog.picker .chips-slot { margin-top: 12px; }
dialog.picker .chips { margin-right: -20px; padding-bottom: 8px; }
@media (max-width: 520px) { dialog.picker .chips { margin-right: -16px; } }
dialog.picker .suggest { flex: 1; min-height: 0; overflow-y: auto; margin-top: 4px; margin-bottom: 12px; }
dialog.picker .suggest li:first-child:not(.group) { background: none; }
dialog.picker .list > li.group { position: sticky; top: 0; z-index: 1; }

/* ----- Fiche article : choix de la photo, quantités par camion ----- */
dialog.item-dlg { width: min(640px, calc(100vw - 24px)); }
@media (max-width: 520px) { dialog.item-dlg { width: 100vw; } }
/* Photo : vignette à gauche, suggestions et état à droite, boutons dessous (téléphone) ou à droite (PC) */
.img-pick {
  display: grid; grid-template-columns: 96px minmax(0, 1fr); column-gap: 12px; align-items: start;
  grid-template-areas: "now results" "now status" "actions actions" "url url";
}
.img-side { display: contents; }
.img-now {
  grid-area: now; width: 96px; height: 96px; display: grid; place-items: center; overflow: hidden;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm);
}
.img-now img { width: 100%; height: 100%; object-fit: contain; padding: 5px; }
.img-now span { font-size: 12px; color: #6b7a8c; text-align: center; padding: 6px; }
.img-results {
  grid-area: results; display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 6px;
  max-height: 132px; overflow-y: auto; margin-bottom: 6px;
}
.img-sugg { min-height: 0; height: 60px; padding: 0; background: #fff; border: 2px solid var(--line); border-radius: 4px; overflow: hidden; }
.img-sugg img { width: 100%; height: 100%; object-fit: contain; }
.img-sugg.on { border-color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.img-status { grid-area: status; align-self: center; font-size: 13px; line-height: 1.35; margin: 0; }
.img-status.err { color: var(--danger); }
.img-actions { grid-area: actions; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.img-actions .btn, .img-actions button { min-height: 40px; padding: 6px 6px; font-size: 14px; letter-spacing: .02em; }
.img-url { grid-area: url; margin-top: 8px; gap: 6px; }
.img-url input { min-height: 40px; padding: 8px 10px; }
@media (min-width: 521px) {
  .img-pick { grid-template-columns: 120px minmax(0, 1fr); grid-template-areas: "now results" "now status" "now actions" "now url"; }
  .img-now { width: 120px; height: 120px; }
  .img-results { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); max-height: 236px; }
  .img-sugg { height: 72px; }
  .img-status { align-self: start; margin-bottom: 4px; }
  .img-actions { margin-top: 6px; }
}
.trucks-qty > li { min-height: 54px; padding: 6px 12px; }
.trucks-qty input { flex: 0 0 76px; width: 76px; min-height: 40px; padding: 6px 8px; text-align: center; font-family: var(--cond); font-size: 20px; font-weight: 700; }

/* ----- Arbre du camion : familles de matériel qui poussent du toit ----- */
.truck-tree { max-width: 440px; margin: 2px auto 4px; }
.fams { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 8px; }
.fam {
  flex-direction: column; gap: 2px; min-height: 0; padding: 10px 1px 8px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--input-line); border-top-width: 3px;
  font-family: inherit; font-size: 13px; text-transform: none; letter-spacing: 0;
  line-height: 1.2; text-align: center; min-width: 0;
}
.fam .ico {
  position: relative; display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 2px;
  color: var(--primary);
}
.fam .fname { font-family: var(--cond); font-weight: 700; font-size: 15px; text-transform: uppercase; letter-spacing: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fam small { font-size: 13px; font-weight: 500; }
.fam .dot {
  position: absolute; top: -2px; right: -10px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 3px;
  background: var(--low); color: #2e1a00; font-family: var(--cond); font-size: 14px; font-weight: 700; line-height: 20px;
}
.fam.none { opacity: .55; }
.fam.on { background: var(--night); border-color: var(--night); border-top-color: var(--cyan); color: #fff; }
.fam.on small { color: #9fb3c8; }
.fam.on .ico { color: var(--cyan); }
/* thème sombre : réglage du téléphone (Auto) ou choix forcé dans Plus › Apparence */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .fam.on { background: #0f2a47; border-color: var(--cyan); }
}
:root[data-theme="dark"] .fam.on { background: #0f2a47; border-color: var(--cyan); }
.branches { display: block; width: 100%; height: 46px; overflow: visible; }
.branches path {
  fill: none; stroke: var(--input-line); stroke-width: 2; stroke-linecap: square;
  vector-effect: non-scaling-stroke; transition: stroke .2s;
}
.branches path.trunk { stroke-width: 3; }
.branches path.on { stroke: var(--cyan); stroke-width: 3; }
/* le toit du camion arrive sous le tronc */
.van { display: block; width: 100%; height: auto; position: relative; }
/* ligne de sol sous les roues */
.truck-tree::after { content: ""; display: block; height: 0; margin: 0 4%; border-top: 2px solid var(--input-line); }
/* Sur téléphone, seule la recherche reste en haut (la barre de catégories défile) */
.toolbar { display: contents; }
.stock-main .search { margin-top: 0; }
.hint-edit { font-size: 13px; margin-top: 10px; }
.summary, .job-preview { display: none; }
/* libellé cliquable dans une ligne de liste (À remettre) : pas le style des étiquettes de champ */
.list label { font-family: inherit; text-transform: none; letter-spacing: 0; font-weight: 600; }
.model-thumb { flex: 0 0 72px; width: 72px; height: 32px; object-fit: contain; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* =====================================================================
   PC (écran large) : barre latérale à gauche, pages en colonnes.
   Le téléphone n'est pas concerné (tout ce qui précède reste valable).
   ===================================================================== */
@media (min-width: 1024px) {
  :root { --side-w: 232px; --head-h: 64px; }
  body { padding-bottom: 40px; padding-left: var(--side-w); }
  /* écran de connexion : pas de menu à gauche, donc pas de place réservée */
  body:has(.login) { padding-left: 0; }
  body:has(.login) main { margin: 0 auto; }
  header#topbar { margin-left: calc(-1 * var(--side-w)); padding: 0 28px 0 20px; }
  header .brand { height: 36px; }
  header h1 { font-size: 22px; }

  /* Onglets -> navigation verticale */
  nav#tabbar {
    top: calc(var(--head-h) + 3px); bottom: 0; right: auto; width: var(--side-w); height: auto;
    display: flex; flex-direction: column; gap: 4px; padding: 20px 12px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  nav#tabbar::after { display: none; }
  nav#tabbar a {
    flex-direction: row; justify-content: flex-start; gap: 14px; height: 50px; padding: 0 14px;
    border-radius: var(--r-sm); font-size: 17px; letter-spacing: .05em;
  }
  nav#tabbar a:hover { background: var(--card-2); color: var(--text); }
  nav#tabbar a.active { background: var(--blue-soft); color: var(--primary); }
  nav#tabbar a.active::before { top: 10px; bottom: 10px; left: 0; right: auto; width: 3px; height: auto; }
  nav#tabbar a[data-tab="plus"] { margin-top: auto; }
  #badge { position: static; margin-left: auto; }

  main { max-width: 1440px; padding: 28px 40px; }
  main:not([data-page="stock"]):not([data-page="chantier"]):not([data-page="job"]) { max-width: 960px; }
  h2 { font-size: 34px; margin: 0 0 22px; }
  .list > li.tap:hover, .suggest li:hover { background: var(--card-2); }
  button:hover:not(:disabled) { filter: brightness(1.06); }
  #toast { left: calc(var(--side-w) + 16px); }

  /* Camion : camion + résumé à gauche (fixe au défilement), stock à droite */
  .stock-layout { display: grid; grid-template-columns: minmax(320px, 440px) minmax(0, 1fr); gap: 36px; align-items: start; }
  .stock-side { position: sticky; top: calc(var(--head-h) + 3px + 28px); }
  .truck-tree { max-width: none; margin: 0; }
  .summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 22px; }
  .summary .stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 12px 10px; }
  .summary .stat b { display: block; font-family: var(--cond); font-size: 32px; font-weight: 700; line-height: 1; }
  .summary .stat span { font-size: 13px; color: var(--muted); }
  .summary .stat.warn { border-left: 4px solid var(--low); }
  .summary .stat.warn b { color: var(--low-text); }
  .summary .stat.ok b { color: var(--ok-text); }
  .summary .btn { grid-column: 1 / -1; }
  /* Recherche + catégories restent ensemble en haut : rien ne passe à moitié dessous */
  .toolbar {
    display: block; position: sticky; top: calc(var(--head-h) + 3px); z-index: 4;
    background: var(--bg); margin: -28px 0 0; padding: 28px 0 0;
  }
  .stock-main .search { position: static; margin: 0; padding: 0 0 12px; }
  .stock-main .chips { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0 0 14px; }
  .stock-main .list > li:not(.group) { min-height: 64px; padding: 8px 18px; }
  .stock-main .list > li.group { padding: 12px 18px; }
  .stock-main .list .bar { max-width: 340px; }

  /* Fin de chantier : les deux origines côte à côte, infos et validation à droite */
  .job-layout {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 340px;
    grid-template-rows: auto 1fr; column-gap: 28px; align-items: start;
  }
  .job-layout > .source { grid-row: 1 / span 2; margin-top: 0; }
  .job-layout > .source[data-src="truck"] { grid-column: 1; }
  .job-layout > .source.other { grid-column: 2; }
  .job-layout > .source h3 { margin-top: 0; }
  .job-info, .job-foot { grid-column: 3; background: var(--card); border: 1px solid var(--line); padding: 4px 16px 16px; }
  .job-info { grid-row: 1; border-radius: var(--radius) var(--radius) 0 0; border-bottom: 0; flex-direction: column; align-items: stretch; gap: 0; }
  .job-info > div, .job-info > .shrink { width: auto !important; }
  .job-foot { grid-row: 2; border-radius: 0 0 var(--radius) var(--radius); border-top: 0; padding-top: 0; }
  .job-preview { display: block; }
  .job-preview h3 { margin: 18px 0 8px; }
  .job-preview .message { font-size: 13px; margin: 0; padding: 12px 12px 12px 14px; max-height: 300px; overflow: auto; background: var(--card-2); }

  /* Détail d'un chantier : message à gauche, détail à droite */
  .job-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 36px; align-items: start; }
  .job-detail > div > h3:first-child { margin-top: 0; }

  dialog.picker { height: min(760px, calc(100dvh - 80px)); width: min(620px, calc(100vw - 48px)); }
}
@media (min-width: 1024px) and (max-width: 1439px) {
  .job-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .job-info, .job-foot { grid-column: 1 / -1; grid-row: auto; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 16px; position: static; padding-top: 4px; }
  .job-layout > .source { grid-row: 2; }
  .job-info { flex-direction: row; gap: 12px; }
  .job-foot { grid-row: 3; margin-top: 20px; }
}

/* ----- Écran de lancement ----- */
#splash {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #0b1e33; color: #fff; transition: opacity .35s ease;
}
#splash img { width: 92px; height: auto; margin-bottom: 22px; }
#splash .splash-brand { font: 600 15px/1 var(--cond); letter-spacing: .3em; text-transform: uppercase; color: var(--cyan); margin-bottom: 8px; padding-left: .3em; }
#splash .splash-title { font: 700 34px/1 var(--cond); letter-spacing: .04em; text-transform: uppercase; }
#splash::after { content: ""; width: 44px; height: 3px; margin-top: 18px; background: var(--cyan); }
#splash.out { opacity: 0; pointer-events: none; }
