* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  padding-bottom: 2rem;
}

header {
  padding: 1.25rem 1rem 0.5rem;
  text-align: center;
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: #6e6e73;
  font-size: 0.9rem;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
}

#capture-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.capture-btn {
  display: block;
  text-align: center;
  padding: 1rem;
  border-radius: 12px;
  background: #0071e3;
  color: white;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.capture-btn.secondary {
  background: white;
  color: #0071e3;
  border: 1px solid #d2d2d7;
}

#preview-section {
  margin-top: 1rem;
  text-align: center;
}

#preview-img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#status-section {
  margin-top: 1rem;
  text-align: center;
  color: #6e6e73;
}

#results-section, #detail-section {
  margin-top: 1.25rem;
}

#results-section h2 {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

#results-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.candidate-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: white;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.candidate-card img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #f0f0f0;
  border-radius: 8px;
  flex-shrink: 0;
}

.candidate-info {
  flex: 1;
  min-width: 0;
}

.candidate-info .part-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.candidate-info .part-num {
  color: #6e6e73;
  font-size: 0.82rem;
}

.score-badge {
  font-size: 0.78rem;
  color: white;
  background: #34c759;
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  flex-shrink: 0;
}

#back-btn {
  background: none;
  border: none;
  color: #0071e3;
  font-size: 0.95rem;
  padding: 0.4rem 0;
  cursor: pointer;
}

#detail-content {
  background: white;
  border-radius: 12px;
  padding: 1rem;
  margin-top: 0.5rem;
}

#detail-content img {
  max-width: 140px;
  display: block;
  margin: 0 auto 0.75rem;
}

.detail-title {
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
}

.detail-num {
  text-align: center;
  color: #6e6e73;
  margin-bottom: 1rem;
}

.set-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.set-list li {
  padding: 0.5rem 0.6rem;
  background: #f5f5f7;
  border-radius: 8px;
  font-size: 0.88rem;
}

.error-text {
  color: #d70015;
  text-align: center;
}

/* ===== Tab nav ===== */
#tab-nav {
  display: flex;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1rem;
  gap: 0.4rem;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  white-space: nowrap;
  border: none;
  background: none;
  padding: 0.6rem 0.4rem;
  font-size: 0.85rem;
  color: #6e6e73;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-btn.active {
  color: #0071e3;
  border-bottom-color: #0071e3;
  font-weight: 600;
}

.view[hidden] { display: none; }

.hint {
  color: #6e6e73;
  font-size: 0.85rem;
  margin: 0.25rem 0 1rem;
}

/* ===== Toolbar / inputs ===== */
.toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.toolbar input[type="search"],
.toolbar input[type="text"],
.toolbar select {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid #d2d2d7;
  font-size: 0.95rem;
  background: white;
}

.toolbar .capture-btn {
  flex: none;
  white-space: nowrap;
}

.link-btn {
  background: none;
  border: none;
  color: #0071e3;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.4rem 0.2rem;
}

/* ===== Image + bbox overlay ===== */
.img-overlay-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin-bottom: 1rem;
}

.img-overlay-wrap img {
  max-width: 100%;
  display: block;
  border-radius: 12px;
}

.img-overlay-wrap svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ===== Scan item cards ===== */
#scan-items-list, .stack-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.scan-item-card {
  background: white;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.scan-item-card.excluded {
  opacity: 0.45;
}

.scan-item-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.scan-item-row img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #f0f0f0;
  border-radius: 8px;
  flex-shrink: 0;
}

.scan-item-info {
  flex: 1;
  min-width: 0;
}

.scan-item-info select {
  width: 100%;
  font-size: 0.88rem;
  padding: 0.3rem;
  border-radius: 6px;
  border: 1px solid #d2d2d7;
}

.scan-item-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid #d2d2d7;
  display: inline-block;
  vertical-align: middle;
}

.qty-input {
  width: 3.5rem;
  padding: 0.25rem;
  border-radius: 6px;
  border: 1px solid #d2d2d7;
  text-align: center;
}

.exclude-toggle {
  margin-left: auto;
  font-size: 0.8rem;
  color: #d70015;
  background: none;
  border: none;
  cursor: pointer;
}

#scan-confirm-btn {
  margin-top: 1rem;
}

/* ===== Inventory rows / report rows ===== */
.inv-row, .report-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: white;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.inv-row img, .report-row img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: #f0f0f0;
  border-radius: 8px;
  flex-shrink: 0;
}

.inv-row-info, .report-row-info {
  flex: 1;
  min-width: 0;
}

.inv-row-info .part-name, .report-row-info .part-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.inv-row-info .part-meta, .report-row-info .part-meta {
  color: #6e6e73;
  font-size: 0.78rem;
}

.qty-badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: #1d1d1f;
  flex-shrink: 0;
}

.needed-badge {
  font-size: 0.78rem;
  color: white;
  background: #d70015;
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  flex-shrink: 0;
}

.bricklink-link {
  font-size: 0.78rem;
  color: #0071e3;
  flex-shrink: 0;
}

.locate-btn {
  font-size: 0.78rem;
  color: #0071e3;
  background: none;
  border: 1px solid #0071e3;
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  flex-shrink: 0;
}

.report-summary {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  text-align: center;
}

.report-summary .stat {
  flex: 1;
  background: white;
  border-radius: 10px;
  padding: 0.6rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.report-summary .stat .num {
  font-size: 1.3rem;
  font-weight: 700;
  display: block;
}

.report-summary .stat .label {
  font-size: 0.75rem;
  color: #6e6e73;
}

.coverage-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: white;
  background: #34c759;
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  flex-shrink: 0;
}

.view-report-btn {
  font-size: 0.78rem;
  color: #0071e3;
  background: none;
  border: 1px solid #0071e3;
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  flex-shrink: 0;
}
