:root {
  --ink: #201d1a;
  --paper: #edeae1;
  --panel: #f8f6f0;
  --line: #cec7b3;
  --amber: #c8791f;
  --amber-deep: #a8620f;
  --green: #3f7d53;
  --red: #ab3a30;
  --muted: #6f6a5d;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input {
  font-family: inherit;
}

/* ---------- Top bar ---------- */

.topbar {
  background: var(--ink);
  color: var(--paper);
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background:
    repeating-linear-gradient(
      90deg,
      var(--amber) 0px, var(--amber) 3px,
      transparent 3px, transparent 5px,
      var(--amber) 5px, var(--amber) 6px,
      transparent 6px, transparent 9px,
      var(--amber) 9px, var(--amber) 12px,
      transparent 12px, transparent 14px
    );
  border-radius: 3px;
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 13px;
  color: #c9c3b2;
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: #d8d3c4;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot.ok { background: var(--green); }
.status-dot.bad { background: var(--red); }

/* ---------- Tab bar ---------- */

.tabbar {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
}

.tab {
  background: none;
  border: none;
  color: #b9b3a1;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 4px 12px;
  margin-right: 18px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--paper);
  border-bottom-color: var(--amber);
}

.tab:hover { color: var(--paper); }

/* ---------- Content ---------- */

.content {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.scan-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 20px;
}

.scan-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.scan-row {
  display: flex;
  gap: 8px;
}

#barcodeInput {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 17px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

#barcodeInput:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.btn {
  font-size: 14.5px;
  font-weight: 600;
  border-radius: 3px;
  border: 1px solid transparent;
  padding: 12px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

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

.btn-primary:hover { background: #34302a; }

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

.btn-secondary:hover { border-color: var(--amber-deep); color: var(--amber-deep); }

.scan-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.scan-actions .btn { flex: 1; }

/* ---------- Camera panel ---------- */

.camera-panel {
  margin-top: 16px;
}

.camera-frame {
  position: relative;
  background: #000;
  border-radius: 4px;
  overflow: hidden;
}

#cameraView {
  width: 100%;
  min-height: 260px;
}

.btn-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.camera-hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 0;
}

/* ---------- Messages ---------- */

.message-panel {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 4px;
  background: #f5e2df;
  border: 1px solid #dcb3ac;
  color: #7a2a22;
  font-size: 14.5px;
}

.message-panel.info {
  background: #eef1ea;
  border-color: #c7d0bc;
  color: #43502f;
}

/* ---------- Results ---------- */

.result-panel {
  margin-top: 20px;
}

.result-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 10px;
  margin-bottom: 16px;
}

.result-header h2 {
  font-size: 21px;
  margin: 0;
  letter-spacing: -0.01em;
}

.result-barcode {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
}

.group-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field-group h3 {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--amber-deep);
  margin: 0 0 8px;
}

.field-table {
  border-top: 1px solid var(--line);
}

.field-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}

.field-row .label {
  color: var(--muted);
  flex-shrink: 0;
}

.field-row .value {
  font-family: var(--mono);
  text-align: right;
  word-break: break-word;
}

.field-row .value.empty {
  color: #a8a290;
}

/* ---------- Select / inputs shared ---------- */

#deptSelect, #deptSearch {
  width: 100%;
  font-size: 15px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}

#deptSelect:focus, #deptSearch:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

/* ---------- Browse list ---------- */

.browse-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.browse-row {
  background: var(--panel);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-align: left;
  border: none;
  width: 100%;
  font: inherit;
  color: inherit;
}

.browse-row:hover { background: #efece2; }

.browse-row .bname {
  font-weight: 600;
  font-size: 14.5px;
}

.browse-row .bmeta {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.browse-row .bprice {
  font-family: var(--mono);
  font-size: 14.5px;
  white-space: nowrap;
}

.browse-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  background: var(--panel);
}

.pager {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  color: var(--muted);
}

.pager .btn { padding: 9px 14px; font-size: 13.5px; }

/* ---------- Upload ---------- */

.upload-hint {
  font-size: 13.5px;
  color: var(--muted);
  margin: 0 0 14px;
}

#uploadInput {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
}

.upload-progress {
  margin-top: 14px;
  font-size: 14px;
  color: var(--muted);
}

.upload-result {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 4px;
  background: #eef1ea;
  border: 1px solid #c7d0bc;
  color: #43502f;
  font-size: 14.5px;
}

.upload-result.error {
  background: #f5e2df;
  border-color: #dcb3ac;
  color: #7a2a22;
}

.upload-result dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 16px;
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 13.5px;
}

.upload-result dt { color: var(--muted); }
.upload-result dd { margin: 0; font-weight: 600; }

/* ---------- Footer ---------- */

.footer {
  border-top: 1px solid var(--line);
  padding: 14px 20px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--amber-deep);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
  .scan-row { flex-direction: column; }
  .scan-actions { flex-direction: column; }
  .field-row { flex-direction: column; gap: 2px; }
  .field-row .value { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Settings ---------- */

code {
  font-family: var(--mono);
  background: #e6e2d5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.92em;
}
