:root {
  --bg: #0f1419;
  --bg-elev: #1a2332;
  --bg-card: #1e2a3a;
  --border: #2d3a4d;
  --text: #e8eef6;
  --muted: #8b9cb3;
  --primary: #f97316;
  --primary-hover: #fb923c;
  --accent: #38bdf8;
  --good: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, #151c27 0%, #0f1419 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  flex-direction: column; /* LOGO 在上、文字在正下方 */
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px 20px;
  min-width: 0;
  text-align: center;
}

/* 賣場 LOGO：加大、維持比例，勿壓成小方塊 */
.brand-logo {
  height: 58px;
  width: auto;
  max-height: 62px;
  max-width: min(100%, 200px);
  object-fit: contain;
  object-position: center;
  border-radius: 10px;
  flex: 0 0 auto;
  background: transparent;
  display: block;
}

.brand-text {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.brand-title {
  font-weight: 700;
  font-size: 17px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 舊版文字圖示（若他處仍用） */
.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f97316, #ea580c);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 4px 16px rgba(249, 115, 22, 0.4);
  flex: 0 0 auto;
}

@media (max-width: 960px) {
  .brand {
    padding: 8px 6px 16px;
    gap: 6px;
  }
  .brand-logo {
    height: 50px;
    max-height: 52px;
    max-width: min(100%, 160px);
  }
  .brand-title {
    font-size: 16px;
  }
}

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: 0.15s;
}

.nav-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-btn.active {
  background: rgba(249, 115, 22, 0.15);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-footer {
  font-size: 11px;
  color: var(--muted);
  padding: 12px 10px 0;
  border-top: 1px solid var(--border);
}

/* Main */
.main {
  padding: 24px 28px 48px;
  overflow-x: hidden;
  max-width: 1400px;
  min-width: 0;
}

/* 商品管理：工具列/分類鈕固定；僅表格內容捲動 */
.view.products-view.active {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* 扣掉 topbar 與 main padding，讓列表吃滿可視高度 */
  height: calc(100vh - 88px);
  max-height: calc(100vh - 88px);
}
.products-fixed-chrome {
  flex: 0 0 auto;
  z-index: 40;
  background: var(--bg);
  padding: 0 0 12px;
  border-bottom: 1px solid var(--border);
}
.products-fixed-chrome .toolbar {
  margin-bottom: 10px;
}
.cat-jump-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 76px;
  overflow-y: auto;
  padding: 2px 0 4px;
}
.cat-jump-btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.3;
  white-space: nowrap;
}
.cat-jump-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}
.cat-jump-btn.active {
  border-color: var(--primary);
  background: rgba(249, 115, 22, 0.18);
  color: #fdba74;
  font-weight: 600;
}
.cat-jump-n {
  opacity: 0.75;
  font-size: 11px;
  margin-left: 2px;
}

/* 列表排序下拉 */
.toolbar-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-direction: row;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.toolbar-sort .input,
.toolbar-sort select {
  min-width: 140px;
  max-width: 180px;
}
.order-fill-time {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* 叫貨帳號／出貨賣場篩選標籤 */
.filter-tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
  max-height: 88px;
  overflow-y: auto;
  padding: 2px 0 4px;
}
.filter-tag-btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.3;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.filter-tag-btn:hover {
  border-color: var(--filter-color, var(--accent));
  background: color-mix(in srgb, var(--filter-color, #38bdf8) 12%, var(--bg-elev));
}
.filter-tag-btn.active {
  border-color: var(--filter-color, var(--primary));
  background: color-mix(in srgb, var(--filter-color, #f97316) 22%, var(--bg-elev));
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--filter-color, #f97316) 35%, transparent);
}
.filter-tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--filter-color, var(--muted));
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.filter-tag-n {
  opacity: 0.75;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.filter-tag-btn.active .filter-tag-n {
  opacity: 0.95;
}

/* 列表時間窗／載入更多 */
.list-range-hint {
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 10px;
  padding: 6px 2px;
}
.list-load-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
}
.list-load-more-text {
  font-size: 13px;
  line-height: 1.45;
}

/* 表格捲動容器：只有這裡會滾 */
.products-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #151c27;
  /* 讓水平捲動時表頭也跟著 */
  overscroll-behavior: contain;
}
#products-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #151c27;
}
/* 欄位標題：完全不透明，黏在表格捲動區頂端 */
#products-table thead th {
  position: sticky;
  top: 0;
  z-index: 25;
  background: #1a2332 !important;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 0 #1a2332, 0 3px 8px rgba(0, 0, 0, 0.35);
  backdrop-filter: none;
}

/* 表格欄寬拖曳（商品管理／庫存明細） */
.table.is-col-resizable {
  table-layout: fixed;
}
.table thead th.col-resizable {
  /* sticky 已在各表定義；此處確保可放 absolute handle */
  overflow: visible;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
}
#products-table thead th.col-resizable,
#stock-table thead th.col-resizable {
  position: sticky;
}
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 30;
}
.col-resize-handle::after {
  content: "";
  position: absolute;
  top: 20%;
  bottom: 20%;
  left: 3px;
  width: 2px;
  border-radius: 1px;
  background: transparent;
  transition: background 0.12s ease;
}
.col-resizable:hover .col-resize-handle::after,
.col-resize-handle:hover::after {
  background: color-mix(in srgb, var(--accent, #38bdf8) 70%, transparent);
}
body.is-col-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.is-col-resizing * {
  cursor: col-resize !important;
}
.col-resize-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--accent, #38bdf8);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent, #38bdf8) 40%, transparent);
  pointer-events: none;
  z-index: 40;
}
#products-table.is-col-resizable tbody td,
#stock-table.is-col-resizable tbody td,
#reorder-table.is-col-resizable tbody td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#reorder-table thead th.col-resizable {
  position: sticky;
}
/* 分類區塊標題：不 sticky，避免與表頭重疊糊掉；僅作分組標記 */
#products-table .cat-header-row td {
  position: static !important;
  top: auto !important;
  z-index: auto !important;
  background: #1e2a3a !important;
  border-top: 1px solid rgba(56, 189, 248, 0.35);
  border-bottom: 1px solid var(--border);
  box-shadow: none;
}
#products-table .cat-header-row.cat-header-flash td,
#stock-table .cat-header-row.cat-header-flash td {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  animation: catFlash 1.2s ease;
}
@keyframes catFlash {
  0% { background: rgba(249, 115, 22, 0.4) !important; }
  100% { background: #1e2a3a !important; }
}

/* 庫存明細分類跳轉（與商品管理共用 cat-jump-btn） */
#view-stock .cat-jump-bar {
  margin: 0 0 12px;
}
#products-table tbody td {
  background: #151c27;
}
#products-table tbody tr:hover td {
  background: #1a2433;
}

/* 設定：分類管理 */
.cat-manage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.cat-manage-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.cat-manage-idx {
  width: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.cat-manage-name {
  font-weight: 600;
  min-width: 100px;
  flex: 1;
}
.cat-manage-item .input {
  flex: 1;
  min-width: 120px;
}
.cat-manage-count {
  font-size: 12px;
  white-space: nowrap;
}
.cat-manage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h1 { font-size: 24px; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.badge {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
  border: 1px solid rgba(251, 191, 36, 0.35);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.badge.hidden { display: none; }

/* Live rate pill */
.rate-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  font-size: 13px;
  cursor: default;
  user-select: none;
}
.rate-pill.loading .rate-pill-btn { animation: spin 0.8s linear infinite; }
.rate-pill.stale { border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.08); }
.rate-pill.error { border-color: rgba(248, 113, 113, 0.4); background: rgba(248, 113, 113, 0.08); }
.rate-pill-label { color: var(--muted); font-size: 11px; font-weight: 600; }
.rate-pill-value { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.2em; }
.rate-pill-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: 0.15s;
}
.rate-pill-btn:hover { background: rgba(56, 189, 248, 0.35); }
@keyframes spin { to { transform: rotate(360deg); } }

.rate-display {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.rate-big { min-width: 180px; }
.rate-big .stat-value { font-size: 36px; color: var(--accent); }
.rate-markup-preview {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.3);
  background: rgba(56, 189, 248, 0.08);
  font-size: 13px;
}
.rate-preview-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 4px 0;
  color: var(--muted);
}
.rate-preview-row strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.rate-preview-total {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}
.rate-preview-total strong {
  color: var(--accent);
  font-size: 18px;
}
.rate-card .check-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}
.rate-card .check-label input { width: auto; }

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.2s ease; }
/* products-view 高度與 flex 見上方 .view.products-view.active */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: #4a5d78; background: #243044; }
.btn-primary {
  background: linear-gradient(135deg, #f97316, #ea580c);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, #fb923c, #f97316); }
.btn-ghost { background: transparent; }
.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.22); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }

/* Inputs */
.input, .select, textarea, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}
.input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}
/* 深色主題：date / month 月曆圖示預設過暗，全面提高可見度（不影響輸入文字與排版） */
input[type="date"],
input[type="month"] {
  color-scheme: dark;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
  opacity: 1;
  cursor: pointer;
  width: 1.1em;
  height: 1.1em;
  padding: 2px;
  margin-left: 4px;
  border-radius: 4px;
  /* invert 讓黑圖示變淺，再提亮／對比，深色底上清晰可辨 */
  filter: invert(1) brightness(1.35) contrast(1.15) saturate(0.9);
  background-color: transparent;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="month"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
  filter: invert(1) brightness(1.65) contrast(1.25) saturate(1);
  background-color: rgba(255, 255, 255, 0.12);
}
input[type="date"]::-webkit-calendar-picker-indicator:active,
input[type="month"]::-webkit-calendar-picker-indicator:active {
  filter: invert(1) brightness(1.8) contrast(1.3);
  background-color: rgba(249, 115, 22, 0.25);
}
/* 保險：若瀏覽器對 .input 內 indicator 有較高特異度覆蓋，再鎖一次 */
.input[type="date"]::-webkit-calendar-picker-indicator,
.input[type="month"]::-webkit-calendar-picker-indicator,
input.input[type="date"]::-webkit-calendar-picker-indicator,
input.input[type="month"]::-webkit-calendar-picker-indicator {
  opacity: 1;
  cursor: pointer;
  filter: invert(1) brightness(1.35) contrast(1.15) saturate(0.9);
}
.input[type="date"]::-webkit-calendar-picker-indicator:hover,
.input[type="month"]::-webkit-calendar-picker-indicator:hover,
input.input[type="date"]::-webkit-calendar-picker-indicator:hover,
input.input[type="month"]::-webkit-calendar-picker-indicator:hover {
  filter: invert(1) brightness(1.65) contrast(1.25) saturate(1);
  background-color: rgba(255, 255, 255, 0.12);
}
textarea { resize: vertical; min-height: 72px; width: 100%; }
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
/* 標題包成單一 flex 子項，避免「進價 (JPY)」被拆成多行 */
.field-label-text {
  display: block;
  line-height: 1.35;
  color: var(--muted);
}
.purchase-line-price-label,
#f-price-label {
  min-width: 0;
}
.purchase-line-price-label .purchase-line-cny,
#f-price-label #f-cny-price {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
label .input, label select, label textarea { color: var(--text); }

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar .input { flex: 1; min-width: 160px; }
.toolbar .select { min-width: 140px; flex: 0 0 auto; }

/* Cards & stats */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.card h2 { font-size: 15px; font-weight: 600; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

/* 備份提醒橫幅（週三／六） */
.backup-reminder-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(245, 158, 11, 0.12);
  border-left: 4px solid #f59e0b;
}
.backup-reminder-banner.hidden {
  display: none;
}
.backup-reminder-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

/* 儀表板 / 成本毛利 / 總營業利益 Chart.js 圖表區 */
.dash-charts,
.profit-charts,
.bp-layout {
  margin-bottom: 20px;
}

/* 總營業利益 */
.bp-intro {
  max-width: 920px;
}
.bp-check-card .card-header {
  margin-bottom: 4px;
}
.bp-check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bp-check-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.bp-check-item.is-ok {
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.06);
}
.bp-check-item.is-miss {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.06);
}
.bp-check-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 1px;
}
.bp-check-item.is-ok .bp-check-icon {
  background: rgba(52, 211, 153, 0.25);
  color: var(--good);
}
.bp-check-item.is-miss .bp-check-icon {
  background: rgba(251, 191, 36, 0.25);
  color: var(--warn);
}
.bp-check-body {
  min-width: 0;
  flex: 1;
}
.bp-check-label {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.bp-check-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
}
.bp-check-item.is-ok .bp-check-badge {
  background: rgba(52, 211, 153, 0.18);
  color: var(--good);
}
.bp-check-item.is-miss .bp-check-badge {
  background: rgba(251, 191, 36, 0.18);
  color: var(--warn);
}
.bp-check-detail {
  font-size: 12px;
  margin-top: 2px;
  line-height: 1.45;
}
.tag-manual {
  background: rgba(251, 191, 36, 0.16);
  color: var(--warn);
  font-size: 10px;
  font-weight: 600;
}

/* 出貨賣場顏色徽章 */
.shop-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  line-height: 1.4;
  color: #0f1419;
  background: color-mix(in srgb, var(--shop-color, #38bdf8) 82%, white);
  border: 1px solid color-mix(in srgb, var(--shop-color, #38bdf8) 70%, #000);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--shop-color, #38bdf8) 25%, transparent);
  vertical-align: middle;
}

/* 叫貨廠商標籤 */
.vendor-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px 2px 8px;
  border-radius: 999px;
  line-height: 1.4;
  color: #0f1419;
  background: color-mix(in srgb, var(--vendor-color, #f97316) 78%, white);
  border: 1px solid color-mix(in srgb, var(--vendor-color, #f97316) 65%, #000);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--vendor-color, #f97316) 22%, transparent);
  vertical-align: middle;
  margin-left: 4px;
}
.vendor-badge-icon {
  font-size: 13px;
  line-height: 1;
  flex: 0 0 auto;
}
.vendor-icon-preview {
  font-size: 18px;
  line-height: 1;
  width: 1.4em;
  text-align: center;
  flex: 0 0 auto;
}
.vendor-icon-picker-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  flex-direction: row;
  color: var(--muted);
}
.vendor-icon-select {
  width: auto;
  min-width: 3.5rem;
  max-width: 5rem;
  padding: 2px 6px;
  font-size: 16px;
  line-height: 1.2;
}
.filter-tag-icon {
  font-size: 13px;
  line-height: 1;
  flex: 0 0 auto;
}
.vendor-item {
  flex-wrap: wrap;
  gap: 8px;
  position: relative;
  transition: box-shadow 0.12s ease, opacity 0.12s ease, border-color 0.12s ease;
}
.vendor-list-sortable {
  position: relative;
}
.vendor-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg, transparent);
  color: var(--muted);
  cursor: grab;
  flex: 0 0 auto;
  user-select: none;
  touch-action: none;
  font-size: 16px;
  line-height: 1;
}
.vendor-drag-handle:hover {
  color: var(--text, inherit);
  border-color: color-mix(in srgb, var(--accent, #38bdf8) 50%, var(--border));
  background: color-mix(in srgb, var(--accent, #38bdf8) 12%, transparent);
}
.vendor-drag-handle:active,
body.is-vendor-sorting .vendor-drag-handle {
  cursor: grabbing;
}
.vendor-item.is-dragging {
  opacity: 0.35;
  border-style: dashed;
}
.vendor-item.is-drag-over.drag-insert-before {
  box-shadow: inset 0 3px 0 0 var(--accent, #38bdf8);
}
.vendor-item.is-drag-over.drag-insert-after {
  box-shadow: inset 0 -3px 0 0 var(--accent, #38bdf8);
}
.vendor-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.92;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  border: 1px solid color-mix(in srgb, var(--accent, #38bdf8) 55%, var(--border));
  border-radius: 8px;
  background: var(--panel, var(--bg, #1a1f26));
  transform: scale(1.02);
}
.vendor-drag-insert-line {
  position: absolute;
  height: 3px;
  border-radius: 2px;
  background: var(--accent, #38bdf8);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #38bdf8) 35%, transparent);
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: top 0.06s ease;
}
.vendor-drag-insert-line.is-visible {
  opacity: 1;
}
body.is-vendor-sorting {
  cursor: grabbing;
  user-select: none;
}
.vendor-sort-actions-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
  min-height: 36px;
}
.vendor-sort-actions-bar.is-sort-dirty {
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, #fbbf24 14%, transparent);
  border: 1px solid color-mix(in srgb, #fbbf24 45%, var(--border));
}
.vendor-sort-dirty-hint {
  font-size: 12px;
  font-weight: 600;
  color: #fbbf24;
  margin-right: auto;
}
#btn-save-vendor-sort.is-sort-dirty,
#btn-save-vendor-sort.btn-primary:not(:disabled) {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #38bdf8) 35%, transparent);
}
#btn-save-vendor-sort:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 商品管理拖曳排序（比照廠商） */
.product-sort-actions-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 8px;
  min-height: 36px;
  padding: 0 2px;
}
.product-sort-actions-bar.is-sort-dirty {
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, #fbbf24 14%, transparent);
  border: 1px solid color-mix(in srgb, #fbbf24 45%, var(--border));
}
.product-sort-dirty-hint {
  font-size: 12px;
  font-weight: 600;
  color: #fbbf24;
}
#btn-save-product-sort.is-sort-dirty,
#btn-save-product-sort.btn-primary:not(:disabled) {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #38bdf8) 35%, transparent);
}
#btn-save-product-sort:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.product-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg, transparent);
  color: var(--muted);
  cursor: grab;
  flex: 0 0 auto;
  user-select: none;
  touch-action: none;
  font-size: 16px;
  line-height: 1;
}
.product-drag-handle:hover {
  color: var(--text, inherit);
  border-color: color-mix(in srgb, var(--accent, #38bdf8) 50%, var(--border));
  background: color-mix(in srgb, var(--accent, #38bdf8) 12%, transparent);
}
.product-drag-handle:active,
body.is-product-sorting .product-drag-handle {
  cursor: grabbing;
}
#products-table tr.product-row.is-dragging {
  opacity: 0.35;
}
#products-table tr.product-row.is-drag-over.drag-insert-before td {
  box-shadow: inset 0 3px 0 0 var(--accent, #38bdf8);
}
#products-table tr.product-row.is-drag-over.drag-insert-after td {
  box-shadow: inset 0 -3px 0 0 var(--accent, #38bdf8);
}
.product-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.92;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  border: 1px solid color-mix(in srgb, var(--accent, #38bdf8) 55%, var(--border));
  border-radius: 8px;
  background: var(--panel, var(--bg, #1a1f26));
  table-layout: fixed;
  border-collapse: collapse;
  transform: scale(1.01);
}
.product-drag-insert-line {
  position: absolute;
  height: 3px;
  border-radius: 2px;
  background: var(--accent, #38bdf8);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #38bdf8) 35%, transparent);
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: top 0.06s ease;
}
.product-drag-insert-line.is-visible {
  opacity: 1;
}
body.is-product-sorting {
  cursor: grabbing;
  user-select: none;
}

.shop-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--shop-color, #38bdf8);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
  flex: 0 0 auto;
}
.shop-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.shop-color-picker-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  flex-direction: row;
  color: var(--muted);
}
.shop-color-input {
  width: 36px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}
.field-error {
  color: var(--danger) !important;
  font-weight: 600;
}
.input-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18) !important;
}
.payroll-week-box {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.bp-stats {
  margin-bottom: 16px;
}
.bp-result-card::before {
  background: linear-gradient(90deg, #38bdf8, #34d399);
  opacity: 1;
}
.bp-result-card .stat-value {
  font-size: 24px;
}
.bp-salary-card .stat-value.is-disabled,
.stat-value.is-disabled {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
}
/* 單賣場：全公司行政／薪資僅參考 */
.bp-stats .stat-card.is-company-ref {
  opacity: 0.72;
  filter: grayscale(0.35);
  border-style: dashed;
}
.bp-stats .stat-card.is-company-ref .stat-value {
  color: var(--muted) !important;
  font-size: 18px;
}
.bp-shop-mode-banner {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  background: color-mix(in srgb, #38bdf8 12%, transparent);
  border: 1px solid color-mix(in srgb, #38bdf8 40%, var(--border));
  color: var(--text);
}
.bp-shop-compare-card {
  margin-bottom: 16px;
}
.bp-shop-compare-card .table tfoot .bp-shop-total-row td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: color-mix(in srgb, var(--bg-elev, #1a1f26) 80%, transparent);
}
.bp-margin-chart-wrap {
  position: relative;
  min-height: 200px;
  max-height: 280px;
}
#bp-business-profit.is-pos,
#bp-shopee-gross.is-pos {
  color: var(--good);
}
#bp-business-profit.is-neg,
#bp-shopee-gross.is-neg {
  color: var(--danger);
}
#bp-admin.is-pos,
#bp-salary.is-pos {
  color: var(--primary);
}
.bp-stats .stat-card.is-company-ref #bp-admin.is-pos,
.bp-stats .stat-card.is-company-ref #bp-salary.is-pos {
  color: var(--muted);
}

/* 員工出勤 */
.payroll-tabs {
  margin-bottom: 16px;
}
/* 與設定分頁按鈕同風格（payroll 用獨立 class，避免與 settings-tab 互相搶 active） */
.payroll-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.payroll-tab:hover {
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.35);
}
.payroll-tab.active {
  color: var(--text);
  background: rgba(249, 115, 22, 0.14);
  border-color: rgba(249, 115, 22, 0.45);
}
.payroll-emp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.payroll-emp-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.payroll-emp-note {
  font-size: 12px;
}
.payroll-adj-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  justify-content: flex-end;
}
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.4;
}
.tag-good {
  background: rgba(52, 211, 153, 0.15);
  color: var(--good);
}
.tag-muted {
  background: rgba(139, 156, 179, 0.15);
  color: var(--muted);
}
.tag-add {
  background: rgba(52, 211, 153, 0.14);
  color: var(--good);
  font-size: 10px;
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag-deduct {
  background: rgba(248, 113, 113, 0.14);
  color: var(--danger);
  font-size: 10px;
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.payroll-suggest-box,
.payroll-trial-box {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.payroll-trial-box {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.06);
}
.payroll-suggest-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.payroll-suggest-row strong {
  font-size: 18px;
  letter-spacing: -0.02em;
}
.payroll-adj-section {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.payroll-adj-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.payroll-adj-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.payroll-adj-row {
  display: grid;
  grid-template-columns: minmax(90px, 120px) 1fr auto;
  gap: 8px;
  align-items: center;
}
.payroll-adj-row .input {
  min-width: 0;
}
.payroll-adj-row [data-adj-remove] {
  min-width: 36px;
  padding-left: 8px;
  padding-right: 8px;
  font-size: 16px;
  line-height: 1;
}
.att-table-wrap {
  overflow-x: auto;
}
#att-table th.att-day-th {
  text-align: center;
  font-size: 12px;
  min-width: 56px;
  line-height: 1.3;
}
#att-table .att-day-date {
  font-size: 10px;
  font-weight: 500;
}
#att-table .att-day-td {
  text-align: center;
  vertical-align: middle;
  padding: 6px 4px;
}
/* 出勤格子：點擊循環 none → full → half */
.att-load-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease,
    box-shadow 0.12s ease;
  user-select: none;
}
.att-load-btn:hover {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.08);
}
.att-load-btn:active {
  transform: scale(0.96);
}
.att-load-btn.att-load-none .att-load-mark {
  opacity: 0.35;
  font-weight: 500;
}
.att-load-btn.att-load-full {
  background: rgba(52, 211, 153, 0.18);
  border-color: rgba(52, 211, 153, 0.55);
  color: var(--good);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.12);
}
.att-load-btn.att-load-half {
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.5);
  color: var(--warn);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.1);
}
.att-load-mark {
  pointer-events: none;
}
.dash-chart-card .card-header {
  margin-bottom: 8px;
}
.dash-chart-sub {
  font-size: 12px;
  font-weight: 500;
}
.dash-chart-wrap {
  position: relative;
  height: 240px;
  max-width: 100%;
}
.dash-chart-wrap-tall {
  height: 280px;
}
.dash-chart-wrap canvas {
  max-width: 100%;
}
.dash-chart-wrap.is-empty canvas {
  display: none;
}
.profit-chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  text-align: center;
}
.profit-chart-empty.hidden {
  display: none;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.7;
}
.stat-card.accent::before { background: var(--primary); }
.stat-card.warn::before { background: var(--warn); }
.stat-card.good::before { background: var(--good); }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }

/* 儀表板統計卡可點擊跳轉 */
.stat-card.is-clickable,
.stat-card[data-goto] {
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease,
    box-shadow 0.15s ease;
}
.stat-card.is-clickable:hover,
.stat-card[data-goto]:hover {
  border-color: rgba(56, 189, 248, 0.55);
  background: #243246;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  transform: translateY(-1px);
}
.stat-card.is-clickable:focus-visible,
.stat-card[data-goto]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.stat-card.is-clickable:active,
.stat-card[data-goto]:active {
  transform: translateY(0);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 960px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* Tables */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(45, 58, 77, 0.6);
  vertical-align: middle;
}
.table tr:hover td { background: rgba(255,255,255,0.02); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; text-align: right; }
.table .actions .btn { margin-left: 4px; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.tag-ok { background: rgba(52, 211, 153, 0.15); color: var(--good); }
.tag-low { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.tag-zero { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.tag-pending { background: rgba(56, 189, 248, 0.15); color: var(--accent); }
.tag-partial { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }
.tag-in { background: rgba(52, 211, 153, 0.15); color: var(--good); }

/* 工具列日期篩選 */
.toolbar-date {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-direction: row;
  color: var(--text);
  font-size: 13px;
}
.toolbar-date .input {
  width: auto;
  min-width: 150px;
}

/* 依日期分組收縮 */
.orders-by-date {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.date-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
}
.date-group-head-wrap {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.12), rgba(0, 0, 0, 0.08));
  border-bottom: 1px solid var(--border);
}
.date-group-head {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 12px 14px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.date-group-head:hover {
  background: rgba(56, 189, 248, 0.08);
}
.date-group.is-collapsed .date-group-head-wrap {
  border-bottom: none;
}
.date-group-chevron {
  color: var(--accent);
  font-size: 11px;
  width: 14px;
}
.date-group-title {
  font-weight: 700;
  color: var(--accent);
  min-width: 100px;
}
.date-group-meta {
  font-size: 12px;
  flex: 1;
}
/* 叫貨系統：已到貨清單彈窗 */
.received-list-modal {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.received-list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  width: 100%;
}
.received-list-meta {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--border);
}
.received-list-meta strong {
  color: var(--text);
  font-weight: 700;
}
.received-list-skus {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-width: 0;
  /* 由 modal-body 負責整體捲動；列表本身不縮成窄欄 */
  max-height: none;
  overflow: visible;
}
.received-list-empty {
  padding: 28px 12px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}
.received-list-sku {
  display: block;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.45);
  overflow: hidden;
}
.received-list-sku.is-expanded {
  border-color: color-mix(in srgb, var(--accent, #38bdf8) 50%, var(--border));
  background: rgba(15, 23, 42, 0.65);
}
/* 重設 button 預設，避免被壓成細條／字色繼承錯誤 */
button.received-list-sku-head,
.received-list-sku-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 52px;
  box-sizing: border-box;
  text-align: left;
  padding: 14px 16px;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text, #e2e8f0);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: normal;
  white-space: normal;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.received-list-sku-head:hover {
  background: color-mix(in srgb, var(--accent, #38bdf8) 10%, transparent);
}
.received-list-chevron {
  flex: 0 0 auto;
  width: 1.25em;
  color: var(--muted, #94a3b8);
  font-size: 12px;
  line-height: 1;
}
.received-list-sku-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 8px;
  overflow: hidden;
}
.received-list-sku-code {
  flex: 0 0 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent, #38bdf8);
  white-space: nowrap;
}
.received-list-sku-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text, #e2e8f0);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.received-list-sku-qty {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text, #e2e8f0);
  white-space: nowrap;
}
.received-list-sku-orders {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #94a3b8);
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.28);
}
.received-list-sku-detail {
  padding: 8px 14px 14px 42px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px dashed color-mix(in srgb, var(--border) 80%, transparent);
  background: rgba(0, 0, 0, 0.18);
}
.received-list-sku-detail.hidden {
  display: none !important;
}
.received-list-detail-line {
  display: grid;
  grid-template-columns: 4.5em 3.5em minmax(4em, 0.9fr) minmax(6em, 1.4fr) auto auto;
  align-items: center;
  gap: 8px 12px;
  width: 100%;
  box-sizing: border-box;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text, #e2e8f0);
}
.received-list-detail-qty {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent, #38bdf8);
}
.received-list-detail-date {
  font-variant-numeric: tabular-nums;
  color: var(--text, #e2e8f0);
}
.received-list-detail-account,
.received-list-detail-vendor {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text, #e2e8f0);
}
.received-list-detail-extra {
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.received-list-order-btn {
  justify-self: end;
  white-space: nowrap;
}
@media (max-width: 640px) {
  .received-list-detail-line {
    grid-template-columns: 4em 3.2em 1fr;
    grid-template-areas:
      "qty date account"
      "vendor vendor vendor"
      "extra extra order";
  }
  .received-list-detail-qty { grid-area: qty; }
  .received-list-detail-date { grid-area: date; }
  .received-list-detail-account { grid-area: account; }
  .received-list-detail-vendor { grid-area: vendor; }
  .received-list-detail-extra { grid-area: extra; }
  .received-list-order-btn { grid-area: order; justify-self: start; }
  .received-list-sku-orders {
    display: none;
  }
}

/* 淘寶叫貨：當日品項總結（表頭可見，+N 可展開） */
.date-group-day-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 6px 8px;
  padding: 8px 14px 12px;
  border-top: 1px dashed rgba(56, 189, 248, 0.22);
}
.date-group-day-label {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
  padding-top: 3px;
}
.date-group-day-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.day-item-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: var(--text);
  max-width: 100%;
  font-family: inherit;
}
button.day-item-chip {
  cursor: pointer;
  appearance: none;
}
button.day-item-chip:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.2);
}
.day-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 9em;
}
.day-item-qty {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.day-item-chip.day-item-more,
.day-item-chip.day-item-collapse {
  background: rgba(139, 156, 179, 0.12);
  border-color: var(--border);
  color: var(--muted);
  font-weight: 600;
}
.day-item-rest {
  display: contents;
}
.day-item-rest.hidden {
  display: none !important;
}
/* 展開時：隱藏 +N 按鈕（rest 顯示後 more 仍在預覽列，用 is-expanded 控制） */
.date-group-day-summary.is-expanded .day-item-more {
  display: none;
}
.date-group-day-summary.is-expanded .day-item-rest {
  display: contents;
}
.date-group-day-summary.is-expanded .day-item-rest.hidden {
  display: contents !important;
}
.date-group-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}
.date-group.is-collapsed .date-group-body {
  display: none;
}
.date-group.is-collapsed .date-group-head {
  border-bottom: none;
}
/* 收合時仍保留當日總結（表頭內），方便一眼看貨 */

/* 叫貨列貨幣徽章（混幣） */
.purchase-line-currency-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 2.6em;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text, #e2e8f0);
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
}
.purchase-line-currency-badge[data-currency="JPY"] {
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.4);
  color: #fbbf24;
}
.purchase-line-currency-badge[data-currency="TWD"] {
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.4);
  color: #34d399;
}
.purchase-line-currency-badge[data-currency="CNY"] {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
  color: #38bdf8;
}

/* 叫貨成本拆分：商品 + 運費 = 合計 */
.purchase-cost-split {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}
.purchase-cost-item strong {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.purchase-cost-total strong {
  color: var(--primary, #38bdf8);
}
.purchase-cost-item.purchase-weight strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.purchase-cost-sep {
  opacity: 0.55;
  font-size: 11px;
}
.date-group-weight {
  font-variant-numeric: tabular-nums;
}

.sa-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.12);
}
.sa-mode-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.sa-mode-opt:has(input:checked) {
  background: var(--bg-elev, var(--card));
  color: var(--text);
}
.sa-mode-opt input {
  margin: 0;
}
.sa-period-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stat-delta {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  line-height: 1.35;
}
.sa-table-wrap {
  overflow-x: auto;
}
#sa-table {
  min-width: 1100px;
}
.sa-sku-link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: var(--accent, #38bdf8);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.sa-sku-link:hover {
  color: var(--text);
}
.sa-new-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #38bdf8;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.3);
}
#sa-table tr.is-low-stock td.sa-low-stock {
  color: #fbbf24;
  font-weight: 700;
}

.purchase-arrival {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.purchase-line-recv-col {
  width: 4.5em;
  text-align: center;
}
.purchase-line-recv {
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
.purchase-line-recv-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  cursor: pointer;
}
.purchase-line-recv-check input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.purchase-order.is-partial {
  border-color: color-mix(in srgb, #fbbf24 45%, var(--border));
}
.purchase-order tr.is-line-received {
  opacity: 0.72;
}
.purchase-line.is-line-posted {
  border-color: color-mix(in srgb, #34d399 40%, var(--border));
}
.purchase-line-posted-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 0 2px;
}

/* 淘寶叫貨：訂單卡片 + 到貨勾選 */
.purchases-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.date-group .purchases-list,
.date-group-body .purchase-order,
.date-group-body .sale-order {
  margin: 0;
}

/* 蝦皮出貨：訂單卡片 */
.sales-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sale-order {
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
}
.sale-order.is-returned {
  opacity: 0.88;
  border-color: rgba(139, 156, 179, 0.45);
  border-left: 4px solid #8b9cb3;
  background: linear-gradient(
    90deg,
    rgba(139, 156, 179, 0.1) 0%,
    var(--bg-elev) 80px
  );
}
.return-order-summary {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.16);
  line-height: 1.45;
}
.tag-returned {
  background: rgba(139, 156, 179, 0.2);
  color: #cbd5e1;
}
.tag-unpicked {
  background: rgba(251, 191, 36, 0.18);
  color: #fbbf24;
}
.return-type-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.return-type-opt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.return-type-opt:has(input:checked) {
  border-color: color-mix(in srgb, var(--accent, #38bdf8) 50%, var(--border));
  background: color-mix(in srgb, var(--accent, #38bdf8) 12%, transparent);
  color: var(--text);
}
.return-type-opt input {
  margin: 0;
}
.return-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 600px) {
  .return-fields-grid {
    grid-template-columns: 1fr;
  }
}
.tag-invoice {
  background: rgba(167, 139, 250, 0.18);
  color: #c4b5fd;
}
.tag-low-margin {
  background: rgba(249, 115, 22, 0.2);
  color: #fdba74;
  font-weight: 700;
}
/* 商品列：低毛利 */
#products-table tr.is-low-margin td {
  background: rgba(249, 115, 22, 0.06);
}
#products-table tr.is-low-margin td.num-margin-low {
  color: #fb923c;
  font-weight: 700;
}
/* 成本毛利 SKU 表 */
#profit-table tr.is-low-margin td {
  background: rgba(249, 115, 22, 0.06);
}
#profit-table tr.is-low-margin td.num-margin-low {
  color: #fb923c;
  font-weight: 700;
}
.sale-order-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}
.sale-order-meta { flex: 1; min-width: 180px; }
.sale-order-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 8px;
  font-size: 14px;
}
.sale-order-sub { margin-top: 4px; font-size: 12px; line-height: 1.5; }
.sale-order-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-left: auto;
}
.sale-order-table {
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.sale-order-table .table { margin: 0; }
.purchase-order {
  --purchase-accent: #f59e0b;
  padding: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--purchase-accent) 45%, var(--border));
  border-radius: 12px;
  background: var(--bg-elev);
  border-left: 4px solid var(--purchase-accent);
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--purchase-accent) 14%, transparent) 0%,
    color-mix(in srgb, var(--purchase-accent) 5%, transparent) 48px,
    var(--bg-elev) 120px
  );
}
.purchase-order.is-pending {
  /* 未到貨：帳號色（由 --purchase-accent 注入） */
}
.purchase-order.is-received {
  /* 已到貨：統一已到貨色 */
  opacity: 0.96;
}
.purchase-order-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--purchase-accent) 8%, rgba(0, 0, 0, 0.12));
}
.purchase-order.is-pending .purchase-order-head {
  background: color-mix(in srgb, var(--purchase-accent) 10%, rgba(0, 0, 0, 0.1));
}
.purchase-order.is-received .purchase-order-head {
  background: color-mix(in srgb, var(--purchase-accent) 8%, rgba(0, 0, 0, 0.1));
}
.purchase-order-meta { flex: 1; min-width: 180px; }
.purchase-order-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 8px;
  font-size: 14px;
}
.purchase-order-sub { margin-top: 4px; font-size: 12px; }
.purchase-arrival {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.purchase-arrival-pending {
  border-color: rgba(245, 158, 11, 0.5);
  background: rgba(245, 158, 11, 0.12);
}
.purchase-arrival-done {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
}
.purchase-arrive-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #fbbf24;
  cursor: pointer;
  user-select: none;
  flex-direction: row;
}
.purchase-arrive-check:hover {
  color: #fcd34d;
}
.purchase-arrive-check input {
  width: 16px;
  height: 16px;
  accent-color: #f59e0b;
  cursor: pointer;
}
.purchase-order-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-left: auto;
}
.purchase-order-table {
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.purchase-order-table .table { margin: 0; }
.reorder-suggest-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.input-sm {
  padding: 6px 10px;
  font-size: 13px;
}
.tag-priority-high { background: rgba(248, 113, 113, 0.2); color: var(--danger); }
.tag-priority-mid { background: rgba(251, 191, 36, 0.2); color: var(--warn); }
.tag-priority-low { background: rgba(56, 189, 248, 0.15); color: var(--accent); }
/* 叫貨提醒：固定高度捲動區 + sticky 表頭 */
.reorder-table-card {
  padding: 0;
  overflow: hidden;
}
.reorder-table-scroll {
  max-height: min(70vh, 720px);
  overflow: auto;
  overscroll-behavior: contain;
  background: #151c27;
  border-radius: inherit;
}
#reorder-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #151c27;
  margin: 0;
}
/* 垂直／水平捲動時表頭固定在上方 */
#reorder-table thead th {
  position: sticky;
  top: 0;
  z-index: 25;
  background: #1a2332 !important;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 0 #1a2332, 0 3px 8px rgba(0, 0, 0, 0.35);
  backdrop-filter: none;
}
/* 叫貨提醒：在途充足列稍淡 */
#reorder-table tr.reorder-row-covered td {
  opacity: 0.88;
}
#reorder-table .tag-pending-num {
  color: var(--accent);
  font-weight: 600;
}

.list-compact { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  gap: 10px;
}
.list-item .left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.list-item .sku { font-weight: 600; }
.list-item .sub { font-size: 11px; color: var(--muted); }
.list-empty { color: var(--muted); font-size: 13px; padding: 16px; text-align: center; }

.muted { color: var(--muted); font-size: 13px; }
.hint { margin-top: 16px; font-size: 13px; color: var(--muted); line-height: 1.7; }
.hint strong { color: var(--text); }
.howto { margin-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.9; }
.howto li { margin-bottom: 4px; }

/* 通用隱藏 */
.hidden { display: none !important; }

/* 設定分頁 */
.settings-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.settings-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.settings-tab:hover {
  color: var(--text);
  border-color: var(--accent, #3b82f6);
}
.settings-tab.active {
  background: var(--accent, #3b82f6);
  border-color: var(--accent, #3b82f6);
  color: #fff;
}
.settings-panel.hidden { display: none; }

.account-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.account-add-row .input { flex: 1; }
.account-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40px;
}
.account-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg, transparent);
}
.account-item .account-name {
  flex: 1;
  font-weight: 600;
  min-width: 0;
  word-break: break-word;
}
.account-item .input {
  flex: 1;
  min-width: 0;
}

/* 出貨賣場手續費方案 */
.shop-fee-list {
  gap: 14px;
}
.shop-fee-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  overflow: hidden;
}
.shop-fee-card-head {
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  flex-wrap: wrap;
}
.shop-fee-summary {
  font-size: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}
.shop-fee-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.shop-fee-tier {
  background: var(--bg-card, var(--bg-elev));
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.shop-fee-tier-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
}
.shop-fee-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
}
@media (min-width: 900px) {
  .shop-fee-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
.shop-fee-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.shop-fee-grid .input-sm {
  padding: 6px 8px;
  font-size: 13px;
}
.shop-fee-actions {
  display: flex;
  justify-content: flex-end;
}

/* 多品項型號列表 */
.sku-multi {
  white-space: normal;
  line-height: 1.45;
}
.sku-multi .sku-line {
  display: block;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0;
}
.form-grid.full { grid-template-columns: 1fr; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}

/* Modal：從上方開始，避免長表單垂直置中導致看不到頂部欄位 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 16px 40px;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}
.modal-panel.modal-wide {
  max-width: 780px;
  width: min(780px, 96vw);
}
.modal-panel.modal-wide .modal-body {
  width: 100%;
  box-sizing: border-box;
}
.modal-panel.modal-wide .modal-body > .received-list-modal {
  width: 100%;
  max-width: none;
}

.modal-panel {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  margin: 0 auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  background: var(--bg-elev);
  z-index: 1;
}
.modal-header h2 { font-size: 17px; }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: 14px 20px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
  background: var(--bg-elev);
}

/* 行政成本 */
.expense-stats {
  margin-bottom: 16px;
}
.expense-layout {
  align-items: start;
}
.expense-by-category {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.expense-cat-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  font-size: 13px;
}
.expense-cat-name {
  font-weight: 600;
}
.expense-cat-amt {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 72px;
  text-align: right;
}

/* 自訂確認框：水平置中、垂直約 60%（正中偏下），蓋在業務 modal 之上 */
.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 2200;
  pointer-events: auto;
}
.confirm-dialog.hidden {
  display: none;
}
.confirm-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
}
.confirm-dialog-panel {
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px));
  max-height: min(70vh, 480px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  padding: 20px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.confirm-dialog-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}
.confirm-dialog-title.hidden {
  display: none;
}
.confirm-dialog-message {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}
.btn-confirm-lg {
  min-width: 96px;
  min-height: 44px;
  padding: 10px 18px;
  font-size: 15px;
}
@media (max-width: 520px) {
  .confirm-dialog-panel {
    top: 58%;
    width: calc(100vw - 28px);
    padding: 18px 16px 16px;
  }
  .confirm-dialog-actions {
    flex-direction: column-reverse;
  }
  .btn-confirm-lg {
    width: 100%;
  }
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toastIn 0.25s ease;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--good); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.money-pos { color: var(--good); }
.money-neg { color: var(--danger); }
.sku-code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-weight: 600;
  color: var(--accent);
}

.calc-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 8px;
  font-size: 13px;
}
.calc-box .row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  color: var(--muted);
}
.calc-box .row.total {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 8px;
  color: var(--text);
  font-weight: 700;
}

/* 實發薪資表單摘要 */
.payroll-summary-box {
  margin-top: 0;
  border-color: rgba(56, 189, 248, 0.28);
  background: rgba(26, 35, 50, 0.9);
}
.payroll-summary-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.payroll-summary-box .row {
  gap: 12px;
  align-items: flex-start;
}
.payroll-summary-box .row > span:last-child {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  max-width: 62%;
  word-break: break-word;
}
.payroll-summary-box .sum-detail-row > span:last-child {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.payroll-summary-box .sum-actual-row.is-manual > span:last-child {
  color: var(--warn);
}
.payroll-summary-box #sum-manual-flag {
  margin-left: 6px;
  vertical-align: middle;
  background: rgba(251, 191, 36, 0.16);
  color: var(--warn);
}

/* 盤點模式 */
.stocktake-banner {
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid rgba(249, 115, 22, 0.35);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 14px;
}
.input-stock {
  width: 88px;
  text-align: right;
  padding: 6px 8px;
  font-variant-numeric: tabular-nums;
}
.stock-delta { font-weight: 600; min-width: 48px; }

/* 庫存明細：固定高度捲動區（虛擬列表 scroll root） */
.stock-table-card {
  padding: 0;
  overflow: hidden;
}
.stock-table-scroll {
  max-height: min(70vh, 640px);
  overflow: auto;
  overscroll-behavior: contain;
  background: #151c27;
}
#stock-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #151c27;
}
#stock-table thead th {
  position: sticky;
  top: 0;
  z-index: 25;
  background: #1a2332 !important;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 0 #1a2332, 0 3px 8px rgba(0, 0, 0, 0.35);
}
/* 固定列高，配合 virtual-table spacer 對齊 */
#stock-table tbody tr:not(.vt-spacer) {
  height: 52px;
}
#stock-table tbody tr:not(.vt-spacer) > td {
  height: 52px;
  box-sizing: border-box;
  overflow: hidden;
}
#stock-table .cat-header-row td {
  position: static !important;
  top: auto !important;
  z-index: auto !important;
  background: #1e2a3a !important;
  border-top: 1px solid rgba(56, 189, 248, 0.35);
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  vertical-align: middle;
}
#stock-table .vt-spacer td {
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
}

.stocktake-history-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  min-height: 200px;
}
@media (max-width: 900px) {
  .stocktake-history-layout { grid-template-columns: 1fr; }
}
.stocktake-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}
.stocktake-date-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.stocktake-date-btn:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.06);
}
.stocktake-date-btn.active {
  border-color: var(--primary);
  background: rgba(249, 115, 22, 0.12);
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.25);
}
.stocktake-date-btn .st-date {
  font-weight: 600;
  font-size: 13px;
}
.stocktake-date-btn .st-meta {
  font-size: 12px;
  color: var(--muted);
}
.stocktake-detail {
  min-width: 0;
}
.stocktake-detail-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 10px;
}
.table tr.row-changed td {
  background: rgba(249, 115, 22, 0.04);
}

/* 分類分組標題（不 sticky，避免與表頭重疊半透明） */
.cat-header-row td {
  background: #1e2a3a !important;
  border-top: 1px solid rgba(56, 189, 248, 0.3);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px !important;
  font-weight: 700;
  letter-spacing: 0.02em;
  position: static;
  top: auto;
  z-index: auto;
}
.cat-header-label {
  color: var(--accent);
  font-size: 14px;
}
.cat-header-count {
  margin-left: 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.sort-col { width: 72px; text-align: center; }
.sort-cell {
  white-space: nowrap;
  text-align: center;
  vertical-align: middle;
}
.btn-sort {
  min-width: 28px;
  padding: 2px 6px !important;
  font-size: 12px !important;
  line-height: 1.2;
}
.btn-sort:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.cat-order-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
}
.cat-order-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.cat-order-name { font-weight: 600; font-size: 14px; }
.cat-order-actions { display: flex; gap: 4px; }

/* 進貨／出貨：多品項 + 商品搜尋 */
.sale-lines-wrap { display: flex; flex-direction: column; gap: 10px; }
.sale-lines-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sale-lines {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sale-line {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sale-line-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.sale-line-idx {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  padding-top: 10px;
  min-width: 22px;
}
.span-grow { flex: 1; min-width: 0; }
.sale-line-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.purchase-line-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 720px) {
  .purchase-line-fields {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
.sale-line-meta { font-size: 12px; }
.field-hint {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 400;
}

.product-search-wrap {
  position: relative;
}
.product-search-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.product-search-dropdown.hidden { display: none; }
.product-search-empty {
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
}
.product-search-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
}
.product-search-item:last-child { border-bottom: none; }
.product-search-item:hover {
  background: rgba(56, 189, 248, 0.1);
}
.psi-main {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
}
.psi-name { font-size: 13px; }
.psi-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  align-items: center;
}
.sale-calc-line {
  opacity: 0.85;
  font-size: 12px;
}
.sale-promo-row {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
}
