:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eaf3fb;
  --border: #c9ddf0;
  --text: #10253a;
  --muted: #5c7a94;
  --blue: #0284c7;
  --blue-dim: #0369a1;
  --green: #15803d;
  --green-bg: #dcfce7;
  --orange: #c2410c;
  --orange-bg: #ffedd5;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #b45309;
  --focus: #0284c7;
  --radius: 10px;
  --tap: 52px;
  --gap: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(16, 37, 58, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  padding-bottom: calc(96px + var(--safe-b));
}

button,
input {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-prepa {
  margin-left: auto;
  max-width: 7.5rem;
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--blue-dim);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.badge-env {
  margin-left: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--orange-bg);
  color: var(--orange);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

[hidden] {
  display: none !important;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--blue-dim);
}

.btn-success {
  background: var(--green);
  color: #fff;
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--red);
  color: #fff;
}

.btn-amber {
  background: #fff7ed;
  border-color: #fdba74;
  color: var(--amber);
}

.btn:focus-visible,
.btn-icon:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.view {
  display: none;
  padding: 12px 14px 0;
  max-width: 720px;
  margin: 0 auto;
}

.view.active {
  display: block;
}

.status-bar {
  min-height: 28px;
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.status-bar.ok {
  background: var(--green-bg);
  border-color: #86efac;
  color: #14532d;
}

.status-bar.err {
  background: var(--red-bg);
  border-color: #fca5a5;
  color: #7f1d1d;
}

.status-bar.warn {
  background: var(--orange-bg);
  border-color: #fdba74;
  color: #7c2d12;
}

.search-box {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-box label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.search-input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.05rem;
}

.order-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  width: 100%;
  min-width: 0;
  padding: 14px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.order-card:hover,
.order-card:active {
  border-color: var(--blue);
  background: var(--surface-2);
}

.order-card .pieceno {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
}

.order-card .magasin {
  grid-column: 1 / -1;
  font-size: 0.98rem;
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}

.order-card .date {
  color: var(--muted);
  font-size: 0.88rem;
}

.order-card .chev {
  color: var(--muted);
  font-size: 1.25rem;
  align-self: start;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.meta-row strong {
  color: var(--text);
  font-family: var(--font-mono);
}

.line-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.line-row:hover,
.line-row:active {
  border-color: var(--blue);
  background: var(--surface-2);
}

.line-row.done {
  border-color: #86efac;
  background: var(--green-bg);
}

.line-row .ref {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
}

.line-row .empl {
  color: var(--blue-dim);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
}

.line-row .desig {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.line-row .qtys {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--muted);
}

.line-row .qtys b {
  color: var(--text);
}

.prep-progress {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.field-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.field.row-2 {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field .value,
.field input {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 600;
}

.field .value.readonly {
  background: var(--surface-2);
}

.field .value.empl {
  border-color: var(--blue);
  background: #eff8ff;
  color: var(--blue-dim);
  font-size: 1.2rem;
}

.field .desig {
  font-family: var(--font);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--muted);
  border: none;
  background: transparent;
  padding: 0;
  min-height: 0;
}

.scan-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.select-input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 1rem;
}

.login-lead {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.assign-bar {
  margin: 0 0 10px;
}

.order-card.selected {
  border-color: var(--blue);
  background: #eff8ff;
  box-shadow: 0 0 0 2px #7dd3fc;
}

.order-card .prepa {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  font-family: var(--font-mono);
  color: var(--amber);
  font-weight: 700;
}

.be-banner {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid #fcd34d;
  background: #fffbeb;
  color: #92400e;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
}

.be-banner strong {
  font-family: var(--font-mono);
}

.be-banner .be-siblings {
  margin-top: 6px;
  font-weight: 500;
  font-size: 0.88rem;
  color: #78350f;
}

.order-card .be {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--blue-dim);
  justify-self: end;
}

.palette-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.palette-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.palette-card .count {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
}

.footer-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: linear-gradient(180deg, transparent, var(--bg) 24%);
  border-top: 1px solid var(--border);
}

.footer-actions.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.footer-actions .btn {
  width: 100%;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  background: rgba(16, 37, 58, 0.35);
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  width: min(480px, 100%);
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(16, 37, 58, 0.12);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.modal p {
  margin: 0 0 14px;
  color: var(--muted);
  white-space: pre-wrap;
}

.modal-actions {
  display: grid;
  gap: 8px;
}

.modal-actions.cols-2 {
  grid-template-columns: 1fr 1fr;
}

.modal-actions.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.summary-grid {
  display: grid;
  gap: 10px;
}

.summary-grid .field input {
  width: 100%;
}

.toggle-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-mode .btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
}

/* —— Popup chargement fetch —— */
.loading-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(16, 37, 58, 0.4);
}

.loading-backdrop.open {
  display: flex;
}

.loading-card {
  width: min(320px, 100%);
  padding: 28px 20px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px rgba(16, 37, 58, 0.16);
  text-align: center;
}

.loading-text {
  margin: 0;
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
}

/* —— Popup progression transmission —— */
.progress-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(16, 37, 58, 0.45);
}

.progress-backdrop.open {
  display: flex;
}

.progress-card {
  width: min(420px, 100%);
  padding: 22px 18px 18px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px rgba(16, 37, 58, 0.18);
  text-align: center;
}

.progress-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.progress-spinner.done {
  animation: none;
  border-color: #86efac;
  border-top-color: var(--green);
  background: var(--green-bg);
}

.progress-spinner.error {
  animation: none;
  border-color: #fca5a5;
  border-top-color: var(--red);
  background: var(--red-bg);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-card h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.progress-sub {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.progress-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-steps li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.progress-steps li .dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.progress-steps li.running {
  border-color: #7dd3fc;
  background: #eff8ff;
}

.progress-steps li.running .dot {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  animation: pulse 1s ease-in-out infinite;
}

.progress-steps li.done .dot {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.progress-steps li.error {
  border-color: #fca5a5;
  background: var(--red-bg);
}

.progress-steps li.error .dot {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.progress-steps .label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.progress-steps .detail {
  margin-top: 2px;
  font-size: 0.82rem;
  color: var(--muted);
}

@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}

.progress-footer {
  display: flex;
  gap: 8px;
  justify-content: stretch;
  margin-top: 16px;
}

.progress-footer .btn {
  flex: 1;
  width: auto;
}

@media (min-width: 768px) {
  .footer-actions {
    left: 50%;
    transform: translateX(-50%);
    width: min(720px, 100%);
  }
}