:root {
  --bg: #f7f6f4;
  --surface: #ffffff;
  --text: #1f1f1f;
  --muted: #5c5c5c;
  --line: #dedbd6;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fff1e8;
  --good: #1f7a3d;
  --good-soft: #e6f4ea;
  --warn: #8a5300;
  --warn-soft: #fff4d6;
  --bad: #b42318;
  --bad-soft: #fde8e7;
  --focus: #1d4ed8;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #211f1d;
    --text: #f2f0ed;
    --muted: #b5b0a8;
    --line: #3a3733;
    --accent: #ff8a4c;
    --accent-ink: #1a0d05;
    --accent-soft: #3a2116;
    --good: #6fd08f;
    --good-soft: #17301f;
    --warn: #f5c35b;
    --warn-soft: #3a2e12;
    --bad: #ff8b80;
    --bad-soft: #3d1a17;
    --focus: #8ab4ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { left: 16px; top: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 8px; }
.topbar nav a[data-nav="list"] { color: var(--text); text-decoration: none; padding: 10px 10px; border-radius: 8px; }
.topbar nav a[aria-current="page"]:not(.btn) { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

h1 { font-size: 26px; line-height: 1.3; margin: 20px 0 4px; }
h2 { font-size: 20px; margin: 28px 0 10px; }
h3 { font-size: 17px; margin: 20px 0 8px; }
p { margin: 6px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 18px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn-small { min-height: 40px; padding: 6px 14px; font-size: 15px; }
.btn-secondary { background: var(--surface); color: var(--accent); }
.btn-plain { background: transparent; color: var(--text); border-color: var(--line); font-weight: 400; }
.btn-danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.hero { padding: 20px 0 4px; }
.hero p { font-size: 18px; color: var(--muted); }
.steps { counter-reset: s; list-style: none; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.steps li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 12px 48px; position: relative; }
.steps li::before { counter-increment: s; content: counter(s); position: absolute; left: 14px; top: 12px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-align: center; line-height: 24px; font-size: 14px; }

.survey-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.survey-list a { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--text); text-decoration: none; }
.survey-list a:hover { border-color: var(--accent); }
.survey-list strong { font-size: 17px; color: var(--accent); }

.breadcrumb { font-size: 14px; margin-top: 16px; color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.breadcrumb b { color: var(--text); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 2px solid var(--accent); margin-top: 16px; scrollbar-width: thin; }
.tabs a {
  flex: 0 0 auto; padding: 10px 14px; min-height: 44px; border: 1px solid var(--line); border-bottom: 0;
  border-radius: 8px 8px 0 0; background: var(--bg); color: var(--text); text-decoration: none; white-space: nowrap;
}
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.tabs .count { font-size: 13px; opacity: .8; }
.panel { background: var(--surface); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); padding: 16px; margin-bottom: 40px; }
.panel > h2:first-child { margin-top: 0; }

label { font-weight: 600; display: block; margin-bottom: 4px; }
.field { margin: 0 0 14px; }
.hint { font-size: 14px; color: var(--muted); font-weight: 400; }
input:not([type]), input[type="text"], input[type="url"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 160px; resize: vertical; }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid4 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.methods { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.methods .card { margin: 0; }
.methods h3 { margin-top: 0; }
.tag { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--good-soft); color: var(--good); font-weight: 700; vertical-align: middle; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumbs img { max-height: 120px; max-width: 100%; border: 1px solid var(--line); border-radius: 6px; cursor: zoom-in; }
.progress { margin-top: 10px; font-size: 14px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: var(--bg); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
/* 商品表：電腦版放進畫面寬度，不需要左右捲動；手機版改成卡片 */
.edit-wrap { border: 1px solid var(--line); border-radius: 8px; }
.edit-table { table-layout: fixed; }
.edit-table th, .edit-table td { padding: 8px 5px; }
/* 欄位：1 排名 2 名稱 3 售價 4 原價 5 折扣 6 評分 7 已售 8 出貨地 9 容量 10 單位價格 11 刪除 */
.edit-table th:nth-child(1) { width: 4.2em; }
.edit-table th:nth-child(3), .edit-table th:nth-child(4), .edit-table th:nth-child(7) { width: 76px; }
.edit-table th:nth-child(5) { width: 64px; }
.edit-table th:nth-child(6) { width: 54px; }
.edit-table th:nth-child(8) { width: 78px; }
.edit-table th:nth-child(9) { width: 112px; }
.edit-table th:nth-child(10) { width: 80px; }
.edit-table th:nth-child(11) { width: 48px; }
/* 所有格子靠上對齊，讓輸入框排成同一條線；純文字格用 40px 行高，對齊輸入框中線 */
.edit-table td { vertical-align: top; }
.edit-table .cell-rank, .edit-table .cell-discount { line-height: 40px; }
.edit-table td[data-unit-price] { line-height: 1.3; padding-top: 10px; }
.pill-deep { background: var(--bad-soft); color: var(--bad); }
.edit-table .cell-discount .pill { line-height: 1.4; vertical-align: middle; }
.edit-table th { white-space: normal; font-size: 14px; line-height: 1.3; }
.edit-table input, .edit-table select { min-height: 40px; padding: 6px 6px; width: 100%; }
.edit-table input.w-num { text-align: right; }
.edit-table .cell-rank { font-size: 14px; color: var(--muted); }
.qty-pair { display: flex; gap: 4px; }
.qty-pair .w-short { flex: 1 1 60%; min-width: 0; }
.qty-pair .w-unit { flex: 1 1 40%; min-width: 0; }
.name-links { display: flex; gap: 12px; align-items: center; font-size: 14px; margin-top: 4px; }
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; font: inherit; cursor: pointer; padding: 6px 0; }
.edit-table input.w-url { margin-top: 4px; }

@media (max-width: 900px) {
  .edit-wrap { border: 0; }
  .edit-table, .edit-table tbody { display: block; }
  .edit-table thead { display: none; }
  .edit-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 12px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 10px; }
  .edit-table td { display: block; padding: 0; border: 0; }
  .edit-table td[data-label]::before { content: attr(data-label); display: block; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
  .edit-table .cell-rank { order: -2; align-self: center; font-weight: 700; color: var(--text); font-size: 16px; }
  .edit-table .cell-del { order: -1; justify-self: end; }
  .edit-table .cell-name { grid-column: 1 / -1; }
  .edit-table td.num { text-align: left; }
  .edit-table input.w-num { text-align: left; }
  .edit-table .cell-rank, .edit-table .cell-discount { line-height: 1.4; }
  .edit-table .cell-discount .pill { margin-top: 10px; }
  .edit-table td[data-unit-price] { padding-top: 0; }
}
.icon-btn { min-width: 40px; min-height: 40px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 8px; cursor: pointer; font-size: 18px; }

.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 10px 0; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.stat .label { font-size: 14px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 13px; color: var(--muted); }

.notice { border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-info { background: var(--accent-soft); color: var(--text); }
.notice-good { background: var(--good-soft); color: var(--good); }

.chart { overflow-x: auto; }
.chart svg { width: 100%; min-width: 520px; max-width: 760px; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 12px; }
.chart .axis { stroke: var(--line); }
.chart .dot { fill: var(--accent); }
.chart .dot.overseas { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .mine { stroke: var(--good); stroke-width: 2; stroke-dasharray: 6 4; }
.chart .mine-label { fill: var(--good); font-weight: 700; }
.chart .band { fill: var(--good-soft); opacity: .7; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 14px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

.pos { color: var(--good); font-weight: 700; }
.neg { color: var(--bad); font-weight: 700; }
.pill { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.pill-base { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.pill-gap { background: var(--good-soft); color: var(--good); }
.pill-common { background: var(--accent-soft); color: var(--accent); }

.bars { list-style: none; padding: 0; margin: 0; }
.bars li { display: grid; grid-template-columns: 7em 1fr 3em; gap: 8px; align-items: center; margin: 6px 0; }
.bars .bar { height: 14px; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bars .n { text-align: right; font-variant-numeric: tabular-nums; }

.summary-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.summary-grid .card { margin: 0; }
.summary-grid h3 { margin-top: 0; }
.big { font-size: 20px; }
.card-wide { grid-column: 1 / -1; }
.img-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.img-grid img, .img-missing { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.img-missing { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }
.img-cap { font-size: 14px; margin-top: 4px; }
.bars.words li { grid-template-columns: 7em 1fr 3em auto; }
.bars.words .btn-small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.bars.words .hint { font-size: 13px; }
.bars.words .btn-small { white-space: nowrap; }
@media (max-width: 600px) {
  .bars.words li { grid-template-columns: 1fr 3.5em auto; }
  .bars.words .bar { display: none; }
  .bars.words .btn-small { min-height: 44px; }
}

.chips {display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; min-width: 32px; min-height: 32px; font-size: 16px; border-radius: 50%; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
#toast.has-action.show { pointer-events: auto; }
#toast button { margin-left: 8px; min-height: 40px; padding: 4px 14px; border: 1px solid currentColor; border-radius: 6px; background: transparent; color: inherit; font: inherit; font-weight: 700; cursor: pointer; }

dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: 96vw; max-height: 92vh; background: var(--surface); }
dialog img { display: block; max-width: 96vw; max-height: 85vh; }
dialog form { text-align: right; padding: 6px; }

.empty { text-align: center; padding: 30px 10px; }
footer.foot { color: var(--muted); font-size: 14px; padding: 20px 0 40px; }

@media (max-width: 600px) {
  h1 { font-size: 22px; }
  .brand span { font-size: 16px; }
  .topbar nav a[data-nav="list"] { padding: 10px 6px; }
  .panel { padding: 12px; }
}
