:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #116b5f;
  --primary-dark: #0b5148;
  --accent: #235b9f;
  --danger: #b42318;
  --warning: #9a6700;
  --shadow: 0 14px 40px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  min-height: 100vh;
  padding: 14px;
  padding-bottom: 84px;
}

.loading,
.login-layout {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.login-panel,
.panel,
.modal,
.scanner-modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(440px, 100%);
  padding: 32px;
}

.login-panel h1,
.topbar h1,
.panel h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-form,
.form-grid,
.toolbar,
.upload-box {
  display: grid;
  gap: 14px;
}

.login-form {
  margin-top: 28px;
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 0.92rem;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:read-only,
textarea:read-only {
  background: #f2f4f7;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 91, 159, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.mini-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 14px;
  font-weight: 750;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  background: #e9f5f2;
  border-color: #b8ddd4;
  color: var(--primary-dark);
}

.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: #344054;
}

.mini-button {
  background: #f8fafc;
  border-color: var(--line);
  color: #344054;
}

.danger-button {
  background: #fff5f5;
  border-color: #f4b8b2;
  color: var(--danger);
}

.topbar,
.toolbar,
.panel-heading,
.button-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar {
  align-items: stretch;
  flex-direction: column;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 16px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
}

.toolbar label:first-child {
  grid-column: 1 / -1;
  min-width: 0;
}

.toolbar label:nth-child(2) {
  grid-column: 1 / -1;
  flex: auto;
}

.results-list {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.results-list button {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 12px;
}

.results-list span,
.results-list small,
td small,
.panel-heading small,
.batch-list small {
  display: block;
  color: var(--muted);
}

.work-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.panel-heading {
  align-items: stretch;
  flex-direction: column;
  justify-content: flex-start;
  margin-bottom: 14px;
}

.form-grid {
  grid-template-columns: 1fr;
}

.form-grid .wide {
  grid-column: auto;
}

.button-row {
  justify-content: stretch;
  flex-wrap: wrap;
  margin-top: 14px;
}

.button-row button,
.toolbar button {
  flex: 1 1 0;
  width: 100%;
}

.input-action {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.input-action input {
  min-width: 0;
}

.table-wrap {
  display: none;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: #344054;
  font-size: 0.86rem;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.mobile-record-list {
  display: grid;
  gap: 10px;
}

.record-card,
.empty-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.record-card {
  display: grid;
  gap: 10px;
}

.record-card.record-editing,
tr.record-editing {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* 卡片被勾選時的視覺強化 */
.record-card.record-selected {
  background: #f0fdfa;
  border: 1px solid var(--primary);
  box-shadow: inset 4px 0 0 var(--primary);
}

/* 桌機表格列被勾選時的視覺強化 */
tr.record-row-selected td {
  background: #f0fdfa;
}
tr.record-row-selected td:first-child {
  box-shadow: inset 4px 0 0 var(--primary);
}

.record-card.record-highlight,
tr.record-highlight {
  animation: recordPulse 1.1s ease-in-out 2;
}

@keyframes recordPulse {
  0%,
  100% {
    box-shadow: none;
  }
  50% {
    box-shadow: 0 0 0 5px rgba(18, 121, 101, 0.18);
  }
}

/* 舊規則拿掉：新版卡片改用更精細的 .card-codes/.card-meta/.card-stocks 樣式控制 */

.check-line {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  cursor: pointer;
  /* 整片 label 都可 tap，padding 撐大可點區域 */
  padding: 4px 0;
}

/* （手機版的 checkbox 統一樣式定義在媒體查詢 < 760px，
    讓全站所有勾選框長一樣） */

.check-line strong {
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}

.record-edit-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.switch-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  font-weight: 800;
  color: var(--brand);
}

.switch-line input {
  width: 42px;
  min-height: 24px;
  accent-color: var(--brand);
}

.record-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.record-card dl div {
  min-width: 0;
  border-radius: 6px;
  background: #f8fafc;
  padding: 8px;
}

/* 布局甲:標了 field-full 的欄位(現有庫存 + 新增/盤點庫存)改占整行全寬,
   讓輸入框寬度翻倍,4-5 位數放得下;其餘短欄(主/選/最大存放量/單位重量G)維持 2 欄。 */
.record-card dl div.field-full {
  grid-column: 1 / -1;
}

.record-card dl div.editable-field {
  background: #f0fdfa;
  border: 1px solid #b8ddd4;
}

.record-card dl div.readonly-field {
  background: #f8fafc;
  border: 1px solid transparent;
}

.record-card dl div.computed-field,
.computed-cell {
  background: #fff7ed;
  color: #8a4b12;
  font-weight: 800;
}

.record-card dt {
  color: var(--muted);
  font-size: 0.78rem;
}

/* 「(單個)」標籤後綴：小字、淡灰，提示輸入的是單個數量而非換算後件數。
   用 0.85em 相對縮小,窄機也不會把標籤撐爆。 */
.unit-scope-note {
  font-size: 0.85em;
  font-weight: 500;
  color: var(--muted);
  margin-left: 1px;
  white-space: nowrap;
}

.record-card dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.record-card dd input,
.table-edit-input {
  min-height: 36px;
  padding: 6px 8px;
  font-weight: 750;
}

.record-card dd input:disabled,
.table-edit-input:disabled {
  background: #eef2f6;
  color: #98a2b3;
}

.table-actions-cell {
  display: grid;
  gap: 6px;
  min-width: 108px;
}

.batch-list {
  display: grid;
  gap: 10px;
}

.batch-list article {
  display: flex;
  align-items: stretch;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

/* 編輯歷史批次時的橘色提醒 banner（桌機 + 手機都套用） */
.editing-history-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 14px;
  padding: 10px 14px;
  background: #fffaeb;
  border: 1px solid #fedf89;
  border-radius: 8px;
  color: var(--warning);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
}

.editing-history-banner .ghost-button {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.84rem;
  background: #fff;
  border: 1px solid #fedf89;
  color: var(--warning);
  flex-shrink: 0;
}

.toast {
  position: fixed;
  right: 20px;
  top: 18px;
  z-index: 20;
  max-width: min(460px, calc(100vw - 40px));
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  background: #ecfdf3;
  border: 1px solid #abefc6;
  color: #067647;
}

.toast.error {
  background: #fff1f3;
  border-color: #fda29b;
  color: var(--danger);
}

.toast.warning {
  background: #fffaeb;
  border-color: #fedf89;
  color: var(--warning);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  background: rgba(12, 18, 28, 0.56);
  padding: 18px;
}

.modal {
  width: min(420px, 100%);
  padding: 18px;
}

.scanner-modal {
  width: min(760px, 100%);
  padding: 18px;
}

.scanner-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.quantity-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.quantity-grid button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.quantity-grid button.active {
  border-color: var(--primary);
  background: #e9f5f2;
  color: var(--primary-dark);
  font-weight: 800;
}

/* ====== 浮動旗子：新批次合併救援提示 ====== */
.merge-reminder-flag {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 13;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: #eff8ff;
  border-bottom: 1px solid #b9e6fe;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.10);
  color: #175cd3;
}

.merge-reminder-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.merge-reminder-text {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
  color: #175cd3;
}

.merge-reminder-action {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #b9e6fe;
  color: #175cd3;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 0.86rem;
  font-weight: 700;
  min-height: 34px;
  cursor: pointer;
}

.merge-reminder-action:active {
  background: #f5fbff;
}

.merge-reminder-close {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: #175cd3;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 6px;
}

.merge-reminder-close:active {
  background: rgba(23, 92, 211, 0.12);
}

/* 滑下/滑上動畫 */
.flag-slide-enter-active,
.flag-slide-leave-active {
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.flag-slide-enter-from,
.flag-slide-leave-to {
  transform: translateY(-100%);
  opacity: 0;
}

/* ====== 合併歷史批次：選擇器 ====== */
.merge-picker-modal {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 36px);
}

.merge-picker-source {
  margin: 0;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.merge-picker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.merge-picker-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.merge-picker-item:active {
  background: #e9f5f2;
  border-color: var(--primary);
}

.merge-picker-item strong {
  font-size: 0.98rem;
  color: var(--text);
}

.merge-picker-item span {
  font-size: 0.84rem;
  color: var(--muted);
}

.merge-picker-empty {
  text-align: center;
  color: var(--muted);
  padding: 20px;
  margin: 0;
}

.merge-picker-cancel {
  min-height: 48px;
  margin-top: 4px;
}

/* ====== 合併確認 modal ====== */
.merge-confirm-modal {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.merge-confirm-summary {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 14px 8px;
}

.merge-side {
  text-align: center;
  padding: 12px 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.merge-side-target {
  background: #f0fdfa;
  border-color: var(--primary);
}

.merge-label {
  margin: 0 0 4px;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.merge-count {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--text);
}

.merge-time {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
}

.merge-arrow {
  font-size: 1.5rem;
  color: var(--primary);
  font-weight: 900;
}

.merge-result-note {
  margin: 0;
  padding: 10px 12px;
  background: #f0fdfa;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-align: center;
}

.merge-conflict-note {
  margin: 0;
  padding: 8px 12px;
  background: #fffaeb;
  border: 1px solid #fedf89;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--warning);
}

.merge-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: auto;
}

.merge-actions button {
  min-height: 52px;
  font-size: 1rem;
  font-weight: 800;
}

/* ====== 存入確認 modal ====== */
.confirm-save-modal {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 36px);
}

.confirm-save-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.confirm-save-header h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text);
}

.confirm-save-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
  padding: 8px 4px;
}

.confirm-spec {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}

.confirm-code-line {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
  word-break: break-all;
}

.confirm-code-line .code-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 26px;
  padding: 0 7px;
  border-radius: 5px;
  color: #fff;
  font-size: 0.92rem;
  font-weight: 800;
  flex-shrink: 0;
}

.confirm-code-line .code-tag-main {
  background: var(--primary);
}

.confirm-code-line .code-tag-variant {
  background: #235b9f;
}

.confirm-code-text {
  word-break: break-all;
}

.confirm-type {
  margin: 4px 0 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
}

/* 大數字 + 邊框 */
.confirm-value-box {
  width: 100%;
  min-height: 110px;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0fdfa;
  border: 3px solid var(--primary);
  border-radius: 14px;
  font-size: clamp(2.8rem, 14vw, 4.5rem);
  font-weight: 900;
  color: var(--text);
  line-height: 1;
  word-break: break-all;
  box-shadow: 0 4px 12px rgba(17, 107, 95, 0.10);
}

.confirm-save-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: auto;
}

.confirm-save-actions button {
  min-height: 56px;
  font-size: 1.05rem;
  font-weight: 800;
}

/* ====== 計算機（新版） ====== */
.stock-calculator {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 36px);
}

/* 標題列：小標題 + 右上 ✕ */
.calc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.calc-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}

.calc-close {
  width: 32px;
  height: 32px;
  min-height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.calc-close:active {
  background: #f5f7fa;
}

/* 顯示算式 + 即時預覽 */
.calc-display {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-height: 78px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #101828;
  color: #ffffff;
  flex-shrink: 0;
  overflow: hidden;
}

.calc-expression {
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  font-weight: 800;
  text-align: right;
  word-break: break-all;
  line-height: 1.2;
  width: 100%;
}

.calc-preview {
  font-size: 0.95rem;
  color: #6ee7b7;
  font-weight: 700;
  text-align: right;
  width: 100%;
}

/* keypad 區（會內捲，套入按鈕還是看得到） */
.stock-calculator .calculator-keypad {
  flex-shrink: 1;
  min-height: 0;
  overflow-y: auto;
  gap: 8px;
}

/* 按鍵樣式 — 跟內建鍵盤統一視覺 */
.calc-key {
  min-height: 54px;
  border: 1.5px solid #d0d5dd;
  border-radius: 10px;
  background: #ffffff;
  color: #17202a;
  font-size: 1.3rem;
  font-weight: 600;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 1px 2px rgba(16, 24, 40, 0.04),
    0 2px 4px rgba(16, 24, 40, 0.04);
  transition: transform 0.08s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.calc-key:active {
  transform: scale(0.94);
  background: #f5f7fa;
}

.calc-key.calc-action {
  background: #f5f7fa;
  color: #667085;
  font-size: 1rem;
}

.calc-key.calc-op {
  background: #eef2f6;
  color: var(--primary-dark);
  font-size: 1.4rem;
  font-weight: 800;
}

.calc-key.equals-key {
  background: var(--primary);
  color: #ffffff;
}

.calc-key.equals-key:active {
  background: var(--primary-dark);
}

/* 套入欄位按鈕：永遠在底部 */
.calc-apply {
  margin: 0;
  width: 100%;
  min-height: 52px;
  font-size: 1rem;
  font-weight: 800;
  flex-shrink: 0;
}

.calculator-display {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101828;
  color: #ffffff;
  padding: 10px 14px;
  font-size: 1.7rem;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.calculator-keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.calculator-keypad button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 800;
}

.calculator-keypad button:hover {
  background: #f8fafc;
}

.calculator-keypad .equals-key {
  grid-row: span 2;
  background: var(--primary);
  color: #fff;
}

.calculator-keypad .zero-key {
  grid-column: span 2;
}

.calculator-rows {
  display: grid;
  gap: 10px;
}

.calculator-row {
  display: grid;
  grid-template-columns: 1fr 24px 1fr;
  align-items: end;
  gap: 8px;
}

.calculator-row .icon-button {
  grid-column: 1 / -1;
}

.times {
  display: grid;
  min-height: 42px;
  place-items: center;
  color: var(--muted);
  font-weight: 900;
}

.icon-button {
  min-width: 48px;
  padding-inline: 10px;
}

.calculator-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 8px;
  background: #f0fdfa;
  color: var(--primary-dark);
  padding: 12px 14px;
}

.calculator-total strong {
  font-size: 1.6rem;
}

.scanner-frame {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #101828;
  aspect-ratio: 4 / 3;
}

.scanner-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-box {
  position: absolute;
  inset: 28%;
  border: 3px solid #ff4d4f;
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.26);
}

.scanner-result {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid #b8ddd4;
  border-radius: 8px;
  background: #f0fdfa;
  padding: 12px;
}

.scanner-result span {
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.scanner-result strong {
  overflow-wrap: anywhere;
  color: #101828;
  font-size: 1.35rem;
}

.scanner-result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.error-text {
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 900px) {
  .login-panel,
  .panel {
    padding: 16px;
  }
}

@media (max-width: 759px) {
  .panel,
  .work-grid > .panel {
    overflow: hidden; /* 防止 panel 內部 input 等元素把 panel 撐爆 */
    max-width: 100%;
  }

  .form-grid,
  .mobile-edit-layout {
    min-width: 0;
    max-width: 100%;
  }
}

/* ---------- Mobile-only layout (< 760px) ---------- */
@media (max-width: 759px) {
  .mobile-hide {
    display: none !important;
  }

  .app-shell {
    /* 200px = 底部 bar 約 70px + 額外 130px 可捲動空間
       讓 scrollKeypadIntoView 永遠有足夠空間把鍵盤捲到 bar 上方 */
    padding-bottom: 200px;
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* 計算機、確認 modal、合併 modal 改成底部 Sheet（手機版） */
  .calculator-backdrop,
  .confirm-save-backdrop,
  .merge-picker-backdrop,
  .merge-confirm-backdrop {
    align-items: end !important;
    justify-items: stretch !important;
    padding: 0 !important;
  }

  .calculator-backdrop .stock-calculator,
  .confirm-save-backdrop .confirm-save-modal,
  .merge-picker-backdrop .merge-picker-modal,
  .merge-confirm-backdrop .merge-confirm-modal {
    width: 100% !important;
    max-width: 100vw !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0 !important;
    padding: 14px 14px 16px !important;
    animation: calcSheetSlideUp 0.25s ease-out;
  }

  @keyframes calcSheetSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* 手機版按鍵字小一點配合可能較窄的螢幕 */
  .calculator-backdrop .calc-key {
    min-height: 50px;
    font-size: 1.2rem;
  }

  .calculator-backdrop .calc-key.calc-op {
    font-size: 1.3rem;
  }

  /* 全域：手機 viewport 內 input 不要有天生 min-width 撐爆容器 */
  input,
  select,
  textarea {
    min-width: 0;
    max-width: 100%;
  }

  /* ===== 全站統一 checkbox 樣式（手機版）=====
     不管出現在哪個頁面、什麼位置，所有勾選框長一樣 */
  input[type="checkbox"] {
    appearance: none !important;
    -webkit-appearance: none !important;
    width: 24px !important;
    min-width: 24px !important;
    height: 24px !important;
    min-height: 24px !important;
    margin: 0 !important;
    padding: 0 !important;
    flex-shrink: 0;
    cursor: pointer;
    background: #ffffff;
    border: 2px solid #cfd6e1;
    border-radius: 5px;
    position: relative;
    transition: background 0.12s, border-color 0.12s, transform 0.08s;
    vertical-align: middle;
  }

  input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
  }

  input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 7px;
    height: 12px;
    border: solid #ffffff;
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
  }

  input[type="checkbox"]:active {
    transform: scale(0.92);
  }

  /* === Topbar 精簡版（一行） === */
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding: 4px 2px;
  }

  .topbar > div:first-child {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .topbar .eyebrow {
    display: none;
  }

  .topbar h1 {
    font-size: 0.98rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
  }

  .topbar h1::before {
    content: '店 ';
    color: var(--muted);
    font-weight: 500;
  }

  .topbar-actions {
    flex-shrink: 0;
    flex-direction: row;
    gap: 8px;
    justify-content: flex-end;
  }

  .topbar-actions > span {
    font-size: 0.84rem;
    color: var(--muted);
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions .ghost-button {
    min-height: 32px;
    padding: 4px 12px;
    font-size: 0.85rem;
  }

  /* 搜尋頁 */
  .mobile-search-view {
    display: grid;
    gap: 14px;
    margin-bottom: 16px;
  }

  .mobile-search-bar {
    display: grid;
    gap: 10px;
    padding: 12px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.06);
  }

  .mobile-store-select {
    min-height: 44px;
  }

  .mobile-search-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .mobile-search-row input {
    min-height: 44px;
  }

  .mobile-scanner-area {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    background: #101828;
    aspect-ratio: 1 / 1;
  }

  .mobile-scanner-area video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .mobile-scanner-area .scan-box {
    position: absolute;
    inset: 22%;
    border: 3px solid #ff4d4f;
    border-radius: 8px;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.30);
  }

  .mobile-scanner-tools {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
  }

  .mobile-scanner-tools .ghost-button {
    background: rgba(255, 255, 255, 0.85);
  }

  .mobile-camera-denied,
  .mobile-scanner-placeholder {
    display: grid;
    place-items: center;
    gap: 12px;
    min-height: 220px;
    padding: 24px;
    border: 1px dashed var(--line);
    border-radius: 10px;
    background: #fff;
    text-align: center;
  }

  .mobile-camera-denied p {
    margin: 0;
    color: var(--muted);
  }

  .mobile-camera-denied small {
    color: var(--muted);
  }

  /* 多筆結果獨立選擇畫面 */
  .mobile-pick-area {
    display: grid;
    gap: 12px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.06);
  }

  .mobile-pick-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--text);
  }

  .mobile-pick-head strong {
    font-size: 0.98rem;
  }

  .mobile-pick-list {
    display: grid;
    gap: 10px;
  }

  .mobile-pick-list button {
    display: grid;
    gap: 4px;
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    padding: 14px;
    min-height: 76px;
  }

  .mobile-pick-list button:active {
    background: #e9f5f2;
    border-color: var(--primary);
  }

  .mobile-pick-list button strong {
    font-size: 1rem;
    color: var(--text);
  }

  .mobile-pick-list button span,
  .mobile-pick-list button small {
    color: var(--muted);
    font-size: 0.86rem;
  }

  /* ===== 填數字頁 新版手機 layout ===== */

  /* 商品資訊精簡卡 */
  .mobile-product-info {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid var(--line);
  }

  .mobile-product-info .product-name {
    margin: 0 0 6px;
    font-size: 0.98rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.35;
    /* 商品名稱最多兩行，超出 ... */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* 主貨號 + 選項貨號 同行 */
  .mobile-product-info .product-codes {
    margin: 0 0 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.4;
  }

  .mobile-product-info .code-main,
  .mobile-product-info .code-variant {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    word-break: break-all;
  }

  .mobile-product-info .code-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 4px;
    border-radius: 4px;
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
  }

  .mobile-product-info .code-variant .code-tag {
    background: #235b9f;
  }

  .mobile-product-info .code-arrow {
    color: var(--muted);
    font-weight: 700;
  }

  .mobile-product-info .product-meta {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.5;
    word-break: break-all;
  }

  .mobile-product-info .product-meta .meta-sep {
    margin: 0 4px;
    color: #d9dee7;
  }

  /* === 內建數字鍵盤（固定 2 行 × 6 列） === */
  .mobile-keypad {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    margin: 6px 0 8px;
    padding: 0;
    /* 進入編輯頁時 scrollIntoView 會用這個邊距，
       讓鍵盤底端跟底部固定 bar 之間留出 90px 空間 */
    scroll-margin-bottom: 90px;
  }

  .mobile-keypad button {
    min-height: 62px;
    border: 1.5px solid #d0d5dd;
    border-radius: 12px;
    background: #ffffff;
    color: #17202a;
    font-size: 1.55rem;
    font-weight: 600;
    font-family: "Noto Sans TC", "Microsoft JhengHei", -apple-system, sans-serif;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
      0 1px 2px rgba(16, 24, 40, 0.04),
      0 2px 6px rgba(16, 24, 40, 0.04),
      inset 0 -1px 0 rgba(16, 24, 40, 0.05);
    transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.1s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-keypad button:active {
    transform: scale(0.94);
    background: #f5f7fa;
    box-shadow:
      0 1px 1px rgba(16, 24, 40, 0.04),
      inset 0 0 0 transparent;
  }

  .mobile-keypad .keypad-digit {
    color: #17202a;
  }

  /* 退格鍵：淡灰底，icon */
  .mobile-keypad .keypad-backspace {
    background: #f5f7fa;
    color: #667085;
  }

  .mobile-keypad .keypad-backspace:active {
    background: #eef2f6;
  }

  /* 清空鍵：淡紅底，警示色 */
  .mobile-keypad .keypad-clear {
    background: #fef3f2;
    color: var(--danger);
    font-size: 0.88rem;
    font-weight: 700;
  }

  .mobile-keypad .keypad-clear:active {
    background: #fee4e2;
  }

  /* Edit layout 順序固定：鍵盤永遠在進階 toggle 之上 */
  .mobile-edit-layout {
    display: flex;
    flex-direction: column;
  }

  /* 模式 tab */
  .mobile-mode-tabs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
    margin-bottom: 10px;
    padding: 4px;
    background: #eef2f6;
    border-radius: 10px;
  }

  .mobile-mode-tab {
    min-width: 0;
    min-height: 40px;
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-mode-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 10px rgba(17, 107, 95, 0.25);
  }

  /* swipe 卡片區 */
  .mobile-stock-cards {
    position: relative;
    margin-bottom: 4px;
    touch-action: pan-y; /* 允許垂直捲動，水平交給我們的 swipe */
  }

  .stock-card {
    padding: 14px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: 0 4px 14px rgba(16, 24, 40, 0.05);
  }

  .stock-card-label {
    margin: 0 0 10px;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--primary-dark);
  }

  .stock-card-input {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 0;
  }

  /* 原庫存純文字（無框） */
  .stock-original-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    min-width: 56px;
    min-height: 56px;
    padding: 0 4px;
    line-height: 1.2;
  }

  .stock-original-label {
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
    text-align: left;
  }

  .stock-original-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--muted);
    text-align: center;
    margin-top: 2px;
  }

  .stock-card-input input {
    min-width: 0;
    width: 100%;
    min-height: 56px;
    font-size: 1.5rem;
    font-weight: 800;
    text-align: right;
    padding: 8px 12px;
  }

  .stock-card-input .mini-button {
    min-height: 56px;
    padding: 8px 14px;
    font-size: 0.95rem;
    white-space: nowrap;
  }

  .stock-conversion {
    margin: 0;
    text-align: right;
    color: #8a4b12;
    font-size: 1.05rem;
    font-weight: 700;
  }

  .stock-conversion strong {
    font-size: 1.25rem;
  }

  .stock-conversion-hint {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.86rem;
    margin-left: 4px;
  }

  /* swipe dot indicator */
  .mobile-stock-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
  }

  .mobile-stock-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d9dee7;
  }

  .mobile-stock-dots .dot.active {
    background: var(--primary);
    width: 22px;
    border-radius: 4px;
  }

  /* 進階欄位收摺 */
  .mobile-advanced-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    padding: 8px 14px;
    margin-top: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    font-size: 0.94rem;
  }

  .mobile-advanced-toggle .caret {
    color: var(--muted);
    font-size: 0.8rem;
  }

  .mobile-advanced-fields {
    display: grid;
    gap: 10px;
    margin-top: 10px;
    padding: 12px;
    background: #fafbfc;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  /* 底部固定按鈕（填數字頁專用） */
  .mobile-edit-bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 8px;
    padding: 10px 12px;
    background: #ffffff;
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 16px rgba(16, 24, 40, 0.10);
    transform: translateY(0);
    transition: transform 0.25s ease;
  }

  /* 原生鍵盤彈出時，把底部 bar 滑下去藏起來，露出欄位 */
  .mobile-edit-bottom-bar.hidden-by-keyboard {
    transform: translateY(110%);
  }

  .mobile-edit-bottom-bar button {
    min-height: 50px;
    font-size: 1rem;
    font-weight: 800;
  }

  /* 進階欄位 input 預留 scroll 邊距，捲到中央時不會貼到頂 */
  .mobile-advanced-fields input {
    scroll-margin-top: 80px;
    scroll-margin-bottom: 80px;
  }

  /* 桌機保留的 conversion-label 樣式 */
  .conversion-label input {
    background: #fff7ed;
    color: #8a4b12;
    font-weight: 800;
  }

  /* 填數字頁返回列 */
  .mobile-page-head {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .mobile-page-head h2 {
    margin: 0;
  }

  .mobile-page-head .ghost-button {
    min-height: 36px;
    padding: 6px 10px;
  }

  /* 覆蓋提示 */
  .overwrite-warning {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fffaeb;
    border: 1px solid #fedf89;
    color: var(--warning);
    font-weight: 700;
    font-size: 0.92rem;
  }

  /* 手機版選取模式工具列（勾任一筆才出現） */
  .mobile-selection-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 12px;
    padding: 10px 12px;
    background: #e9f5f2;
    border: 1px solid #b8ddd4;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(17, 107, 95, 0.10);
  }

  .mobile-selection-toolbar .selection-count {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--primary-dark);
    flex-shrink: 0;
  }

  .mobile-selection-toolbar .selection-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .mobile-selection-toolbar .ghost-button {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.86rem;
  }

  .mobile-selection-toolbar .danger-button {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 0.92rem;
    font-weight: 800;
  }

  /* 目前批次頁面：全部展開 toggle */
  .mobile-batch-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    padding: 0 2px;
  }

  .mobile-batch-meta small {
    color: var(--muted);
    font-size: 0.84rem;
  }

  .expand-all-toggle {
    min-height: 32px;
    font-size: 0.9rem;
  }

  /* === 新版卡片摺疊狀態 === */
  .record-card.record-collapsed .record-detail-list {
    display: none;
  }

  /* 卡片上方一列：勾選框 + 商品名（可展開） */
  .card-top-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
  }

  .card-checkbox {
    display: flex;
    align-items: center;
    padding-top: 2px;
    cursor: pointer;
  }

  .card-name-area {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    cursor: pointer;
    padding: 2px 0;
  }

  .card-product-name {
    flex: 1;
    min-width: 0;
    font-size: 0.92rem;
    font-weight: 800;
    line-height: 1.4;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
  }

  /* 點了 ▾ 後展開所有行 */
  .record-card.name-expanded .card-product-name {
    -webkit-line-clamp: unset;
    overflow: visible;
    display: block;
  }

  .card-name-toggle {
    color: var(--muted);
    font-size: 0.95rem;
    flex-shrink: 0;
    user-select: none;
    padding: 0 2px;
  }

  /* 貨號行：[主] 主貨號 → [選] 選項貨號 */
  .card-codes {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--text);
  }

  .card-codes .code-main,
  .card-codes .code-variant {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    word-break: break-all;
  }

  .card-codes .code-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 4px;
    border-radius: 4px;
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
  }

  .card-codes .code-variant .code-tag {
    background: #235b9f;
  }

  .card-codes .code-arrow {
    color: var(--muted);
    font-weight: 700;
  }

  /* 規格 + 每組 */
  .card-meta {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.4;
    word-break: break-all;
  }

  .card-meta .meta-sep {
    margin: 0 4px;
    color: #d9dee7;
  }

  /* 新增 / 盤點 純文字一行（不再是輸入框樣子） */
  .card-stocks {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.5;
  }

  .card-stocks strong {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin: 0 2px;
  }

  .card-stocks .stocks-sep {
    margin: 0 10px;
    color: #d9dee7;
  }

  /* 底部固定 bar */
  .mobile-bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--line);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 16px rgba(16, 24, 40, 0.08);
  }

  .mobile-bottom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 60px;
    padding: 10px;
    background: #fff;
    border: none;
    color: var(--text);
    font-weight: 700;
  }

  .mobile-bottom-btn.active {
    background: #e9f5f2;
    color: var(--primary-dark);
  }

  .bottom-btn-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 0.84rem;
    font-weight: 800;
  }
}

/* ---------- Desktop (>= 760px) 隱藏手機元件 ---------- */
@media (min-width: 760px) {
  .mobile-search-view,
  .mobile-bottom-bar,
  .mobile-edit-bottom-bar,
  .mobile-batch-meta,
  .mobile-page-head,
  .mobile-edit-layout,
  .mobile-product-info,
  .mobile-mode-tabs,
  .mobile-stock-cards,
  .mobile-advanced-toggle,
  .mobile-advanced-fields,
  .record-collapsed-summary {
    display: none !important;
  }
}

@media (min-width: 760px) {
  .app-shell {
    padding: 24px;
  }

  .topbar,
  .panel-heading,
  .batch-list article {
    align-items: center;
    flex-direction: row;
  }

  .toolbar {
    grid-template-columns: minmax(180px, 240px) minmax(260px, 1fr) auto auto;
  }

  .toolbar label:first-child,
  .toolbar label:nth-child(2) {
    grid-column: auto;
  }

  .work-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .form-grid .wide {
    grid-column: span 2;
  }

  .button-row {
    justify-content: flex-end;
  }

  .button-row button,
  .toolbar button {
    flex: initial;
    width: auto;
  }

  .input-action {
    grid-template-columns: 1fr auto;
  }

  .calculator-row {
    grid-template-columns: 1fr 24px 1fr auto;
  }

  .calculator-row .icon-button {
    grid-column: auto;
  }

  .mobile-record-list {
    display: none;
  }

  .table-wrap {
    display: block;
  }
}

/* ===== 版本 X UI（規格類別感知 + 件全藏） ===== */

/* 規格倍數提示條 */
.spec-meta-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: linear-gradient(90deg, #ecf6f4 0%, #f5fbf9 100%);
  border: 1px solid #cfe7df;
  color: var(--primary-dark);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  width: fit-content;
  max-width: 100%;
}

/* 輸入欄 + 單位 + 計算 按鈕 - 桌機 */
.input-with-unit {
  grid-template-columns: minmax(0, 1fr) auto auto !important;
  gap: 6px;
  align-items: stretch;
}

.input-with-unit input[type="number"] {
  text-align: right;
  font-weight: 600;
  font-size: 1.05rem;
}

/* 單位下拉 */
.unit-select {
  min-width: 64px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary-dark);
  cursor: pointer;
  transition: all 0.15s ease;
}

.unit-select:hover:not(:disabled) {
  border-color: var(--primary);
  background: #fff;
}

.unit-select:focus {
  outline: 2px solid rgba(17, 107, 95, 0.18);
  outline-offset: 1px;
  border-color: var(--primary);
}

.unit-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 固定單位 label（離散品用） */
.unit-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 6px 12px;
  border-radius: 8px;
  background: #f1f5f4;
  border: 1px solid #d8e4e0;
  color: var(--primary-dark);
  font-size: 0.95rem;
  font-weight: 700;
}

/* 算式提示小字 */
.stock-calc-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: #8a8a8a;
  text-align: right;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* 批次卡片內的「輸入 + 單位」一體 */
.record-input-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.record-input-row input[type="number"] {
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 6px;
  padding-right: 4px;
  /* 移除手機數字框的上下箭頭(spinner),省下右側約 20px 給數字 */
  -moz-appearance: textfield;
}
.record-input-row input[type="number"]::-webkit-outer-spin-button,
.record-input-row input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.unit-select-sm,
.unit-label-sm {
  flex: 0 0 auto;
  width: 46px;
  padding: 4px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-dark);
  text-align: center;
}

.unit-label-sm {
  background: #f1f5f4;
  border-color: #d8e4e0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.unit-select-sm:disabled,
.unit-label-sm:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 批次卡片的算式提示 */
.record-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  font-weight: 500;
}

/* ----- 手機版適配 ----- */
@media (max-width: 759px) {
  /* 手機版 stock-card 標題列：左標題 + 右 [現] tag */
  .stock-card-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
  }

  .stock-card-label-text {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--primary-dark);
  }

  /* 標題列右側的 [現] 庫存 N m */
  .stock-card-current {
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 500;
  }
  .stock-card-current .code-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 4px;
    border-radius: 4px;
    background: #d97706;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
  }

  /* 商品資訊卡：[單] 標籤所在行（class 已用 product-codes） */
  .mobile-product-info .product-codes + .product-codes {
    margin-top: 4px;
  }

  /* 確認視窗：類型 + 單位小字 */
  .confirm-type-unit {
    margin-left: 6px;
    font-size: 0.78em;
    opacity: 0.75;
    font-weight: 500;
  }

  /* 確認視窗：值 + 單位小字 */
  .confirm-value-unit {
    margin-left: 8px;
    font-size: 0.4em;
    color: #888;
    font-weight: 500;
    vertical-align: super;
  }

  /* 計算機 title：單位小字 */
  .calc-title-unit {
    margin-left: 8px;
    font-size: 0.7em;
    opacity: 0.7;
    font-weight: 500;
  }

  /* 桌機限定樣式在手機略縮 */
  .spec-meta-bar {
    font-size: 0.85rem;
    padding: 6px 12px;
  }

  /* 手機版原庫存顯示（含副單位小字，壓窄寬度避免擠輸入框） */
  .stock-original-sub {
    display: block;
    font-size: 0.62rem;
    color: var(--muted);
    font-weight: 500;
    margin-top: 1px;
    text-align: center;
    letter-spacing: 0.1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 手機版單位下拉（固定寬度，不讓 browser 自動展開） */
  .stock-card-input .unit-select {
    width: 64px;
    min-width: 64px;
    max-width: 64px;
    min-height: 56px;
    padding: 6px 4px;
    font-size: 1.05rem;
    font-weight: 700;
    text-align: center;
    text-align-last: center;
  }

  .stock-card-input .unit-label {
    width: 56px;
    min-width: 56px;
    max-width: 56px;
    min-height: 56px;
    font-size: 1.05rem;
    padding: 6px 0;
  }

  /* 手機版算式提示（小字、靠右、不額外占太多高度） */
  .stock-card-hint {
    margin: 6px 0 0;
    font-size: 0.78rem;
    color: var(--muted);
    text-align: right;
    font-weight: 500;
    letter-spacing: 0.3px;
    min-height: 16px;
  }

  /* C 方案：3 欄輸入區（輸入 / 單位 / 計算），全部同列 */
  .stock-card-input-three {
    grid-template-columns: minmax(0, 1fr) 64px auto;
    gap: 6px;
  }

  /* 三欄輸入下：計算按鈕大小 */
  .stock-card-input-three .mini-button {
    min-width: 60px;
    padding: 8px 12px;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  /* 桌機限定樣式在手機略縮 */
  .spec-meta-bar {
    font-size: 0.85rem;
    padding: 6px 12px;
  }
}

/* ----- 超窄螢幕（< 380px）保護 ----- */
@media (max-width: 379px) {
  /* 計算按鈕縮窄 */
  .stock-card-input-three {
    grid-template-columns: minmax(0, 1fr) 56px auto;
    gap: 4px;
  }
  .stock-card-input-three .mini-button {
    min-width: 50px;
    padding: 8px 6px;
    font-size: 0.82rem;
  }
  .stock-card-input-three .unit-select {
    width: 56px;
    min-width: 56px;
    max-width: 56px;
  }
}

/* ----- 小螢幕極限保護（< 640px 高） ----- */
@media (max-height: 640px) and (max-width: 759px) {
  .stock-card-hint {
    font-size: 0.7rem;
    margin-top: 2px;
  }
  .chip {
    font-size: 0.68rem;
    padding: 2px 8px;
  }
}
