/* ---------- Design tokens ---------- */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --ink: #14171c;
  --ink-2: #5b6470;
  --line: #dee2e8;
  --accent: #1e4fd8;
  --accent-ink: #ffffff;
  --accent-soft: #e9effd;
  --ok: #187a3c;   --ok-soft: #e2f3e8;
  --err: #bb3226;  --err-soft: #fbe9e7;
  --warn: #91650a; --warn-soft: #f7efd9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #21252d;
    --ink: #e8eaee;
    --ink-2: #99a2ae;
    --line: #2a2f39;
    --accent: #85a8ff;
    --accent-ink: #0e1526;
    --accent-soft: #202c4b;
    --ok: #66c689;   --ok-soft: #12301c;
    --err: #f2857b;  --err-soft: #3a1713;
    --warn: #e0b25c; --warn-soft: #322408;
    --shadow: none;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; font-weight: 650; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .01em;
}
.wordmark svg { color: var(--accent); flex: none; }

/* Segmented controls (top tabs + Quick type picker) */
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  flex: 1;
  min-height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.seg button[aria-selected="true"], .seg button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

@media (min-width: 480px) {
  .topbar-inner { flex-direction: row; align-items: center; justify-content: space-between; }
  .topbar .seg { flex: none; }
  .topbar .seg button { min-width: 92px; padding: 0 14px; }
}

/* ---------- Layout ---------- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card > h2, .section-head h2 {
  font-size: 12.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-2);
  margin-bottom: 12px;
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.section-head h2 { margin-bottom: 0; }
footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(36px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-2);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: 11px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .12s;
}
.btn:active:not(:disabled) { filter: brightness(.92); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.btn.big { width: 100%; min-height: 50px; font-size: 16px; }
.btn-link {
  background: none;
  border: none;
  padding: 6px 4px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

/* ---------- Dropzone ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 30px 16px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { color: var(--accent); margin-bottom: 4px; }
.dropzone strong { font-size: 15.5px; }
.dz-hint { font-size: 13px; color: var(--ink-2); }
.dz-file {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-foot {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.format-guide summary {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  min-height: 32px;
  display: flex;
  align-items: center;
}
.format-guide[open] summary { margin-bottom: 6px; }
.format-guide p, .format-guide li { font-size: 13.5px; color: var(--ink-2); }
.format-guide ul { margin: 0 0 10px; padding-left: 20px; }
.format-guide strong { color: var(--ink); }
.inline-error {
  margin-top: 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--err);
  background: var(--err-soft);
  border-radius: 10px;
  padding: 10px 14px;
}

/* ---------- Chips ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12.5px;
  font-weight: 650;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.err { background: var(--err-soft); color: var(--err); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Review row cards ---------- */
.row-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: 12px;
  padding: 13px 15px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.row-card.has-err { border-left-color: var(--err); }
.row-card.has-warn { border-left-color: var(--warn); }
.row-card header {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 9px;
}
.row-num { font-size: 11px; color: var(--ink-2); font-family: var(--mono); flex: none; }
.row-card h3 {
  font-size: 15px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.codes { margin: 0; display: grid; gap: 4px; }
.codes > div { display: flex; align-items: baseline; gap: 10px; }
.codes dt { font-size: 12px; color: var(--ink-2); width: 78px; flex: none; }
.codes dd { margin: 0; font-family: var(--mono); font-size: 14.5px; letter-spacing: .02em; }
.issues { margin: 9px 0 0; padding: 0; list-style: none; font-size: 12.5px; }
.issues li { padding-left: 16px; position: relative; }
.issues li::before { content: "•"; position: absolute; left: 3px; }
.issues.err { color: var(--err); }
.issues.warn { color: var(--warn); }

/* ---------- Sticky action bar ---------- */
.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 26%);
}

/* ---------- Progress ---------- */
.progress-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .15s;
}
.progress-text { font-size: 13px; color: var(--ink-2); margin-top: 7px; }

/* ---------- Results ---------- */
.results-summary { font-size: 13.5px; color: var(--ink-2); }
.results-issues { font-size: 13px; color: var(--err); margin-top: 6px; }
.thumb-group { margin-bottom: 16px; }
.thumb-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.thumb-group-head h3 {
  font-size: 14.5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thumb-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}
.thumb-card {
  flex: none;
  width: 168px;
  background: #fff; /* barcodes stay black-on-white even in dark mode */
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 10px 6px;
  text-align: center;
}
.thumb-card img { display: block; height: 58px; margin: 0 auto 6px; max-width: 100%; object-fit: contain; }
.thumb-label { font-size: 11.5px; font-weight: 650; color: #5b6470; }
.thumb-actions { display: flex; justify-content: center; gap: 2px; }

/* ---------- Quick mode ---------- */
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 11px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.code-input { font-family: var(--mono); font-size: 20px; letter-spacing: .08em; }
.quick-status { margin-top: 10px; font-size: 13.5px; color: var(--ink-2); min-height: 21px; }
.quick-status.ok { color: var(--ok); font-weight: 650; }
.quick-status.err { color: var(--err); font-weight: 650; }
.suggestion-btn {
  margin-top: 4px;
  width: 100%;
  min-height: 44px;
  border: 1.5px dashed var(--accent);
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}
.quick-preview {
  background: #fff; /* barcode readability */
  border: 1px solid var(--line);
  border-radius: 11px;
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow-x: auto;
}
.quick-preview svg { max-width: 100%; height: auto; }
.quick-preview .placeholder { color: #99a2ae; font-size: 13px; }
.actionbar-inline { display: flex; gap: 10px; margin-top: 14px; }
.actionbar-inline .btn { flex: 1; }

/* ---------- Misc ---------- */
.lib-error {
  background: var(--err-soft);
  color: var(--err);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
}
noscript p {
  max-width: 640px;
  margin: 24px auto;
  padding: 0 16px;
  text-align: center;
}
