:root {
  --bg: #f3f1ee;
  --card: #ffffff;
  --ink: #161616;
  --muted: #6f6f6f;
  --line: #e4e0da;
  --red: #c41218;
  --red-deep: #9a0e12;
  --ok: #1b7a3d;
  --warn: #a65f00;
  --font: "DM Sans", "Avenir Next", "Segoe UI", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 100% 0%, rgba(196, 18, 24, 0.07), transparent 55%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 220px);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding: 1.15rem 1.75rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 #fff, 0 10px 30px rgba(20, 20, 20, 0.04);
  position: relative;
}
.top::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--red) 0%, var(--red) 160px, transparent 420px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 1.15rem;
  min-width: 0;
}

.brand-logo {
  height: 58px;
  width: auto;
  max-width: min(260px, 46vw);
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

.brand-text { min-width: 0; }
.brand-kicker {
  margin: 0 0 .1rem;
  font-size: .68rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--red);
  font-weight: 700;
}
.top h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.55rem, 3vw, 2.05rem);
  font-weight: 400;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.sub {
  margin: .28rem 0 0;
  color: var(--muted);
  font-size: .88rem;
}

.health {
  font-size: .8rem;
  padding: .5rem .85rem;
  border-radius: 999px;
  background: #f6f4f1;
  color: #555;
  border: 1px solid var(--line);
  white-space: nowrap;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.health.ok {
  background: #eef8f1;
  color: var(--ok);
  border-color: #cfe8d7;
}
.health.bad {
  background: #fdeeee;
  color: var(--red);
  border-color: #f3c7c9;
}

main {
  padding: 1.35rem 1.5rem 2rem;
  max-width: 1120px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  margin-bottom: 1.1rem;
}

.btn {
  border: 1px solid #d5d0c8;
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: .58rem 1rem;
  cursor: pointer;
  font-weight: 650;
  font-family: inherit;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { border-color: #aaa; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn.accent {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn.accent:hover { background: var(--red-deep); border-color: var(--red-deep); }
.btn.danger {
  background: #fff;
  color: var(--red);
  border-color: #f0c4c6;
}
.btn.danger:hover {
  background: #fff5f5;
  border-color: var(--red);
}

.match-box {
  margin: .85rem 0 .2rem;
  padding: .85rem .95rem;
  border: 1px solid #f0c4c6;
  background: linear-gradient(180deg, #fff8f8 0%, #fff 100%);
  border-radius: 12px;
}
.match-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: .55rem;
}
.match-title { color: var(--red); font-size: .95rem; }
.match-hint { color: var(--muted); font-size: .78rem; }
.match-list {
  list-style: none;
  margin: 0 0 .7rem;
  padding: 0;
  display: grid;
  gap: .35rem;
}
.match-list li {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  align-items: center;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.match-list li.active {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(196, 18, 24, 0.12);
}
.match-list .meta { color: var(--muted); font-size: .78rem; }
.match-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.cards { display: grid; gap: 1rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.05rem 1.1rem 1.15rem;
  box-shadow: 0 10px 28px rgba(20, 20, 20, 0.05);
  position: relative;
  overflow: visible;
}
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--red), #7a0a0d);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
  padding-left: .35rem;
}
.card-title {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.mode-tabs {
  display: inline-flex;
  gap: .25rem;
  padding: .25rem;
  background: #f3f1ee;
  border-radius: 12px;
  margin: 0 0 .85rem .2rem;
}
.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  font-size: .88rem;
  padding: .45rem .9rem;
  border-radius: 9px;
  cursor: pointer;
}
.tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.search-box {
  margin: 0 0 1rem;
  position: relative;
  max-width: none;
  z-index: 20;
  padding: .85rem .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(180deg, #fff 0%, #faf8f6 100%);
  box-shadow: 0 6px 18px rgba(20, 20, 20, 0.04);
}
.search-head {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  margin-bottom: .65rem;
}
.search-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.search-hint {
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.35;
}
.search-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: .45rem;
  align-items: stretch;
}
.search-box .inp-search {
  width: 100%;
  min-width: 0;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: .75rem .85rem;
  font-size: 16px; /* évite le zoom iOS */
  line-height: 1.25;
  color: var(--ink);
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
}
.search-box .inp-search:focus {
  outline: 2px solid rgba(196, 18, 24, 0.22);
  border-color: #e08a8d;
}
.search-box .btn-search-go,
.search-box .btn-scan-qr {
  min-height: 48px;
  min-width: 52px;
  padding: .65rem .9rem;
  border-radius: 12px;
  font-size: .92rem;
  font-weight: 700;
  white-space: nowrap;
}
.search-box .btn-scan-qr {
  background: #161616;
  color: #fff;
  border-color: #161616;
}
.search-box .btn-scan-qr .scan-label-short { display: none; }
.search-box .btn-scan-qr .scan-label-full { display: inline; }
.search-results {
  list-style: none;
  margin: .65rem 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  max-height: min(52vh, 360px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 10px 24px rgba(0,0,0,.08);
  position: relative;
  z-index: 30;
}
.search-results[hidden] {
  display: none !important;
}
.search-results li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  padding: .85rem .9rem;
  cursor: pointer;
  border-bottom: 1px solid #f0ece7;
  font-size: .95rem;
  min-height: 64px;
  -webkit-tap-highlight-color: rgba(196, 18, 24, 0.08);
}
.search-results li .btn,
.match-list li .btn {
  flex-shrink: 0;
  padding: .55rem .85rem;
  font-size: .88rem;
  min-height: 44px;
  border-radius: 10px;
  font-weight: 700;
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover,
.search-results li:active { background: #fff5f5; }
.search-results .meta {
  color: var(--muted);
  font-size: .8rem;
  margin-top: .2rem;
  line-height: 1.3;
}
.search-results .meta-empty,
.search-results li.meta {
  display: block;
  padding: 1rem .9rem;
  color: var(--muted);
  font-size: .9rem;
  min-height: 0;
  cursor: default;
}
.search-picked {
  margin: .55rem 0 0;
  padding: .55rem .7rem;
  font-size: .88rem;
  color: var(--ok);
  font-weight: 650;
  background: #eef8f1;
  border-radius: 10px;
  line-height: 1.35;
}
@media (max-width: 720px) {
  .search-box {
    margin: 0 -.15rem 1rem;
    border-radius: 12px;
    padding: .8rem .75rem .9rem;
  }
  .search-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "input input"
      "go scan";
  }
  .search-box .inp-search { grid-area: input; }
  .search-box .btn-search-go { grid-area: go; width: 100%; }
  .search-box .btn-scan-qr { grid-area: scan; width: 100%; }
  .search-results li {
    flex-direction: column;
    align-items: stretch;
    gap: .55rem;
    padding: .9rem .85rem;
  }
  .search-results li .btn {
    width: 100%;
    min-height: 48px;
  }
}

.grid-photos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
@media (max-width: 720px) {
  .grid-photos { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
  .health { max-width: 100%; }
}

.top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .45rem;
}
.mobile-url {
  font-size: .78rem;
  color: #444;
  background: #f6f4f1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .45rem .7rem;
  max-width: min(420px, 90vw);
  word-break: break-all;
}
.mobile-url strong { color: var(--red); }
.mobile-url a { color: var(--ink); font-weight: 650; }

.photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .15rem;
}
.photo-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: .55rem .85rem;
  font-size: .85rem;
  cursor: pointer;
}
.photo-actions .btn.cam {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.photo-box {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  border: 1px dashed #d5cbcb;
  border-radius: 12px;
  padding: .75rem;
  background: #fafaf8;
  cursor: default;
  min-height: 160px;
  transition: border-color .15s ease, background .15s ease;
}
.photo-box:hover {
  border-color: var(--red);
  background: #fff8f8;
}
.photo-box > span {
  font-size: .85rem;
  color: var(--muted);
  font-weight: 650;
}
@media (max-width: 720px) {
  .photo-actions .btn {
    flex: 1 1 calc(50% - .25rem);
    min-height: 48px;
  }
  .top-right { align-items: stretch; width: 100%; }
  .mobile-url, .health { max-width: 100%; }
}
.preview {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 8px;
  background: #f2f2f0;
}
.preview-pack {
  max-height: min(48vh, 420px);
}

.mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: end;
  margin: .95rem 0;
}
.mode-row label,
.fields label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .78rem;
  color: var(--muted);
  font-weight: 600;
}
.mode-row input,
.mode-row select,
.fields input,
.fields select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .48rem .55rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
.mode-row input:focus,
.mode-row select:focus,
.fields input:focus,
.fields select:focus {
  outline: 2px solid rgba(196, 18, 24, 0.2);
  border-color: #e08a8d;
}

.fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .55rem;
}
@media (max-width: 720px) {
  .fields { grid-template-columns: 1fr; }
}
.fields label.full { grid-column: 1 / -1; }
.stock-field input {
  border-color: #f0c4c6;
  background: #fff8f8;
}
.fields .f-volume {
  background: #f4f6f8;
  color: var(--ink);
  font-weight: 600;
  cursor: default;
}
.fields .f-l,
.fields .f-w,
.fields .f-h {
  border-color: #c5d4e8;
  background: #f8fbff;
}

.odoo-details {
  margin: .8rem 0;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
}
.odoo-details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem .9rem;
  margin: .55rem 0 0;
}
.odoo-details-grid div { min-width: 0; }
.odoo-details-grid dt { font-size: .72rem; color: var(--muted); font-weight: 600; }
.odoo-details-grid dd { margin: .12rem 0 0; overflow-wrap: anywhere; }
@media (max-width: 720px) { .odoo-details-grid { grid-template-columns: 1fr; } }

.status {
  min-height: 1.2em;
  font-size: .88rem;
  margin: .65rem 0 0;
  color: var(--muted);
}
.status.ok { color: var(--ok); }
.status.err { color: var(--red); }
.status.busy { color: var(--warn); }
.status.warn { color: var(--warn); }

.ocr-box {
  margin-top: .65rem;
  font-size: .78rem;
  color: var(--muted);
}
.ocr-box summary { cursor: pointer; }
.ocr-text {
  margin: .4rem 0 0;
  padding: .55rem .65rem;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  background: #f6f4f1;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .72rem;
  color: #333;
}

.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  padding: 1.25rem 1rem 1.75rem;
  color: #8a8a8a;
  font-size: .8rem;
  letter-spacing: .04em;
}
.foot-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
}
.cam-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0;
}
.cam-overlay[hidden] { display: none !important; }
.cam-panel {
  width: 100%;
  height: 100%;
  max-width: none;
  background: #000;
  color: #fff;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  display: flex;
  flex-direction: column;
}
.cam-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .85rem 1.1rem;
  background: rgba(0,0,0,.75);
  flex-shrink: 0;
}
.cam-top .btn.ghost { color: #ccc; }
#camVideo {
  display: block;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  background: #000;
  object-fit: contain;
}
.cam-controls {
  display: flex;
  gap: .75rem;
  justify-content: center;
  align-items: center;
  padding: 1rem 1rem 1.35rem;
  background: rgba(0,0,0,.8);
  flex-shrink: 0;
}
.cam-controls .btn.accent {
  min-width: 180px;
  min-height: 56px;
  font-size: 1.1rem;
  border-radius: 999px;
}
.cam-error {
  margin: 0;
  padding: .75rem 1rem;
  background: #3a1214;
  color: #ffb4b7;
  font-size: .88rem;
}
.scan-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#scanVideo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.scan-reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(72vw, 280px);
  height: min(72vw, 280px);
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.scan-reticle::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  height: 2px;
  background: rgba(196, 18, 24, 0.85);
  animation: scan-line 1.6s ease-in-out infinite;
}
@keyframes scan-line {
  0%, 100% { transform: translateY(-70px); opacity: .35; }
  50% { transform: translateY(70px); opacity: 1; }
}
.scan-status {
  margin: 0;
  padding: .7rem 1rem;
  text-align: center;
  background: rgba(0,0,0,.8);
  color: #eee;
  font-size: .92rem;
}
@media (max-width: 720px) {
  #camVideo { object-fit: cover; }
  .preview-pack { max-height: 46vh; }
  .cam-controls .btn.accent {
    min-width: 160px;
    min-height: 54px;
  }
}
