:root {
  --bg: #f6f4ef;
  --surface: #fffdfa;
  --surface-alt: #f8f5ef;
  --border: #e9e4d9;
  --border-strong: #ddd6c7;
  --text: #35322c;
  --text-muted: #756f63;
  --text-faint: #a19a8a;
  --nav-bg: #322f29;
  --nav-text: rgba(255, 255, 255, 0.88);
  --accent: #4f9d6e;
  --accent-hover: #418559;
  --accent-soft: #eaf4ee;
  --secondary: #a39a89;
  --danger: #b8564c;
  --danger-soft: #fbebe9;
  --warn: #b1813a;
  --warn-soft: #faf0dd;
  --success-soft: #e7f3e6;
  --success-text: #3c6b3f;
  --row-hover: #f5f1e7;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-soft: 0 1px 2px rgba(50, 42, 20, 0.04), 0 4px 12px rgba(50, 42, 20, 0.05);
}

* { box-sizing: border-box; }
body {
  font-family: -apple-system, "Microsoft JhengHei", "PingFang TC", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
nav {
  background: var(--nav-bg);
  padding: 12px 24px;
}
nav a {
  color: var(--nav-text);
  text-decoration: none;
  margin-right: 4px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}
nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
nav a.nav-primary {
  background: var(--accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  margin-right: 16px;
}
nav a.nav-primary:hover { background: var(--accent-hover); }
main { padding: 28px 24px; }
h1 { font-size: 20px; margin-bottom: 16px; color: var(--text); font-weight: 600; }

.flash-messages { margin-bottom: 20px; }
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 8px; font-size: 14px; border: 1px solid transparent; }
.flash-success { background: var(--success-soft); color: var(--success-text); border-color: #c7e0c5; }
.flash-error { background: var(--danger-soft); color: #8f3d35; border-color: #edc4c0; }
.flash-warning { background: var(--warn-soft); color: #8a611f; border-color: #ecd8ac; }

.upload-zones { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.upload-zone {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px;
  box-shadow: var(--shadow-soft);
}
.upload-zone h2 { font-size: 16px; margin: 0 0 6px; color: var(--text); }
.upload-zone .freq { display: inline-block; font-size: 11px; color: #fff; background: var(--secondary); border-radius: 10px; padding: 2px 10px; margin-bottom: 10px; }
.upload-zone p.desc { font-size: 13px; color: var(--text-muted); margin: 0 0 14px; line-height: 1.6; }
.upload-zone form { display: flex; flex-direction: column; gap: 10px; }
.upload-zone input[type=file] { font-size: 13px; }
.upload-zone button { padding: 10px; font-size: 14px; }

.run-calc-form {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.run-calc-form label { font-size: 14px; display: flex; align-items: center; gap: 6px; color: var(--text-muted); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}
/* 圓角故意不靠table本身的overflow:hidden裁切——那樣做會讓sticky表頭在部分瀏覽器
   失效(overflow:hidden會變成sticky定位的裁切邊界，導致往下捲動時表頭黏不住
   視窗頂端，不同瀏覽器對這個邊界情況的處理不一致，才會有些人的電腦會固定、
   有些人的不會)。改成只把第一列/最後一列的頭尾儲存格自己裁圓角，不動table
   本身的overflow。*/
thead tr:first-child th:first-child { border-top-left-radius: var(--radius-md); }
thead tr:first-child th:last-child { border-top-right-radius: var(--radius-md); }
tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-md); }
tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius-md); }
th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
}
tr:hover { background: var(--row-hover); }
tr:last-child td { border-bottom: none; }

.rules { max-width: 260px; }
.rule { color: var(--text-muted); font-size: 12px; }
.warn { color: var(--warn); font-size: 12px; font-weight: 600; }
.hint { color: var(--text-muted); font-size: 12px; }

.actions form {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
  align-items: center;
}
.qty-input { width: 70px; }
.note-input { width: 110px; }

input, select {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  transition: background 0.15s ease, opacity 0.15s ease;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: var(--secondary); }
button.secondary:hover { opacity: 0.85; background: var(--secondary); }

.empty { color: var(--text-muted); padding: 40px; text-align: center; background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-soft); }
.empty-highlight { color: var(--success-text); background: var(--success-soft); padding: 16px; text-align: left; box-shadow: none; border: 1px solid #c7e0c5; }

/* 商品分級頁共用(product_profit/product_scorecard/sales_momentum)：分級篩選chip + 分頁器 */
.tier-summary { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tier-chip {
  display: inline-block; padding: 6px 14px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px;
  text-decoration: none; color: var(--text-muted);
}
.tier-chip:hover { border-color: var(--border-strong); color: var(--text); }
.tier-chip.active { background: var(--nav-bg); color: #fff; border-color: var(--nav-bg); }
.tier-chip.small { padding: 3px 10px; font-size: 12px; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 14px; font-size: 13px; color: var(--text-muted); }
.pager a.disabled { pointer-events: none; opacity: 0.4; }

.btn {
  display: inline-block; text-decoration: none; cursor: pointer;
  border-radius: var(--radius-sm); padding: 6px 14px; font-size: 13px;
  background: var(--accent); color: #fff; border: 1px solid transparent;
}
.btn:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--surface); color: var(--text-muted); border-color: var(--border-strong); }
.btn.ghost:hover { color: var(--text); border-color: var(--secondary); }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* 需留意/熱銷加碼等詳情頁共用的原因列表卡片 */
.review-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 16px 16px 36px; margin: 0; box-shadow: var(--shadow-soft); }
.review-list li { margin-bottom: 8px; line-height: 1.5; }
.review-list li:last-child { margin-bottom: 0; }
