:root {
  --bg: #f3f0e8;
  --surface: #fffdf8;
  --surface-strong: #f8f3e6;
  --text: #231910;
  --muted: #76675a;
  --line: #dccfbd;
  --accent: #0e7a53;
  --accent-dark: #095b3d;
  --accent-soft: #e7f7ef;
  --shadow: 0 20px 45px rgba(48, 34, 18, 0.08);
  --radius: 24px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.92), transparent 38%),
    linear-gradient(180deg, #f8f4ec 0%, var(--bg) 100%);
  color: var(--text);
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  border-radius: 16px;
  min-height: 48px;
  padding: 12px 18px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 16px;
  background: #fffefb;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(14, 122, 83, 0.12);
}

label {
  display: block;
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.shell {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.card {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(220, 207, 189, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

.hero,
.form-card,
.list-card {
  padding: 24px;
}

.hero {
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  max-width: 650px;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 0.98;
}

.intro {
  max-width: 620px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
}

.scan-btn {
  margin-top: 24px;
  width: 100%;
  min-height: 86px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent) 0%, #16a36e 100%);
  color: #ffffff;
  font-size: clamp(22px, 4vw, 30px);
  letter-spacing: 0.01em;
  box-shadow: 0 18px 36px rgba(14, 122, 83, 0.24);
}

.scan-btn:hover,
.primary-btn:hover,
.dark-btn:hover {
  transform: translateY(-1px);
}

.barcode-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 12px;
  margin-top: 18px;
  align-items: end;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.section-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-head h2 {
  margin: 0;
  font-size: 24px;
}

.form-card {
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.bottom-download-row {
  justify-content: flex-end;
}

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

.dark-btn {
  background: #1f3028;
}

.secondary-btn {
  background: var(--accent-soft);
  color: var(--accent);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.status-msg {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--accent);
  font-weight: 700;
}

.status-msg.error {
  color: #b44a1f;
}

.count-pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th, td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.empty-row {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.remove-btn {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fff3eb;
  color: #b44a1f;
}

dialog {
  width: min(760px, calc(100vw - 24px));
  border: 0;
  border-radius: 28px;
  padding: 0;
  box-shadow: 0 30px 70px rgba(21, 19, 16, 0.24);
}

dialog::backdrop {
  background: rgba(18, 15, 11, 0.55);
}

.scanner-dialog-body {
  padding: 22px;
  background: var(--surface);
}

.picker-dialog-body {
  padding: 22px;
  background: var(--surface);
}

.scanner-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.scanner-head h2 {
  margin: 0;
  font-size: 28px;
}

.scanner-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.scanner-stage {
  position: relative;
  min-height: 340px;
  border-radius: 22px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(12, 18, 14, 0.92), rgba(26, 35, 29, 0.94));
}

.scanner-stage::after {
  content: "";
  position: absolute;
  inset: 16% 9%;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.15);
  pointer-events: none;
}

.scanner-video,
.reader-box {
  width: 100%;
  min-height: 340px;
  object-fit: cover;
  background: #111;
}

#reader video,
#reader canvas {
  width: 100% !important;
  height: 340px !important;
  object-fit: cover;
}

.scanner-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.picker-select {
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .shell {
    width: min(100% - 16px, 100%);
    padding: 16px 0 24px;
  }

  .hero,
  .form-card,
  .list-card,
  .scanner-dialog-body {
    padding: 18px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .barcode-row {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-head-actions {
    width: 100%;
  }

  .actions-row button,
  .barcode-row button {
    width: 100%;
  }

  dialog {
    width: 100vw;
    max-width: 100vw;
    min-height: 100dvh;
    border-radius: 0;
  }

  .scanner-stage,
  .scanner-video,
  .reader-box,
  #reader video,
  #reader canvas {
    min-height: 420px;
    height: 420px !important;
  }
}

@media (max-width: 520px) {
  .hero h1 {
    font-size: 34px;
  }

  .scan-btn {
    min-height: 76px;
    font-size: 24px;
  }

  th, td {
    padding-inline: 10px;
  }
}
