:root {
  --bg: #f4f3f0;
  --card: #ffffff;
  --text: #2a2a2c;
  --muted: #8a8780;
  --line: #e7e4de;
  --accent: #2a2a2c;
  --accent-soft: #ecebe8;
  --link: #2a2a2c;
  --danger: #c0392b;
  --ok: #2e7d4f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 96px;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
.hidden { display: none !important; }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }

/* ---------- 頂部 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(244,243,240,.92);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  /* iPhone App 裡網頁會延伸到最上面，要讓出時間、電量那一列 */
  padding-top: env(safe-area-inset-top);
}
.topbar .wrap { display: flex; align-items: center; gap: 10px; height: 60px; }
.brand { font-weight: 700; letter-spacing: .02em; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--text); color: #fff;
  display: block; object-fit: cover; flex: none;
}
.brand-name { display: none; }
@media (min-width: 560px) { .brand-name { display: inline; } }
.search {
  flex: 1; min-width: 0; height: 38px; border-radius: 19px; border: 1px solid var(--line);
  background: #fff; padding: 0 14px 0 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a8780' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
/* 自己畫的清除鈕（手機的 search 欄位不一定有叉叉），系統內建的藏起來免得出現兩個 */
.search-box { position: relative; flex: 1; min-width: 0; display: flex; }
.search-box .search { padding-right: 40px; width: 100%; }
.search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }
.search-clear {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--line); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.search-clear svg { width: 14px; height: 14px; }
.search-clear.hidden { display: none; }
/* App 裡搜尋欄右邊的掃描鈕；有字的時候清除鈕排在它左邊 */
.search-scan {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 50%; border: 0; background: none; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.search-scan svg { width: 20px; height: 20px; }
.search-scan.hidden { display: none; }
.search-box.has-scan .search { padding-right: 72px; }
.search-box.has-scan .search-clear { right: 38px; }
.icon-btn {
  height: 38px; min-width: 38px; padding: 0 10px; border-radius: 19px; border: 1px solid var(--line);
  background: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- 統計 ---------- */
.hero { margin: 16px 0 8px; display: flex; gap: 22px; color: var(--muted); font-size: 14px; flex-wrap: wrap; }
.hero b { color: var(--text); font-size: 18px; margin-left: 4px; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 12px;
  font-size: 13px; white-space: nowrap; color: var(--muted);
}
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }
.chip small { opacity: .7; margin-left: 2px; }

.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--line); margin: 4px 0 6px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; padding: 8px 0 10px; font-size: 16px; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tab small { font-size: 12px; margin-left: 3px; }
.tab.active { color: var(--text); font-weight: 700; border-bottom-color: var(--accent); }
.chip-label { font-size: 12px; color: var(--muted); align-self: center; white-space: nowrap; }
.chips:empty { display: none; }

/* ---------- 相簿卡片 ---------- */
.post {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px; display: grid; grid-template-columns: 44px 1fr; gap: 0 12px;
  border: 2px solid transparent; transition: border-color .15s;
}
.post.selected { border-color: var(--accent); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.post-head { display: flex; align-items: flex-start; gap: 8px; min-height: 44px; }
.post-head > div:first-child { flex: 1; min-width: 0; }
.post-author { font-weight: 600; color: var(--link); }
.post-author .tag.sold-date { margin-left: 8px; font-size: 12px; vertical-align: 1px; }
.post-meta { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tag { background: #f0eee9; border-radius: 6px; padding: 1px 7px; font-size: 12px; color: #5d5a54; }
.tag.sku { background: var(--text); color: #fff; font-weight: 600; letter-spacing: .02em; }
.tag.new { background: #e9f4ee; color: var(--ok); font-weight: 600; }
.tag.status-sold { background: #fbe9e7; color: var(--danger); font-weight: 600; }
.tag.status-reserved { background: #fbf3dc; color: #8a6d1a; font-weight: 600; }
.post.sold .grid img { filter: grayscale(.6) opacity(.75); }
.status-pick { display: inline-flex; align-items: center; gap: 4px; color: var(--link); font-size: 14px; position: relative; }
.status-pick svg { width: 16px; height: 16px; }
.status-pick select { border: 0; background: none; padding: 4px 0; color: var(--link); width: auto; font-size: 14px; cursor: pointer; }
.select-box {
  margin: 8px 0 0 auto; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #cfcac1; background: #fff;
  display: grid; place-items: center; color: #fff; flex: none;
}
.post.selected .select-box { background: var(--accent); border-color: var(--accent); }
.post-body { grid-column: 2; }
.post-text { white-space: pre-wrap; word-break: break-word; margin: 4px 0 10px; font-size: 16px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; max-width: 480px; }
.grid.single { grid-template-columns: 1fr; max-width: 300px; }
.thumb {
  position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 4px; background: #eceae5; border: 0; padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .more {
  position: absolute; inset: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 22px; font-weight: 600;
  display: grid; place-items: center;
}
.post-actions { display: flex; gap: 4px 16px; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.post-actions button, .post-actions a {
  border: 0; background: none; padding: 4px 0; color: var(--link); font-size: 14px;
  display: inline-flex; align-items: center; gap: 4px;
}
.post-actions .danger { color: var(--danger); margin-left: auto; }
.post-actions svg { width: 16px; height: 16px; }

.empty { text-align: center; color: var(--muted); padding: 60px 0; }
.loader { text-align: center; color: var(--muted); padding: 20px 0; font-size: 14px; }

/* ---------- 底部批量操作 ---------- */
.fab {
  position: fixed; right: max(16px, calc(50% - 414px)); bottom: 24px; z-index: 15;
  height: 52px; padding: 0 22px; border-radius: 26px; border: 0; background: var(--text); color: #fff;
  font-weight: 600; font-size: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.2); display: flex; align-items: center; gap: 6px;
}
.selbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 16; background: #fff; border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}
.selbar .wrap { display: flex; align-items: center; gap: 10px; }
.selbar .count { flex: 1; font-weight: 600; }

/* ---------- 通用按鈕、表單 ---------- */
.btn {
  height: 42px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.field > span em { color: var(--danger); font-style: normal; }
input[type=text], input[type=password], input:not([type]), textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
}
textarea { min-height: 130px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- 對話框 ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px - 2 * max(env(safe-area-inset-top), env(safe-area-inset-bottom)));
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(20,20,20,.5); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-body { padding: 18px 20px; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; }
.close-x { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); padding: 0 4px; }

.dropzone {
  border: 2px dashed #d6d1c7; border-radius: 12px; padding: 22px; text-align: center; color: var(--muted);
  background: #faf9f6; cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone strong { color: var(--text); }
.edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.edit-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #eee; }
.edit-item img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.edit-item { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; cursor: grab; }
.edit-item.drag-src { opacity: .3; }
.edit-item.drag-ghost { position: fixed; z-index: 10; margin: 0; pointer-events: none; transform: scale(1.08); box-shadow: 0 8px 24px rgba(0,0,0,.35); opacity: .95; }
.edit-item .idx { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; border-radius: 4px; padding: 0 5px; }
.edit-item .cover { position: absolute; left: 4px; bottom: 4px; background: var(--accent); color: #fff; font-size: 11px; border-radius: 4px; padding: 0 5px; }
.edit-item .tools { position: absolute; right: 2px; top: 2px; display: flex; flex-direction: column; gap: 2px; }
.edit-item .tools button {
  width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; line-height: 1; padding: 0;
}
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- 看大圖 ---------- */
#lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; border-radius: 0; background: #000; color: #fff; }
/* 圖片區要讓開 iPhone 瀏海和底部橫條，不然在 App 裡會蓋住「關閉」「存這張」，按了沒反應 */
#lightbox .lb-img { position: absolute; inset: calc(56px + env(safe-area-inset-top)) 0 calc(64px + env(safe-area-inset-bottom)); display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; overflow: hidden; touch-action: none; }
#lightbox .lb-img img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; will-change: transform; cursor: zoom-in; }
#lightbox.zoomed .lb-img img { cursor: grab; }
#lightbox.zoomed .lb-nav { opacity: .35; }
#lightbox .lb-top, #lightbox .lb-bottom { position: absolute; z-index: 2; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 0 16px; }
#lightbox .lb-top { top: env(safe-area-inset-top); height: 56px; justify-content: space-between; }
#lightbox .lb-bottom { bottom: env(safe-area-inset-bottom); height: 64px; justify-content: center; }
#lightbox button, #lightbox a { color: #fff; background: rgba(255,255,255,.12); border: 0; border-radius: 20px; height: 40px; padding: 0 16px; display: inline-flex; align-items: center; gap: 6px; }
#lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; padding: 0; justify-content: center; font-size: 22px; }
#lightbox .lb-prev { left: 12px; }
#lightbox .lb-next { right: 12px; }

/* ---------- 設定 ---------- */
.settings-section { margin-bottom: 26px; }
.settings-section h3 { margin: 0 0 10px; font-size: 15px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list td, table.list th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 500; font-size: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > input, .row > select { flex: 1; min-width: 120px; width: auto; }
.keybox { background: #2a2a2c; color: #f4f3f0; border-radius: 8px; padding: 10px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; margin: 8px 0; }
pre.code { background: #f0eee9; border-radius: 8px; padding: 10px 12px; font-size: 12px; overflow-x: auto; }

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 100;
  background: rgba(29,29,31,.92); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px;
  max-width: calc(100vw - 32px); text-align: center;
}

/* ---------- 登入頁 ---------- */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; width: min(380px, 100%); }
.login-logo { display: block; width: 76px; height: 76px; }
.login-card h1 { font-size: 22px; margin: 12px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.error-text { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

#feed { margin-top: 10px; }
.import-result { background: #faf9f6; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 10px 0; }
.import-result ul { margin: 6px 0 0; padding-left: 18px; }
.import-result .skufix-list { list-style: none; padding-left: 0; }
.skufix-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.skufix-list s { color: var(--muted); }
.dup-group { padding: 8px 0; border-bottom: 1px solid var(--line); }
.dup-list { list-style: none; padding-left: 0; margin: 4px 0 0; }
.dup-list li { padding: 4px 0; }
.dup-list label { display: flex; align-items: center; gap: 8px; }
.dup-list img, .dup-empty { width: 56px; height: 56px; flex: none; border-radius: 6px; object-fit: cover; cursor: zoom-in; }
.dup-empty { display: grid; place-items: center; background: var(--line); color: var(--muted); font-size: 12px; cursor: default; }
.dup-list label > span:last-child { display: flex; flex-direction: column; }
.job { border-top: 1px solid var(--line); padding: 8px 0; font-size: 13px; }
.job pre { white-space: pre-wrap; max-height: 120px; overflow: auto; background: #f0eee9; border-radius: 6px; padding: 6px 8px; margin: 6px 0 0; font-size: 12px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }

/* ---------- 下載全部只在電腦上出現（手機、平板用「存到手機」） ---------- */
@media (max-width: 767px), (pointer: coarse) { .desktop-only { display: none !important; } }

/* ---------- 觀看者：沒有上傳按鈕 ---------- */
body.read-only .fab { display: none; }

/* ---------- 選取打勾（小圖格、列表） ---------- */
.tile-check {
  position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.25); color: #fff; display: none; place-items: center;
}
.tile-check svg { width: 14px; height: 14px; }
body.select-mode .tile-check { display: grid; }
.selected > .tile-check { background: var(--accent); border-color: var(--accent); }

/* ---------- 小圖格 ---------- */
.grid-box { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin: 0 -16px; }
@media (min-width: 600px) { .grid-box { grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0; } }
@media (min-width: 820px) { .grid-box { grid-template-columns: repeat(5, 1fr); } }
.tile { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: #eceae5; overflow: hidden; }
@media (min-width: 600px) { .tile { border-radius: 8px; } }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-count {
  position: absolute; left: 6px; bottom: 4px; color: #fff; font-weight: 700; font-size: 15px;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.tile-status { position: absolute; left: 6px; top: 6px; font-size: 11px; font-weight: 700; border-radius: 4px; padding: 0 6px; }
.tile-status.status-sold { background: var(--danger); color: #fff; }
.tile-status.status-reserved { background: #e0b23c; color: #fff; }
.tile.sold img, .row-item.sold img, .daily-item.sold img { filter: grayscale(.6) opacity(.75); }
.tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ---------- 單圖列表、多圖列表 ---------- */
.list-box, .day-group { display: flex; flex-direction: column; gap: 10px; }
.row-item, .daily-item {
  position: relative; display: flex; gap: 12px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px; border: 2px solid transparent;
}
.row-item.selected, .daily-item.selected { border-color: var(--accent); }
.row-cover { position: relative; flex: none; width: 112px; height: 112px; border: 0; padding: 0; border-radius: 8px; overflow: hidden; background: #eceae5; }
.row-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.row-text {
  border: 0; background: none; padding: 0; text-align: left; font-size: 15px; font-weight: 600; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; word-break: break-word;
}
.post-actions.compact { margin-top: auto; padding-top: 4px; border-top: 0; gap: 2px 14px; }
.post-actions.compact .status-pick, .post-actions.compact .status-pick select { font-size: 13px; }
.daily-grid {
  flex: none; width: 112px; height: 112px; border: 0; padding: 0; display: grid; gap: 2px;
  grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; border-radius: 8px; overflow: hidden; background: #eceae5;
}
.daily-grid img { width: 100%; height: 100%; object-fit: cover; display: block; min-width: 0; min-height: 0; }
.daily-grid.n1 img { grid-column: span 2; grid-row: span 2; }
.daily-grid.n2 img { grid-row: span 2; }
.daily-grid.n3 img:first-child { grid-row: span 2; }
.day-group { margin-bottom: 18px; }
.day-label { margin: 6px 0 2px; font-size: 18px; }

/* ---------- 展示方式選單（手機從下面滑出） ---------- */
dialog.sheet { width: min(520px, 100vw); }
@media (max-width: 599px) {
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
.view-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.view-option {
  border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 12px; text-align: left;
  display: flex; flex-direction: column; gap: 4px;
}
.view-option.active { border-color: var(--ok); }
.view-option b { font-size: 15px; }
.view-option small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.view-icon { display: grid; gap: 3px; height: 54px; margin-bottom: 4px; }
.view-icon i { background: #e7e4de; border-radius: 3px; }
.view-icon-feed { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 10px 1fr; }
.view-icon-feed i:first-child { grid-column: span 3; background: #d6d1c7; }
.view-icon-grid { grid-template-columns: repeat(4, 1fr); }
.view-icon-list { grid-template-columns: 40px 1fr; grid-template-rows: 1fr 1fr; }
.view-icon-list i:nth-child(odd) { background: #d6d1c7; }
.view-icon-daily { grid-template-columns: 1fr 1fr 2fr; grid-template-rows: 1fr 1fr; }
.view-icon-daily i { background: #d6d1c7; }
.view-icon-daily::after { content: ''; grid-column: 3; grid-row: 1 / span 2; background: #e7e4de; border-radius: 3px; }

/* ---------- 加到主畫面（全螢幕 App 模式）：避開 iPhone 底部橫條 ---------- */
.fab { bottom: calc(24px + env(safe-area-inset-bottom)); }
/* 回到最上面：往下滑一段才出現，疊在「上傳商品」上面 */
.to-top {
  position: fixed; right: max(16px, calc(50% - 414px)); bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 15;
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--text);
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.12); cursor: pointer;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
body.read-only .to-top { bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---------- 商品下方按鈕：圓角膠囊（複製文字／下載全部／存到手機／狀態／編輯） ---------- */
.post-actions { gap: 8px; padding-top: 12px; }
.post-actions button, .post-actions a, .post-actions .status-pick {
  height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; background: #fff;
  color: var(--text); font-size: 15px; gap: 8px; white-space: nowrap; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.post-actions button:hover, .post-actions a:hover, .post-actions .status-pick:hover { background: var(--bg); border-color: #d6d1c7; }
.post-actions button:active, .post-actions a:active { background: var(--line); }
.post-actions svg { width: 18px; height: 18px; flex: none; }
.post-actions .status-pick select {
  -webkit-appearance: none; appearance: none; padding: 0; color: var(--text); font-size: 15px; height: 100%;
}
.post-actions .status-pick { gap: 6px; }
.post-actions .status-pick svg:last-child { width: 16px; height: 16px; margin-left: 2px; pointer-events: none; }
.post-actions .danger { color: var(--danger); margin-left: auto; }
.post-actions.compact { gap: 6px; padding-top: 6px; }
.post-actions.compact button, .post-actions.compact a, .post-actions.compact .status-pick { height: 32px; padding: 0 12px; font-size: 13px; gap: 5px; }
.post-actions.compact .status-pick select { font-size: 13px; }
.post-actions.compact svg { width: 15px; height: 15px; }

/* ---------- 視窗右上角的關閉叉叉：圓形 ---------- */
.close-x {
  width: 36px; height: 36px; padding: 0; border-radius: 50%; background: var(--bg); color: var(--text);
  display: grid; place-items: center; font-size: 22px; line-height: 1; flex: none; transition: background .15s;
}
.close-x:hover { background: var(--line); }
.close-x:focus { outline: none; }
.close-x:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.post-actions .status-pick select { field-sizing: content; }
@media (max-width: 480px) {
  .post-actions { gap: 6px; }
  .post-actions button, .post-actions a, .post-actions .status-pick { height: 36px; padding: 0 12px; font-size: 14px; gap: 6px; }
  .post-actions .status-pick select { font-size: 14px; }
  .post-actions svg { width: 16px; height: 16px; }
}

/* ---------- 第一次登入設定密碼 ---------- */
dialog.first-login { width: fit-content; }
.first-login form { padding: 24px 22px; width: min(380px, 92vw); }
.first-login h2 { margin: 0 0 6px; font-size: 20px; }
.first-login .hint { margin: 0 0 18px; }

/* 每篇商品左上角：REBUY logo */
img.avatar { display: block; object-fit: cover; background: #2a2a2c; }

/* ---------- 忘記密碼 ---------- */
.link-btn { display: block; width: 100%; margin-top: 14px; border: 0; background: none; color: var(--muted); font-size: 14px; text-align: center; cursor: pointer; }
.link-btn:hover { color: var(--text); }
.error-text.ok { color: var(--ok); }

/* ---------- 帳號群組、刪除權限 ---------- */

label.check.perm { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---------- 手機：畫面固定、不會左右晃 ---------- */
/* 網頁不准比螢幕寬；字小於 16px 的輸入框 iPhone 一點就會自動放大、整頁跟著左右跑，所以手機上輸入框一律 16px */
html, body { overflow-x: clip; overscroll-behavior-x: none; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (pointer: coarse) {
  input, select, textarea, .status-pick select { font-size: 16px !important; }
}

/* ---------- 設定頁：卡片排版 ---------- */
#settings .dlg-body { background: var(--bg); }
.settings-section { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.settings-section.hint { background: none; border: 0; padding: 0 4px; }
.settings-section h4 { margin: 16px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.me-head { display: flex; align-items: center; gap: 12px; }
.me-head .avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; }
.me-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-info b { font-size: 16px; }
details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: '›'; font-size: 22px; color: var(--muted); transform: rotate(90deg); transition: transform .15s; }
details.fold[open] > summary::after { transform: rotate(-90deg); }
details.fold > summary h3 { margin: 0; }
details.fold[open] > summary { margin-bottom: 12px; }
details.help { margin-top: 8px; }
details.help summary { font-size: 13px; color: var(--link); cursor: pointer; }
details.help p { margin: 6px 0; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.users { border-top: 1px solid var(--line); }
.group-row { background: var(--bg); font-weight: 700; padding: 10px 10px; margin: 0 -16px; font-size: 14px; }
.group-row small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.user-card { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.user-card.off .u-main { opacity: .5; }
.u-main { min-width: 0; overflow-wrap: anywhere; }
.u-role { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.u-role select { width: auto; min-width: 110px; }
.u-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 599px) {
  .row.stack { flex-direction: column; align-items: stretch; }
  .row.stack > input, .row.stack > select, .row.stack > .btn { width: 100%; min-width: 0; }
  .row.stack > .btn.small { height: 42px; font-size: 15px; }
  .u-actions .btn { flex: 1 1 auto; }
}

/* 存到手機：照片抓好但系統要再點一下時，按鈕變成黑底提示 */
.ready-to-save { background: var(--text) !important; color: #fff !important; border-color: var(--text) !important; }

/* 手機往下拉重新整理 */
.ptr {
  position: fixed; top: -44px; left: 50%; transform: translate(-50%, 0); z-index: 50;
  display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  background: var(--card); color: var(--text); font-size: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15); opacity: 0; pointer-events: none; transition: opacity .15s;
}
.ptr.show { opacity: 1; }
.ptr-icon { display: inline-block; transition: transform .15s; }
.ptr.armed .ptr-icon { transform: rotate(180deg); }
/* 關掉瀏覽器自己的下拉重整，避免跟上面的一起觸發重整兩次 */
html { overscroll-behavior-y: contain; }

/* 在庫天數 */
.tag.age { font-weight: 600; }
.tag.age-g { background: #e9f4ee; color: #2e7d4f; }
.tag.age-y { background: #fdf6d8; color: #8a6d00; }
.tag.age-o { background: #fde9d6; color: #b45309; }
.tag.age-r { background: #fbe9e7; color: #c0392b; }

/* 成本（只有看得到成本的人有） */
.post-meta.extra { margin-top: 6px; }
.post-meta.extra:not(:has(.tag)) { display: none; }
/* 錢相關（成本、售價）同一個樣子，管道一個顏色、毛利綠／虧錢紅，看起來不會花 */
.tag.money { background: #f1f1ee; color: #33332f; font-weight: 600; font-variant-numeric: tabular-nums; }
.tag.sold-date { background: #eef1f6; color: #3d5a80; font-weight: 600; font-variant-numeric: tabular-nums; }
.tag.channel { background: #efe9fb; color: #5b3fa0; font-weight: 600; }
.tag.margin { background: #e9f4ee; color: #2e7d4f; font-weight: 600; font-variant-numeric: tabular-nums; }
.tag.margin.loss { background: #fbe9e7; color: #c0392b; }
.tag.quote { background: #f4f4f2; color: #6b6b66; font-variant-numeric: tabular-nums; }
.sales-src { border: 1px solid var(--line, #e6e3dc); border-radius: 12px; padding: 10px; margin: 8px 0; display: grid; gap: 6px; }
/* 在庫天數篩選：顏色跟「在庫 N 天」標籤一樣 */
.chip.channel-chip.active { background: #5b3fa0; border-color: #5b3fa0; color: #fff; }
.age-toggle .caret { display: inline-block; margin-left: 4px; transform: rotate(90deg); transition: transform .15s; }
.age-toggle.open .caret { transform: rotate(-90deg); }
.chip.age-g { background: #e9f4ee; color: #2e7d4f; border-color: #cfe6d8; }
.chip.age-y { background: #fdf6d8; color: #8a6d00; border-color: #f1e3a6; }
.chip.age-o { background: #fde9d6; color: #b45309; border-color: #f6d2b0; }
.chip.age-r { background: #fbe9e7; color: #c0392b; border-color: #f2c9c4; }
.chip.age-chip.active { color: #fff; }
.chip.age-g.active { background: #2e7d4f; border-color: #2e7d4f; }
.chip.age-y.active { background: #b08c00; border-color: #b08c00; }
.chip.age-o.active { background: #d2691e; border-color: #d2691e; }
.chip.age-r.active { background: #c0392b; border-color: #c0392b; }

/* 設定：總覽 */
.overview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.overview .ov { background: var(--bg, #f4f3f0); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.overview .ov b { font-size: 20px; font-variant-numeric: tabular-nums; }
.overview .ov span { font-size: 12px; color: var(--muted); }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.sec-head h3 { margin: 0; }
/* 員工帳號：群組可以收起來 */
.group-fold { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 0 12px; }
.group-fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 12px 0; }
.group-fold > summary::-webkit-details-marker { display: none; }
.group-fold > summary::after { content: '›'; margin-left: auto; font-size: 20px; color: var(--muted); transform: rotate(90deg); transition: transform .15s; }
.group-fold[open] > summary::after { transform: rotate(-90deg); }
.group-fold[open] > summary { border-bottom: 1px solid var(--line); }
.group-fold .g-name { font-weight: 700; }
.group-fold .g-count { font-size: 12px; background: var(--text); color: #fff; border-radius: 10px; padding: 1px 8px; }
.group-fold .g-roles { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-fold .user-card:last-child { border-bottom: 0; }
.add-user { margin-top: 12px; }
.add-user > summary { list-style: none; display: inline-flex; cursor: pointer; }
.add-user > summary::-webkit-details-marker { display: none; }
.add-user[open] > summary { margin-bottom: 10px; }
.add-user-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-items: end; background: var(--bg, #f4f3f0); border-radius: 12px; padding: 12px; }
.add-user-form .field { margin: 0; }
.add-user-form .btn { grid-column: 1 / -1; }
@media (max-width: 640px) { .add-user-form { grid-template-columns: 1fr; } .overview { grid-template-columns: repeat(3, 1fr); } }
.group-fold .user-card { padding: 10px 0; }
.group-fold .u-role { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 4px 12px; }
.group-fold .u-actions .btn { height: 32px; padding: 0 12px; font-size: 13px; }
/* 名字、帳號、Email 排一列，權限勾選放下一列（權限變多後擠在右邊會把 Email 擠成直的） */
.group-fold .user-card { grid-template-columns: 1fr; }
.group-fold .u-role { justify-content: flex-start; }
.group-fold .u-main { overflow-wrap: break-word; }
.u-mail { display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }

/* 上傳：從收購表帶入的提示 */
.sheet-hint { font-size: 13px; border-radius: 10px; padding: 8px 12px; margin: -4px 0 10px; }
.sheet-hint.ok { background: #e9f4ee; color: #2e7d4f; }
.size-hint { margin-top: 6px; padding-top: 6px; border-top: 1px dashed rgba(46,125,79,.3); color: var(--text); line-height: 1.7; }
.size-hint .btn { margin-left: 4px; vertical-align: middle; }
.size-hint .hint { display: block; }
.sheet-hint.miss { background: var(--accent-soft); color: var(--muted); }

/* 搬家瘦身 */
.slim-on { background: #fff6e0; border-radius: 10px; padding: 10px 12px; color: #6b4e00; }
.slim-form { display: grid; gap: 8px; margin-top: 10px; }
.slim-form label { display: flex; gap: 8px; align-items: flex-start; line-height: 1.5; }
.slim-form input[type=checkbox] { margin-top: 4px; flex: none; }
.slim-form p { margin: 4px 0; }
.pack-h { margin: 14px 0 4px; font-size: 15px; }

/* 銷售來源的上下移動按鈕靠右 */
.sales-src .sales-head { display: flex; gap: 6px; align-items: center; }
.sales-src .sales-head input { flex: 1; min-width: 0; }
.sales-src .sales-move { display: inline-flex; gap: 6px; flex: none; }
.sales-orphans { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: #fff6e5; border: 1px solid #f3d9a4; }
.sales-orphans ul { list-style: none; padding: 0; margin: 6px 0 10px; max-height: 320px; overflow: auto; }
.sales-orphans li { padding: 3px 0; }
.sales-detail summary { cursor: pointer; color: var(--link); }
.sales-detail[open] summary { margin-bottom: 4px; }
.field-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.tag.grade { background: #fff; border: 1px solid var(--text); color: var(--text); font-weight: 600; }

/* 介面語言切換（登入頁）、帳號管理的語言選單 */
.lang-switch { display: flex; justify-content: center; gap: 4px; margin-top: 14px; }
.lang-switch button { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.lang-switch button.active { color: var(--text); font-weight: 600; background: var(--accent-soft); }
label.check.lang-pick select { width: auto; min-width: 0; padding: 2px 6px; font-size: 12px; height: auto; }
/* 翻成英文、泰文的字比較長：批量選取那排不要斷行 */
html[lang=en] .selbar .btn, html[lang=en] .selbar .count, html[lang=th] .selbar .btn, html[lang=th] .selbar .count { white-space: nowrap; }

/* ---------- 電腦大螢幕：畫面加寬，左右不要留一大片空白 ----------
   只有電腦（滑鼠＋寬螢幕）才放寬，手機網頁和 App 維持原本的窄版。
   動態卡片一列並排 2～3 件商品（螢幕夠寬就 3 件），不要一件商品放很大。 */
@media (min-width: 1100px) and (hover: hover) and (pointer: fine) {
  .wrap { max-width: 1360px; padding: 0 32px; }
  .fab { right: max(32px, calc(50% - 648px)); }
  #feed:has(> .post) { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 16px; align-items: start; }
  #feed:has(> .post) > .post { margin-bottom: 0; min-width: 0; }
  #feed:has(> .post) > :not(.post) { grid-column: 1 / -1; }
  #feed .post .grid { max-width: none; }
  /* 卡片變窄：內容從頭像下面開始用滿整張卡片寬度，按鈕縮小一點，不會排成三四行 */
  #feed:has(> .post) > .post { padding: 16px; }
  #feed:has(> .post) .post-body { grid-column: 1 / -1; margin-top: 8px; }
  #feed:has(> .post) .post-actions { gap: 6px; }
  #feed:has(> .post) .post-actions button, #feed:has(> .post) .post-actions a, #feed:has(> .post) .post-actions .status-pick { height: 32px; padding: 0 10px; font-size: 13px; gap: 5px; }
  #feed:has(> .post) .post-actions .status-pick select { font-size: 13px; }
  #feed:has(> .post) .post-actions svg { width: 15px; height: 15px; }
  .grid-box { grid-template-columns: repeat(7, 1fr); gap: 8px; }
}
