:root {
  --bg0: #f7f4f5;
  --bg1: #fbf9fa;
  --ink: #1a1214;
  --ink-soft: #5c4a4e;
  --line: rgba(28, 16, 18, 0.08);
  --panel: rgba(255, 255, 255, 0.78);
  --accent: #e4002d;
  --accent-deep: #b80024;
  --accent-soft: #f8eef0;
  --accent-mid: #f04a66;
  --warn: #b45309;
  --ok: #e4002d;
  --danger: #b42318;
  --shadow: 0 12px 40px rgba(228, 0, 45, 0.08);
  --radius: 16px;
  --dock-h: 210px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: "Syne", "Noto Sans SC", sans-serif;
  --font-body: "Noto Sans SC", sans-serif;
  /* 数字键专用真实字体 */
  --font-numpad: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1000px 480px at 10% -10%, #f3e6e9 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #efe8ea 0%, transparent 50%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    linear-gradient(rgba(228, 0, 45, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(228, 0, 45, 0.018) 1px, transparent 1px),
    radial-gradient(1000px 480px at 10% -10%, #f3e6e9 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #efe8ea 0%, transparent 50%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  background-size:
    28px 28px,
    28px 28px,
    auto,
    auto,
    auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  width: min(430px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: 18px 16px 0;
  /* 为底部语音区留出空间，商品列表不再伸到其下方 */
  padding-bottom: calc(var(--dock-h) + var(--safe-bottom) + 12px);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  animation: rise 0.55s ease both;
}

.brand-block {
  margin-top: 5px;
  margin-left: 5px;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--accent-deep);
}

.task-title {
  margin: 6px 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.task-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.top-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.submit-btn {
  border: 0;
  border-radius: 12px;
  padding: 8px 11px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.04em;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 48px;
  height: 48px;
  box-sizing: border-box;
}

.submit-btn:active {
  background: var(--accent-deep);
}

.progress-ring {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

.ring-svg {
  width: 56px;
  height: 56px;
  transform: rotate(-90deg);
}

.ring-track,
.ring-fill {
  fill: none;
  stroke-width: 5;
}

.ring-track {
  stroke: rgba(228, 0, 45, 0.15);
}

.ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 138.2;
  stroke-dashoffset: 138.2;
  transition: stroke-dashoffset 0.45s ease;
}

.ring-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 600;
}

.toolbar {
  margin-top: 18px;
  flex-shrink: 0;
  animation: rise 0.55s ease 0.06s both;
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  outline: none;
}

.search input:focus {
  border-color: rgba(228, 0, 45, 0.45);
  box-shadow: 0 0 0 3px rgba(228, 0, 45, 0.12);
}

.hint {
  margin: 10px 2px 0 15px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  min-height: 1.2em;
}

.list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 8px;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(28, 16, 18, 0.08) transparent;
}

.list::-webkit-scrollbar {
  width: 1.5px;
}

.list::-webkit-scrollbar-track {
  background: transparent;
  margin-block: 6px;
}

.list::-webkit-scrollbar-thumb {
  background: rgba(28, 16, 18, 0.08);
  border-radius: 999px;
}

.list::-webkit-scrollbar-thumb:hover {
  background: rgba(28, 16, 18, 0.16);
}

.list::-webkit-scrollbar-corner {
  background: transparent;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  padding: 14px 14px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(10px);
  transition:
    border-color 0.25s ease,
    background 0.25s ease,
    transform 0.25s ease;
  animation: rise 0.45s ease both;
}

.row:nth-child(1) {
  animation-delay: 0.08s;
}
.row:nth-child(2) {
  animation-delay: 0.11s;
}
.row:nth-child(3) {
  animation-delay: 0.14s;
}
.row:nth-child(4) {
  animation-delay: 0.17s;
}
.row:nth-child(5) {
  animation-delay: 0.2s;
}
.row:nth-child(6) {
  animation-delay: 0.23s;
}
.row:nth-child(7) {
  animation-delay: 0.26s;
}
.row:nth-child(8) {
  animation-delay: 0.29s;
}

.row.matched {
  border-color: rgba(228, 0, 45, 0.35);
  background: linear-gradient(120deg, #f9f0f2, rgba(255, 255, 255, 0.9));
  transform: translateY(-1px);
}

.row.filled .name::after {
  content: "已盘点";
  margin-left: 8px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ok);
  letter-spacing: 0.04em;
  vertical-align: middle;
}

.name {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.meta {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.meta .diff-line {
  display: block;
  margin-top: 4px;
  font-weight: 600;
}

.meta .diff-line.up {
  color: #0f7a45;
}

.meta .diff-line.down {
  color: var(--accent);
}

.meta .diff-line.flat {
  color: var(--ink-soft);
  font-weight: 500;
}

.qty-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-wrap input {
  width: 86px;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  background: #fff;
  outline: none;
}

.qty-wrap input:focus {
  border-color: rgba(228, 0, 45, 0.5);
}

.qty-wrap input.numpad-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(228, 0, 45, 0.12);
  caret-color: transparent;
}

.unit {
  min-width: 28px;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* 自定义数字键盘（底部弹起，固定不随滚动） */
.numpad[hidden] {
  display: none !important;
}

.numpad {
  position: fixed;
  left: 50%;
  bottom: 0;
  top: 0;
  transform: translateX(-50%);
  width: min(430px, 100%);
  z-index: 45;
  display: flex;
  align-items: flex-end;
  justify-content: stretch;
  overflow: hidden;
  pointer-events: none;
}

.numpad-mask {
  position: absolute;
  inset: 0;
  background: rgba(28, 12, 16, 0.28);
  animation: fade-in 0.2s ease;
  pointer-events: auto;
}

.numpad-panel {
  position: relative;
  width: 100%;
  background: #f7f7f7;
  border-radius: 16px 16px 0 0;
  padding: 12px 10px calc(12px + var(--safe-bottom));
  box-shadow: 0 -6px 24px rgba(28, 12, 16, 0.12);
  animation: keypad-up 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: auto;
}

.numpad-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 0 2px 4px;
}

.numpad-name {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.numpad-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.numpad-value em {
  font-style: normal;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 1ch;
}

.numpad-value i {
  font-style: normal;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.numpad-keys {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, 48px);
  gap: 8px;
}

.numpad-keys button {
  border: 0;
  border-radius: 5px;
  background: #fff;
  color: #111;
  font-family: var(--font-numpad);
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  cursor: pointer;
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: none;
}

.numpad-keys button:not(.key-confirm) {
  font-family: var(--font-numpad) !important;
}

.numpad-keys button:active {
  background: #ebebeb;
}

.numpad-keys button:disabled {
  background: #fff;
  color: #c8c8c8;
  opacity: 1;
  cursor: not-allowed;
}

.numpad-keys .key-del {
  color: #333;
}

.del-icon {
  width: 24px;
  height: 17px;
  display: block;
  background: #333;
  clip-path: polygon(22% 0, 100% 0, 100% 100%, 22% 100%, 0 50%);
  position: relative;
}

.del-icon::before,
.del-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 54%;
  width: 10px;
  height: 1.5px;
  background: #fff;
  border-radius: 1px;
}

.del-icon::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.del-icon::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.numpad-keys .key-confirm {
  background: var(--accent);
  color: #fff;
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.numpad-keys .key-confirm:active {
  background: var(--accent-deep);
  color: #fff;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes keypad-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.voice-dock {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(430px, 100%);
  padding: 0 12px calc(12px + var(--safe-bottom));
  z-index: 20;
  animation: dock-in 0.5s ease 0.15s both;
}

.voice-panel {
  border: 1px solid rgba(228, 0, 45, 0.14);
  border-radius: 22px 22px 18px 18px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  padding: 14px 14px 12px;
}

.voice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.voice-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  margin-bottom: 10px;
  /* 仅展示两行芯片 */
  max-height: calc(28px * 2 + 6px);
  overflow: hidden;
}

.examples[hidden] {
  display: none !important;
}

.chip {
  border: 1px solid rgba(228, 0, 45, 0.18);
  background: var(--accent-soft);
  color: var(--accent-deep);
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.75rem;
  line-height: 1;
  height: 28px;
  box-sizing: border-box;
  cursor: pointer;
  flex: 0 0 auto;
}

.chip:active {
  transform: scale(0.98);
}

.voice-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.voice-input-row input {
  flex: 1;
  min-width: 0;
  height: 44px;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px; /* 避免 iOS 聚焦时自动放大 */
  line-height: 44px;
  outline: none;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
}

.voice-input-row input:focus {
  border-color: rgba(228, 0, 45, 0.45);
}

.voice-input-row .btn {
  height: 44px;
  min-height: 44px;
  box-sizing: border-box;
  padding: 0 16px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.9rem;
  line-height: 1;
  -webkit-appearance: none;
  appearance: none;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn.compact {
  padding-inline: 16px;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:active {
  background: var(--accent-deep);
}

.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.mic-btn {
  position: relative;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-mid));
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
}

.mic-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--accent-deep), var(--accent));
}

.mic-btn[aria-pressed="true"] .mic-pulse {
  opacity: 1;
  animation: pulse 1.2s ease-out infinite;
}

.mic-pulse {
  position: absolute;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  opacity: 0;
  pointer-events: none;
}

.mic-icon {
  width: 14px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 8px;
  position: relative;
  flex-shrink: 0;
}

.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 10px;
  height: 2px;
  background: #fff;
  transform: translateX(-50%);
  border-radius: 1px;
}

.voice-result {
  margin: 10px 2px 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  min-height: 1.2em;
}

.toast {
  position: fixed;
  left: 50%;
  /* 默认抬高；实际位置由 JS 按语音操作区顶部动态计算 */
  bottom: calc(var(--dock-h) + 48px);
  transform: translateX(-50%) translateY(8px);
  width: min(390px, calc(100% - 32px));
  max-width: 406px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.85rem;
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    bottom 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.confirm-sheet[hidden] {
  display: none;
}

.submit-dialog[hidden] {
  display: none !important;
}

.submit-dialog {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.submit-dialog-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.submit-dialog-panel {
  position: relative;
  width: min(300px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 22px 18px 16px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  animation: rise 0.22s ease;
}

.submit-dialog-panel h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

.submit-dialog-desc {
  margin: 10px 0 0;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.submit-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.submit-dialog-actions .btn {
  min-height: 40px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.confirm-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 12, 16, 0.42);
}

.sheet-panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(430px, 100%);
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(18px + var(--safe-bottom));
  animation: sheet-up 0.28s ease;
}

.sheet-panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.sheet-raw {
  margin: 8px 0 14px;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.sheet-candidates {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-candidates li {
  margin: 0;
}

.candidate {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #faf6f7;
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  cursor: pointer;
}

.candidate.selected {
  border-color: rgba(228, 0, 45, 0.5);
  background: var(--accent-soft);
}

.candidate strong {
  display: block;
  font-size: 0.95rem;
}

.candidate span {
  display: block;
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
  margin-top: 16px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dock-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(0.7);
    opacity: 0.7;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}

@keyframes sheet-up {
  from {
    transform: translateX(-50%) translateY(24px);
  }
  to {
    transform: translateX(-50%) translateY(0);
  }
}

@media (min-width: 860px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px 0;
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: calc(100dvh - 48px);
    max-height: calc(100dvh - 48px);
    min-height: 0;
    border: 1px solid rgba(228, 0, 45, 0.1);
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.35);
    box-shadow: var(--shadow);
  }

  .voice-dock {
    bottom: 24px;
  }

  .numpad {
    top: 24px;
    bottom: 24px;
    border-radius: 28px;
  }

  .numpad-panel {
    border-radius: 16px 16px 28px 28px;
  }
}
