:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font-family: inherit; font-size: 1rem; }
button { cursor: pointer; }

/* ---------- 头部 ---------- */
.header {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .3);
}
.header-inner { max-width: 760px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: rgba(255, 255, 255, .18);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-logo svg { width: 24px; height: 24px; }
.brand h1 { font-size: 1.15rem; font-weight: 600; letter-spacing: .5px; }
.brand-sub { font-size: .75rem; opacity: .85; margin-top: 2px; }

.stats-chips { display: flex; gap: 8px; margin-top: 12px; }
.chip {
  flex: 1; background: rgba(255, 255, 255, .14);
  border-radius: 10px; padding: 6px 10px;
  display: flex; flex-direction: column; align-items: center; min-width: 0;
}
.chip-num { font-size: 1.15rem; font-weight: 700; line-height: 1.2; }
.chip-label { font-size: .7rem; opacity: .85; }
.chip-green { background: rgba(22, 163, 74, .35); }
.chip-dark { background: rgba(15, 23, 42, .25); }

/* ---------- 底部导航（手机） ---------- */
.main-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, .06);
}
.nav-btn {
  flex: 1; border: none; background: none;
  padding: 8px 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: .72rem;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--primary); font-weight: 600; }

/* ---------- 主体 ---------- */
.main {
  max-width: 760px; margin: 0 auto;
  padding: 14px 14px calc(84px + env(safe-area-inset-bottom));
}
.page { display: none; animation: fadeIn .18s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.footer {
  max-width: 760px; margin: 0 auto;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
  font-size: .72rem; text-align: center;
}
.muted { color: var(--muted); }
.center { text-align: center; }
.tip { font-size: .78rem; margin-top: 10px; line-height: 1.6; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}

/* ---------- 分段控件 ---------- */
.seg {
  display: flex; background: #eef2f7; border-radius: 12px;
  padding: 4px; margin-bottom: 14px; gap: 4px;
}
.seg-sm { padding: 3px; margin-bottom: 12px; }
.seg-btn {
  flex: 1; border: none; background: transparent; border-radius: 9px;
  padding: 9px 6px; font-size: .92rem; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all .15s;
}
.seg-sm .seg-btn { padding: 7px 6px; font-size: .85rem; }
.seg-btn.active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: 0 1px 4px rgba(15, 23, 42, .1); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-blue { background: var(--primary); }
.dot-green { background: var(--green); }

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.field-label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.req { color: var(--red); font-style: normal; }
.input {
  width: 100%; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 10px 12px; background: #fff; color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
  min-height: 44px;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.input-lg { font-size: 1.08rem; padding: 12px 14px; font-weight: 600; letter-spacing: .5px; }
textarea.input { resize: none; min-height: 56px; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 10px; padding: 10px 18px; font-size: .95rem; font-weight: 500;
  border: 1.5px solid transparent; transition: all .15s; text-decoration: none;
  min-height: 44px;
}
.btn svg { width: 17px; height: 17px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(37, 99, 235, .35); }
.btn-primary:not(:disabled):active { background: var(--primary-dark); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger-outline { background: #fff; border-color: #fecaca; color: var(--red); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 18px; font-size: 1.05rem; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: .82rem; }

/* ---------- 摄像头 ---------- */
.camera-box {
  position: relative; background: #0f172a; border-radius: 12px;
  overflow: hidden; aspect-ratio: 4 / 3; max-height: 52vh; width: 100%;
}
.camera-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
#camPlayback { object-fit: contain; background: #000; }
.camera-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, .65); font-size: .85rem; pointer-events: none;
}
.rec-indicator {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0, 0, 0, .6); border-radius: 20px;
  padding: 4px 12px; display: none; align-items: center; gap: 6px;
  color: #fff; font-size: .85rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.camera-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.camera-actions .btn { flex: 1; min-width: 100px; }
#btnRecord.recording { background: var(--red); box-shadow: 0 2px 6px rgba(220, 38, 38, .4); }

/* ---------- 扫码连录 ---------- */
.auto-status {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 12px;
  background: var(--primary-light); border: 1px solid rgba(37, 99, 235, .25);
}
.auto-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--primary); animation: pulse 1.6s infinite; }
.auto-dot.rec { background: var(--red); }
.auto-dot.error { background: var(--red); animation: none; }
.auto-dot.done { background: var(--green); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.auto-text { flex: 1; min-width: 0; }
.auto-main { font-weight: 600; font-size: .95rem; color: var(--text); word-break: break-all; }
.auto-sub { font-size: .8rem; color: var(--muted); margin-top: 2px; word-break: break-all; }
.auto-status .btn-sm { flex: none; }
#recOrder { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-outline.torch-on { background: #38bdf8; border-color: #38bdf8; color: #0c4a6e; }

/* ---------- 文件选择 ---------- */
.file-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; border: 2px dashed var(--border); border-radius: 12px;
  padding: 30px 16px; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s; text-align: center;
}
.file-drop:active { border-color: var(--primary); background: #f8faff; }
.file-drop input { display: none; }
.file-drop-icon svg { width: 34px; height: 34px; color: var(--primary); }
.file-drop-title { color: var(--text); font-weight: 500; }
.file-info video { width: 100%; border-radius: 12px; background: #000; max-height: 46vh; }
.file-meta-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.file-meta { font-size: .82rem; color: var(--muted); word-break: break-all; }

/* ---------- 进度条 ---------- */
.progress-wrap { margin-top: 12px; }
.progress { height: 8px; background: #e2e8f0; border-radius: 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--primary); border-radius: 6px; transition: width .2s; }
.progress-text { font-size: .78rem; color: var(--muted); margin-top: 6px; text-align: center; }

/* ---------- 查询 ---------- */
.search-row { display: flex; gap: 8px; }
.search-row .input { flex: 1; }
.recent { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.recent-label { font-size: .78rem; flex-shrink: 0; }
.recent-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.recent-chip {
  background: var(--primary-light); color: var(--primary-dark);
  border: none; border-radius: 16px; padding: 4px 12px; font-size: .78rem;
}
.recent-chip:active { opacity: .7; }

/* ---------- 列表 ---------- */
.list-count { font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.vcard {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px;
  box-shadow: var(--shadow); cursor: pointer;
  transition: transform .12s;
}
.vcard:active { transform: scale(.98); }
.vcard-thumb {
  width: 46px; height: 46px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.vcard-thumb svg { width: 20px; height: 20px; }
.thumb-ship { background: var(--primary-light); color: var(--primary); }
.thumb-receive { background: var(--green-light); color: var(--green); }
.vcard-body { flex: 1; min-width: 0; }
.vcard-order { font-weight: 600; font-size: .95rem; word-break: break-all; }
.vcard-sub { font-size: .75rem; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.vcard-remark { font-size: .78rem; color: var(--text); background: #f8fafc; border-radius: 8px; padding: 5px 8px; margin-top: 6px; word-break: break-all; }
.badge { font-size: .68rem; padding: 1px 8px; border-radius: 10px; font-weight: 500; }
.badge-ship { background: var(--primary-light); color: var(--primary-dark); }
.badge-receive { background: var(--green-light); color: var(--green); }
.vcard-play {
  width: 36px; height: 36px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
}
.vcard-play svg { width: 15px; height: 15px; margin-left: 2px; }

.empty {
  text-align: center; color: var(--muted); padding: 40px 16px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
}
.empty svg { width: 40px; height: 40px; color: #cbd5e1; margin-bottom: 10px; }
.empty-title { font-size: .9rem; }
.empty-sub { font-size: .78rem; margin-top: 4px; }

.loading { text-align: center; color: var(--muted); padding: 30px; font-size: .85rem; }

/* ---------- 筛选 ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 10px; }
.filters .input { flex: 1; min-width: 0; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .6); }
.modal-box {
  position: relative; background: #fff; border-radius: 16px;
  width: calc(100% - 32px); max-width: 560px; max-height: calc(100% - 60px);
  overflow-y: auto; padding: 14px; animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-title { font-weight: 600; font-size: 1rem; word-break: break-all; }
.icon-btn { border: none; background: #f1f5f9; border-radius: 8px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.icon-btn svg { width: 16px; height: 16px; }
.modal-box video { width: 100%; border-radius: 10px; background: #000; max-height: 52vh; }
.pm-meta { font-size: .78rem; color: var(--muted); margin-top: 10px; line-height: 1.7; word-break: break-all; }
.pm-actions { display: flex; gap: 10px; margin-top: 12px; }
.pm-actions .btn { flex: 1; }

/* ---------- 密码门 ---------- */
.auth-box {
  position: relative; background: #fff; border-radius: 16px;
  width: calc(100% - 48px); max-width: 340px; padding: 28px 22px;
  text-align: center; animation: pop .18s ease;
}
.auth-icon {
  width: 54px; height: 54px; border-radius: 14px; margin: 0 auto 14px;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
}
.auth-icon svg { width: 26px; height: 26px; }
.auth-box h2 { font-size: 1.05rem; margin-bottom: 6px; }
.auth-box p { font-size: .8rem; margin-bottom: 14px; }
.auth-box .input { margin-bottom: 12px; text-align: center; }

/* ---------- 扫码 ---------- */
.order-row { display: flex; gap: 8px; }
.order-row .input { flex: 1; min-width: 0; }
.btn-scan {
  flex-shrink: 0; border: 1px solid var(--border); background: #fff;
  border-radius: 10px; color: var(--primary); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; min-width: 60px;
  font-size: .68rem; padding: 6px 8px; cursor: pointer;
}
.btn-scan svg { width: 20px; height: 20px; }
.btn-scan:active { background: var(--primary-light); }
.btn-scan-square { min-width: 48px; padding: 8px; border-radius: 10px; }

.scanner { position: fixed; inset: 0; z-index: 250; background: #000; display: flex; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner-head {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
}
.scanner-title { color: #fff; font-weight: 600; font-size: .95rem; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.icon-btn-dark { background: rgba(15, 23, 42, .55); color: #fff; }
.scanner-frame {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%);
  width: 82%; max-width: 380px; height: 190px;
}
.sf-corner { position: absolute; width: 26px; height: 26px; border: 3px solid #fff; }
.sf-tl { left: 0; top: 0; border-right: none; border-bottom: none; border-radius: 4px 0 0 0; }
.sf-tr { right: 0; top: 0; border-left: none; border-bottom: none; border-radius: 0 4px 0 0; }
.sf-bl { left: 0; bottom: 0; border-right: none; border-top: none; border-radius: 0 0 0 4px; }
.sf-br { right: 0; bottom: 0; border-left: none; border-top: none; border-radius: 0 0 4px 0; }
.scanner-line {
  position: absolute; left: 6%; right: 6%; top: 8%; height: 2px;
  background: linear-gradient(90deg, transparent, #38bdf8, transparent);
  box-shadow: 0 0 10px rgba(56, 189, 248, .9);
  animation: scanline 2s ease-in-out infinite;
}
@keyframes scanline { 0%, 100% { top: 8%; } 50% { top: 92%; } }
.scanner-foot {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 14px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.scanner-tip { color: rgba(255, 255, 255, .92); font-size: .85rem; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.btn-dark-o { background: rgba(15, 23, 42, .5); border-color: rgba(255, 255, 255, .25); color: #fff; }
.btn-dark-o.torch-on { background: #38bdf8; border-color: #38bdf8; color: #0c4a6e; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(15, 23, 42, .92); color: #fff;
  border-radius: 10px; padding: 10px 18px; font-size: .85rem;
  z-index: 300; opacity: 0; pointer-events: none;
  transition: all .25s; max-width: calc(100% - 40px); text-align: center;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ---------- 平板 / 桌面 ---------- */
@media (min-width: 768px) {
  .header { padding: 22px 16px 18px; }
  .brand h1 { font-size: 1.35rem; }
  .main-nav {
    position: sticky; top: 0; bottom: auto; z-index: 100;
    max-width: 760px; margin: 0 auto;
    border-top: none; border-bottom: 1px solid var(--border);
    border-radius: 0; box-shadow: 0 2px 10px rgba(15, 23, 42, .05);
    background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px);
  }
  .nav-btn { flex-direction: row; gap: 7px; padding: 13px 10px; font-size: .9rem; }
  .nav-btn svg { width: 19px; height: 19px; }
  .nav-btn.active { border-bottom: 2.5px solid var(--primary); border-radius: 0; }
  .main { padding-top: 16px; padding-bottom: 30px; }
  .footer { padding-bottom: 30px; }
  .field-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 20px; }
}
