/* ============================================================================
   供应商收据识别 · 离线版
   布局目标：一屏之内「选图 / 看图 / 改数据」同时在场，左右两栏各自滚动，
   页面本身不滚（桌面端）。所以 body 是 flex 列，.board 是 2×2 网格：
         ┌─────────────┬───────────────┐
         │ 图片队列     │               │
         ├─────────────┤   识别结果     │
         │ 当前图片     │               │
         └─────────────┴───────────────┘
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e4e7eb;
  --line-2: #d3d8de;
  --ink: #1b1f24;
  --ink-2: #59636e;
  --ink-3: #8b949e;
  --brand: #2f6fed;
  --brand-d: #1d55c4;
  --brand-w: #eaf1ff;
  --green: #12805c;
  --green-w: #e6f6ef;
  --orange: #b26900;
  --orange-w: #fff3e0;
  --red: #d33b3b;
  --red-w: #fdeceb;
  --r: 10px;
  --r-sm: 7px;
  --sh: 0 1px 2px rgba(16, 24, 40, .06);
  --sh-2: 0 8px 24px rgba(16, 24, 40, .14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ 顶栏 */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  padding: 0 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand__mark {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  flex: 0 0 auto;
}
.brand__name { font-size: 14.5px; font-weight: 650; letter-spacing: .2px; }
.brand__tag {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #fafbfc;
  color: var(--ink-3);
  font-size: 11px;
  white-space: nowrap;
}

.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.engine {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #fafbfc;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.engine:hover { border-color: var(--line-2); background: #fff; }
.engine i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  flex: 0 0 auto;
}
.engine.is-ok { border-color: #bfe3d4; background: var(--green-w); color: var(--green); }
.engine.is-ok i { background: var(--green); }
.engine.is-run { border-color: #c9dafa; background: var(--brand-w); color: var(--brand-d); }
.engine.is-run i { background: var(--brand); animation: pulse 1s ease-in-out infinite; }
.engine.is-bad { border-color: #f0c4c4; background: var(--red-w); color: var(--red); }
.engine.is-bad i { background: var(--red); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ----------------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s, opacity .12s;
}
.btn:hover { background: #f7f8fa; border-color: #bfc6ce; }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: #fff; border-color: var(--line-2); }

.btn--sm { height: 28px; padding: 0 9px; font-size: 12px; border-radius: 6px; }

.btn--primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  box-shadow: 0 1px 2px rgba(47, 111, 237, .3);
}
.btn--primary:hover { background: var(--brand-d); border-color: var(--brand-d); }
.btn--primary:disabled:hover { background: var(--brand); border-color: var(--brand); }

.btn--danger { color: var(--red); border-color: #efc2c2; background: #fff; }
.btn--danger:hover { background: var(--red); border-color: var(--red); color: #fff; }

.btn--ghost { color: var(--ink-2); }

/* ----------------------------------------------------------------- 布局 */
.board {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(400px, 45%) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 10px 12px 12px;
}

.zone {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh);
  overflow: hidden;
}

.zone--queue { grid-column: 1; grid-row: 1; }
.zone--shot { grid-column: 1; grid-row: 2; }
.zone--result { grid-column: 2; grid-row: 1 / span 2; }

.zone__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#fdfdfe, #fafbfc);
}

.zone__head h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
  font-weight: 620;
  letter-spacing: .2px;
  white-space: nowrap;
}
.zone__head h2 .t {
  overflow: hidden;
  text-overflow: ellipsis;
}
.zone--shot .zone__head h2 { flex: 1 1 auto; }
.zone--shot .zone__head h2 .t { display: block; }

.zone__head .tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 7px;
  border-radius: 99px;
  background: #eef1f4;
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.pill--green { background: var(--green-w); color: var(--green); }
.pill--orange { background: var(--orange-w); color: var(--orange); }
.pill--gray { background: #eef1f4; color: var(--ink-3); }

.hint {
  margin: 0;
  padding: 0 12px 9px;
  color: var(--ink-3);
  font-size: 11.5px;
  line-height: 1.45;
}

/* ------------------------------------------------------------- 图片队列 */
.thumbs {
  flex: 0 0 auto;
  display: flex;
  gap: 9px;
  padding: 10px 12px 7px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.thumbs::-webkit-scrollbar { height: 6px; }
.thumbs::-webkit-scrollbar-thumb { background: #cfd5dc; border-radius: 99px; }

.thumbs-empty {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 76px;
  padding: 10px;
  border: 1.5px dashed var(--line-2);
  border-radius: 8px;
  color: var(--ink-3);
  font-size: 12px;
  text-align: center;
}

.thumb {
  position: relative;
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 1.5px solid var(--line-2);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.thumb:hover { border-color: #a9b3bf; }
.thumb.is-on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-w); }
.thumb.is-drag { opacity: .4; }
.thumb.is-over { border-color: var(--brand); border-style: dashed; }

.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }

.thumb__no {
  position: absolute;
  left: 0; top: 0;
  padding: 0 4px;
  border-bottom-right-radius: 6px;
  background: rgba(20, 24, 28, .68);
  color: #fff;
  font-size: 10px;
  line-height: 15px;
}

.thumb__tick {
  position: absolute;
  right: 3px; top: 3px;
  display: grid;
  place-items: center;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 9px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}

.thumb__state {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 1px 0;
  background: rgba(20, 24, 28, .62);
  color: #fff;
  font-size: 9.5px;
  text-align: center;
  letter-spacing: .2px;
}
.thumb__state--done { background: rgba(18, 128, 92, .82); }
.thumb__state--run { background: rgba(47, 111, 237, .82); }

.thumb__scan {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(47, 111, 237, .06), rgba(47, 111, 237, .3));
}
.thumb__scan::after {
  content: "";
  position: absolute;
  left: 0; right: 0; height: 2px;
  background: #fff;
  box-shadow: 0 0 8px 2px rgba(47, 111, 237, .9);
  animation: scan 1.1s ease-in-out infinite;
}
@keyframes scan { 0% { top: 4%; } 50% { top: 92%; } 100% { top: 4%; } }

.thumb--add {
  display: grid;
  place-items: center;
  gap: 2px;
  border-style: dashed;
  color: var(--ink-3);
  background: #fbfcfd;
}
.thumb--add i { font-style: normal; font-size: 19px; line-height: 1; }
.thumb--add em { font-style: normal; font-size: 11px; }
.thumb--add:hover { color: var(--brand); border-color: var(--brand); background: var(--brand-w); }

.zone--queue.is-drop .thumbs { background: var(--brand-w); border-radius: 8px; }

/* --------------------------------------------------------------- 图片区 */
.imgview {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background:
    linear-gradient(45deg, #f7f8fa 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, #f7f8fa 25%, transparent 25%) 0 8px / 16px 16px,
    #fbfcfd;
  cursor: zoom-in;
  overflow: hidden;
}
/* 图片必须完整可见：contain + 不超过容器，宁可有留白也不裁切 */
.imgview img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(16, 24, 40, .12);
}

.imgview__empty {
  display: grid;
  place-items: center;
  gap: 6px;
  color: var(--ink-3);
  font-size: 12.5px;
  text-align: center;
  cursor: default;
}
.imgview__empty i {
  font-style: normal;
  font-size: 26px;
  opacity: .5;
}

.imgview__note {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 3px 8px;
  background: rgba(20, 24, 28, .72);
  color: #fff;
  font-size: 11px;
  text-align: center;
}

.imgview__cta {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
}

.imgview__err {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 7px 11px;
  border-radius: var(--r-sm);
  background: rgba(211, 59, 59, .96);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  cursor: default;
}
.imgview__err span { flex: 1; min-width: 0; }
.imgview__err .btn {
  flex: 0 0 auto;
  height: 24px;
  padding: 0 8px;
  border-color: rgba(255, 255, 255, .6);
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 11.5px;
}
.imgview__err .btn:hover { background: #fff; color: var(--red); border-color: #fff; }

.imgview.is-running::after {
  content: "识别中…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .55);
  color: var(--brand-d);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .5px;
}

/* --------------------------------------------------------- 图片底部导轨 */
.shotbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  background: #fcfcfd;
}

.rail {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }

.rail__btn {
  flex: 0 0 auto;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: #fff;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.rail__btn:hover { border-color: #a9b3bf; background: #f6f8fa; }
.rail__btn.is-on {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
.rail__btn.is-done { border-color: #bfe3d4; color: var(--green); background: var(--green-w); }
.rail__btn.is-done.is-on { border-color: var(--brand); background: var(--brand); color: #fff; }

.shotbar .tools { display: flex; gap: 6px; flex: 0 0 auto; }

/* --------------------------------------------------------------- 结果表 */
.table-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; }

table.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  table-layout: fixed;
}

table.grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 32px;
  padding: 0 6px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

table.grid td {
  padding: 0;
  border-bottom: 1px solid #f0f2f4;
  vertical-align: middle;
}
table.grid tr:hover td { background: #fafcff; }

.c-no { width: 36px; text-align: center; color: var(--ink-3); font-size: 12px; }
.c-unit { width: 62px; }
.c-num { width: 74px; }
.c-sum { width: 88px; }
.c-del { width: 40px; }

table.grid th.c-num, table.grid th.c-sum { text-align: right; }
table.grid th.c-no, table.grid th.c-unit { text-align: center; }

td.c-no, td.c-unit, td.c-sum, td.c-del { text-align: center; }
td.c-sum {
  padding: 0 8px 0 0 !important;
  text-align: right;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

input.cell {
  width: 100%;
  height: 34px;
  padding: 0 7px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
input.cell:focus {
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--brand), 0 0 0 2px var(--brand-w);
  border-radius: 4px;
}
input.cell--c { text-align: center; }
input.cell--n { text-align: right; font-variant-numeric: tabular-nums; }
input.cell--n::-webkit-outer-spin-button,
input.cell--n::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

td.is-empty {
  padding: 26px 16px !important;
  color: var(--ink-3);
  font-size: 12.5px;
  text-align: center;
}

td.c-del .btn {
  width: 22px;
  height: 22px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--red);
  opacity: 0;
}
tr:hover td.c-del .btn { opacity: .8; }
td.c-del .btn:hover { opacity: 1; border-color: var(--red); background: var(--red-w); }

/* -------------------------------------------------------- 合计 / 保存条 */
.foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #fcfcfd;
}

.totals { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.totals__label { color: var(--ink-2); font-size: 12px; }
.totals b {
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
}
.totals__tip {
  color: var(--ink-3);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.totals__tip::before { content: "· "; }

.savebar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}
.savebar__hint { color: var(--ink-3); font-size: 12px; }
.savebar__hint.is-saved { color: var(--green); }
.savebar__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: transparent;
}
.savebar__hint.is-saved + .savebar__dot { background: var(--green); }

/* ---------------------------------------------------------------- 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
}
.modal.is-open { display: grid; }

.modal__mask {
  position: absolute;
  inset: 0;
  background: rgba(16, 20, 26, .42);
}

.modal__box {
  position: relative;
  width: min(440px, calc(100vw - 32px));
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--sh-2);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
}
.modal__head h3 { margin: 0; font-size: 14.5px; font-weight: 620; }

.modal__body { padding: 0 16px 14px; }

.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}

.scope {
  display: flex;
  gap: 6px;
  padding: 3px;
  margin-bottom: 12px;
  border-radius: 9px;
  background: #f1f3f6;
}
.scope__opt {
  flex: 1;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.scope__opt.is-on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}

.field { display: block; }
.field > span { display: block; margin-bottom: 5px; color: var(--ink-2); font-size: 12px; }

.input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-w); }

.modal .hint { padding: 8px 0 0; }

/* ---------------------------------------------------------------- 放大 */
.zoom {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(12, 15, 19, .88);
  cursor: zoom-out;
}
.zoom.is-open { display: grid; }
.zoom img { max-width: 100%; max-height: calc(100vh - 70px); object-fit: contain; }
.zoom span {
  position: absolute;
  bottom: 14px;
  color: rgba(255, 255, 255, .65);
  font-size: 12px;
}

/* --------------------------------------------------------------- toast */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  max-width: min(560px, calc(100vw - 40px));
  padding: 9px 14px;
  border-radius: 8px;
  background: #232a31;
  color: #fff;
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: var(--sh-2);
  animation: toast-in .18s ease-out;
}
.toast--success { background: #14704f; }
.toast--warning { background: #8a5a00; }
.toast--danger { background: #b3352f; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ============================================================ 窄屏适配 */
@media (max-width: 980px) {
  body { overflow: auto; }
  .board {
    display: flex;
    flex-direction: column;
    height: auto;
    padding: 8px;
  }
  .zone--shot { min-height: 0; }
  .imgview { height: min(56vh, 420px); flex: none; }
  .table-wrap { max-height: none; }
  .brand__tag { display: none; }
  .zone__head { flex-wrap: wrap; }
  .zone__head .tools { margin-left: 0; }
  .zone--shot .zone__head .tools { margin-left: auto; }
}

@media (max-width: 560px) {
  .topbar { height: auto; padding: 8px 10px; flex-wrap: wrap; gap: 8px; }
  .brand__name { font-size: 13.5px; }
  .engine { font-size: 11.5px; }
  .zone--shot .zone__head .tools { width: 100%; margin-left: 0; }
  .zone--shot .zone__head .tools .btn { flex: 1 1 auto; }
  .imgview { height: 40vh; }
  .c-unit { width: 54px; }
  .c-num { width: 64px; }
  .c-sum { width: 70px; }
  .c-del { width: 34px; }
  table.grid { font-size: 12px; }
  input.cell { font-size: 12px; height: 32px; }
  td.c-del .btn { opacity: .75; }
  .hint { font-size: 11px; }
  .foot { flex-wrap: wrap; gap: 6px; }
  .savebar { margin-left: 0; }
  .totals__tip { display: none; }
}
