/* ============================================================
   shell.css — 外殼專屬樣式（頂欄 + 左欄）
   完全獨立，不依賴 style.css，避免被內容頁的樣式干擾或重載閃跳。
   ============================================================ */

/* ===== 主題變數：白日 ===== */
: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-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-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

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

html, body { height: 100vh; height: 100dvh; height: var(--app-vh, 100dvh); overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, "Microsoft JhengHei", sans-serif;
  background: var(--fb-bg);
  color: var(--fb-text);
}
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); }

/* ===== 頂欄 ===== */
.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: 2000;            /* 蓋住 iframe 內頁自帶的頂欄 */
  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 {
  display: block;
  width: 40px; height: 40px;
  border-radius: 8px;
  background: url('/img/logo.svg') center / contain no-repeat;
  cursor: pointer;
  font-size: 0;
  flex-shrink: 0;
  transition: opacity .2s;
}
.nav-logo:hover { opacity: .82; }
.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-wrap { width: 40px; height: 40px; border-radius: 50%; }
#nav-avatar-wrap img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }

/* ===== 左欄 ===== */
.app-sidebar {
  position: fixed;
  left: 0;
  top: var(--nav-height);
  width: 210px;
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 12px 10px 12px 14px;
  background: var(--fb-bg);
  border-right: 1px solid var(--fb-border);
  z-index: 500;
}
.sidebar-menu-item {
  display: grid; grid-template-columns: 44px 1fr;
  align-items: center;
  padding: 8px 0; 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.active { background: var(--fb-hover); font-weight: 700; }
.sidebar-menu-item .icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--fb-input);
  display: flex; align-items: center; justify-content: center;
  justify-self: center;
}
.sidebar-menu-item .menu-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; justify-self: center; }
.sidebar-menu-item > img:first-child,
.sidebar-menu-item > div:first-child { justify-self: center; }
.sidebar-divider { display: none; }

/* ===== 通知下拉 ===== */
.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);
}
@keyframes notifPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.25); } }
.notif-item { display: flex; align-items: flex-start; transition: background .15s; }
.notif-item:hover { background: var(--fb-hover); }
.notif-item.unread { background: rgba(24,119,242,.08); }

/* ===== 按鈕 ===== */
.btn {
  padding: 8px 12px; border-radius: 6px; border: none;
  font-weight: 600; cursor: pointer; font-size: 15px;
  font-family: inherit; transition: background 0.2s;
}
.btn-secondary { background: var(--fb-input); color: var(--fb-text); }
.btn-secondary:hover { background: var(--fb-hover2); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ===== 內容區 iframe ===== */
#content-frame {
  position: fixed;
  top: 0; left: 210px; right: 0; bottom: 0;
  width: calc(100vw - 210px);
  height: 100vh;
  height: 100dvh;
  height: var(--app-vh, 100dvh);
  border: none;
  background: var(--fb-bg);
  transition: left 0.2s ease, width 0.2s ease;
}
@media (max-width: 768px) {
  #content-frame { left: 0; width: 100vw; }
}

/* ===== 左欄 compact 模式（聊天室等需要更多橫向空間的頁面）=====
   同時支援 body.sidebar-compact（執行期由 JS 切換）與 html.init-compact（reload 前置：避免閃跳）*/
body.sidebar-compact .app-sidebar,
html.init-compact .app-sidebar {
  width: 60px;
  padding: 12px 0 12px 14px;
}
body.sidebar-compact .app-sidebar .menu-label,
html.init-compact .app-sidebar .menu-label { display: none; }
body.sidebar-compact .app-sidebar .sidebar-menu-item,
html.init-compact .app-sidebar .sidebar-menu-item {
  padding: 8px 0;
}
body.sidebar-compact .app-sidebar .sidebar-upload-btn,
html.init-compact .app-sidebar .sidebar-upload-btn {
  padding: 8px 0;
  margin: 4px 0;
  border: none;
}
/* iframe 跟著左移 */
body.sidebar-compact #content-frame,
html.init-compact #content-frame {
  left: 60px;
  width: calc(100vw - 60px);
}
/* 為了避免從 init-compact 切到正常狀態時的瞬間動畫，初始 paint 時禁用 transition */
html.init-compact #content-frame,
html.init-compact .app-sidebar { transition: none !important; }

/* ============================================================
   響應式：平板與手機（FB 樣式）
   ============================================================ */

/* 平板（≤1024px）：縮窄搜尋框與導覽鈕，釋放中央空間 */
@media (max-width: 1024px) {
  .nav-left  { min-width: 0; }
  .nav-right { min-width: 0; }
  .nav-search input { width: 120px; }
  .nav-btn { width: 92px; }
}

/* 中型（≤860px）：導覽鈕自動分配寬度、搜尋框收窄 */
@media (max-width: 860px) {
  .navbar { padding: 0 8px; }
  .nav-left { gap: 6px; }
  .nav-search { padding: 0 10px; }
  .nav-search input { width: 84px; }
  .nav-center { gap: 2px; }
  .nav-btn { width: auto; flex: 1 1 0; max-width: 96px; margin: 0; }
}

/* 手機（≤768px）：隱藏左欄、內容區全寬、導覽列精簡 */
@media (max-width: 768px) {
  .app-sidebar { display: none; }
  #content-frame,
  body.sidebar-compact #content-frame {
    left: 0;
    width: 100vw;
  }
  .nav-right { gap: 4px; }
  .nav-icon-btn { width: 38px; height: 38px; }
  #nav-avatar-wrap, #nav-avatar-wrap img { width: 36px; height: 36px; }
}

/* 小手機（≤480px）：隱藏搜尋框、進一步縮小元件 */
@media (max-width: 480px) {
  .navbar { padding: 0 4px; }
  .nav-search { display: none; }
  .nav-logo { width: 34px; height: 34px; }
  .nav-btn { height: 50px; }
  .nav-btn .ic { width: 24px; height: 24px; }
  .nav-icon-btn { width: 34px; height: 34px; }
  .nav-icon-btn .ic { width: 18px; height: 18px; }
  #nav-avatar-wrap, #nav-avatar-wrap img { width: 32px; height: 32px; }
  /* 通知下拉改為近全寬浮層 */
  .dropdown {
    position: fixed !important;
    top: 56px !important;
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-height: calc(100vh - 70px) !important;
  }
}

/* ===== Shell Navbar Dropdown ===== */
.nav-dropdown-wrap { position: relative; }
.nav-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: var(--fb-card, #fff);
  border: 1px solid var(--fb-border, #ced0d4);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  z-index: 9999;
  overflow: hidden;
  padding: 6px 0;
}
[data-theme="dark"] .nav-dropdown {
  background: #242526;
  border-color: #3a3b3c;
  box-shadow: 0 8px 24px rgba(0,0,0,.7);
}
.nav-dropdown.open { display: block; }
.nav-dd-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--fb-text-primary, #050505);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s;
  font-family: inherit;
}
.nav-dd-item:hover { background: var(--fb-hover, #f0f2f5); }
[data-theme="dark"] .nav-dd-item { color: #e4e6eb; }
[data-theme="dark"] .nav-dd-item:hover { background: #3a3b3c; }
.nav-dd-sep { height: 1px; background: var(--fb-border, #ced0d4); margin: 4px 0; }
[data-theme="dark"] .nav-dd-sep { background: #3a3b3c; }
/* 帳號資訊區（下拉頂端） */
.nav-dd-account {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; cursor: pointer; border-radius: 8px;
  transition: background .12s; margin: 4px;
}
.nav-dd-account:hover { background: var(--fb-hover, #f0f2f5); }
[data-theme="dark"] .nav-dd-account:hover { background: #3a3b3c; }
.nav-dd-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px;
  /* 預設無底色；由 avatarEl 或 fallback 提供。避免空狀態的藍色圓 */
}
.nav-dd-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
/* 從 avatarEl 插進來的內層 div 也撐滿整個 cell */
.nav-dd-avatar > div { width: 100% !important; height: 100% !important; border-radius: 50% !important; }
.nav-dd-account-info { flex: 1; min-width: 0; }
.nav-dd-name {
  font-weight: 700; font-size: 15px;
  color: var(--fb-text, #050505);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-dd-email {
  font-size: 12px; color: var(--fb-text-secondary, #65676b);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}
[data-theme="dark"] .nav-dd-name { color: #e4e6eb; }
[data-theme="dark"] .nav-dd-email { color: #b0b3b8; }
.nav-dd-logout { color: #e41e3f !important; }
.nav-dd-logout:hover { background: #fce4e4 !important; }
[data-theme="dark"] .nav-dd-logout:hover { background: #3a1010 !important; }

/* ===== Edit Profile Modal ===== */
.cr-edit-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
}
.cr-edit-box {
  background: var(--fb-card, #fff);
  border-radius: 12px;
  width: 100%; max-width: 380px;
  padding: 24px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,.4);
}
[data-theme="dark"] .cr-edit-box { background: #242526; color: #e4e6eb; }
.cr-edit-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 17px; font-weight: 700;
  margin-bottom: 4px;
}
.cr-edit-close {
  background: #e4e6eb; border: none; border-radius: 50%;
  width: 32px; height: 32px; cursor: pointer; font-size: 16px;
}
[data-theme="dark"] .cr-edit-close { background: #3a3b3c; color: #e4e6eb; }
.cr-edit-input {
  width: 100%; padding: 12px 14px;
  background: #f0f2f5; border: 1px solid transparent;
  border-radius: 8px; font-size: 15px;
  font-family: inherit;
}
[data-theme="dark"] .cr-edit-input { background: #3a3b3c; color: #e4e6eb; border-color: #3a3b3c; }
.cr-edit-input:focus { outline: none; border-color: #1877f2; background: #fff; }
[data-theme="dark"] .cr-edit-input:focus { background: #242526; }
.cr-edit-err { color: #e41e3f; font-size: 13px; min-height: 18px; }
.cr-edit-submit {
  width: 100%; padding: 12px;
  background: #1877f2; border: none; border-radius: 8px;
  color: #fff; font-size: 15px; font-weight: 700; cursor: pointer;
  margin-top: 4px;
}
.cr-edit-submit:hover { background: #166fe5; }
.nav-dd-ico { display: inline-block; width: 22px; margin-right: 8px; text-align: center; font-size: 15px; }
.nav-dd-item { display: flex !important; align-items: center; }


/* ===== 全站滾動條深色主題 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; }
