* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f4f7f0;
  --surface: #ffffff;
  --primary: #2d5016;
  --primary-hover: #3d6b1f;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --border: #d0d8c8;
  --danger: #b33;
  --camera-min-h: 220px;
}

html,
body {
  height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  min-height: 100%;
}

.app-header {
  text-align: center;
  padding: 8px 0 16px;
}

.app-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
}

.app-nav {
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.app-nav a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.app-nav a:hover {
  text-decoration: underline;
}

.app-nav-muted {
  color: var(--muted);
  font-weight: 400;
}

.mode-switch {
  display: inline-flex;
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 20px;
  cursor: pointer;
  min-height: 40px;
}

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

.weigh-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.weigh-bag-label {
  font-weight: 600;
  font-size: 1rem;
  color: var(--primary);
  text-align: center;
  line-height: 1.35;
}

.weigh-group-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.weigh-or {
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.weigh-preview {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--primary);
}

.weigh-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.btn-weigh-save {
  width: 100%;
  min-height: 48px;
  font-size: 1.1rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 40px;
  cursor: pointer;
}

.btn-ghost:hover {
  color: var(--text);
}

.camera-panel {
  position: relative;
  background: #111;
  border-radius: 12px;
  overflow: hidden;
  min-height: var(--camera-min-h);
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.qr-reader {
  width: 100%;
  min-height: var(--camera-min-h);
}

.qr-reader video {
  object-fit: cover !important;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(26, 26, 26, 0.92);
  z-index: 2;
}

#scan-loading {
  color: #fff;
}

.scan-loading-text {
  font-size: 0.95rem;
  color: #e0e0e0;
}

.scan-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: scan-spin 0.75s linear infinite;
}

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

/* Reduce html5-qrcode green scan flash while camera is active */
#qr-reader img[alt="Info icon"],
#qr-reader__dashboard_section,
#qr-reader__scan_region {
  display: none !important;
}

.hidden {
  display: none !important;
}

.seed-info {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.seed-details .detail-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.seed-details .detail-row:last-child {
  border-bottom: none;
}

.seed-details dt {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.9rem;
}

.seed-details dd {
  font-size: 1.05rem;
}

.seed-details dd.purpose-warning {
  color: var(--danger);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.action-input,
.action-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  min-height: 44px;
}

.action-input:focus,
.action-select:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  padding: 0 16px;
  white-space: nowrap;
}

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

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

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

.btn-action {
  background: var(--primary);
  color: #fff;
  min-width: 5.5rem;
}

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

.btn-scan {
  font-size: 1.25rem;
  padding: 14px 32px;
  min-height: 52px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.95rem;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.toast.error {
  background: var(--danger);
}

/* Label Register (migration companion) */
.register-header {
  text-align: center;
  padding: 4px 0 8px;
}

.register-header .app-title {
  font-size: 1.45rem;
  margin-bottom: 0;
}

.register-eyebrow {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}

.register-lead {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.45;
}

.register-back {
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  margin-bottom: 4px;
}

.register-back:hover {
  text-decoration: underline;
}

.register-align-hint {
  margin-bottom: 10px;
}

.register-camera-panel {
  width: 100%;
  aspect-ratio: 11 / 5;
  max-height: 40vh;
  min-height: 150px;
  position: relative;
  overflow: hidden;
  background: #111;
}

.register-video {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
  object-position: center;
  display: block;
}

.label-guide {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.label-guide-frame {
  position: relative;
  width: 90%;
  max-height: 84%;
  aspect-ratio: 2.5 / 1;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(45, 80, 22, 0.35);
}

/* The two read zones — match ID_BAND / LOT_BAND fractions in label-ocr.js */
.label-guide-band {
  position: absolute;
  border: 2px solid rgba(76, 220, 100, 0.95);
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.label-guide-band-id {
  left: 50%;
  top: 0;
  width: 50%;
  height: 36%;
}

.label-guide-band-lot {
  left: 28%;
  top: 58%;
  width: 72%;
  height: 40%;
}

.label-guide-tag {
  position: absolute;
  top: -1px;
  left: -1px;
  transform: translateY(-100%);
  background: rgba(76, 220, 100, 0.95);
  color: #06330f;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 3px 3px 0 0;
  white-space: nowrap;
}

/* Live status pill at the bottom of the camera preview */
.scan-status {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 4;
  max-width: 92%;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.scan-status-warn {
  background: rgba(176, 58, 46, 0.92);
}

/* Confirmation overlay shown briefly after an auto-add */
.added-overlay {
  background: rgba(31, 92, 38, 0.94);
  color: #fff;
}

.added-check {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
}

.added-title {
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  padding: 0 12px;
}

.added-sub {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

.register-capture-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.register-capture-row .btn {
  flex: 1;
  min-height: 48px;
  font-size: 1.05rem;
}

#btn-scan-toggle {
  flex: 2;
}

.register-file-label {
  margin-top: 8px;
  cursor: pointer;
  text-align: center;
  display: block;
}

.register-file-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}

.register-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}

.register-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.register-review {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.register-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.register-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.register-field span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.register-from-inv {
  font-weight: 400;
  font-style: normal;
  color: var(--muted);
  font-size: 0.8rem;
}

.register-input-readonly {
  background: var(--bg);
  color: var(--text);
}

.inventory-status {
  font-size: 0.85rem;
  color: var(--primary);
  margin-top: 4px;
  min-height: 1.2em;
}

.inventory-status-error {
  color: var(--danger);
}

.ocr-debug-wrap {
  margin-top: 8px;
  font-size: 0.8rem;
}

.ocr-debug-wrap summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.ocr-debug {
  margin-top: 6px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
}

.register-field-readonly output {
  font-family: ui-monospace, monospace;
  font-size: 0.95rem;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  word-break: break-all;
}

.register-review-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.register-review-actions .btn-primary {
  width: 100%;
  min-height: 48px;
}

.register-queue {
  margin-bottom: 24px;
}

.register-queue-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.register-count {
  font-weight: 400;
  color: var(--muted);
}

.register-queue-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.register-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.register-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.register-table th,
.register-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.register-table-subhead th {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.72rem;
}

.register-bag-cell {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  max-width: 7rem;
  word-break: break-all;
}

.btn-row-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  min-height: 32px;
}

.btn-row-remove:hover {
  color: var(--danger);
}

.register-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.register-empty.hidden {
  display: none;
}
