:root {
  --variance-pos: #198754;
  --variance-neg: #dc3545;
  --variance-zero: #6c757d;
}

body {
  background: #f6f7f9;
  padding-bottom: 2rem;
}

/* Landing page store cards */
.store-card {
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  color: inherit;
}
.store-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.store-card .store-code {
  font-size: 1.75rem;
  font-weight: 700;
  color: #0d6efd;
  letter-spacing: 0.05em;
}
.store-card .store-name {
  font-size: 1rem;
  color: #343a40;
}

/* Count page header */
.app-header {
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Search + autocomplete */
.search-wrap {
  position: relative;
}

#search-input.scan-error-flash {
  border-color: #dc3545;
  box-shadow: 0 0 0 .2rem rgba(220, 53, 69, .35);
  background: #fff5f5;
  animation: scanErrorFlash .6s ease-out 1;
}
@keyframes scanErrorFlash {
  0%   { background: #f8d7da; }
  100% { background: #fff5f5; }
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #dee2e6;
  border-top: none;
  border-radius: 0 0 .375rem .375rem;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.search-result {
  padding: .6rem .75rem;
  border-bottom: 1px solid #f1f3f5;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover,
.search-result.active { background: #e7f1ff; }
.search-result .model {
  font-weight: 600;
  font-family: 'Courier New', monospace;
  color: #0d6efd;
}
.search-result .desc {
  color: #6c757d;
  font-size: .875rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result .expected {
  font-size: .8rem;
  color: #495057;
  white-space: nowrap;
}

/* Count table */
.count-table th { white-space: nowrap; font-size: .8rem; }
.count-table td { vertical-align: middle; }

.count-table .model {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  white-space: nowrap;
}

.qty-controls {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}
.qty-controls button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.25rem;
  font-weight: 700;
}
.qty-controls .qty-display {
  min-width: 3rem;
  text-align: center;
  font-weight: 600;
  font-size: 1.1rem;
}

.variance-pos { color: var(--variance-pos); font-weight: 600; }
.variance-neg { color: var(--variance-neg); font-weight: 600; }
.variance-zero { color: var(--variance-zero); }

.row-manual { background-color: #fff7e6; }
.row-archive { background-color: #f3f4f6; }

.badge-archive {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  background: #e9ecef;
  color: #6c757d;
  border-radius: .25rem;
  padding: .1rem .4rem;
  margin-left: .4rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.search-result.archive .model { color: #6c757d; }
.search-result.archive .desc { font-style: italic; }

/* Multi-piece SKU styling */
.cartins-badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  background: #e7f1ff;
  color: #0d6efd;
  border-radius: .25rem;
  padding: .1rem .4rem;
  margin-left: .4rem;
  white-space: nowrap;
}
.qty-small {
  font-size: .8rem;
  color: #6c757d;
  display: block;
}
.pieces-row > td {
  background: #f8f9fa;
  padding: .5rem 1rem .75rem;
  border-top: none;
}
.pieces-panel {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.piece-cell {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .5rem;
  border: 1px solid #dee2e6;
  border-radius: .375rem;
  background: #fff;
  min-width: 170px;
}
.piece-label {
  font-weight: 600;
  font-size: .85rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.piece-qty {
  font-weight: 600;
  font-size: 1rem;
  min-width: 1.75rem;
  text-align: center;
}
.piece-cell button {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
}
.btn-expand {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
  transition: transform .15s ease;
}
.btn-expand.expanded {
  transform: rotate(90deg);
}

/* Barcode scanner */
#qr-reader {
  width: 100%;
  background: #000;
  min-height: 360px;
  position: relative;
  overflow: hidden;
}
#qr-reader video {
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: cover;
}
/* Hide html5-qrcode's default qrbox overlay — we draw our own wider reticle
   that's easier to see for 1D barcodes. */
#qr-reader__scan_region { background: transparent !important; }
#qr-reader__dashboard { display: none !important; }

/* Custom reticle optimized for wide 1D barcodes */
.scanner-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(88%, 540px);
  height: 110px;
  border: 2px solid rgba(13, 110, 253, 0.85);
  border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 2;
}
.scanner-reticle::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 2px;
  background: rgba(255, 0, 0, 0.8);
  animation: scan-line 1.4s linear infinite;
}
@keyframes scan-line {
  0%, 100% { transform: translateY(-50%) scaleY(1); opacity: .9; }
  50%      { transform: translateY(-50%) scaleY(0.5); opacity: .4; }
}

.scanner-status {
  padding: .5rem 1rem;
  font-size: .9rem;
  color: #495057;
  background: #f8f9fa;
  border-top: 1px solid #dee2e6;
  position: relative;
  z-index: 3;
}
#btn-scan {
  font-size: 1.4rem;
  line-height: 1;
  padding: .375rem .65rem;
}
#btn-torch.torch-on {
  background: #ffc107;
  color: #000;
  border-color: #ffc107;
}

/* Landing panel (when no open session) */
.landing-panel {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: .5rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.resume-card {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e9ecef;
}
.resume-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #6c757d;
  margin-bottom: .25rem;
}
.resume-details {
  font-size: .95rem;
  color: #212529;
}

/* Photo lookup — match cards + tier badges + skeleton loaders */
.lookup-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0 0 .375rem .375rem;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  padding: .25rem 0;
}
.lookup-ocr {
  padding: .5rem .75rem;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  font-size: .8rem;
  color: #495057;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}
.lookup-ocr .label { font-weight: 600; color: #6c757d; margin-right: .25rem; }
.lookup-ocr .ocr-pill {
  background: #e9ecef;
  color: #495057;
  padding: .05rem .4rem;
  border-radius: .25rem;
  font-size: .75rem;
  font-family: 'Courier New', monospace;
}
.lookup-ocr .ocr-pill.desc {
  font-family: inherit;
  background: #e7f1ff;
  color: #0a58ca;
}
.lookup-card {
  display: flex;
  gap: .75rem;
  padding: .6rem .75rem;
  align-items: center;
  border-bottom: 1px solid #f1f3f5;
}
.lookup-card:last-child { border-bottom: none; }
.lookup-card .lookup-main {
  flex: 1;
  min-width: 0;
}
.lookup-card .top-line {
  display: flex;
  gap: .5rem;
  align-items: baseline;
  flex-wrap: wrap;
}
.lookup-card .model {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  color: #0d6efd;
  font-size: 1rem;
}
.lookup-card .desc {
  font-size: .85rem;
  color: #495057;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lookup-card .meta {
  font-size: .75rem;
  color: #6c757d;
  margin-top: .15rem;
}
.lookup-card .btn-add {
  min-width: 76px;
  height: 44px;
  font-weight: 600;
  white-space: nowrap;
}

.tier-badge {
  display: inline-block;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: .1rem .4rem;
  border-radius: .25rem;
  text-transform: uppercase;
  vertical-align: middle;
}
.tier-EXACT    { background: #d1e7dd; color: #0f5132; }
.tier-SECT     { background: #cfe2ff; color: #084298; }
.tier-VAR      { background: #e2d9f3; color: #432874; }
.tier-COMBINED { background: #ffe5d0; color: #984c0c; }
.tier-SUBSTR   { background: #e9ecef; color: #495057; }
.tier-AI       { background: #cff4fc; color: #055160; }

.lookup-empty {
  padding: 1rem .75rem;
  text-align: center;
  color: #6c757d;
  font-size: .9rem;
}

/* Skeleton loading state */
.lookup-skeleton {
  padding: .25rem 0;
}
.lookup-skeleton .skeleton-card {
  display: flex;
  gap: .75rem;
  padding: .6rem .75rem;
  align-items: center;
  border-bottom: 1px solid #f1f3f5;
}
.lookup-skeleton .skeleton-line {
  background: linear-gradient(90deg, #e9ecef 0%, #f4f5f7 50%, #e9ecef 100%);
  background-size: 200% 100%;
  border-radius: .25rem;
  height: 12px;
  animation: shimmer 1.4s infinite linear;
}
.lookup-skeleton .skeleton-card .lookup-main { flex: 1; }
.lookup-skeleton .skeleton-card .skeleton-line.short { width: 35%; }
.lookup-skeleton .skeleton-card .skeleton-line.long  { width: 80%; margin-top: 6px; }
.lookup-skeleton .skeleton-card .skeleton-btn {
  width: 76px; height: 38px; border-radius: .375rem;
  background: linear-gradient(90deg, #e9ecef 0%, #f4f5f7 50%, #e9ecef 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

#btn-photo,
#btn-upload {
  font-size: 1.4rem;
  line-height: 1;
  padding: .375rem .65rem;
}

/* Toast */
.toast-msg {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #212529;
  color: #fff;
  padding: .6rem 1rem;
  border-radius: .375rem;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: toast-in .15s ease;
}
.toast-msg.error { background: #dc3545; }
.toast-msg.success { background: #198754; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Mobile layout */
@media (max-width: 640px) {
  .count-table thead { display: none; }
  .count-table, .count-table tbody, .count-table tr, .count-table td {
    display: block;
    width: 100%;
  }
  .count-table tr {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    margin-bottom: .5rem;
    padding: .5rem .75rem;
  }
  .count-table td {
    padding: .25rem 0;
    border: none;
    text-align: left !important;
  }
  .count-table td::before {
    content: attr(data-label);
    font-weight: 600;
    display: inline-block;
    min-width: 6rem;
    color: #6c757d;
    font-size: .8rem;
  }
  .count-table td.model-cell::before { display: none; }
  .count-table td.model-cell {
    font-size: 1rem;
    margin-bottom: .25rem;
  }
}
