/* ===== TikTok-style page transitions ===== */
@view-transition { navigation: auto; }

@keyframes _pgFadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes _pgFadeOut { from { opacity: 1; } to { opacity: 0; } }

::view-transition-old(root) { animation: 120ms ease-in  both _pgFadeOut; }
::view-transition-new(root) { animation: 150ms ease-out both _pgFadeIn;  }

/* Fallback: animate body on every page load */
body { animation: _pgFadeIn 150ms ease-out both; }

/* ===== 主題變量：白日 ===== */
:root {
  --fb-blue: #1877f2;
  --fb-blue-dark: #166fe5;
  --fb-green: #42b72a;
  --fb-bg: #dfe3e8;
  --fb-white: #eef1f4;
  --fb-border: #cfd4da;
  --fb-text: #4a4f57;
  --fb-text-secondary: #65676b;
  --fb-hover: #e5e9ee;
  --fb-hover2: #d9dee4;
  --fb-card: #eef1f4;
  --fb-input: #e3e7ec;
  --fb-unread: #e7f3ff;
  --fb-shadow: 0 1px 2px rgba(0,0,0,0.1);
  --nav-height: 56px;
}

/* ===== 主題變量：黑夜 ===== */
[data-theme="dark"] {
  --fb-bg: #18191a;
  --fb-white: #242526;
  --fb-border: #3e4042;
  --fb-text: #e4e6eb;
  --fb-text-secondary: #b0b3b8;
  --fb-hover: #3a3b3c;
  --fb-hover2: #4e4f50;
  --fb-card: #242526;
  --fb-input: #3a3b3c;
  --fb-unread: #263951;
  --fb-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, "Microsoft JhengHei", sans-serif;
  background: var(--fb-bg);
  color: var(--fb-text);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

a { text-decoration: none; color: inherit; }

/* ===== 圖示 ===== */
.ic { display: inline-flex; align-items: center; justify-content: center; }
.ic svg { width: 100%; height: 100%; display: block; }
.nav-btn .ic { width: 27px; height: 27px; }
.nav-icon-btn .ic { width: 21px; height: 21px; }
.sidebar-menu-item .icon .ic { width: 20px; height: 20px; }
.ic-search { width: 17px; height: 17px; color: var(--fb-text-secondary); }
.create-post-btn .ic { width: 22px; height: 22px; }
.post-action-btn .ic { width: 20px; height: 20px; }

/* ===== 導航列 ===== */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--fb-white);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1), 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  z-index: 1000;
  padding: 0 16px;
}
[data-theme="dark"] .navbar { box-shadow: 0 1px 2px rgba(0,0,0,0.5); }

.nav-left { display: flex; align-items: center; gap: 8px; min-width: 240px; }
.nav-logo {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: url('/img/nav-logo.png') center / contain no-repeat;
  cursor: pointer;
  font-size: 0;
  flex-shrink: 0;
  transition: opacity .2s;
}
.nav-logo:hover { opacity: .82; }
.nav-logo::before { content: none; }
.nav-search {
  display: flex; align-items: center;
  background: var(--fb-input);
  border-radius: 50px;
  padding: 0 12px;
  gap: 8px;
  cursor: text;
  height: 40px;
}
.nav-search input {
  border: none; background: transparent;
  font-size: 15px; outline: none; width: 180px;
  color: var(--fb-text);
}
.nav-search input::placeholder { color: var(--fb-text-secondary); }

.nav-center {
  flex: 1; display: flex; align-items: center;
  justify-content: center; gap: 4px;
}
.nav-btn {
  display: flex; align-items: center; justify-content: center;
  width: 110px; height: 52px; border-radius: 8px;
  border: none; background: transparent; cursor: pointer;
  color: var(--fb-text-secondary);
  transition: background 0.15s;
  position: relative; text-decoration: none;
  margin: 0 2px;
}
.nav-btn:hover { background: var(--fb-hover); }
.nav-btn.active { color: var(--fb-blue); }
.nav-btn.active::after {
  content: ''; position: absolute; bottom: 0;
  left: 0; right: 0; height: 3px;
  background: var(--fb-blue); border-radius: 2px 2px 0 0;
}

.nav-right { display: flex; align-items: center; gap: 8px; min-width: 240px; justify-content: flex-end; }
.nav-icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--fb-input); border: none; cursor: pointer;
  color: var(--fb-text);
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: background 0.2s;
}
.nav-icon-btn:hover { background: var(--fb-hover2); }
.badge {
  position: absolute; top: -2px; right: -2px;
  background: #e41e3f; color: white;
  font-size: 11px; font-weight: 700;
  padding: 2px 5px; border-radius: 10px;
  min-width: 18px; text-align: center;
}
.nav-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; cursor: pointer;
}

/* ===== 全站固定左側導航欄（切換頁面不隱藏、捲動不動）===== */
.app-sidebar {
  position: fixed;
  left: 0;
  top: var(--nav-height);
  width: 60px;
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 12px 0 12px 8px;
  background: var(--fb-bg);
  border-right: 1px solid var(--fb-border);
  z-index: 500;
}
body.has-app-sidebar { padding-left: 60px; }
/* 精簡圖示模式：隱藏文字標籤、置中圖示（高特異度，蓋過執行期注入的 upload 樣式）*/
body.has-app-sidebar .app-sidebar .menu-label { display: none; }
body.has-app-sidebar .app-sidebar .sidebar-menu-item { justify-content: center; padding: 8px 0; gap: 0; }
body.has-app-sidebar .app-sidebar .sidebar-upload-btn { grid-template-columns: 1fr; justify-items: center; padding: 8px 0; margin: 4px 0; border: none; }
.sidebar-menu-item.active { background: var(--fb-hover); font-weight: 700; }

/* ===== 主版面：左欄固定、右欄靠右 ===== */
.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 0;
  padding-top: var(--nav-height);
  min-height: 100vh;
  width: 100%;
}
.sidebar-right {
  position: sticky;
  top: var(--nav-height);
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  scrollbar-width: thin;
  min-width: 0;
  padding: 16px 16px 16px 8px;
}
/* 中欄內容置中（動態牆維持適中寬度）*/
.main-content { padding: 16px 8px; min-width: 0; }
.main-content > * {
  max-width: 590px;
  margin-left: auto;
  margin-right: auto;
}

/* ===== 側邊欄選單 ===== */
.sidebar-menu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 8px;
  cursor: pointer; transition: background 0.2s;
  font-size: 15px; font-weight: 500;
  margin-bottom: 4px;
  color: var(--fb-text);
}
.sidebar-menu-item:hover { background: var(--fb-hover); }
.sidebar-menu-item .icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--fb-input);
  display: flex; align-items: center; justify-content: center;
}
.sidebar-menu-item .menu-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.sidebar-divider { border: none; border-top: 1px solid var(--fb-border); margin: 8px 4px; }

/* ===== 卡片 ===== */
.card {
  background: var(--fb-card);
  border-radius: 8px;
  box-shadow: var(--fb-shadow);
  margin-bottom: 12px;
  overflow: hidden;
  color: var(--fb-text);
}

/* ===== 建立貼文 ===== */
.create-post {
  background: var(--fb-card);
  border-radius: 8px;
  box-shadow: var(--fb-shadow);
  padding: 12px 16px;
  margin-bottom: 12px;
}
.create-post-top { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.create-post-input {
  flex: 1; padding: 8px 12px;
  background: var(--fb-input);
  border: none; border-radius: 20px;
  font-size: 16px; cursor: pointer;
  color: var(--fb-text-secondary);
  outline: none;
}
.create-post-input:hover { background: var(--fb-hover2); }
.create-post-divider { height: 1px; background: var(--fb-border); margin: 4px 0; }
.create-post-actions { display: flex; }
.create-post-btn {
  flex: 1; display: flex; align-items: center;
  justify-content: center; gap: 8px;
  padding: 8px; border-radius: 8px;
  border: none; background: transparent;
  font-size: 14px; font-weight: 600;
  color: var(--fb-text-secondary);
  cursor: pointer; transition: background 0.2s;
}
.create-post-btn:hover { background: var(--fb-hover); }

/* ===== 貼文 ===== */
.post {
  background: var(--fb-card);
  border-radius: 8px;
  box-shadow: var(--fb-shadow);
  margin-bottom: 12px;
}
.post-header { display: flex; align-items: center; padding: 12px 16px; gap: 8px; }
.post-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.post-author-name { font-weight: 600; font-size: 14px; color: var(--fb-text); }
.post-time { font-size: 12px; color: var(--fb-text-secondary); }
.post-content { padding: 0 16px 12px; font-size: 15px; line-height: 1.5; overflow-wrap: break-word; }
.post-images { display: grid; gap: 2px; }
.post-images img { width: 100%; cursor: pointer; display: block; }
/* Single image: enlarge to full width even if small source */
.post-images.one img {
  width: 100% !important;
  height: auto;
  max-height: min(640px, 70vh);
  object-fit: contain;
  background: #0a0a0a;
  image-rendering: auto;
}
.post-images.two { grid-template-columns: 1fr 1fr; }
.post-images.two img { width: 100%; height: 280px; object-fit: cover; }
/* Post videos also full width */
.post-video, .post-vid, .post-images video { width: 100% !important; max-height: min(640px, 70vh); background: #000; display: block; }
.post-stats {
  display: flex; justify-content: space-between;
  padding: 10px 16px; font-size: 14px;
  color: var(--fb-text-secondary);
}
.post-actions {
  display: flex; border-top: 1px solid var(--fb-border);
  margin: 0 8px; padding: 4px 0;
}
.post-action-btn {
  flex: 1; display: flex; align-items: center;
  justify-content: center; gap: 6px;
  padding: 8px; border-radius: 8px;
  border: none; background: transparent;
  font-size: 14px; font-weight: 600;
  color: var(--fb-text-secondary);
  cursor: pointer; transition: background 0.2s;
}
.post-action-btn:hover { background: var(--fb-hover); }
.post-action-btn.liked { color: var(--fb-blue); }

.post-comments { padding: 8px 16px; border-top: 1px solid var(--fb-border); }
.comment-input-area { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.comment-input {
  flex: 1; padding: 8px 12px;
  background: var(--fb-input); border: none;
  border-radius: 20px; font-size: 14px;
  outline: none; resize: none; color: var(--fb-text);
}
.comment-item { display: flex; gap: 8px; margin-bottom: 8px; }
.comment-bubble { background: var(--fb-input); border-radius: 16px; padding: 8px 12px; }
.comment-author { font-weight: 600; font-size: 13px; }
.comment-text { font-size: 14px; }

/* ===== OG 連結預覽 ===== */
.link-preview {
  display: block;
  border: 1px solid var(--fb-border);
  border-top: 1px solid var(--fb-border);
  margin: 0 0 0;
  background: var(--fb-input);
  overflow: hidden;
}
.link-preview:hover { background: var(--fb-hover2); }
.lp-img {
  width: 100%; height: 280px;
  background-size: cover; background-position: center;
  background-color: var(--fb-hover2);
}
.lp-img.small { height: 120px; }
/* 無大圖時：漸層底 + 網站圖示 */
.lp-img-fallback {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--fb-blue), #6c47ff);
  height: 180px;
}
.lp-img-fallback img {
  width: 84px; height: 84px;
  border-radius: 16px; background: #fff;
  padding: 10px; object-fit: contain;
  box-shadow: 0 3px 10px rgba(0,0,0,.3);
}
.lp-img.small.lp-img-fallback { height: 100px; }
.lp-img.small.lp-img-fallback img { width: 54px; height: 54px; padding: 7px; border-radius: 11px; }
.lp-body { padding: 10px 12px; }
.lp-site { font-size: 12px; color: var(--fb-text-secondary); text-transform: uppercase; }
.lp-title {
  font-size: 16px; font-weight: 600; margin: 3px 0;
  color: var(--fb-text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lp-desc {
  font-size: 14px; color: var(--fb-text-secondary);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
/* 編輯框內即時預覽 */
.lp-compose {
  border: 1px solid var(--fb-border);
  border-radius: 8px;
  margin-top: 10px;
  position: relative;
  background: var(--fb-input);
  overflow: hidden;
}
.lp-compose .lp-close {
  position: absolute; top: 6px; right: 6px;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff;
  border: none; cursor: pointer; font-size: 14px;
}

/* ===== 通知下拉 ===== */
.dropdown {
  position: absolute; top: 100%; right: 0;
  background: var(--fb-white); border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  width: 360px; max-height: 480px; overflow-y: auto;
  z-index: 999; padding: 8px 0;
  color: var(--fb-text);
}
.dropdown-header { padding: 8px 16px 4px; font-size: 20px; font-weight: 700; }
.notif-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; cursor: pointer;
  transition: background 0.2s;
}
.notif-item:hover { background: var(--fb-hover); }
.notif-item.unread { background: var(--fb-unread); }

/* ===== 模態視窗 ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.modal {
  background: var(--fb-white);
  border-radius: 8px;
  width: 90%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  color: var(--fb-text);
}
.modal-header {
  display: flex; align-items: center;
  padding: 16px; border-bottom: 1px solid var(--fb-border);
  font-size: 20px; font-weight: 700;
}
.modal-header .close-btn {
  margin-left: auto; width: 36px; height: 36px;
  border-radius: 50%; background: var(--fb-input);
  border: none; cursor: pointer; font-size: 18px;
  color: var(--fb-text);
  display: flex; align-items: center; justify-content: center;
}
.modal-body { padding: 16px; }
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--fb-border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ===== 按鈕 ===== */
.btn {
  padding: 8px 16px; border-radius: 6px;
  border: none; cursor: pointer;
  font-size: 15px; font-weight: 600;
  transition: filter 0.15s, background 0.15s;
}
.btn-primary { background: var(--fb-blue); color: white; }
.btn-primary:hover { background: var(--fb-blue-dark); }
.btn-secondary { background: var(--fb-input); color: var(--fb-text); }
.btn-secondary:hover { background: var(--fb-hover2); }
.btn-success { background: var(--fb-green); color: white; }
.btn-danger { background: #e41e3f; color: white; }
.btn-outline { background: transparent; border: 1.5px solid var(--fb-blue); color: var(--fb-blue); }
.btn-block { width: 100%; display: block; text-align: center; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

/* ===== 表單 ===== */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.form-control {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--fb-border);
  border-radius: 6px; font-size: 16px;
  outline: none; transition: border-color 0.2s;
  background: var(--fb-white); color: var(--fb-text);
}
.form-control:focus { border-color: var(--fb-blue); }
.form-control::placeholder { color: var(--fb-text-secondary); }

/* ===== 故事 ===== */
.stories-bar {
  display: flex; gap: 8px;
  overflow-x: auto; padding-bottom: 8px;
  margin-bottom: 12px; scrollbar-width: thin;
}
.story-card {
  min-width: 112px; width: 112px; height: 200px;
  border-radius: 12px; overflow: hidden;
  position: relative; cursor: pointer;
  box-shadow: var(--fb-shadow);
  flex-shrink: 0;
}
.story-bg {
  width: 100%; height: 100%; object-fit: cover;
  background: linear-gradient(135deg, var(--fb-blue), #6c47ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
}
.story-avatar {
  position: absolute; top: 8px; left: 8px;
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--fb-blue); object-fit: cover;
}
.story-name {
  position: absolute; bottom: 8px; left: 8px; right: 8px;
  color: white; font-size: 13px; font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* ===== 聊天/好友列表 ===== */
.chat-list-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 8px;
  cursor: pointer; transition: background 0.2s;
}
.chat-list-item:hover { background: var(--fb-hover); }
.chat-avatar { position: relative; }
.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; font-size: 14px; }
.chat-last-msg { font-size: 13px; color: var(--fb-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.online-dot {
  position: absolute; bottom: 2px; right: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #31a24c; border: 2px solid var(--fb-white);
}

/* ===== 個人檔案 ===== */
.profile-cover { width: 100%; height: 350px; object-fit: cover; }
.profile-name { font-size: 28px; font-weight: 800; }
.profile-bio { color: var(--fb-text-secondary); font-size: 15px; margin: 4px 0; }

/* ===== 商店（FB Marketplace 風） ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.product-card {
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
  cursor: pointer;
  transition: opacity 0.12s;
}
.product-card:hover { transform: none; box-shadow: none; opacity: 0.92; }
.product-card:hover .product-img,
.product-card:hover .product-img-wrap { box-shadow: 0 4px 14px rgba(0,0,0,.3); }

/* 1:1 正方圖（FB 風） */
.product-img,
.product-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  background: var(--fb-input);
  border-radius: 8px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 56px;
  transition: box-shadow .15s;
}
.product-img img,
.product-img-wrap img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}

/* 角落徽章：剛剛上架、新上架、免費 */
.product-badge {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(255,255,255,.95);
  color: #050505;
  font-size: 12px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 4px;
  z-index: 1;
  pointer-events: none;
}
.product-badge.free { background: #42b72a; color: #fff; }
.product-badge.sold { background: #65676b; color: #fff; }

/* 已售出 overlay */
.product-card.sold .product-img-wrap::after,
.product-card.sold .product-img::after {
  content: '已售出';
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800;
  letter-spacing: 4px;
}

/* 資訊區：價格大、標題小、地點淡 */
.product-info { padding: 8px 2px 0; }
.product-price {
  color: var(--fb-text);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.3;
  margin: 0;
}
.product-price.free-text { color: #42b72a; font-weight: 800; }
.product-price-orig {
  color: var(--fb-text-secondary);
  font-size: 13px;
  text-decoration: line-through;
  font-weight: 500;
  margin-left: 6px;
}
.product-title {
  font-weight: 400;
  font-size: 14px;
  color: var(--fb-text);
  margin-top: 2px;
  margin-bottom: 0;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  line-height: 1.35;
}
.product-location {
  font-size: 13px;
  color: var(--fb-text-secondary);
  margin-top: 2px;
}
.product-condition { display: none; }  /* FB 風卡片不顯示狀況 */

/* ===== 社團 ===== */
.group-card {
  background: var(--fb-card); border-radius: 8px;
  box-shadow: var(--fb-shadow); overflow: hidden;
  cursor: pointer; transition: box-shadow 0.15s;
}
.group-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.18); }
.group-cover {
  width: 100%; height: 130px; object-fit: cover;
  background: linear-gradient(135deg, var(--fb-blue), #6c47ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
}
.group-info { padding: 12px; }
.group-name { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.group-meta { font-size: 13px; color: var(--fb-text-secondary); }
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }

/* ===== Toast / Spinner ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #323232; color: white;
  padding: 12px 24px; border-radius: 8px;
  font-size: 14px; z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; }
.spinner {
  border: 3px solid var(--fb-input);
  border-top: 3px solid var(--fb-blue);
  border-radius: 50%; width: 32px; height: 32px;
  animation: spin 0.8s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 響應式 ===== */
@media (max-width: 1100px) {
  .main-layout { grid-template-columns: minmax(0,1fr); }
  .sidebar-left, .sidebar-right { display: none; }
  .app-sidebar { display: none; }
  body.has-app-sidebar { padding-left: 0; }
}
@media (max-width: 768px) {
  .main-content { padding: 10px 6px; }
  .main-content > * { max-width: 100%; }
  .stories-bar { gap: 6px; }
  .story-card { min-width: 104px; width: 104px; height: 184px; }
  .post-images.two img { height: 190px; }
  .group-grid { grid-template-columns: 1fr 1fr; }
  .product-grid { grid-template-columns: repeat(3, 1fr); }
  .modal { width: 94%; }
}
@media (max-width: 600px) {
  .nav-search, .nav-center { display: none; }
  .nav-left, .nav-right { min-width: auto; }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .main-content { padding: 8px 0; }
  .create-post, .post, .card { border-radius: 0; }
  .create-post { padding: 10px 12px; }
  .create-post-btn { font-size: 12px; gap: 4px; padding: 8px 2px; }
  .create-post-btn .ic { width: 18px; height: 18px; }
  .post-action-btn { font-size: 13px; }
  .post-action-btn .ic { width: 18px; height: 18px; }
  .group-grid { grid-template-columns: 1fr; }
  .story-card { min-width: 88px; width: 88px; height: 158px; }
  .modal { width: 100%; }
  .modal-overlay { padding: 0 8px; }
}

/* === FB-style Comments === */
.fb-comment { margin-top: 8px; }
.fb-comment-row { display: flex; gap: 8px; align-items: flex-start; }
.fb-comment-body { flex: 1; min-width: 0; }
.fb-comment-bubble {
  background: var(--fb-hover, #f0f2f5);
  border-radius: 16px;
  padding: 8px 12px;
  display: inline-block;
  max-width: 100%;
}
[data-theme="dark"] .fb-comment-bubble { background: #3a3b3c; }
.fb-comment-name { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.fb-comment-text { font-size: 14px; word-break: break-word; }
.fb-comment-meta {
  display: flex; gap: 12px; align-items: center;
  font-size: 12px; padding: 4px 12px 0;
  color: var(--fb-text-secondary, #65676b);
}
.fb-cm-act { cursor: pointer; font-weight: 600; }
.fb-cm-act:hover { text-decoration: underline; }
.fb-cm-act.liked { color: #1877f2; }
.fb-cm-time { color: #999; }
.fb-cm-likes {
  background: #fff;
  border: 1px solid #e4e6eb;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  color: #65676b;
  margin-left: auto;
}
[data-theme="dark"] .fb-cm-likes { background: #242526; border-color: #3a3b3c; }
.fb-replies { margin-top: 4px; }
.fb-reply { margin-top: 6px; }
.fb-reply-box {
  display: flex; gap: 8px; align-items: center;
  margin-top: 6px;
}
.fb-reply-input {
  flex: 1;
  border: none;
  background: var(--fb-hover, #f0f2f5);
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 13px;
  outline: none;
}
[data-theme="dark"] .fb-reply-input { background: #3a3b3c; color: #e4e6eb; }

.fb-children {
  margin-top: 6px;
  padding-left: 0;
}
.fb-children .fb-comment {
  margin-top: 8px;
}
/* Visual thread line for nested */
.fb-children .fb-comment-row::before {
  content: '';
  display: none;
}
.fb-comment .fb-comment-body { position: relative; }

/* === FB comment input with tools === */
.fb-comment-inputwrap {
  flex: 1;
  position: relative;
  display: flex;
  background: var(--fb-input, #f0f2f5);
  border-radius: 20px;
  padding: 0 8px 0 0;
  align-items: center;
}
[data-theme="dark"] .fb-comment-inputwrap { background: #3a3b3c; }
.fb-comment-inputwrap .comment-input {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  min-width: 0;
  color: var(--fb-text);
}
.fb-comment-tools {
  display: flex;
  gap: 2px;
  position: relative;
}
.fb-ct-btn {
  background: none;
  border: 0;
  cursor: pointer;
  width: 30px;
  height: 30px;
  font-size: 14px;
  font-weight: 700;
  color: #65676b;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fb-ct-btn:hover { background: rgba(0,0,0,0.06); }
[data-theme="dark"] .fb-ct-btn { color: #b0b3b8; }
[data-theme="dark"] .fb-ct-btn:hover { background: rgba(255,255,255,0.08); }
.fb-cmt-preview { padding: 6px 0 8px 40px; }


/* ===== 全站滾動條深色主題 v2（全域 pseudo selector，不用 * 提高相容性）===== */
html { scrollbar-width: thin; scrollbar-color: #3a3b3c transparent; }
body { scrollbar-color: #3a3b3c transparent; }

::-webkit-scrollbar { width: 10px; height: 10px; background: transparent; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #3a3b3c;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: #4e4f50;
  background-clip: content-box;
}
::-webkit-scrollbar-corner { background: transparent; }

/* 亮色主題 */
:root[data-theme="light"] html,
:root[data-theme="light"] body { scrollbar-color: #c1c4c8 transparent; }
:root[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c1c4c8; }
:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #9aa0a6; }

/* 已知會出現滾動條的元素：明確強制深色（保險） */
.mp-aside,
.grp-fixed-aside,
.gd-aside,
.app-sidebar,
.cr-left,
.cr-right,
.cr-messages,
#groupsListView,
#postsSection,
.modal-body {
  scrollbar-width: thin;
  scrollbar-color: #3a3b3c transparent;
}
.mp-aside::-webkit-scrollbar,
.grp-fixed-aside::-webkit-scrollbar,
.gd-aside::-webkit-scrollbar,
.app-sidebar::-webkit-scrollbar,
.cr-left::-webkit-scrollbar,
.cr-right::-webkit-scrollbar,
.modal-body::-webkit-scrollbar { width: 10px; height: 10px; }
.mp-aside::-webkit-scrollbar-thumb,
.grp-fixed-aside::-webkit-scrollbar-thumb,
.gd-aside::-webkit-scrollbar-thumb,
.app-sidebar::-webkit-scrollbar-thumb,
.cr-left::-webkit-scrollbar-thumb,
.cr-right::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: #3a3b3c;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.mp-aside::-webkit-scrollbar-track,
.grp-fixed-aside::-webkit-scrollbar-track,
.gd-aside::-webkit-scrollbar-track,
.app-sidebar::-webkit-scrollbar-track,
.cr-left::-webkit-scrollbar-track,
.cr-right::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track { background: transparent; }

/* ===== 限時動態：左右箭頭導覽（取代捲軸） ===== */
.stories-wrap {
  position: relative;
  margin-bottom: 12px;
}
.stories-wrap .stories-bar {
  scroll-behavior: smooth;
  scrollbar-width: none !important;            /* Firefox */
  -ms-overflow-style: none;         /* IE/Edge */
  margin-bottom: 0;
  padding-bottom: 0;
}
.stories-wrap .stories-bar::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }
.stories-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.95);
  color: #050505;
  border: 1px solid rgba(0,0,0,.08);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: none;                    /* JS 依需要顯示 */
  align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  z-index: 5;
  transition: transform .12s, background .12s;
}
.stories-arrow:hover { transform: translateY(-50%) scale(1.08); background: #fff; }
.stories-arrow-left  { left: -10px; }
.stories-arrow-right { right: -10px; }
[data-theme="dark"] .stories-arrow {
  background: #3a3b3c; color: #e4e6eb; border-color: rgba(255,255,255,.08);
}
[data-theme="dark"] .stories-arrow:hover { background: #4e4f50; }

/* light: product card border */
html[data-theme="light"] .product-img,
html[data-theme="light"] .product-img-wrap {
  border: 1px solid #c4cad2;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
}
html[data-theme="light"] .product-card:hover .product-img,
html[data-theme="light"] .product-card:hover .product-img-wrap {
  box-shadow: 0 4px 14px rgba(0,0,0,.16);
  border-color: #aab0b8;
}

/* === FB composer 2-row === */
.create-post-actions { display: flex; flex-wrap: wrap; gap: 2px; }
.create-post-btn { flex: 1 1 22%; font-size: 13px; gap: 6px; padding: 8px 4px; white-space: nowrap; }
.cpa-emo { font-size: 18px; line-height: 1; }
@media (max-width: 768px) {
  .create-post-btn { flex-basis: 44%; font-size: 12px; }
}

/* === purple like badge === */
.post-stat-like { display: inline-flex; align-items: center; gap: 5px; }
.like-dot { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: #7c3aed; color: #fff; flex-shrink: 0; }
.like-dot .ic { width: 12px; height: 12px; }

/* === FB reactions bar (cartoon) === */
.reaction-bar { position: fixed; z-index: 9999; display: none; align-items: center; gap: 4px; background: var(--fb-card,#fff); border: 1px solid var(--fb-border,#e4e6eb); border-radius: 30px; box-shadow: 0 6px 18px rgba(0,0,0,.28); padding: 5px 8px; transform: translateY(8px) scale(.85); opacity: 0; transition: transform .14s ease, opacity .14s ease; }
.reaction-bar.show { transform: translateY(0) scale(1); opacity: 1; }
.reaction-opt { border: none; background: transparent; cursor: pointer; padding: 0; line-height: 0; }
.reaction-img { width: 38px; height: 38px; display: block; transform-origin: bottom center; transition: transform .12s ease; }
.reaction-opt:hover .reaction-img { transform: scale(1.35) translateY(-8px); }

/* === reaction summary (stacked) === */
.post-stat-like { gap: 0 !important; }
.react-mini { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--fb-card,#fff); display: inline-block; vertical-align: middle; background: var(--fb-card,#fff); }
.like-count-num { margin-left: 6px; }
