:root {
  --bg: #f3efe6;
  --bg-accent: #e4dcc8;
  --ink: #1c1a16;
  --muted: #5c564c;
  --primary: #1f6b4a;
  --primary-ink: #fff;
  --danger: #9b2c2c;
  --ok: #1f6b4a;
  --border: #cbbfa8;
  --radius: 10px;
  --font: "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse at top left, #fff8ea 0%, transparent 55%),
    linear-gradient(160deg, var(--bg), var(--bg-accent));
  min-height: 100%;
}

body {
  max-width: 480px;
  margin: 0 auto;
  min-width: 360px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: 1rem; }
.userbox { display: flex; gap: 10px; align-items: center; font-size: 0.85rem; }
.user-name { color: var(--muted); }

.page {
  padding: 16px 16px 96px;
}

h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }
.muted { color: var(--muted); margin: 0 0 16px; }

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

.form.inline {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
}

input, select {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: #fff;
}

.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 1.05rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

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

.btn-secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn-action {
  width: 100%;
  background: var(--primary);
  color: var(--primary-ink);
  margin-bottom: 10px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  background: #8a857a;
  color: #eee;
}

.action-grid {
  display: flex;
  flex-direction: column;
  margin-top: 24px;
}

.admin-link { margin-top: 24px; }
.link { color: var(--primary); }

.error {
  background: #fde8e8;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius);
}

.ok {
  background: #e6f4ec;
  color: var(--ok);
  padding: 10px 12px;
  border-radius: var(--radius);
}

.user-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.user-card {
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.login { margin-top: 32px; }
.stub { margin-top: 16px; }

.small { font-size: 0.8rem; }

/* --- Scan page --- */
.scan-page { display: flex; flex-direction: column; gap: 12px; }

.scan-camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #111;
  border-radius: var(--radius);
  overflow: hidden;
}

.scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scan-reticle {
  pointer-events: none;
  position: absolute;
  inset: 18% 12%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28);
}

.btn-torch {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-height: 48px;
}

.scan-manual {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.scan-card {
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.75);
}

.ok-card {
  background: #e6f4ec;
  border-color: #8fc9a8;
}

.danger-card {
  background: #fde8e8;
  border-color: #e2a0a0;
}

.muted-card { color: var(--muted); }

.scan-code {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 4px 0 8px;
  word-break: break-all;
}

.stock-big {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary);
  margin: 8px 0 12px;
  line-height: 1.1;
}

.stock-unit {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.stock-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  background: #fff;
}

.stock-table th,
.stock-table td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}

.bc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.bc-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}

.bc-row.inactive { opacity: 0.65; }

.btn-sm {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.badge-off {
  font-size: 0.8rem;
  color: var(--danger);
}

.bind-panel {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.8);
}

/* Product picker */
.product-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.pp-search-label { font-size: 0.9rem; }

.pp-results,
.pp-tree,
.pp-recent {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow: auto;
}

.pp-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  margin-top: 4px;
}

.pp-product,
.pp-group,
.pp-crumb {
  text-align: left;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font: inherit;
}

.pp-group { font-weight: 600; }

.pp-name { display: block; font-weight: 600; }
.pp-meta { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.pp-bc { color: var(--primary); font-weight: 700; }

.pp-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
}

.pp-crumb {
  min-height: 36px;
  padding: 6px 8px;
  background: transparent;
  border: none;
  color: var(--primary);
}

.pp-crumb.current {
  color: var(--ink);
  font-weight: 700;
  cursor: default;
}

.pp-sep { color: var(--muted); }

mark {
  background: #ffe08a;
  color: inherit;
  padding: 0 1px;
}

/* Test codes print sheet */
.code-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 700px) {
  body { max-width: 900px; }
  .code-grid { grid-template-columns: 1fr 1fr; }
}

.code-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  break-inside: avoid;
}

.code-card.danger-outline { border-color: var(--danger); }

.barcode-svg {
  width: 100%;
  max-width: 280px;
  height: auto;
  background: #fff;
}

@media print {
  .topbar, .link { display: none !important; }
  body { max-width: none; background: #fff; }
  .code-grid { grid-template-columns: 1fr 1fr; }
}
