/* ---------- 设计变量 ---------- */
:root {
  --brand: #0B8A4B;
  --brand-strong: #066B39;
  --brand-soft: #E7F7EE;
  --brand-line: #BFE8D2;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6B7280;
  --line: #E5E7EB;
  --bg: #F4F6F5;
  --card: #FFFFFF;
  --danger: #DC2626;
  --danger-soft: #FEF2F2;
  --warn: #B45309;
  --warn-soft: #FFFBEB;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 8px 24px rgba(17, 24, 39, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

body { min-height: 100vh; -webkit-font-smoothing: antialiased; }

h1, h2, h3, p { margin: 0; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }

.logo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
}
.logo.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 15px; }

/* ---------- 登录 ---------- */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 0%, #E7F7EE 0, transparent 42%),
    radial-gradient(circle at 100% 100%, #EAF2FF 0, transparent 40%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.login-brand h1 { font-size: 19px; font-weight: 600; }
.login-brand p { color: var(--muted); font-size: 12px; margin-top: 2px; }
.login-tip { margin-top: 14px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 138, 75, .12);
}
.field textarea { resize: vertical; min-height: 64px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--brand-soft); border-color: var(--brand-line); }
.btn.danger { color: var(--danger); border-color: #FBD5D5; background: var(--danger-soft); }
.btn.light { background: rgba(255, 255, 255, .92); border-color: transparent; color: var(--ink); }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* ---------- 应用外壳 ---------- */
.app { min-height: 100vh; padding-bottom: calc(74px + var(--safe-b)); }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.app-brand { display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.app-brand:active { opacity: .7; }
.app-brand-text { display: grid; line-height: 1.25; min-width: 0; }
.app-brand-text strong { font-size: 15px; }
.app-brand-text small { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.net-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
}
.net-badge.off { background: var(--warn-soft); color: var(--warn); }

.main { max-width: 760px; margin: 0 auto; padding: 16px; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.page-head h1 { font-size: 19px; font-weight: 600; }
.page-head .hint { color: var(--muted); font-size: 12px; }

/* ---------- 通用卡片 / 列表 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title strong { font-size: 15px; font-weight: 600; }
.card-title .more { color: var(--brand); font-size: 13px; background: none; border: 0; cursor: pointer; }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
}
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.stat.warn .v { color: var(--warn); }

.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.quick {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 12px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
}
.quick:active { background: var(--brand-soft); }
.quick span { font-size: 12px; color: var(--ink-2); }
.quick i {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
}

.list { display: grid; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; }
.row-title { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.row-title b { font-weight: 600; }
.row-sub { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { text-align: right; flex: none; }
.row-side .num { font-weight: 600; }
.row-side .tagline { font-size: 11px; color: var(--muted); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--brand-soft);
  color: var(--brand-strong);
  white-space: nowrap;
}
.pill.out { background: #F3F4F6; color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.device { background: #EEF4FF; color: #1D4ED8; }
.pill.material { background: #F5F0FF; color: #6D28D9; }

.empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- 搜索 / 筛选 ---------- */
.searchbar { position: relative; margin-bottom: 10px; }
.searchbar input {
  width: 100%;
  padding: 11px 12px 11px 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
}
.searchbar input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(11, 138, 75, .1); }
.searchbar::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 50%;
  width: 12px;
  height: 12px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  transform: translateY(-55%);
}
.searchbar::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 50%;
  width: 6px;
  height: 2px;
  background: var(--muted);
  transform: rotate(45deg) translateY(2px);
  border-radius: 2px;
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- 扫码作业 ---------- */
.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: #EAEFEC;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.segmented button {
  padding: 9px 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.segmented button.on { background: #fff; color: var(--brand-strong); box-shadow: 0 1px 3px rgba(17, 24, 39, .1); }

.scan-box { display: flex; gap: 8px; }
.scan-input {
  flex: 1;
  min-width: 0;
  padding: 14px 14px;
  border: 2px solid var(--brand);
  border-radius: 12px;
  background: #fff;
  font-size: 16px;
  letter-spacing: .02em;
  outline: none;
  box-shadow: 0 0 0 4px rgba(11, 138, 75, .08);
}
.scan-input::placeholder { color: #9CA3AF; font-size: 14px; }

.scan-feedback { min-height: 20px; margin: 8px 2px 2px; font-size: 12.5px; color: var(--muted); }
.scan-feedback.err { color: var(--danger); }
.scan-feedback.ok { color: var(--brand-strong); }

.line-list { display: grid; gap: 8px; margin: 10px 0 4px; }
.line {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.line-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.line-name { font-weight: 500; }
.line-code { color: var(--muted); font-size: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; margin-top: 2px; }
.line-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.line-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.stepper button { width: 34px; height: 32px; border: 0; background: #fff; font-size: 17px; line-height: 1; cursor: pointer; }
.stepper button:active { background: var(--brand-soft); }
.stepper input { width: 54px; height: 32px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; outline: none; }
.line-remove { margin-left: auto; color: var(--muted); background: none; border: 0; font-size: 12px; cursor: pointer; }
.line-remove:active { color: var(--danger); }

.photo-box { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.photo-thumb { width: 56px; height: 56px; border-radius: 9px; object-fit: cover; border: 1px solid var(--line); }
.photo-empty { width: 56px; height: 56px; border: 1px dashed #CBD5E1; border-radius: 9px; display: grid; place-items: center; color: var(--muted); font-size: 11px; }

.submit-bar {
  position: sticky;
  bottom: calc(66px + var(--safe-b));
  margin-top: 14px;
  padding: 10px;
  background: rgba(244, 246, 245, .93);
  backdrop-filter: blur(8px);
  border-radius: 14px;
}
.submit-bar .btn { min-height: 48px; font-size: 16px; }
.submit-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  max-width: 760px;
  margin: 0 auto;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: grid;
  gap: 3px;
  justify-items: center;
  padding: 7px 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  border-radius: 10px;
}
.tabbar .dot { display: grid; place-items: center; width: 6px; height: 6px; border-radius: 50%; background: #D1D5DB; }
.tabbar button.on { color: var(--brand-strong); font-weight: 600; }
.tabbar button.on .dot { background: var(--brand); }
.tabbar .primary-tab { margin-top: -18px; }
.tabbar .primary-tab .dot {
  width: 42px;
  height: 42px;
  background: var(--brand);
  box-shadow: 0 6px 16px rgba(11, 138, 75, .32);
  margin-bottom: 2px;
  border: 4px solid #fff;
}
.tabbar .primary-tab .dot em {
  font-style: normal;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  line-height: 1;
}
.tabbar .primary-tab.on .dot { background: var(--brand-strong); }

/* ---------- 弹层 ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet-mask { position: absolute; inset: 0; background: rgba(17, 24, 39, .42); }
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 760px;
  max-height: 88vh;
  margin: 0 auto;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: sheetUp .18s ease-out;
}
@keyframes sheetUp { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sheet-body { padding: 16px; overflow: auto; -webkit-overflow-scrolling: touch; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: 88px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translate(-50%, 12px);
  z-index: 90;
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(17, 24, 39, .92);
  color: #fff;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #B91C1C; }
.toast.ok { background: #065F46; }

/* ---------- 摄像头扫码 ---------- */
.scanner { position: fixed; inset: 0; z-index: 80; background: #000; display: grid; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 66vw;
  max-width: 340px;
  height: 42vh;
  max-height: 220px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, .9);
  border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
.scanner-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(24px + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  color: #fff;
  font-size: 13px;
}

/* ---------- 打印标签 ---------- */
.print-area { display: none; }
.label-sheet { display: flex; flex-wrap: wrap; gap: 12px; }
.label {
  width: 220px;
  padding: 12px;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  text-align: center;
  page-break-inside: avoid;
}
.label .label-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; font-weight: 600; letter-spacing: .04em; margin-top: 6px; }
.label .label-name { font-size: 12px; color: #374151; margin-top: 2px; }
.label .label-meta { font-size: 11px; color: #6B7280; margin-top: 2px; }
.label canvas, .label img, .label svg { display: block; margin: 0 auto; }
.label .qr-fallback { display: grid; place-items: center; height: 108px; border: 1px dashed #CBD5E1; border-radius: 6px; color: #6B7280; font-size: 11px; }

@media print {
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }
  .label { border-color: #94A3B8; }
  body { background: #fff; }
}

/* ---------- 宽屏 ---------- */
@media (min-width: 900px) {
  .main { padding: 24px 20px; }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .quick-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .app { padding-bottom: 90px; }
}

@media (max-width: 360px) {
  .segmented button { font-size: 12px; }
  .stat .v { font-size: 19px; }
}
