:root {
  --ink: #1c1c1e;
  --muted: #8e8e93;
  --blue: #007aff;
  --bg: #f2f2f7;
  --card: #ffffff;
  --line: #e5e5ea;
  --fill: #f2f2f7;
  --ok: #248a3d;
  --ok-bg: #e9f8ee;
  --warn: #c93400;
  --warn-bg: #fff4e8;
  --bad: #d70015;
  --bad-bg: #fff1f0;
  --info: #636366;
  --pdf: #e5e5ea;
  --sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  min-height: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
.eyebrow { margin: 0; color: var(--muted); font-size: 12px; }
h1 { margin: 2px 0 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.primary, .ghost {
  border-radius: 12px;
  padding: 9px 14px;
  border: 0;
}
.segment {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: #e5e5ea;
}
.segment button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--ink);
}
.segment button.on {
  background: white;
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.primary { background: var(--blue); color: white; font-weight: 600; }
.primary:disabled { background: #c7c7cc; cursor: not-allowed; }
.ghost { background: var(--fill); color: var(--ink); }
.status { display: flex; gap: 6px; align-items: center; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  background: var(--fill);
  color: var(--info);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.banner {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn);
}
.banner.bad { background: var(--bad-bg); color: var(--bad); }

.dropzone {
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.dropzone input { display: none; }
.dropzone.hot .drop-card { background: white; }
.drop-card {
  width: min(640px, 100%);
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 40px 32px;
}
.drop-kicker { margin: 0 0 8px; color: var(--blue); font-size: 13px; font-weight: 600; }
.drop-card h2 { margin: 0 0 12px; font-size: 32px; font-weight: 700; letter-spacing: -0.03em; }
.drop-copy { margin: 0 0 24px; color: var(--muted); line-height: 1.6; }

.workspace {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(340px, 1.05fr) minmax(460px, 1fr);
  gap: 12px;
  padding: 12px;
}
.pdf-pane {
  background: var(--pdf);
  border-radius: 16px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.pane-head { padding: 14px 16px 8px; }
.pane-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.pane-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; word-break: break-all; }
.pdf-pane iframe { flex: 1; width: 100%; border: 0; background: white; }

.form-pane { overflow: auto; padding: 8px 8px 48px; }
.tally { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stamp {
  background: var(--ok-bg);
  color: var(--ok);
  border-radius: 16px;
  padding: 12px 12px 14px;
  min-height: 108px;
}
.stamp.bad { background: var(--bad-bg); color: var(--bad); }
.stamp.warn { background: var(--warn-bg); color: var(--warn); }
.stamp .cap { margin: 0; font-size: 12px; font-weight: 600; }
.stamp .num { margin: 6px 0 0; font-family: var(--mono); font-size: 20px; font-weight: 600; line-height: 1.2; }
.stamp .sub { margin: 8px 0 0; font-size: 12px; opacity: 0.8; }
.stamp label { display: block; margin-top: 8px; font-size: 11px; }
.stamp input {
  width: 100%;
  margin-top: 4px;
  border: 0;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  padding: 4px 6px;
  font-family: var(--mono);
  font-size: 12px;
}

.issues { margin: 16px 0 8px; display: grid; gap: 8px; }
.status-row {
  margin: 0;
  padding: 10px 12px;
  background: var(--card);
  border-radius: 12px;
}
.status-row.ok { background: var(--ok-bg); }
.status-row.warning { background: var(--warn-bg); }
.status-row.error { background: var(--bad-bg); }
.status-row.info { background: var(--card); }
.status-kicker { margin: 0; font-size: 14px; font-weight: 650; }
.status-row.ok .status-kicker { color: var(--ok); }
.status-row.warning .status-kicker { color: var(--warn); }
.status-row.error .status-kicker { color: var(--bad); }
.status-row.info .status-kicker { color: var(--info); }
.status-body { margin: 4px 0 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }

.block { margin-top: 22px; }
.block h3 { margin: 0 0 12px; font-size: 17px; font-weight: 700; }
.fields { display: grid; gap: 12px; }
.field { display: grid; grid-template-columns: 9.2rem 1fr; gap: 10px; align-items: start; }
.field span { padding-top: 10px; color: var(--muted); font-size: 13px; }
.field input, .field textarea, .field select, .table-wrap input {
  width: 100%;
  border: 0;
  background: var(--card);
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.field textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
.field input.bad, .field textarea.bad, .field select.bad { box-shadow: inset 0 0 0 1.5px var(--bad); background: #fff8f8; }
.choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
}
.choice label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  padding: 5px 10px 5px 7px;
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}
.choice label.choice-custom { min-width: 4.6rem; }
.choice label:has(input:checked) {
  background: #e8f1ff;
  box-shadow: inset 0 0 0 1.5px #007aff;
}
.field .choice input[type="radio"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  flex: 0 0 16px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  accent-color: #007aff;
}
.field .choice input[data-field="internal_bl_no"] {
  flex: 1 1 10rem;
  width: auto;
  min-width: 9rem;
  margin-left: 2px;
}

.table-wrap { overflow-x: auto; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); }
.cn-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.cn-table th, .cn-table td { padding: 6px 4px; text-align: left; vertical-align: top; }
.cn-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.cn-table td input {
  width: 100%;
  box-shadow: none;
  background: var(--fill);
  padding: 6px 8px;
}
.cn-table .col-no { width: 26%; }
.cn-table .col-seal { width: 18%; }
.cn-table .col-unit { width: 14%; }
.cn-table .col-type,
.cn-table .col-pkgs,
.cn-table .col-kg,
.cn-table .col-cbm { width: 8%; }
.cn-table .col-del { width: 10%; padding-right: 8px; text-align: right; }
.cn-table .col-no input,
.cn-table .col-seal input { font-family: var(--mono); font-size: 12px; }
tr.bad td { background: #fff6f6; }
.row-note { margin: 4px 0 0; color: var(--warn); font-size: 12px; line-height: 1.35; }
.row-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 0;
  margin: 2px 0 0;
  padding: 3px 8px;
  border: 0;
  border-radius: 999px;
  background: #ff3b30;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.row-x:hover { background: #e0352b; }
.row-x:active { background: #c6281f; }
.add-row { margin-top: 10px; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .pdf-pane { height: 70vh; }
  .tally { grid-template-columns: 1fr 1fr; }
  .topbar { height: auto; align-items: flex-start; flex-wrap: wrap; }
  .top-actions { width: 100%; }
  .primary, .ghost, .pill { white-space: nowrap; flex: 0 0 auto; }
  .field { grid-template-columns: 1fr; }
  .field span { padding-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
