:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1e222b;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #4d8dff;
  --ok: #35c77a;
  --warn: #f0b429;
  --bad: #ef5a5a;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Sarabun", "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }

.hidden { display: none !important; }
.spacer { flex: 1; }

/* ------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.conn { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
}
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

/* --------------------------------------------------------------- cards */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}
.pill {
  margin-left: auto;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--muted);
}

.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.progress { color: var(--muted); font-size: 13px; }
.err { color: var(--bad); font-size: 13px; margin: 10px 0 0; }

/* ------------------------------------------------------------- buttons */

.btn {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 16px;
  font: inherit;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.ghost { background: transparent; }

.link {
  background: none; border: none; padding: 0;
  color: var(--accent); font: inherit; cursor: pointer;
  text-decoration: underline;
}

/* ------------------------------------------------------------ dropzone */

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: rgba(77, 141, 255, .07); }
.dz-main { margin: 0 0 6px; font-size: 15px; }
.dz-sub { margin: 0; color: var(--muted); font-size: 12.5px; }

.paste { margin-top: 14px; }
.paste summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.paste textarea {
  width: 100%; margin: 10px 0;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px; resize: vertical;
}

/* --------------------------------------------------------------- stats */

.stats { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 16px; }
.stat {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  min-width: 96px;
}
.stat b { display: block; font-size: 20px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--bad); }

.toolbar { margin-bottom: 14px; }
.toolbar input[type="search"] {
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font: inherit; min-width: 240px;
}
.chk { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }

/* --------------------------------------------------------------- tiers */

.tier { margin-bottom: 18px; }
.tier-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 2px; border-bottom: 1px solid var(--line); margin-bottom: 10px;
}
.tier-head h3 { font-size: 15px; }
.tier-head .count { color: var(--muted); font-size: 12.5px; }

.items { display: grid; gap: 10px; }

.item {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 10px;
  padding: 10px 14px;
}
.item.auto   { border-left-color: var(--ok); }
.item.picked { border-left-color: var(--accent); }
.item.review { border-left-color: var(--warn); }
.item.missing{ border-left-color: var(--bad); }
.item.skipped { opacity: .4; }

.thumb {
  width: 68px; height: 68px;
  background: #0b0d11 center/contain no-repeat;
  border: 1px solid var(--line); border-radius: 8px;
  display: grid; place-items: center;
  color: var(--muted); font-size: 11px; text-align: center;
}

.meta { min-width: 0; }
.meta .name-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.meta input {
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 6px;
  padding: 3px 6px; font: inherit;
}
.meta input:hover { border-color: var(--line); }
.meta input:focus { border-color: var(--accent); outline: none; background: var(--card); }
.meta .in-name { flex: 1 1 320px; font-weight: 600; }
.meta .in-id { width: 120px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.meta .file {
  color: var(--muted); font-size: 12.5px; margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.meta .file a { color: var(--muted); }

.actions { display: flex; align-items: center; gap: 8px; }
.actions select {
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font: inherit; font-size: 13px; max-width: 260px;
}

.badge {
  font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.auto   { color: var(--ok);     border-color: rgba(53,199,122,.4); }
.badge.picked { color: var(--accent); border-color: rgba(77,141,255,.4); }
.badge.review { color: var(--warn);   border-color: rgba(240,180,41,.4); }
.badge.missing{ color: var(--bad);    border-color: rgba(239,90,90,.4); }

/* -------------------------------------------------------------- picker */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6);
  display: grid; place-items: center; padding: 20px;
}
.modal-box {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  width: min(720px, 100%); max-height: 82vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-box input[type="search"] {
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font: inherit; margin-bottom: 12px;
}
.picker-results { overflow-y: auto; display: grid; gap: 8px; }
.pick {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 12px;
  align-items: center; padding: 8px; border-radius: 8px;
  border: 1px solid var(--line); cursor: pointer; background: var(--card-2);
}
.pick:hover { border-color: var(--accent); }
.pick .thumb { width: 52px; height: 52px; }
.pick .pname { font-size: 13.5px; word-break: break-word; }
.pick .ppath { color: var(--muted); font-size: 11.5px; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 999px; z-index: 60; font-size: 14px;
}
.toast.bad { border-color: var(--bad); color: var(--bad); }

@media (max-width: 720px) {
  .item { grid-template-columns: 56px 1fr; }
  .actions { grid-column: 1 / -1; }
}

/* --------------------------------------------------------- setup card */

.setup { border-color: rgba(240, 180, 41, .45); }
.setup .num { background: var(--warn); color: #1a1300; }
.setup-steps { margin: 6px 0 0; padding-left: 22px; display: grid; gap: 9px; font-size: 14px; }
.setup-steps a { color: var(--accent); }
.setup-steps code {
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 7px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
  word-break: break-all;
}
.hint-inline { color: var(--muted); font-size: 12.5px; }

/* HD marker on a candidate: the render to hand over when one exists. */
.tag-hd {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(53, 199, 122, .15);
  border: 1px solid rgba(53, 199, 122, .45);
  color: var(--ok);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .3px;
  vertical-align: middle;
}

/* Google Sheets link input */
.sheet-row { margin-top: 16px; }
.sheet-row label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.sheet-row input[type="url"] {
  flex: 1 1 380px;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font: inherit; font-size: 13.5px;
}
.sheet-row input[type="url"]:focus { border-color: var(--accent); outline: none; }

/* --------------------------------------------- section > bundle grouping */

.section-group { margin-bottom: 26px; }

.section-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}
.section-no {
  font-size: 12px; font-weight: 700; color: var(--accent);
  background: rgba(77,141,255,.12); border-radius: 6px; padding: 2px 8px;
}
.section-name {
  flex: 1 1 260px; min-width: 0;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 6px;
  padding: 4px 8px; font: inherit; font-size: 15px; font-weight: 650;
}
.section-name:hover { border-color: var(--line); }
.section-name:focus { border-color: var(--accent); outline: none; background: var(--card); }

.tier.nested { margin-left: 16px; }
.tier-no {
  font-size: 11.5px; font-weight: 700; color: var(--muted);
  background: var(--card-2); border-radius: 5px; padding: 2px 7px;
}
.tier-name {
  flex: 1 1 220px; min-width: 0;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 6px;
  padding: 3px 7px; font: inherit; font-size: 14.5px; font-weight: 600;
}
.tier-name:hover { border-color: var(--line); }
.tier-name:focus { border-color: var(--accent); outline: none; background: var(--card); }

/* ------------------------------------------------------- progress bar */

/* Long jobs (reading a document, packing the ZIP) report here so the page
   never just sits there looking frozen. */
.task {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.task-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 13px;
}

.task-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.task-time { color: var(--muted); font-variant-numeric: tabular-nums; }

.task-track {
  height: 8px;
  border-radius: 999px;
  background: #0d1016;
  overflow: hidden;
}

.task-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width .25s ease;
}

/* Before the worker knows how many steps there are, a sliding sliver says
   "running" without claiming a fraction it cannot back up. */
.task.indeterminate .task-fill {
  width: 35%;
  transition: none;
  animation: task-slide 1.1s ease-in-out infinite;
}

@keyframes task-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

.task.done .task-fill { width: 100%; background: var(--ok); }
.task.error .task-fill { width: 100%; background: var(--bad); }
.task.error .task-label { color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
  .task.indeterminate .task-fill { animation: none; width: 100%; opacity: .45; }
  .task-fill { transition: none; }
}

/* A pick carried over from an earlier job, so the reviewer can tell at a
   glance which rows they are being asked to trust rather than re-check. */
.tag-mem {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(110, 150, 255, .15);
  border: 1px solid rgba(110, 150, 255, .45);
  color: #8fb0ff;
  font-size: 10.5px;
  font-weight: 700;
  vertical-align: middle;
}
/* A remembered pick found through the name-only or index-only fallback: the
   right picture for a reward written differently, probably. Worn in a warmer
   colour so it does not read as settled the way an exact confirmation does. */
.tag-mem.weak {
  background: rgba(240, 180, 41, .14);
  border-color: rgba(240, 180, 41, .45);
  color: var(--warn);
}

/* A confirmation whose picture the current index cannot see. The pick still
   stands - this is a prompt to scan or reconnect, not an error. */
.mem-missing {
  margin-top: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(240, 180, 41, .4);
  background: rgba(240, 180, 41, .08);
  font-size: 12.5px;
  line-height: 1.5;
}
.mem-missing strong { color: var(--warn); }

/* This copy is older than the team server's. Informational, not a failure -
   so it sits above the work rather than interrupting it. */
.update-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(77, 141, 255, .45);
  background: rgba(77, 141, 255, .10);
  font-size: 13.5px;
}
.update-bar strong { color: var(--accent); }
.update-bar a { margin-left: auto; }

/* ------------------------------------------------ first-run walkthrough */
.warn-bar {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(255, 184, 77, .12);
  border: 1px solid rgba(255, 184, 77, .4);
  color: #ffb84d;
  font-size: 13.5px;
}
.onboard-steps { list-style: none; margin: 14px 0 0; padding: 0; }
.onboard-steps > li {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line, #262a33);
  margin-bottom: 10px;
}
.onboard-steps > li.done { opacity: .6; }
.onboard-steps > li.wait { opacity: .5; }
.onboard-steps > li.now { border-color: rgba(77, 141, 255, .5); }
.ob-head { display: flex; align-items: center; gap: 10px; }
.ob-mark {
  width: 22px; height: 22px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(77, 141, 255, .18);
  color: #8fb0ff;
  font-size: 12px; font-weight: 700;
}
.done .ob-mark { background: rgba(53, 199, 122, .18); color: var(--ok, #35c77a); }
.ob-state { margin-left: auto; font-size: 12.5px; color: #8a8f9b; }
.done .ob-state { color: var(--ok, #35c77a); }
.ob-body { margin: 8px 0 0 32px; font-size: 13.5px; line-height: 1.7; }
.ob-body p { margin: 0 0 8px; }
.ob-notes { margin: 8px 0 0; padding-left: 18px; color: #a8adb8; font-size: 13px; }
.ob-notes li { margin-bottom: 4px; }
.ob-warn {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 184, 77, .1);
  border: 1px solid rgba(255, 184, 77, .35);
  color: #ffb84d;
}

/* Upload straight from the picker: the moment someone finds the library has
   nothing for a reward is the moment to let them add it. */
.picker-upload {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

/* Before-and-after for a picture the browser had to shrink. Shown only when
   something actually changed - approving an upload that needed no work would
   be a dialog for its own sake. */
.shrink-box { width: min(620px, 100%); }
.shrink-list {
  overflow-y: auto;
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}
.shrink-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: center;
  padding: 10px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.shrink-row img {
  width: 96px; height: 96px;
  object-fit: contain;
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.shrink-meta { min-width: 0; display: grid; gap: 4px; }
.shrink-name { font-weight: 600; word-break: break-all; font-size: 13.5px; }
.shrink-nums { font-size: 13px; }
.shrink-nums b { color: var(--ok); }
.shrink-pct {
  margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  background: rgba(53,199,122,.15); border: 1px solid rgba(53,199,122,.4);
  color: var(--ok); font-size: 11.5px;
}
.shrink-dim { color: var(--muted); font-size: 12px; }
.shrink-warn { color: var(--bad); font-size: 12.5px; }
.shrink-actions { margin: 0; }
