/* Magasinier — interface tablette (tactile, lisible à bout de bras, impression A4) */

:root {
  --ink: #14181f;
  --ink-2: #2a303b;
  --muted: #5b6270;
  --paper: #f3f1ec;
  --card: #ffffff;
  --line: #d9d5cc;
  --line-2: #e8e5de;
  --accent: #1847c9;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecfb;
  --label: #ffd21f;         /* étiquette d'emplacement, comme les plaques des racks */
  --label-ink: #14181f;
  --ok: #17803d;
  --ok-soft: #e3f3e8;
  --warn: #b25b00;
  --danger: #c0271f;
  --radius: 12px;
  --tap: 56px;              /* taille minimale d'une cible tactile */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 17px/1.35 var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ barre du haut */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: .01em; }
.logo { width: 30px; height: 30px; flex: none; display: block; }
.logo.big { width: 64px; height: 64px; }

.sync {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.22); background: transparent; color: #fff; font-size: 15px; white-space: nowrap;
}
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: #5ad17f; }
.sync[data-state="busy"] .dot { background: var(--label); animation: pulse 1s infinite; }
.sync[data-state="warn"] .dot { background: #ff8a3d; }
@keyframes pulse { 50% { opacity: .3; } }
.bar-actions { display: flex; gap: 6px; }
.ghost {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: 8px;
  background: transparent; border: 0; color: #cfd5df; text-decoration: none; font-size: 15px;
}
.ghost:hover { color: #fff; background: rgba(255,255,255,.08); }

/* ------------------------------------------------------------------ disposition */
.split {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); gap: 16px;
  padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
  height: calc(100dvh - 60px);
}
.pane {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.tabs { display: none; }

@media (max-width: 899px) {
  .split { grid-template-columns: 1fr; height: calc(100dvh - 60px - 64px); padding-bottom: 8px; }
  .split[data-tab="search"] .pane-tour, .split[data-tab="tour"] .pane-search { display: none; }
  .tabs {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid var(--line);
  }
  .tabs button {
    min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600;
  }
  .tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
  .tabs .count { background: var(--label); color: var(--ink); }
  .bar .brand { font-size: 17px; }
  .bar-actions .ghost { padding: 0 8px; }
}
@media (max-width: 520px) {
  .bar-actions a.ghost { display: none; }
  .sync { padding: 0 10px; }
}

/* ------------------------------------------------------------------ recherche */
.searchbox { display: flex; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line-2); }
.mode { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.mode button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 64px; min-height: var(--tap); padding: 0 8px; border: 0; background: var(--card);
  font-weight: 800; font-size: 16px; letter-spacing: .02em;
}
.mode button small { font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: 0; }
.mode button + button { border-left: 1px solid var(--line); }
.mode button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.mode button[aria-pressed="true"] small { color: #c7ccd6; }
.field { position: relative; flex: 1; min-width: 0; }
.field input {
  width: 100%; height: var(--tap); padding: 0 48px 0 16px;
  border: 2px solid var(--line); border-radius: 10px; background: #fff; font-size: 20px;
  -webkit-appearance: none; appearance: none;
}
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px var(--accent-soft); }
.field input::-webkit-search-cancel-button { display: none; }
.clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; font-size: 28px; color: var(--muted);
}

.results { list-style: none; margin: 0; padding: 6px 8px 12px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.results li { padding: 2px 0; }
.results .empty { padding: 28px 12px; color: var(--muted); text-align: center; }
.result {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 52px; align-items: center; gap: 12px;
  width: 100%; min-height: 68px; padding: 8px 8px 8px 12px; text-align: left;
  border: 1px solid transparent; border-radius: 10px; background: transparent;
}
.result:active { background: var(--accent-soft); }
.result.in-tour { background: var(--ok-soft); border-color: #bfe3cb; }
.r-main { display: flex; flex-direction: column; min-width: 0; }
.r-lib { font-weight: 650; overflow-wrap: anywhere; }
.r-meta, .t-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 14px; color: var(--muted); margin-top: 2px; }
.code { font-family: var(--mono); font-size: 14px; }
.fam { font-size: 12px; font-weight: 700; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; background: var(--line-2); }
.r-locs { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; max-width: 190px; }
.r-add {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 26px; font-weight: 600; line-height: 1;
}
.result.in-tour .r-add { background: var(--ok); font-size: 17px; font-weight: 800; }

/* étiquette d'emplacement */
.loc {
  display: inline-block; padding: 2px 7px; border-radius: 5px; border: 2px solid var(--label-ink);
  background: var(--label); color: var(--label-ink);
  font: 800 15px/1.2 var(--mono); letter-spacing: .02em; white-space: nowrap;
}
.loc.big { font-size: 20px; padding: 4px 10px; min-width: 76px; max-width: 100%; text-align: center; overflow: hidden; text-overflow: ellipsis; }
.t-loc { display: flex; min-width: 0; }
.loc.more { background: #fff; }
.loc.none { background: #fff; border-style: dashed; border-color: var(--danger); color: var(--danger); font-family: var(--font); font-size: 13px; font-weight: 700; }

/* ------------------------------------------------------------------ tournée */
.tour-head { display: flex; align-items: center; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.tour-head h2 { margin: 0; font-size: 22px; display: flex; align-items: center; gap: 8px; }
.count {
  display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 8px; border-radius: 999px;
  background: var(--ink); color: #fff; font-size: 15px; font-weight: 700;
}
.tour-head input {
  flex: 1; min-width: 180px; height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px;
}
.tour { list-style: none; margin: 0; padding: 4px 10px 12px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.zone-h {
  position: sticky; top: 0; z-index: 1;
  margin: 8px -10px 2px; padding: 6px 14px; background: #f7f6f2; border-block: 1px solid var(--line-2);
  font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2);
}
.t-item {
  display: grid; grid-template-columns: 48px 156px minmax(0, 1fr) auto 44px; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line-2);
}
.t-item:last-child { border-bottom: 0; }
.check {
  width: 44px; height: 44px; border-radius: 10px; border: 2px solid var(--line); background: #fff;
  font-size: 24px; font-weight: 900; color: #fff; line-height: 1;
}
.check[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); }
.t-item.done .t-lib { text-decoration: line-through; color: var(--muted); }
.t-item.done .loc { opacity: .5; }
.t-lib { font-weight: 650; overflow-wrap: anywhere; }
.also { font-family: var(--mono); font-size: 13px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 44px; height: 44px; border: 0; background: #fff; font-size: 24px; line-height: 1; }
.stepper button:active { background: var(--accent-soft); }
.stepper output { min-width: 34px; text-align: center; font-weight: 800; font-size: 18px; }
.remove { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 28px; }
.remove:active { background: #fbe4e2; color: var(--danger); }

@media (max-width: 640px) {
  .t-item { grid-template-columns: 44px minmax(0, 1fr) auto; grid-template-areas: "c l l" "c m m" "c s r"; row-gap: 6px; }
  .t-item .check { grid-area: c; align-self: start; }
  .t-item .t-loc { grid-area: l; }
  .t-item .t-main { grid-area: m; }
  .t-item .stepper { grid-area: s; justify-self: start; }
  .t-item .remove { grid-area: r; }
  .result { grid-template-columns: minmax(0, 1fr) 48px; }
  .r-locs { grid-column: 1; justify-content: flex-start; max-width: none; }
  .r-add { grid-column: 2; grid-row: 1 / span 2; }
}

.tour-actions {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line-2); background: #fbfaf7;
}
.btn {
  min-height: var(--tap); padding: 0 20px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  font-weight: 700; font-size: 17px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-size: 19px; }
.btn.danger { background: #fff; border-color: #efb4af; color: var(--danger); }
#btn-clear[data-confirm] { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ------------------------------------------------------------------ aides / messages */
.hint { padding: 28px 24px; color: var(--muted); max-width: 520px; }
.hint p { margin: 0 0 10px; }
.hint-title { color: var(--ink); font-weight: 700; font-size: 19px; }
.hint-small { font-size: 14px; }
.hint b { color: var(--ink); font-weight: 650; background: var(--line-2); padding: 0 5px; border-radius: 4px; }

#toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 560px);
}
@media (max-width: 899px) { #toasts { bottom: 84px; } }
.toast {
  padding: 12px 18px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); transition: opacity .35s, transform .35s; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

.banner {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  padding: 12px 12px 12px 18px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0,0,0,.16); font-weight: 600; width: max-content; max-width: calc(100vw - 32px);
}

/* ------------------------------------------------------------------ connexion */
.login {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: var(--ink);
}
.login-card {
  width: min(380px, 100%); display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px 24px; border-radius: 18px; background: var(--card); text-align: center;
}
.login-card h1 { margin: 6px 0 0; font-size: 24px; }
.login-card p { margin: 0; color: var(--muted); }
.login-card input {
  width: 100%; height: 60px; margin-top: 6px; text-align: center; font: 700 30px var(--mono); letter-spacing: .3em;
  border: 2px solid var(--line); border-radius: 12px;
}
.login-card input:focus { border-color: var(--accent); outline: none; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; margin-top: 6px; }
.pinpad button {
  height: 64px; border-radius: 12px; border: 1px solid var(--line); background: #f7f6f2; font-size: 26px; font-weight: 700;
}
.pinpad button:active { background: var(--accent-soft); }
.pinpad .primary { background: var(--accent); color: #fff; border-color: var(--accent); font-size: 20px; }
.login-error { min-height: 1.4em; color: var(--danger) !important; font-weight: 600; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ------------------------------------------------------------------ impression */
.print-only { display: none; }

@page { size: A4 portrait; margin: 11mm 10mm 12mm; }

@media print {
  body { background: #fff; font-size: 11pt; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; color: #000; }
  .p-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; border-bottom: 2.5pt solid #000; padding-bottom: 6pt; }
  .p-head h1 { margin: 0; font-size: 20pt; }
  .p-date { margin: 2pt 0 0; font-size: 11pt; text-transform: capitalize; }
  .p-who { display: flex; flex-direction: column; min-width: 60mm; font-size: 9pt; }
  .p-who strong { font-size: 13pt; border-bottom: 1pt solid #000; min-height: 18pt; padding-top: 4pt; }
  .p-sum { margin: 6pt 0 8pt; font-size: 11pt; }
  .p-table { width: 100%; border-collapse: collapse; }
  .p-table thead th {
    text-align: left; font-size: 8.5pt; text-transform: uppercase; letter-spacing: .06em;
    border-bottom: 1pt solid #000; padding: 3pt 4pt;
  }
  .p-table thead { display: table-header-group; }
  .p-table tr { break-inside: avoid; page-break-inside: avoid; }
  .p-table td { padding: 5pt 4pt; border-bottom: .5pt solid #999; vertical-align: middle; }
  .p-zone th {
    text-align: left; padding: 8pt 4pt 3pt; font-size: 10pt; letter-spacing: .1em; text-transform: uppercase;
    border-bottom: 1.5pt solid #000; break-after: avoid; page-break-after: avoid;
  }
  .p-check { width: 9mm; }
  .box { display: block; width: 5.5mm; height: 5.5mm; border: 1.3pt solid #000; border-radius: 1pt; }
  .p-loc { width: 40mm; }
  .p-loc-main { display: block; font: 800 15pt/1.1 var(--mono); white-space: nowrap; }
  .same .p-loc-main { font-weight: 400; color: #555; }
  .p-loc-also { display: block; font: 8pt var(--mono); color: #333; }
  .p-lib b { display: block; font-size: 11pt; }
  .p-code { font: 8.5pt var(--mono); color: #333; }
  .p-qty { width: 12mm; text-align: center; font-size: 14pt; font-weight: 800; }
  .p-cdt { width: 26mm; font: 8.5pt var(--mono); }
  .p-note { margin-top: 10pt; font-size: 9.5pt; font-style: italic; }
  .p-foot { margin-top: 12pt; font-size: 8pt; color: #555; }
}

/* ------------------------------------------------------------------ admin */
.admin .wrap { max-width: 1180px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); }
.admin h2 { margin: 0 0 4px; font-size: 21px; }
.admin .sub { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.admin-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.admin-tabs button {
  min-height: 46px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 650;
}
.admin-tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 14px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1; min-width: 220px; height: 50px; padding: 0 14px; border: 2px solid var(--line); border-radius: 10px; font-size: 18px; }
.toolbar input[type="search"]:focus { border-color: var(--accent); outline: none; }
.toolbar select { height: 50px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line-2); border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px; background: #f7f6f2; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr.row { cursor: pointer; }
.tbl tr.row:hover td { background: #faf9f5; }
.tbl .locs { display: flex; flex-wrap: wrap; gap: 4px; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 650; color: var(--ink-2); }
.form .wide { grid-column: 1 / -1; }
.form .wide > label { margin-bottom: 4px; }
.form input, .form textarea {
  height: 48px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 17px; font-weight: 400;
}
.form input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 48px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.chip { display: inline-flex; align-items: center; gap: 2px; }
.chip .loc { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.chip button { height: 29px; width: 30px; border: 2px solid var(--label-ink); border-left: 0; border-radius: 0 5px 5px 0; background: #fff; font-weight: 800; }
.chips input { flex: 1; min-width: 120px; height: 36px; border: 0; padding: 0 6px; font: 700 16px var(--mono); text-transform: none; }
.chips input:focus { outline: none; box-shadow: none; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.actions .spacer { flex: 1; }

dialog.sheet { width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); border: 0; border-radius: 16px; padding: 22px; box-shadow: 0 24px 60px rgba(0,0,0,.28); }
dialog.sheet::backdrop { background: rgba(20,24,31,.55); }
dialog.sheet h3 { margin: 0 0 14px; font-size: 20px; }

.route-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-width: 520px; }
.route-list li {
  display: grid; grid-template-columns: 34px 1fr auto auto auto; align-items: center; gap: 8px;
  padding: 6px 6px 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.route-list .n { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.route-list button { width: 44px; height: 40px; border: 1px solid var(--line); border-radius: 8px; background: #f7f6f2; font-size: 18px; }
.route-list .zn { font: 800 16px var(--mono); }
.route-list .cnt { font-size: 13px; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 10px; margin: 14px 0; font-weight: 600; }
.switch input { width: 24px; height: 24px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.stat { padding: 12px 14px; border-radius: 10px; background: #f7f6f2; border: 1px solid var(--line-2); }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.new b { color: var(--ok); }
.stat.chg b { color: var(--accent); }
.stat.del b { color: var(--danger); }
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 140px; border: 2px dashed var(--line); border-radius: 12px; background: #faf9f5; text-align: center; padding: 16px; cursor: pointer;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { font-size: 18px; }
.diff { max-height: 320px; overflow: auto; }
.diff td.old { color: var(--danger); text-decoration: line-through; }
.diff td.new { color: var(--ok); }
.ghost { white-space: nowrap; }
@media (max-width: 520px) { .admin .sync { display: none; } }
