/* ============================================================
   Test lecture codes-barres — feuille de style
   Mobile d'abord, gros éléments tactiles, thème clair / sombre.
   ============================================================ */

:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --text: #16202b;
  --muted: #5b6878;
  --border: #d5dbe3;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --accent-soft: #e3eefa;
  --ok: #1a7f37;
  --ok-soft: #e1f4e6;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --err: #c62828;
  --err-soft: #fde6e6;
  --topbar: #0b3d6b;
  --topbar-text: #ffffff;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  --tabbar-h: 64px;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319;
    --surface: #171e27;
    --surface-2: #1e2732;
    --text: #e6ebf1;
    --muted: #97a3b2;
    --border: #2c3643;
    --accent: #4c9bec;
    --accent-text: #06121f;
    --accent-soft: #15283d;
    --ok: #3fb95f;
    --ok-soft: #13301c;
    --warn: #e0a526;
    --warn-soft: #33290f;
    --err: #f06a6a;
    --err-soft: #3a1717;
    --topbar: #0a2744;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

code, .mono { font-family: var(--mono); font-size: 0.92em; }

h2 { font-size: 1.05rem; margin: 0 0 0.6rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Barre de titre ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--topbar);
  color: var(--topbar-text);
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 1rem; min-width: 0; }
.topbar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 24px; height: 24px; flex: none; }
.session-chip {
  flex: none;
  max-width: 45%;
  border: 1px solid rgb(255 255 255 / 35%);
  background: rgb(255 255 255 / 10%);
  color: inherit;
  border-radius: 999px;
  padding: 3px 10px;
  font: inherit;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.session-chip:empty { display: none; }

/* ---------- Mise en page ---------- */
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; }
.tab { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card > p:first-child { margin-top: 0; }
.card > p:last-child { margin-bottom: 0; }
.card-title { margin-bottom: 0.7rem; }

details.card > summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
details.card[open] > summary::after { transform: rotate(180deg); }
details.card[open] > summary { margin-bottom: 10px; }
details.help ul { padding-left: 1.1rem; }
details.help li { margin-bottom: 0.4rem; }

/* ---------- Boutons et champs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { color: var(--err); }
.btn-lg { min-height: 56px; padding: 0 24px; font-size: 1.05rem; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.85rem; }
.btn.is-on { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.btn-file { position: relative; }

.input, select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.field-label { display: block; font-weight: 600; margin-bottom: 6px; }

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px 12px;
  margin-bottom: 8px;
}
.form-grid > label { font-size: 0.88rem; color: var(--muted); margin-top: 6px; }
@media (min-width: 560px) {
  .form-grid { grid-template-columns: 200px minmax(0, 1fr); align-items: center; gap: 8px 12px; }
  .form-grid > label { margin-top: 0; }
}

.field-row { display: flex; align-items: center; gap: 10px; }
.field-row > label { flex: none; font-weight: 600; }
.field-row > select { flex: 1; }
.field-row > input[type="range"] { flex: 1; accent-color: var(--accent); }
.field-row > output { flex: none; min-width: 3.5em; text-align: right; font-family: var(--mono); }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}
.switch-row input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Lecteur intégré ---------- */
.wedge-zone { position: relative; margin: 0; }
.wedge-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 170px;
  padding: 20px;
  border-radius: var(--radius);
  border: 2px dashed var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
  text-align: center;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.wedge-status-text { font-size: 1.25rem; font-weight: 700; }
.wedge-hint { font-size: 0.9rem; color: var(--muted); }
.wedge-led { width: 18px; height: 18px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 18%, transparent); }
.wedge-zone.is-ready .wedge-status { border-style: solid; border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.wedge-zone.is-ready .wedge-led { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
/* Le champ reste focalisable mais invisible : il reçoit les frappes du lecteur. */
#wedge-input {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px; /* évite le zoom automatique d'iOS */
}
.wedge-zone.is-manual #wedge-input {
  position: static;
  height: 48px;
  opacity: 1;
  margin-top: 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
}

/* ---------- Carte résultat ---------- */
.result-card { border-left: 5px solid var(--ok); }
.result-card.is-warn { border-left-color: var(--warn); }
.result-card.is-error { border-left-color: var(--err); }
.result-value {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 700;
  word-break: break-all;
  line-height: 1.3;
  margin: 2px 0 8px;
}
.result-value.is-long { font-size: 1rem; }
.gs {
  display: inline-block;
  font-size: 0.62em;
  vertical-align: middle;
  padding: 0 3px;
  margin: 0 2px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.chip.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.chip.err { background: var(--err-soft); border-color: transparent; color: var(--err); }
.chip.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }

.gs1-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-top: 6px; }
.gs1-table th, .gs1-table td { text-align: left; padding: 5px 6px; border-top: 1px solid var(--border); vertical-align: top; }
.gs1-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
.gs1-table td:first-child { font-family: var(--mono); white-space: nowrap; }
.gs1-table td:last-child { font-family: var(--mono); word-break: break-all; }
.gs1-title { font-size: 0.85rem; font-weight: 600; margin-top: 8px; }

/* ---------- Caméra ---------- */
.cam-view {
  position: relative;
  width: 100%;
  height: min(62vh, 560px);
  min-height: 300px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  touch-action: manipulation;
}
#cam-video { width: 100%; height: 100%; object-fit: cover; display: block; }
#cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cam-roi {
  position: absolute;
  left: 10%;
  width: 80%;
  top: 30%;
  height: 40%;
  border-radius: 10px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 38%);
  pointer-events: none;
}
.cam-roi i { position: absolute; width: 28px; height: 28px; border: 4px solid #fff; }
.cam-roi i:nth-child(1) { left: -2px; top: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 10px; }
.cam-roi i:nth-child(2) { right: -2px; top: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 10px; }
.cam-roi i:nth-child(3) { left: -2px; bottom: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 10px; }
.cam-roi i:nth-child(4) { right: -2px; bottom: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 10px; }
.cam-laser { position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff5a4e; box-shadow: 0 0 8px #ff5a4e; opacity: 0.8; }
.cam-view:not(.is-running) .cam-roi, .cam-view.no-roi .cam-roi { display: none; }
.cam-view.is-paused .cam-laser { display: none; }

.cam-badges { position: absolute; left: 8px; top: 8px; right: 8px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.badge {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgb(0 0 0 / 55%);
  color: #fff;
  font-size: 0.75rem;
  font-family: var(--mono);
  backdrop-filter: blur(4px);
}
.cam-message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: #e8edf3;
  background: radial-gradient(circle at 50% 40%, #1d2a38, #05080c);
}
.cam-message-text { margin: 0; max-width: 32ch; font-size: 0.92rem; }
.cam-message.is-error .cam-message-text { color: #ffb4b4; }
.cam-view.is-running .cam-message { display: none; }
.cam-paused {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding-bottom: 28px;
  color: #fff;
  font-weight: 600;
  background: linear-gradient(transparent 55%, rgb(0 0 0 / 60%));
  cursor: pointer;
}
.cam-paused-icon {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ok); color: #fff; font-size: 1.8rem;
}

.cam-controls { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }

fieldset.formats { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 8px 0 0; }
fieldset.formats legend { font-weight: 600; font-size: 0.9rem; padding: 0 4px; }
.formats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(125px, 1fr)); gap: 2px 10px; }
.formats-grid label { display: flex; align-items: center; gap: 8px; min-height: 38px; font-size: 0.92rem; }
.formats-grid input { width: 20px; height: 20px; accent-color: var(--accent); }
.formats-grid small { color: var(--muted); }
.formats-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Journal ---------- */
.journal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.journal-list { display: flex; flex-direction: column; gap: 6px; }
.journal-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.journal-item > summary {
  list-style: none;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 2px 10px;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
}
.journal-item > summary::-webkit-details-marker { display: none; }
.journal-item .j-time { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }
.journal-item .j-value { font-family: var(--mono); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.journal-item .j-meta { grid-column: 2 / 4; font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.journal-item .j-src { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; color: var(--accent); }
.journal-item[open] > summary { border-bottom: 1px solid var(--border); }
.journal-item .j-body { padding: 10px 12px; }
.journal-empty { text-align: center; padding: 28px 12px; color: var(--muted); }

.stats { overflow-x: auto; }
.stats table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.stats th, .stats td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.stats td:first-child { white-space: normal; min-width: 7em; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
.stats td { font-variant-numeric: tabular-nums; }

/* ---------- Étiquettes ---------- */
.labels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.label-card {
  background: #fff;
  color: #111;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  break-inside: avoid;
}
.label-card h3 { margin: 0; font-size: 0.95rem; }
.label-card .label-use { font-size: 0.8rem; color: #555; }
.label-card .label-code { display: flex; justify-content: center; align-items: center; min-height: 90px; padding: 8px 0; }
.label-card .label-code svg { display: block; max-width: 100%; height: auto; }
.label-card .label-data { font-family: var(--mono); font-size: 0.75rem; color: #333; word-break: break-all; }
.label-card .label-tag { align-self: flex-start; font-size: 0.7rem; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: #fff4d6; color: #7a5200; }
.label-card .label-check { font-size: 0.75rem; color: #0b5cad; }
.custom-output { margin-top: 12px; display: flex; justify-content: center; background: #fff; border-radius: 8px; }
.custom-output:empty { display: none; }
.custom-output svg { max-width: 100%; height: auto; padding: 8px; }
.custom-output .error { color: #c62828; padding: 12px; }

/* ---------- Diagnostic ---------- */
.diag-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; margin: 0; }
.diag-list dt { font-size: 0.8rem; color: var(--muted); margin-top: 8px; }
.diag-list dd { margin: 0; padding-bottom: 8px; border-bottom: 1px solid var(--border); word-break: break-word; }
.diag-list dd.ok::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.diag-list dd.ko::before { content: "✗ "; color: var(--err); font-weight: 700; }
.diag-list dd.warn::before { content: "! "; color: var(--warn); font-weight: 700; }
@media (min-width: 560px) {
  .diag-list { grid-template-columns: 220px minmax(0, 1fr); }
  .diag-list dt, .diag-list dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--border); }
}

.selftest-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.86rem; }
.selftest-table th, .selftest-table td { padding: 6px; border-bottom: 1px solid var(--border); text-align: left; }
.selftest-table th { color: var(--muted); font-size: 0.78rem; }
.selftest-table .ok { color: var(--ok); font-weight: 700; }
.selftest-table .ko { color: var(--err); font-weight: 700; }
.selftest-table .na { color: var(--muted); }
.selftest-summary { margin-top: 10px; font-weight: 600; }

/* ---------- Barre d'onglets ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
}
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.is-active { color: var(--accent); }
.tabbar a.is-active::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tab-count {
  position: absolute;
  top: 6px;
  left: calc(50% + 8px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.68rem;
  line-height: 18px;
  text-align: center;
}

/* ---------- Retours visuels ---------- */
.flash {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  box-shadow: inset 0 0 0 10px var(--ok);
  opacity: 0;
}
.flash.is-on { animation: flash 0.45s ease-out; }
.flash.is-warn { box-shadow: inset 0 0 0 10px var(--warn); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 60;
  transform: translateX(-50%) translateY(20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #1c2733;
  color: #fff;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Impression de la planche d'étiquettes ---------- */
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; padding: 0; }
  .topbar, .tabbar, .no-print, .flash, .toast, .tab:not(#tab-etiquettes) { display: none !important; }
  main { max-width: none; padding: 0; }
  .labels-grid { grid-template-columns: repeat(2, 1fr); gap: 6mm; }
  .label-card { border: 1px solid #999; border-radius: 0; box-shadow: none; }
}
