:root {
  --bg: #f4f3f0;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #8a8780;
  --line: #e7e4de;
  --accent: #9a7b4f;
  --accent-soft: #f6efe4;
  --link: #3a5a8c;
  --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);
}
.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: grid; place-items: center; font-size: 13px; font-weight: 800; letter-spacing: 0;
}
.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; }
.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-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; }
.drive-badge { font-size: 12px; border-radius: 6px; padding: 1px 7px; }
.drive-badge.synced { color: var(--ok); background: #e9f4ee; }
.drive-badge.pending { color: #8a6d1a; background: #fbf3dc; }
.drive-badge.error { color: var(--danger); background: #fbe9e7; 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);
  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; }
.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; }
#lightbox .lb-img { position: absolute; inset: 56px 0 64px; display: grid; place-items: center; }
#lightbox .lb-img img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; }
#lightbox .lb-top, #lightbox .lb-bottom { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 0 16px; }
#lightbox .lb-top { top: 0; height: 56px; justify-content: space-between; }
#lightbox .lb-bottom { bottom: 0; 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: #1d1d1f; color: #f6efe4; 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-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; }
.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; }
