/* 全站樣式。顏色、字體、圓角一律用 CSS 變數，值來自後台「品牌風格」（views/partials/head.ejs 注入）。
   Sharon 改 CIS：先在後台改變數；要改版面再改這支檔案。 */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  overflow-x: hidden;
  font-size: 16px; line-height: 1.6;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .6em; overflow-wrap: anywhere; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }

/* 頁首 */
.site-head { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.site-head .wrap { display: flex; align-items: center; gap: 16px; height: 64px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--text); }
.logo img { height: 36px; width: auto; }
.nav { display: flex; gap: 16px; align-items: center; }
.nav a { color: var(--text); }
.nav a.on { color: var(--link); font-weight: 600; }
.cart-link { position: relative; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: .75rem; text-align: center; line-height: 20px; }
.search { display: flex; }
.search input { width: 200px; }
@media (max-width: 760px) {
  .site-head .wrap { height: auto; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
  .search { order: 3; width: 100%; } .search input { width: 100%; }
  .nav { gap: 12px; font-size: .95rem; }
}

main { padding: 24px 0 48px; min-height: 60vh; }
.site-foot { background: var(--surface); border-top: 1px solid var(--border); padding: 24px 0; color: var(--muted); font-size: .875rem; }
.site-foot .wrap { display: flex; flex-wrap: wrap; gap: 8px 24px; }

/* 元件 */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; min-height: 44px;
  border-radius: var(--radius); border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--link); }
.btn.sm { padding: 4px 12px; min-height: 34px; font-size: .875rem; }
.btn.danger { background: #b3261e; border-color: #b3261e; color: #fff; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: calc(var(--radius) * .6); padding: 9px 12px; min-height: 42px; width: 100%;
}
textarea { min-height: 90px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.flash.ok { background: #e7f4ec; color: #1d5b36; }
.flash.error { background: #fdecea; color: #8a1c14; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; background: var(--bg); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.pill.warn { background: #fff4e0; border-color: #f0c27a; color: #7a4b00; }
.pill.ok { background: #e7f4ec; border-color: #9ccfaf; color: #1d5b36; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.price { font-weight: 700; color: var(--text); }
.price del { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: .85em; }

/* 首頁 */
.hero { background: var(--primary); color: var(--primary-ink); border-radius: var(--radius); padding: 40px 28px; margin-bottom: 28px; }
.hero h1 { font-size: 1.9rem; margin-bottom: .3em; }
.hero p { margin: 0; opacity: .9; }
.brands { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 32px; }
.brand-card { display: block; color: var(--text); }
.brand-card:hover { text-decoration: none; border-color: var(--primary); }
.brand-card img { height: 48px; width: auto; margin-bottom: 8px; }
@media (max-width: 760px) { .brands { grid-template-columns: 1fr; } }

/* 商品格 */
.products { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 960px) { .products { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .products { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.pcard { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); }
.pcard:hover { text-decoration: none; border-color: var(--primary); }
.pcard .img { aspect-ratio: 1; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.pcard .img img { width: 100%; height: 100%; object-fit: cover; }
.pcard .body { padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.pcard .vendor { font-size: .78rem; color: var(--muted); }
.pcard .name { font-size: .95rem; line-height: 1.4; }
.pcard .price { margin-top: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters select { width: auto; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 24px; }

/* 商品頁 */
.pdp { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
@media (max-width: 760px) { .pdp { grid-template-columns: 1fr; gap: 16px; } }
.pdp > *, .layout-2 > *, .grid2 > *, .grid3 > *, .products > * { min-width: 0; }
.pcard .name, .line > div { overflow-wrap: anywhere; }
.gallery .main { aspect-ratio: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.gallery .main img { width: 100%; height: 100%; object-fit: contain; }
.thumbs { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; }
.thumbs button { border: 1px solid var(--border); border-radius: 8px; padding: 0; background: var(--surface); width: 64px; height: 64px; flex: 0 0 64px; cursor: pointer; overflow: hidden; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.variant-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.variant-pick label { margin: 0; }
.variant-pick input { position: absolute; opacity: 0; }
.variant-pick span { display: inline-block; padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; }
.variant-pick input:checked + span { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
.variant-pick input:disabled + span { opacity: .45; text-decoration: line-through; cursor: not-allowed; }
.variant-pick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.qty { width: 90px; }
.desc { overflow-wrap: anywhere; }
.desc img { margin: 8px 0; }

/* 表格：手機寬自動收成卡片（data-label 當欄名） */
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.tbl th { font-size: .85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }
.tbl-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
@media (max-width: 760px) {
  table.fold thead { display: none; }
  table.fold, table.fold tbody, table.fold tr, table.fold td { display: block; width: 100%; }
  table.fold tr { border-bottom: 1px solid var(--border); padding: 8px 4px; }
  table.fold td { border: 0; padding: 4px 8px; display: flex; gap: 12px; justify-content: space-between; text-align: right; }
  table.fold td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex: 0 0 auto; }
  table.fold td.num { text-align: right; }
}

/* 購物車／結帳 */
.layout-2 { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
@media (max-width: 860px) { .layout-2 { grid-template-columns: 1fr; } }
.line { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.line:last-child { border-bottom: 0; }
.line img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.sum-row { display: flex; justify-content: space-between; padding: 4px 0; }
.sum-row.total { font-size: 1.15rem; font-weight: 700; border-top: 1px solid var(--border); margin-top: 8px; padding-top: 10px; }

/* 後台 */
.admin-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.admin-nav a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .9rem; }
.admin-nav a.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.vtable input { min-height: 36px; padding: 6px 8px; }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--border); vertical-align: middle; }

/* 設定頁：比照聯合銷售平台（區塊收合＋已設定標記） */
.note { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: .92rem; }
.cfg-card { padding: 14px 16px; scroll-margin-top: 80px; }
.cfg-hd { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; cursor: pointer; user-select: none; }
.cfg-hd h2 { margin: 0 0 4px; }
.cfg-hd .desc { font-size: .84rem; color: var(--muted); line-height: 1.7; }
.cfg-badge { flex: none; font-size: .84rem; font-weight: 700; color: #1d5b36; white-space: nowrap; display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.cfg-badge.zero { color: var(--muted); }
.cfg-badge .ar { color: var(--muted); font-size: .75rem; transition: transform .15s; }
.cfg-card.open .cfg-badge .ar { transform: rotate(180deg); }
.cfg-bd { display: none; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.cfg-card.open .cfg-bd { display: block; }
.cfg-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.ak-res { font-size: .84rem; font-weight: 700; }
.ak-tbl input[type=password] { min-width: 200px; }
@media (max-width: 820px) { .cfg-hd { flex-wrap: wrap; gap: 6px 14px; } .cfg-hd > div:first-child { flex: 1 1 100%; } .cfg-hd > .cfg-badge { margin-left: auto; } }
