/* 镜头群组验证 — 移动优先样式 */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --na: #f3f4f6;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --ok-line: #86efac;
  --ng: #b91c1c;
  --ng-bg: #fee2e2;
  --ng-line: #fca5a5;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --warn: #b45309;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 10px 30px rgba(0, 0, 0, .08);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #111a2b;
    --ink: #e5e7eb;
    --muted: #94a3b8;
    --faint: #64748b;
    --line: #1f2b40;
    --line-strong: #334155;
    --na: #0f172a;
    --ok: #4ade80;
    --ok-bg: #052e16;
    --ok-line: #166534;
    --ng: #f87171;
    --ng-bg: #450a0a;
    --ng-line: #991b1b;
    --accent: #60a5fa;
    --accent-bg: #0c1e3a;
    --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 14px 40px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  font-size: 15px;
}

h1, h2, h3 { margin: 0; font-weight: 700; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea, button { font-size: 16px; }

/* ---------- 顶栏 ---------- */
#topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  padding-top: var(--safe-top);
  height: calc(52px + var(--safe-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
#title { font-size: 17px; letter-spacing: .2px; }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--na); }

/* ---------- 主区域 ---------- */
#view { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.pad { padding: 14px 14px calc(24px + var(--safe-bottom)); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }
.hint { font-size: 12px; color: var(--faint); line-height: 1.55; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- 底部 tab ---------- */
#tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}
#tabbar button {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 9px 0 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  letter-spacing: .3px;
}
#tabbar .ico { font-size: 17px; line-height: 1; }
#tabbar button.active { color: var(--accent); font-weight: 600; }

/* ---------- 矩阵 ---------- */
.toolbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.group-tabs {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px 8px;
  scrollbar-width: none;
}
.group-tabs::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--panel); }
@media (prefers-color-scheme: dark) {
  .chip.active { background: var(--accent); border-color: var(--accent); color: #04111f; }
}

.filters { display: flex; gap: 8px; padding: 0 12px 10px; align-items: center; flex-wrap: wrap; }
.filter {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12.5px;
}
.filter.active { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); font-weight: 600; }
.summary { margin-left: auto; font-size: 12px; color: var(--muted); }

.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--panel); }
table.matrix { border-collapse: separate; border-spacing: 0; min-width: 100%; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; }
table.matrix thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--panel);
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  height: 46px; padding: 4px 6px;
  min-width: 84px; max-width: 84px;
  vertical-align: middle;
}
table.matrix thead th .col-name {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.25; text-align: left;
}
table.matrix thead th .col-focal { display: block; font-weight: 500; font-size: 10.5px; color: var(--faint); margin-top: 2px; }

table.matrix th.row-head, table.matrix td.row-head {
  position: sticky; left: 0; z-index: 2;
  background: var(--panel);
  min-width: 84px; max-width: 120px;
  padding: 6px 8px;
  text-align: left;
  font-size: 13px; font-weight: 700;
}
table.matrix thead th.row-head { z-index: 4; }
table.matrix th.row-head .sub, table.matrix td.row-head .sub { display: block; font-weight: 400; font-size: 10.5px; color: var(--faint); margin-top: 1px; }
table.matrix tbody tr:nth-child(even) th.row-head,
table.matrix tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--panel) 92%, var(--bg)); }

.cell {
  display: flex; width: 100%; min-width: 84px; height: 46px;
  align-items: center; justify-content: center;
  border: 0; background: transparent;
  font-size: 15px; font-weight: 700;
  color: var(--faint);
}
.cell.ok { background: var(--ok-bg); color: var(--ok); }
.cell.ng { background: var(--ng-bg); color: var(--ng); }
.cell.na { background: var(--na); color: var(--line-strong); cursor: default; }
.cell .dot { font-size: 20px; line-height: 1; }
.cell:active:not(.na) { filter: brightness(.94); }

.legend { display: flex; gap: 14px; padding: 10px 14px calc(20px + var(--safe-bottom)); font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- 通用组件 ---------- */
.btn {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  min-height: 46px;
}
.btn:active { filter: brightness(.95); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #04111f; } }
.btn-danger { color: var(--ng); border-color: var(--ng-line); }
.btn-block { display: block; width: 100%; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }
.btn-sm { padding: 8px 12px; min-height: 38px; font-size: 14px; border-radius: 10px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  margin-bottom: 10px;
}
.card-tap:active { background: var(--na); }
.card-top { display: flex; align-items: baseline; gap: 8px; }
.card-title { font-weight: 700; font-size: 15px; }
.card-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.tag {
  display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 600;
  background: var(--na); color: var(--muted); border: 1px solid var(--line);
}
.tag.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.tag.ng { background: var(--ng-bg); color: var(--ng); border-color: var(--ng-line); }
.tag.accent { background: var(--accent-bg); color: var(--accent); border-color: transparent; }

.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .55; }
.empty p { margin: 6px 0 18px; font-size: 13.5px; line-height: 1.6; }

.section-title { font-size: 12px; font-weight: 700; letter-spacing: .6px; color: var(--faint); text-transform: uppercase; margin: 18px 2px 8px; }

/* ---------- 弹层 ---------- */
#sheet-root { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
.overlay {
  position: absolute; inset: 0; background: rgba(8, 12, 20, .5);
  display: flex; align-items: flex-end; justify-content: center;
  pointer-events: auto;
  animation: fade .16s ease-out;
}
.sheet {
  width: 100%; max-width: 660px;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideup .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet-head {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 12px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 16px; }
.sheet-head .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.sheet-body { overflow: auto; -webkit-overflow-scrolling: touch; padding: 16px; padding-bottom: calc(20px + var(--safe-bottom)); }
.sheet-foot { flex: none; border-top: 1px solid var(--line); padding: 12px 16px calc(12px + var(--safe-bottom)); display: flex; gap: 10px; }
.sheet-foot .btn { flex: 1; }

@media (min-width: 720px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; max-height: 86dvh; }
  .sheet-body { padding-bottom: 20px; }
  .sheet-foot { padding-bottom: 12px; }
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(18px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--faint); margin-top: 5px; line-height: 1.5; }
input, select, textarea {
  width: 100%;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 11px 12px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 74px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="datetime-local"] { min-height: 46px; }
.inline { display: flex; gap: 10px; }
.inline > * { flex: 1; min-width: 0; }

/* 结论选择 */
.result-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-toggle button {
  height: 62px; border-radius: 14px; border: 2px solid var(--line-strong);
  background: var(--panel); color: var(--muted);
  font-size: 17px; font-weight: 700;
}
.result-toggle button.on-ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.result-toggle button.on-ng { background: var(--ng-bg); border-color: var(--ng); color: var(--ng); }

/* ---------- 照片 ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.photo-cell {
  position: relative; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden;
  background: var(--na); border: 1px dashed var(--line-strong);
}
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell .rm {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .62); color: #fff; font-size: 15px; line-height: 26px; padding: 0;
}
.photo-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; border-style: dashed; background: var(--panel);
}
.photo-add .plus { font-size: 20px; line-height: 1; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

/* ---------- 历史 ---------- */
.hist-item { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.hist-item:first-child { border-top: 0; }
.hist-main { flex: 1; min-width: 0; }
.hist-note { font-size: 13px; color: var(--ink); margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.hist-time { font-size: 11.5px; color: var(--faint); margin-top: 3px; }
.hist-photos { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.hist-photos img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

/* ---------- 更换 ---------- */
.swap-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.swap-arrow { color: var(--accent); font-weight: 700; }
.unit-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--na); border: 1px solid var(--line); color: var(--ink);
}
.unit-pill.stock { color: var(--warn); }

/* ---------- 空状态 ---------- */
.skeleton { height: 12px; background: var(--na); border-radius: 6px; margin: 8px 0; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(78px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  background: #111827; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; max-width: 84vw; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 300;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-color-scheme: dark) { #toast { background: #e5e7eb; color: #0b1220; } }

/* ---------- 小屏微调 ---------- */
@media (max-width: 380px) {
  table.matrix thead th { min-width: 76px; max-width: 76px; }
  .cell { min-width: 76px; }
  table.matrix th.row-head, table.matrix td.row-head { min-width: 76px; }
}
