*{box-sizing:border-box}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft JhengHei",Arial,sans-serif;background:#f3f4f6;color:#111827}.app-header{display:flex;justify-content:space-between;align-items:center;padding:16px;background:#111827;color:#fff}.app-header h1{font-size:20px;margin:0}.container{max-width:980px;margin:0 auto;padding:14px}.tabs{display:flex;gap:8px;overflow:auto;padding:10px;background:#fff;border-bottom:1px solid #e5e7eb;position:sticky;top:0;z-index:2}.tab{white-space:nowrap;border:1px solid #d1d5db;background:#fff;border-radius:999px;padding:10px 14px;font-size:15px}.tab.active{background:#2563eb;color:#fff;border-color:#2563eb}.tab-panel{display:none}.tab-panel.active{display:block}.card{background:#fff;border-radius:16px;padding:16px;margin-bottom:14px;box-shadow:0 2px 12px rgba(0,0,0,.06)}h2{font-size:20px;margin:0 0 14px}h3{font-size:16px;margin:18px 0 10px}.label{display:block;font-weight:700;margin:12px 0 6px}.text-input,select{width:100%;padding:13px 12px;border:1px solid #d1d5db;border-radius:10px;font-size:16px;background:#fff}.row{display:flex;align-items:center}.gap{gap:10px}.wrap{flex-wrap:wrap}.full{width:100%}.primary-btn,.secondary-btn,.ghost-btn,.danger-btn{border:0;border-radius:10px;padding:13px 16px;font-size:16px;font-weight:700;cursor:pointer}.primary-btn{background:#2563eb;color:#fff}.secondary-btn{background:#059669;color:#fff}.ghost-btn{background:#e5e7eb;color:#111827}.danger-btn{background:#dc2626;color:#fff}.small{font-size:13px;padding:8px 10px}.ghost-link{display:inline-block;text-decoration:none;color:#111827;background:#e5e7eb;border-radius:10px;padding:13px 16px;font-weight:700}.action-row{margin-top:16px}.hint{color:#6b7280;font-size:14px;line-height:1.5}.msg{margin:10px 0 0;font-weight:700}.error{color:#dc2626}.success{color:#059669}.hidden{display:none!important}.reader{width:100%;max-width:420px;margin:10px auto;border:1px solid #d1d5db;border-radius:12px;overflow:hidden}.pcs-box{margin:8px 0 12px;background:#eff6ff;color:#1d4ed8;padding:10px;border-radius:10px;font-weight:800}.lot-list.empty{color:#6b7280;background:#f9fafb;padding:12px;border-radius:10px}.lot-row{border:1px solid #e5e7eb;border-radius:12px;padding:12px;margin-bottom:10px;background:#fafafa}.lot-row-head{display:flex;justify-content:space-between;gap:8px;margin-bottom:8px}.lot-row-grid{display:grid;grid-template-columns:1fr 1fr 90px;gap:8px;align-items:end}.lot-row label{font-size:13px;font-weight:700;color:#374151}.mini-input{width:100%;padding:10px;border:1px solid #d1d5db;border-radius:8px;font-size:15px}.remove-btn{background:#fee2e2;color:#991b1b;border:0;border-radius:8px;padding:8px 10px;font-weight:700}.chips{display:flex;gap:8px;flex-wrap:wrap;margin-top:8px}.chip{background:#eef2ff;color:#3730a3;border:1px solid #c7d2fe;border-radius:999px;padding:8px 12px}.result-box{margin-top:14px}.summary{background:#f0fdf4;border:1px solid #bbf7d0;border-radius:12px;padding:12px;margin:12px 0}.table-wrap{overflow:auto;border:1px solid #e5e7eb;border-radius:12px}table{width:100%;border-collapse:collapse;background:#fff}th,td{padding:10px;border-bottom:1px solid #e5e7eb;text-align:left;white-space:nowrap}th{background:#f9fafb}.qr-canvas{display:block;width:240px!important;height:240px!important;margin:12px auto}.small-text{font-size:13px;color:#4b5563;word-break:break-all}.danger-card{border:1px solid #fecaca}.login-mask{position:fixed;inset:0;background:rgba(17,24,39,.94);display:flex;align-items:center;justify-content:center;z-index:20;padding:16px}.login-card{background:#fff;border-radius:18px;padding:22px;max-width:360px;width:100%;box-shadow:0 20px 60px rgba(0,0,0,.35)}.login-card h1{font-size:22px;margin:0 0 8px}.center{justify-content:center}.print-body{background:#fff}.print-wrap{max-width:520px;margin:0 auto;padding:24px;text-align:center}.print-label{border:2px solid #111827;border-radius:14px;padding:22px;margin-bottom:18px}.print-label h1{font-size:24px;margin:0 0 6px}.print-pallet-id{font-size:30px;font-weight:900;margin:8px 0 14px}.print-qr{width:260px!important;height:260px!important}.print-date{font-size:13px;color:#6b7280;margin-top:8px}@media (max-width:640px){.row{flex-direction:column;align-items:stretch}.lot-row-grid{grid-template-columns:1fr}.tabs{gap:6px}.tab{font-size:14px;padding:9px 12px}.primary-btn,.secondary-btn,.ghost-btn,.danger-btn{width:100%}}@media print{.no-print{display:none!important}body{background:#fff}.print-wrap{padding:0}.print-label{border:0;margin:0}.print-pallet-id{font-size:32px}}


/* 系統標題與維護資訊 */
.app-title-block{display:flex;flex-direction:column;gap:4px;min-width:0}
.app-title-block h1{margin:0;font-size:20px;line-height:1.25}
.system-subtitle{margin:0;font-size:13px;font-weight:500;color:#d1d5db;line-height:1.45;word-break:break-word}
.login-subtitle{color:#6b7280;margin:6px 0 12px;text-align:left}
@media (max-width:640px){.app-header{align-items:flex-start;gap:10px}.app-title-block h1{font-size:19px}.system-subtitle{font-size:12px}.app-header .small{width:auto;min-width:64px}}


/* 浮動提示：掃描 / 加入 / 刪除時顯示在畫面下方 */
.toast-area {
  position: fixed;
  left: 50%;
  bottom: max(26px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  pointer-events: none;
  width: min(92vw, 520px);
}

/* 棧板 ID 操作區：三個操作按鈕保持整齊，不再各自佔滿一整排。 */
.pallet-id-control {
  display: grid;
  gap: 10px;
}

.pallet-id-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.pallet-id-actions .primary-btn,
.pallet-id-actions .secondary-btn {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  white-space: nowrap;
}

.pallet-scan-stop-row {
  margin-top: 10px;
}

@media (max-width: 640px) {
  .pallet-id-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pallet-id-actions #startCreatePalletScanBtn {
    grid-column: 1 / -1;
  }
}

.toast {
  width: fit-content;
  max-width: 100%;
  padding: 13px 18px;
  border-radius: 999px;
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,.22);
  animation: toast-pop .18s ease-out;
  white-space: normal;
}

.toast-success { background: #16803a; }
.toast-error { background: #dc2626; }
.toast-hide { opacity: 0; transform: translateY(8px); transition: opacity .25s ease, transform .25s ease; }

@keyframes toast-pop {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}


/* 明細專用數字鍵盤 */
.detail-keypad-input {
  cursor: pointer;
  caret-color: transparent;
  background-image: linear-gradient(#fff, #fff);
}

.detail-keypad-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .16);
  outline: none;
}

body.detail-keypad-open {
  overflow: hidden;
}

.detail-keypad-mask {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  background: rgba(17, 24, 39, .58);
  backdrop-filter: blur(2px);
}

.detail-keypad-panel {
  width: min(100%, 460px);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-radius: 20px 20px 14px 14px;
  background: #fff;
  box-shadow: 0 -14px 50px rgba(0, 0, 0, .28);
  animation: detail-keypad-slide-up .18s ease-out;
}

.detail-keypad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-keypad-header strong {
  display: block;
  font-size: 18px;
}

.detail-keypad-hint {
  margin-top: 3px;
  color: #6b7280;
  font-size: 13px;
}

.detail-keypad-close {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: #e5e7eb;
  color: #111827;
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
}

.detail-keypad-screen {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 2px solid #bfdbfe;
  border-radius: 14px;
  background: #eff6ff;
}

.detail-keypad-expression {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #111827;
  font-size: 25px;
  font-weight: 900;
  letter-spacing: .5px;
}

.detail-keypad-pcs {
  flex: 0 0 auto;
  color: #1d4ed8;
  font-size: 16px;
  white-space: nowrap;
}

.detail-keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.detail-key {
  min-height: 58px;
  border: 1px solid #d1d5db;
  border-radius: 13px;
  background: #f9fafb;
  color: #111827;
  font-size: 24px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.detail-key:active {
  transform: scale(.97);
  background: #e5e7eb;
}

.detail-key-operator {
  border-color: #93c5fd;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 28px;
}

.detail-key-backspace {
  background: #fef3c7;
  color: #92400e;
}

.detail-key-clear {
  grid-column: span 2;
  background: #fee2e2;
  color: #991b1b;
  font-size: 18px;
}

.detail-key-zero {
  font-size: 24px;
}

.detail-key-done {
  background: #059669;
  color: #fff;
  border-color: #059669;
  font-size: 18px;
}

.detail-keypad-msg {
  min-height: 22px;
  margin: 9px 2px 0;
  color: #dc2626;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

@keyframes detail-keypad-slide-up {
  from { opacity: 0; transform: translateY(22px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 700px) {
  .detail-keypad-mask { align-items: center; }
  .detail-keypad-panel { border-radius: 20px; }
}

/* 日期區間明細勾選刪除 */
.field-grow {
  flex: 1 1 220px;
  min-width: 0;
}

.primary-btn:disabled,
.secondary-btn:disabled,
.ghost-btn:disabled,
.danger-btn:disabled,
.danger-outline-btn:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.danger-outline-btn {
  border: 1px solid #dc2626;
  border-radius: 10px;
  padding: 13px 16px;
  background: #fff;
  color: #b91c1c;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.delete-preview-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #fecaca;
}

.delete-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
}

.delete-selected-summary {
  margin-top: 4px;
  color: #6b7280;
  font-size: 14px;
  font-weight: 700;
}

.delete-select-all-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.delete-select-all-label input,
.delete-row-checkbox {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: #dc2626;
  cursor: pointer;
}

.delete-action-row {
  margin-bottom: 10px;
}

.delete-warning {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

/* 明細改為橫向表格，一列只顯示：勾選、Lot ID、明細、總數、日期。 */
.delete-preview-list {
  max-height: 60vh;
  overflow: auto;
  padding: 0;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  background: #fff;
  overscroll-behavior: contain;
}

.delete-preview-table {
  min-width: 620px;
  width: 100%;
}

.delete-preview-header,
.delete-preview-item {
  display: grid;
  grid-template-columns: 54px minmax(150px, 1.45fr) minmax(155px, 1.55fr) 96px 116px;
  align-items: center;
}

.delete-preview-header {
  position: sticky;
  top: 0;
  z-index: 1;
  min-height: 44px;
  border-bottom: 1px solid #d1d5db;
  background: #f3f4f6;
  color: #374151;
  font-size: 14px;
  font-weight: 900;
}

.delete-preview-body {
  display: block;
}

.delete-preview-item {
  min-height: 46px;
  margin: 0;
  border: 0;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.delete-preview-item:last-child {
  border-bottom: 0;
}

.delete-preview-item:hover {
  background: #f9fafb;
}

.delete-preview-item:has(.delete-row-checkbox:checked) {
  background: #fef2f2;
  box-shadow: inset 4px 0 0 #dc2626;
}

.delete-cell {
  min-width: 0;
  padding: 9px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.delete-cell + .delete-cell {
  border-left: 1px solid #f1f5f9;
}

.delete-cell-check {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 6px;
  padding-left: 6px;
}

.delete-cell-lot {
  color: #111827;
  font-weight: 850;
}

.delete-cell-detail {
  color: #374151;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.delete-cell-date {
  color: #4b5563;
}

.delete-cell-number {
  color: #1d4ed8;
  font-weight: 900;
  text-align: right;
}

.delete-empty {
  padding: 22px 12px;
  color: #6b7280;
  text-align: center;
  font-weight: 700;
}

@media (max-width: 640px) {
  .danger-outline-btn { width: 100%; }
  .delete-preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .delete-select-all-label {
    justify-content: center;
    width: 100%;
  }
  .delete-preview-list {
    max-height: 62vh;
  }
  .delete-preview-table {
    min-width: 590px;
  }
  .delete-preview-header,
  .delete-preview-item {
    grid-template-columns: 50px 145px 150px 90px 110px;
  }
  .delete-cell {
    padding: 8px;
    font-size: 13px;
  }
}
