/* LUCENT PDA — 零依赖 / 低功耗：仅用原生 CSS，适配扫码枪常见分辨率 320–480px */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3b52;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-dim: #2563c9;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --tap: 52px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'PingFang SC', sans-serif;
  /* 数字/条码区：与正文一致，避免 ui-monospace、Cascadia Code 等把 0 画成带点/穿线样式 */
  --mono: system-ui, -apple-system, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  --fs-body: 18px;
  --fs-detail: 18px;
  --fs-label: 15px;
  --fs-scan: 24px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

/* 减少动画耗电：仅按钮轻微过渡 */
button,
.tab,
.nav-link {
  transition: background 0.12s ease, transform 0.08s ease;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
  background: linear-gradient(180deg, #1e293b 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
  padding: 4px 8px 6px;
}

.app-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* 与顶栏少量留白即可；过大易与首屏标题区重复留白 */
  padding-top: 8px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* 首屏已有醒目标题（如库存 scan-hint）时不再额外叠一大段空白 */
.app-main .view-panel > .scan-zone:first-child {
  padding-top: 8px;
}

.view-panel {
  animation: view-in 0.18s ease-out;
}

@keyframes view-in {
  from {
    opacity: 0.85;
  }
  to {
    opacity: 1;
  }
}

.page-head {
  padding: 16px 10px 8px;
}

.page-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
}

.page-desc {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.seg-group {
  display: flex;
  gap: 8px;
  margin: 0 10px 8px;
}

.seg-btn {
  flex: 1;
  min-height: 46px;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.seg-btn.active {
  color: #fff;
  background: var(--accent-dim);
  border-color: var(--accent);
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 10px;
}

.date-row .field-label {
  margin-left: 0;
  margin-right: 0;
}

.date-row .field-input {
  width: 100%;
  margin-left: 0;
  margin-right: 0;
}

.field-label {
  display: block;
  margin: 12px 10px 6px;
  font-size: var(--fs-label);
  color: var(--muted);
}

.field-label.pad-x {
  margin-left: 10px;
  margin-right: 10px;
}

.field-select {
  position: relative;
  width: calc(100% - 20px);
  margin: 0 10px 8px;
  min-height: 50px;
  padding: 0 40px 0 12px;
  font-size: 19px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  max-width: 100%;
  box-sizing: border-box;
  overflow: visible;
}

.field-select::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b9cb3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
}

.field-input {
  width: calc(100% - 20px);
  margin: 0 10px 8px;
  min-height: 50px;
  padding: 0 12px;
  font-size: 19px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  cursor: text;
  max-width: 100%;
  box-sizing: border-box;
}

.field-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}

.field-select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}

.pad-x.field-input,
.pad-x.field-select {
  width: calc(100% - 20px);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 10px 24px;
}

.btn-row.single {
  padding-top: 8px;
}

.btn-row.pad-x {
  padding-left: 10px;
  padding-right: 10px;
}

.btn-secondary {
  flex: 1 1 120px;
  min-height: 48px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-secondary:active,
.nav-link:active,
.tab:active {
  transform: scale(0.98);
}

.btn-secondary:focus-visible,
.nav-link:focus-visible,
.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* —— 进货入库：扫描区 + 明细表 + 入库数量 —— */
#view-count .count-scan-panel {
  margin: 0 10px 12px;
  padding: 14px 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

#view-count .count-scan-title {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  letter-spacing: 0.02em;
}

.count-filter-row {
  display: flex;
  gap: 22px;
  margin-bottom: 12px;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
}

.count-chk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.count-chk input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

#view-count .count-panel-barcode {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 50px;
  margin: 0 0 12px;
  padding: 12px 14px;
  font-size: 20px;
  font-family: var(--mono);
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}

#view-count .count-panel-barcode:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.35);
}

#view-count .btn-count-next {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dim) 100%);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

#view-count .btn-count-next:active {
  transform: scale(0.98);
}

#view-count .count-qty-row {
  align-items: stretch;
}

#view-count .detail-qty-input {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 4px 0;
  font-family: var(--mono);
  font-size: var(--fs-detail);
  font-weight: 600;
  text-align: right;
  color: var(--accent);
  background: transparent;
  border: none;
  outline: none;
}

#view-count .detail-qty-input:focus {
  color: var(--text);
}

#view-count .detail-qty-input::placeholder {
  color: var(--accent);
  opacity: 0.85;
}

#view-count #count-detail-card {
  margin-top: 0;
}

/* 计件：YYYY-MM-DD - YYYY-MM-DD，默认单行；极窄屏才换行 */
.piece-date-row {
  padding: 4px 10px 6px;
  box-sizing: border-box;
}

.piece-range-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 4px 6px;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-sizing: border-box;
}

@media (max-width: 320px) {
  .piece-range-bar {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  :root {
    --fs-body: 15px;
    --fs-detail: 15px;
    --fs-label: 12px;
    --fs-scan: 19px;
    --tap: 44px;
    --radius: 9px;
  }

  .piece-cal-cell {
    min-height: 36px;
    max-height: 46px;
  }

  .piece-cal-day {
    min-height: 36px;
    font-size: 14px;
  }
}

.piece-range-seg {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 0;
  padding: 4px 6px;
  font-size: clamp(14px, 3.5vw, 17px);
  font-family: var(--mono);
  line-height: 1.2;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  outline: none;
}

.piece-range-seg:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.2);
}

.piece-range-sep {
  flex: 0 0 auto;
  padding: 0 1px;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
}

.piece-date-display {
  white-space: nowrap;
}

.piece-range-inline-icon {
  flex-shrink: 0;
  color: #fff;
  display: flex;
  align-items: center;
  opacity: 0.95;
}

.piece-date-icon-svg {
  display: block;
}

/* 日历弹层：宽度随屏（左右留白），最大宽度避免桌面过宽 */
.piece-cal-root {
  position: fixed;
  inset: 0;
  z-index: 97;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(10px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  pointer-events: none;
}

.piece-cal-root:not([hidden]) {
  pointer-events: auto;
}

/* 防止 author 的 display:flex 盖掉 [hidden]：关闭时必须不参与命中 */
.piece-cal-root[hidden] {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden;
}

.piece-cal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 25, 0.78);
}

.piece-cal-dialog {
  position: relative;
  width: min(100%, calc(100vw - 24px));
  max-width: 420px;
  padding: 14px 12px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

.piece-cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.piece-cal-nav {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #fff;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.piece-cal-nav:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.piece-cal-chevron {
  display: block;
}

.piece-cal-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: clamp(17px, 4.2vw, 19px);
  font-weight: 700;
  color: var(--text);
}

.piece-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.piece-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.piece-cal-cell {
  aspect-ratio: 1;
  min-height: 40px;
  max-height: 52px;
}

.piece-cal-day {
  width: 100%;
  height: 100%;
  min-height: 40px;
  padding: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
}

.piece-cal-day:hover,
.piece-cal-day:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.piece-cal-day.is-out {
  color: var(--muted);
  opacity: 0.45;
}

.piece-cal-day.is-today {
  border-color: var(--accent);
}

.piece-cal-day.is-selected {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}

.piece-cal-empty {
  min-height: 40px;
}

.piece-cal-foot {
  margin-top: 12px;
  display: flex;
  justify-content: stretch;
}

.piece-cal-close-btn {
  width: 100%;
  min-height: 46px;
}

.stat-bar {
  display: flex;
  justify-content: space-around;
  gap: 12px;
  margin: 12px 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  color: var(--muted);
}

.stat-bar strong {
  color: var(--success);
  font-size: 20px;
}

.list-card {
  margin: 8px 10px 12px;
  min-height: 120px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
}

.list-placeholder {
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}

.list-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.list-row:last-child {
  border-bottom: none;
}

.list-row span:last-child {
  color: var(--warn);
  font-family: var(--mono);
  font-size: 14px;
}

.progress-card {
  min-height: 0;
  max-height: 180px;
  overflow: auto;
}

.list-row.is-done span:last-child {
  color: var(--success);
}

.list-row.is-pending {
  background: rgba(245, 158, 11, 0.08);
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
  border-radius: 8px;
}

.piece-summary {
  margin-top: 4px;
}

#view-piece .btn-row.single {
  padding-top: 6px;
}

.nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 8px;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}

.nav-link:hover,
.nav-link:focus-visible {
  color: var(--text);
  background: var(--surface2);
  outline: none;
}

.nav-link.active {
  color: #fff;
  background: var(--accent-dim);
  border-color: var(--accent);
}

.sub-nav {
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 12px 10px 0;
}

.tab {
  flex: 1;
  min-height: var(--tap);
  font-size: 17px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.tab.active {
  color: #fff;
  background: var(--accent-dim);
  border-color: var(--accent);
}

.scan-zone {
  padding: 12px 10px 8px;
}

.scan-hint {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--warn);
  text-align: center;
  font-weight: 600;
}

.scan-input-wrap {
  position: relative;
  padding: 0 10px;
}

.scan-input {
  width: 100%;
  min-height: 56px;
  padding: 14px 12px;
  font-size: var(--fs-scan);
  font-family: var(--mono);
  letter-spacing: 0.05em;
  color: var(--text);
  background: var(--surface2);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  outline: none;
}

.scan-input:focus {
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.35);
}

.section-title {
  margin: 14px 10px 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.detail-card {
  margin: 0 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.detail-row {
  display: grid;
  grid-template-columns: 104px 1fr;
  gap: 8px;
  align-items: center;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-detail);
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  color: var(--muted);
  font-size: var(--fs-label);
}

.detail-value {
  font-family: var(--mono);
  font-size: var(--fs-detail);
  word-break: break-all;
  color: var(--text);
}

.detail-value.empty {
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 24px;
}

.choice-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.choice-label {
  font-size: 15px;
  color: var(--muted);
  white-space: nowrap;
}

.choice-btns {
  display: flex;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.choice-btns button {
  min-width: 64px;
  min-height: 48px;
  padding: 0 14px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
}

.choice-btns button.active-yes {
  background: rgba(34, 197, 94, 0.25);
  color: var(--success);
}

.choice-btns button.active-no {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.btn-confirm {
  flex: 1 1 140px;
  min-height: 54px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dim) 100%);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-confirm:active {
  transform: scale(0.98);
}

.btn-confirm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.user-bar {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2px 0 4px;
  font-size: 13px;
  color: var(--muted);
}

.user-bar #user-display {
  flex: 1 1 auto;
  min-width: 0;
  text-align: start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#btn-logout {
  flex-shrink: 0;
  margin-inline-start: 0;
}

.lang-row-login {
  position: relative;
  z-index: 5;
  margin-bottom: 14px;
}

.lang-label,
.lang-label-inline {
  font-size: 14px;
  color: var(--muted);
  margin-inline-end: 8px;
}

.lang-select {
  width: 100%;
  min-height: 52px;
  padding: 0 10px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.lang-select-native {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 1px;
  padding: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.lang-picker {
  position: relative;
}

.lang-picker-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.lang-picker-arrow {
  margin-inline-start: 10px;
  color: var(--muted);
}

.lang-picker-menu {
  position: absolute;
  z-index: 80;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: min(320px, 48vh);
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.35);
}

.lang-picker-menu[hidden] {
  display: none !important;
}

.lang-picker.open .lang-picker-menu:not([hidden]) {
  display: block;
}

.lang-picker-option {
  display: block;
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  text-align: start;
  font-size: 16px;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.lang-picker-option.active,
.lang-picker-option:active {
  color: #fff;
  background: var(--accent);
}

.lang-select-inline {
  width: auto;
  min-width: 130px;
  min-height: 38px;
  margin-inline-end: 4px;
}

.btn-text {
  padding: 4px 6px;
  font-size: 13px;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: underline;
}

/* 退出 / 重新登录 二次确认 */
.pda-dialog-mask {
  position: fixed;
  inset: 0;
  z-index: 96;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 20, 25, 0.78);
}

.pda-dialog-mask.show {
  display: flex;
}

.pda-dialog {
  width: 100%;
  max-width: 360px;
  padding: 18px 16px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.pda-dialog-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.pda-dialog-body {
  margin: 0 0 18px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted);
  text-align: center;
}

.pda-dialog-actions {
  display: flex;
  gap: 10px;
}

.pda-dialog-actions .pda-dialog-btn {
  flex: 1;
  min-height: 48px;
  margin: 0;
}

/* Toast */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(100px);
  z-index: 100;
  max-width: min(92vw, 420px);
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 500;
  color: #fff;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.toast-host.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-host.ok {
  border-color: var(--success);
}

.toast-host.err {
  border-color: var(--danger);
}

/* 最近一次接口返回：贴在应用区最底部（随文档流，非 fixed 悬浮） */
.api-result-panel {
  flex-shrink: 0;
  width: 100%;
  max-height: min(32vh, 260px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--accent);
  border-left: none;
  border-right: none;
  border-bottom: none;
  overflow: hidden;
  margin-top: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.api-result-panel[hidden] {
  display: none !important;
}

.api-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.api-result-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.api-result-toggle {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.api-result-body {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  overflow: auto;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}

.api-result-panel.collapsed .api-result-body {
  display: none;
}

/* Loading overlay */
.loading-mask {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 25, 0.72);
}

.loading-mask.show {
  display: flex;
}

.loading-box {
  padding: 20px 28px;
  font-size: 17px;
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* Login */
.screen-login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a5f 0%, var(--bg) 55%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  text-align: center;
}

.login-card .sub {
  margin: 0 0 22px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.login-card label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--muted);
}

.login-card input {
  width: 100%;
  min-height: 50px;
  margin-bottom: 14px;
  padding: 0 12px;
  font-size: 18px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.login-card button[type='submit'] {
  width: 100%;
  min-height: 52px;
  margin-top: 8px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.screen-app {
  display: none;
}

.screen-app.visible {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen-login.hidden {
  display: none;
}

/* 更小机身 / 窄屏 PDA（≤380px）：压缩边距与控件高度，保留扫码框可读性 */
@media (max-width: 380px) {
  :root {
    --fs-body: 16px;
    --fs-detail: 16px;
    --fs-label: 13px;
    --fs-scan: 20px;
    --radius: 10px;
    --tap: 46px;
  }

  .app-header {
    padding-left: max(6px, env(safe-area-inset-left, 0px));
    padding-right: max(6px, env(safe-area-inset-right, 0px));
    padding-top: max(2px, env(safe-area-inset-top, 0px));
  }

  .app-main {
    padding-top: 4px;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }

  .field-label {
    margin: 8px 10px 4px;
  }

  .field-select {
    position: relative;
    min-height: 46px;
    margin: 0 8px 6px;
    width: calc(100% - 16px);
    font-size: 17px;
    padding: 0 36px 0 10px;
  }

  .field-select::after {
    right: 10px;
    width: 16px;
    height: 16px;
  }

  .field-input {
    min-height: 46px;
    margin: 0 8px 6px;
    width: calc(100% - 16px);
    font-size: 17px;
    padding: 0 10px;
  }

  .pad-x.field-input,
  .pad-x.field-select {
    width: calc(100% - 16px);
  }

  .btn-row {
    gap: 8px;
    padding: 10px 8px 16px;
  }

  .btn-secondary {
    min-height: 44px;
    font-size: 14px;
  }

  .tabs {
    gap: 6px;
    margin: 8px 8px 0;
  }

  .tab {
    font-size: 15px;
  }

  .scan-zone {
    padding: 8px 8px 6px;
  }

  .scan-hint {
    font-size: 14px;
    margin-bottom: 6px;
  }

  .scan-input {
    min-height: 50px;
    padding: 10px 12px;
  }

  .section-title {
    margin: 10px 8px 6px;
    font-size: 16px;
  }

  .detail-card {
    margin: 0 8px 10px;
  }

  .detail-row {
    grid-template-columns: minmax(72px, 96px) minmax(0, 1fr);
    padding: 10px 10px;
    gap: 6px;
  }

  .actions {
    padding: 10px 8px 18px;
    gap: 8px;
  }

  .btn-confirm {
    min-height: 48px;
    font-size: 16px;
  }

  .choice-btns button {
    min-height: 44px;
    min-width: 56px;
    padding: 0 10px;
    font-size: 16px;
  }

  #view-count .count-scan-panel {
    margin: 0 8px 10px;
    padding: 10px 10px 12px;
  }

  #view-count .count-scan-title {
    font-size: 16px;
    margin-bottom: 8px;
  }

  #view-count .count-panel-barcode {
    min-height: 46px;
    font-size: 17px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }

  #view-count .btn-count-next {
    min-height: 44px;
    font-size: 16px;
  }

  .count-filter-row {
    gap: 12px;
    margin-bottom: 8px;
  }

  .count-chk {
    font-size: 14px;
  }

  .stat-bar {
    margin: 8px 8px;
    padding: 10px;
    font-size: 14px;
    gap: 8px;
  }

  .stat-bar strong {
    font-size: 17px;
  }

  .list-card {
    margin: 6px 8px 10px;
    padding: 10px;
    min-height: 100px;
  }

  .list-row {
    padding: 8px 0;
  }

  .nav-row {
    gap: 2px;
  }

  .nav-link {
    min-height: 32px;
    padding: 0 6px;
    font-size: 13px;
  }

  .user-bar {
    font-size: 12px;
    gap: 6px;
  }

  .login-card {
    padding: 14px 14px;
    margin: 0 max(10px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
    max-width: 100%;
  }

  .login-card h1 {
    font-size: 19px;
  }

  .login-card input {
    min-height: 46px;
    font-size: 17px;
    margin-bottom: 12px;
  }

  .login-card button[type='submit'] {
    min-height: 48px;
    font-size: 17px;
  }

  .pda-dialog {
    max-width: calc(100vw - 20px);
    padding: 14px 12px 12px;
  }

  .toast-host {
    max-width: min(94vw, 380px);
    padding: 12px 14px;
    font-size: 15px;
  }

  .api-result-head {
    padding: 8px 10px;
  }

  .api-result-body {
    padding: 10px 10px;
    font-size: 13px;
  }
}

/* 极窄屏：详情行改上下堆叠，避免标签列挤压条码 */
@media (max-width: 300px) {
  .detail-row {
    grid-template-columns: 1fr;
    align-items: start;
    padding: 8px 10px;
    gap: 4px;
  }

  .detail-label {
    font-size: 12px;
  }

  .detail-value {
    font-size: 15px;
  }

}

@media (min-width: 480px) {
  body {
    font-size: 19px;
  }

  .detail-row {
    grid-template-columns: 120px 1fr;
  }

  :root {
    --fs-scan: 26px;
    --fs-detail: 19px;
    --fs-body: 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,

  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* 全局扫码接收框：保持焦点以接收 HID 楔入，不占用界面 */
.pda-scan-sink {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: 0;
  padding: 0;
  margin: 0;
}

/* ========================
   列表页通用样式 (page-list)
   ======================== */
.page-list {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.page-list__header {
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #1e293b 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
}

.page-list__title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.page-list__loading,
.page-list__empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.page-list__body {
  flex: 1;
  padding: 8px 0;
}

.page-list__pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 16px 10px;
  font-size: 14px;
}

.page-list__pagination button {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.page-list__pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 列表卡片 */
.page-list .list-card {
  margin: 8px 10px 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.page-list .list-card:active {
  transform: scale(0.99);
}

.page-list .list-card__row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
}

.page-list .list-card__row:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

.page-list .list-card__label {
  color: var(--muted);
  flex-shrink: 0;
}

.page-list .list-card__value {
  color: var(--text);
  font-family: var(--mono);
  text-align: right;
  word-break: break-all;
}

.page-list .list-card__badge {
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
}

.page-list .badge--0,
.page-list .badge--1,
.page-list .badge--2,
.page-list .badge--3 {
  background: var(--surface2);
  color: var(--text);
}

/* ========================
   表单页通用样式 (page-form)
   ======================== */
.page-form {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.page-form__header {
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #1e293b 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
}

.page-form__title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.page-form__body {
  flex: 1;
  padding-bottom: 24px;
}

/* 表单字段 */
.form-field {
  margin: 12px 14px 0;
}

.form-field label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-label);
  color: var(--muted);
}

.form-input {
  width: calc(100% - 20px);
  min-height: 50px;
  margin: 0;
  padding: 0 12px;
  font-size: 19px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}

.form-textarea {
  width: calc(100% - 20px);
  min-height: 100px;
  margin: 0;
  padding: 12px;
  font-size: 16px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  resize: vertical;
}

.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}

.form-error {
  margin: 12px 14px 0;
  padding: 12px;
  font-size: 14px;
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  border-radius: 8px;
}

/* 搜索栏 */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 12px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.search-input {
  flex: 1;
  min-height: 44px;
  padding: 0 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-input::placeholder {
  color: var(--muted);
}

.filter-select {
  min-width: 100px;
  min-height: 44px;
  padding: 0 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  cursor: pointer;
}

.btn-search {
  min-width: 60px;
  min-height: 44px;
  padding: 0 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.btn-search:active {
  transform: scale(0.98);
}

.btn-back {
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.btn-back:active {
  transform: scale(0.98);
}

.btn-primary {
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* 进度卡片 */
.progress-card {
  min-height: 0;
  max-height: 180px;
  overflow: auto;
}

.piece-summary {
  margin-top: 4px;
}

#view-piece .btn-row.single {
  padding-top: 6px;
}

/* 列表中操作按钮行 */
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 24px;
}

/* ========================
   响应式：窄屏适配
   ======================== */
@media (max-width: 380px) {
  .page-list__header,
  .page-form__header {
    padding: 6px 8px;
    gap: 6px;
  }

  .page-list__title,
  .page-form__title {
    font-size: 16px;
  }

  .form-field {
    margin: 10px 8px 0;
  }

  .form-input {
    width: calc(100% - 16px);
    min-height: 46px;
    font-size: 17px;
  }

  .search-bar {
    padding: 10px 8px;
    gap: 6px;
  }

  .search-input {
    min-height: 42px;
    font-size: 15px;
  }

  .btn-back,
  .btn-primary {
    padding: 5px 10px;
    font-size: 13px;
  }

  .page-list .list-card {
    margin: 6px 8px 10px;
    padding: 12px;
  }

  .page-list .list-card__row {
    font-size: 13px;
    padding: 5px 0;
  }

  .form-textarea {
    width: calc(100% - 16px);
    min-height: 80px;
    font-size: 15px;
  }
}
