/* 主站功能網殼：隱藏入口／多頁籤導覽；網殼與主 header 合併為單一頂欄 */
html.tm-feature-net,
body.tm-feature-net {
  --tm-feature-net-bar-h: 52px;
}

/* 前往獨立網（聊天／聚落／揪團等）前的極短淡出，減少白屏感 */
html.tm-nav-leaving {
  opacity: 0.94;
  transition: opacity 0.08s ease-out;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
  html.tm-nav-leaving {
    opacity: 1;
    transition: none;
  }
}

/* 併入 header-top-row 的網殼叢集（不再獨立 sticky 第二列） */
.tm-feature-net-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  /* 勿吃滿整列，否則 tools 的 margin-left:auto 會與右側 header-actions 搶位、擠壓 logo */
  flex: 0 1 auto;
  min-height: 0;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  position: static;
  box-sizing: border-box;
}

body.tm-feature-net .header-top-row.header-top-row--feature-net,
body.tm-feature-net #home-view .header .header-top-row,
body.tm-feature-net .header .header-top-row {
  position: sticky;
  top: 0;
  z-index: 12000;
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: var(--tm-feature-net-bar-h);
  margin-bottom: 10px;
  padding: 6px 4px;
  padding-top: max(6px, env(safe-area-inset-top));
  padding-left: max(4px, env(safe-area-inset-left));
  padding-right: max(4px, env(safe-area-inset-right));
  background: var(--bg-main, rgba(255, 255, 255, 0.96));
  border-bottom: 1px solid var(--border-soft, #e2e8f0);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-sizing: border-box;
}

body.dark-mode.tm-feature-net #home-view .header .header-top-row,
html.dark body.tm-feature-net #home-view .header .header-top-row,
html[data-tm-scheme="dark"] body.tm-feature-net #home-view .header .header-top-row,
body.dark-mode.tm-feature-net .header .header-top-row,
html[data-tm-scheme="dark"] body.tm-feature-net .header .header-top-row {
  background: var(--bg-main, rgba(15, 23, 42, 0.96));
  border-bottom-color: var(--border-soft, #334155);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* 尚未掛入 header 前的暫掛狀態（避免閃兩列；掛入後改為透明內嵌） */
body > .tm-feature-net-bar {
  position: sticky;
  top: 0;
  z-index: 12000;
  width: 100%;
  min-height: var(--tm-feature-net-bar-h);
  padding: 6px 10px;
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--bg-main, rgba(255, 255, 255, 0.94));
  border-bottom: 1px solid var(--border-soft, #e2e8f0);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

body.dark-mode > .tm-feature-net-bar,
html.dark body > .tm-feature-net-bar,
html[data-tm-scheme="dark"] body > .tm-feature-net-bar {
  background: var(--bg-main, rgba(15, 23, 42, 0.94));
  border-bottom-color: var(--border-soft, #334155);
}

.tm-feature-net-bar__home,
.tm-feature-net-bar__refresh,
.tm-feature-net-bar__install,
.tm-feature-net-bar__ai {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-soft, #e2e8f0);
  background: var(--card-bg, var(--bg-surface, #f8fafc));
  color: var(--text-main, #0f172a);
  text-decoration: none;
  cursor: pointer;
  padding: 0;
}

body.dark-mode .tm-feature-net-bar__home,
body.dark-mode .tm-feature-net-bar__refresh,
body.dark-mode .tm-feature-net-bar__install,
body.dark-mode .tm-feature-net-bar__ai,
html.dark .tm-feature-net-bar__home,
html.dark .tm-feature-net-bar__refresh,
html.dark .tm-feature-net-bar__install,
html.dark .tm-feature-net-bar__ai,
html[data-tm-scheme="dark"] .tm-feature-net-bar__home,
html[data-tm-scheme="dark"] .tm-feature-net-bar__refresh,
html[data-tm-scheme="dark"] .tm-feature-net-bar__install,
html[data-tm-scheme="dark"] .tm-feature-net-bar__ai {
  background: var(--card-bg, var(--bg-surface, #1e293b));
  border-color: var(--border-soft, #334155);
  color: var(--text-main, #f1f5f9);
}

.tm-feature-net-bar__home svg,
.tm-feature-net-bar__refresh svg,
.tm-feature-net-bar__install svg,
.tm-feature-net-bar__ai svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tm-feature-net-bar__install[hidden] {
  display: none !important;
}

.tm-feature-net-bar__brand {
  flex: 0 0 auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: none;
  overflow: visible;
}

.tm-feature-net-bar__title {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 9em;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  color: var(--text-main, #0f172a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.dark-mode .tm-feature-net-bar__title,
html.dark .tm-feature-net-bar__title,
html[data-tm-scheme="dark"] .tm-feature-net-bar__title {
  color: var(--text-main, #f8fafc);
}

.tm-feature-net-bar__tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  /* 貼近左側網殼（回主頁／logo／網名），右側空間留給 header-actions */
  margin-left: 4px;
}

body.tm-feature-net #home-view .header .header-actions,
body.tm-feature-net .header .header-actions {
  flex: 0 0 auto;
  flex-shrink: 0;
  margin-left: auto !important;
  margin-right: 0 !important;
  gap: 8px;
}

/* 功能網殼已有 AI：隱藏主站 header 再插的那顆，避免雙 AI 疊在一起 */
body.tm-feature-net #home-view .header .header-actions .tm-mate-assist-btn--header,
body.tm-feature-net .header .header-actions .tm-mate-assist-btn--header,
body.tm-feature-net #home-view .header .header-actions > [data-tm-mate-assist-btn].tm-mate-assist-btn--header {
  display: none !important;
}

/* 功能網：縮小 LOGO，與單列頂欄比例一致；避免被 flex 擠扁／裁切 */
body.tm-feature-net #main-title-area {
  flex: 0 0 auto !important;
  min-width: 0;
  max-width: none !important;
  overflow: visible !important;
  align-items: center;
}

body.tm-feature-net #main-title-area .tm-hub-logo-btn {
  flex: 0 0 auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  max-width: none;
}

body.tm-feature-net #main-title-area .tm-brand-logo,
body.tm-feature-net #main-title-area img.tm-brand-logo {
  height: 40px !important;
  width: auto !important;
  max-width: none !important;
  max-height: 40px !important;
  margin-right: 0 !important;
  object-fit: contain !important;
  flex-shrink: 0;
}

body.tm-feature-net .app-bottom-nav,
body.tm-feature-net #app-bottom-nav,
body.tm-feature-net #village-menu-container,
body.tm-feature-net #village-sub-buttons,
body.tm-feature-net #quick-nav-sidebar,
body.tm-feature-net #sidebar-toggle-btn,
body.tm-feature-net .quick-nav-sidebar,
body.tm-feature-net .mega-tab-buttons,
body.tm-feature-net .sub-tab-row,
body.tm-feature-net #android-app-promo,
body.tm-feature-net .android-app-promo,
body.tm-feature-net .tm-hub-nav-btn {
  display: none !important;
}

body.tm-feature-net #home-view .header .header-top-row .mega-tab-buttons,
body.tm-feature-net #home-view .header .sub-pill-bar,
body.tm-feature-net .sub-pill-bar {
  display: none !important;
}

body.tm-feature-net .app-container {
  padding-bottom: 12px !important;
}

body.tm-feature-net #home-view > .header {
  margin-bottom: 8px;
}

@media (max-width: 900px) {
  body.tm-feature-net .header-colony-btn__label,
  body.tm-feature-net .header-chat-btn__label,
  body.tm-feature-net .header-menu-btn__label {
    display: none;
  }

  body.tm-feature-net #home-view .header .header-actions,
  body.tm-feature-net .header .header-actions {
    gap: 6px;
  }
}

@media (max-width: 800px) {
  /* 手機：功能網次要工具（AI／刷新／加到主畫面）收進「更多」選單，左側只留回主頁＋logo */
  body.tm-feature-net .tm-feature-net-bar__tools {
    display: none !important;
  }

  body.tm-feature-net .tm-feature-net-bar {
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 7.75rem);
    overflow: hidden;
  }

  body.tm-feature-net #home-view .header .header-top-row,
  body.tm-feature-net .header .header-top-row {
    gap: 6px;
  }

  body.tm-feature-net #home-view .header .header-actions,
  body.tm-feature-net .header .header-actions {
    margin-left: 0 !important;
  }
}

@media (max-width: 720px) {
  body.tm-feature-net #home-view .header .header-brand-text,
  body.tm-feature-net #main-title-area .brand-sub {
    display: none;
  }

  body.tm-feature-net #main-title-area .tm-brand-logo,
  body.tm-feature-net #main-title-area img.tm-brand-logo {
    height: 32px !important;
    max-height: 32px !important;
    width: auto !important;
  }

  body.tm-feature-net .tm-feature-net-bar__title {
    max-width: 4.8em;
    font-size: 0.88rem;
  }

  body.tm-feature-net .tm-feature-net-bar__home,
  body.tm-feature-net .tm-feature-net-bar__refresh,
  body.tm-feature-net .tm-feature-net-bar__install,
  body.tm-feature-net .tm-feature-net-bar__ai {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }

  /* 極窄：加到主畫面收入次要（仍可於選單下載 Apps） */
  body.tm-feature-net .tm-feature-net-bar__install {
    display: none !important;
  }
}

@media (max-width: 520px) {
  body.tm-feature-net .tm-feature-net-bar__title {
    display: none;
  }

  body.tm-feature-net #layout-switch-btn {
    display: none !important;
  }
}
