:root {
  --ink: #16232b;
  --paper: #e8eef0;
  --panel: #f6faf9;
  --line: #c3d3d1;
  --amber: #2a8f82;
  --amber-deep: #1c6a60;
  --green: #3f7d53;
  --red: #ab3a30;
  --muted: #5c6a68;
  --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: #b8c7c4;
}

.status-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

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

.status-updated {
  font-size: 11.5px;
  color: #8a9997;
  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: #a9b8b5;
  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;
}

.scan-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

#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-icon {
  width: 46px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
}

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

.btn-block {
  width: 100%;
}

.field {
  margin-bottom: 14px;
}

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

.field input[type="text"] {
  width: 100%;
  font-size: 15px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

.field input[type="text"]: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); }

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

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

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

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

/* Green scan-target overlay (corner brackets + moving laser line),
   sized to line up with the qrbox area html5-qrcode scans within. */
#scanBox {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 260px;
  height: 140px;
  pointer-events: none;
  z-index: 5;
}

#scanBox .corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid #4ade80;
}

#scanBox .corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
#scanBox .corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
#scanBox .corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
#scanBox .corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }

#scanBox .scan-line {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 2px;
  background: #4ade80;
  box-shadow: 0 0 8px 2px rgba(74, 222, 128, 0.8);
  animation: scanMove 2s ease-in-out infinite;
}

@keyframes scanMove {
  0% { top: 6px; }
  50% { top: calc(100% - 6px); }
  100% { top: 6px; }
}

.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;
}

/* ---------- 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);
}

.progress-bar-track {
  margin-top: 8px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--amber);
  border-radius: 3px;
  width: 0%;
  transition: width 0.2s ease;
}

.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; }

/* ---------- Upload: validation warnings ---------- */

#validationList {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.validation-item {
  padding: 11px 13px;
  border-radius: 4px;
  background: #fdf2e3;
  border: 1px solid #e8cfa0;
  color: #6b4b17;
  font-size: 13.5px;
  line-height: 1.5;
}

.validation-item strong { font-weight: 700; }

/* ---------- Upload: replace summary ---------- */

.preview-summary {
  font-size: 14.5px;
  line-height: 1.5;
}

/* ---------- 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; }
  .field-row { flex-direction: column; gap: 2px; }
  .field-row .value { text-align: left; }
}

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

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

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

/* ---------- Tab badge ---------- */

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
  margin-left: 2px;
}

/* ---------- Expiry batches (on scan result) ---------- */

.batches-section {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.batches-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.batches-header h3 {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--amber-deep);
  margin: 0;
  text-transform: none;
}

.batches-empty {
  font-size: 13.5px;
  color: var(--muted);
  margin: 4px 0 0;
}

.batches-list, .reminders-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.batch-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 12px;
}

.batch-item-main { flex: 1; min-width: 120px; }

.batch-item-date {
  font-family: var(--mono);
  font-size: 14.5px;
  font-weight: 600;
}

.batch-item-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.batch-item-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 4px;
}

.snooze-select {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

.link-btn-danger { color: var(--red); }
.link-btn-danger:hover { color: #7a231b; }

.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  background: #eef1ea;
  color: #43502f;
  white-space: nowrap;
}

.badge-overdue { background: #f5e2df; color: #7a2a22; }
.badge-soon { background: #fdf2e3; color: #6b4b17; }
.badge-snoozed { background: #e6e2d5; color: var(--muted); }
.badge-dismissed { background: #e6e2d5; color: var(--muted); }

/* ---------- Add-batch form ---------- */

.add-batch-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.field-pair {
  display: flex;
  gap: 12px;
}

.field-pair .field { flex: 1; }

.add-batch-form select {
  width: 100%;
  font-size: 15px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

.add-batch-form input[type="date"] {
  width: 100%;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

/* ---------- Reminders tab ---------- */

.reminder-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 14px;
}

.reminder-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.reminder-card-name {
  font-weight: 600;
  font-size: 15px;
}

.reminder-card-barcode {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.reminder-card-meta {
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 2px;
}

@media (max-width: 480px) {
  .field-pair { flex-direction: column; gap: 14px; }
}
