/* 手機版專用樣式（≤900px）— 與桌面版分開維護 */

.forum-mobile-topbar,
.forum-sidebar-backdrop,
.forum-sidebar-close,
.forum-mobile-bottomnav {
  display: none;
}

html.forum-is-mobile .forum-mobile-topbar,
html.forum-is-mobile .forum-mobile-bottomnav {
  display: flex;
}

@media (max-width: 900px) {
  .forum-mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    position: sticky;
    top: 0;
    z-index: 120;
    padding: 0.6rem 0.85rem;
    padding-top: max(0.6rem, env(safe-area-inset-top));
    background: linear-gradient(135deg, var(--btn-from), var(--btn-to));
    border-bottom: none;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  }

  .forum-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    margin: 0;
    padding: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.45);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
  }

  .forum-menu-icon {
    display: block;
    width: 1.15rem;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
  }

  .forum-mobile-brand {
    flex: 1;
    min-width: 0;
    font-weight: 900;
    font-size: 1rem;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .forum-mobile-account {
    flex-shrink: 0;
    padding: 0.45rem 0.8rem;
    border-radius: var(--radius-btn);
    border: 1.5px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 800;
    text-decoration: none;
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
  }

  .forum-mobile-account-primary {
    background: #fff;
    color: var(--accent-text);
    border-color: #fff;
  }

  /* 側欄：預設完全隱藏，開啟時才顯示抽屜 */
  .forum-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
    width: min(300px, 90vw);
    height: 100%;
    height: 100dvh;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 8px 0 32px rgba(15, 23, 42, 0.2);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.forum-nav-open .forum-sidebar {
    display: flex;
  }

  .forum-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 180;
    background: rgba(15, 23, 42, 0.5);
  }

  .forum-sidebar-backdrop[hidden] {
    display: none !important;
  }

  .forum-sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: max(0.65rem, env(safe-area-inset-top));
    right: 0.65rem;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    border-radius: 10px;
    background: var(--bg-panel);
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
  }

  .forum-shell {
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .forum-brand {
    padding-right: 2.75rem;
  }

  .forum-nav {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .forum-nav-item {
    min-height: 2.85rem;
    display: flex;
    align-items: center;
    font-size: 0.95rem;
  }

  .forum-nav-item:hover {
    transform: none;
  }

  .forum-main {
    flex: 1;
    width: 100%;
    max-width: 100%;
    padding: 0.75rem 0.65rem 5rem;
    padding-bottom: max(5rem, calc(env(safe-area-inset-bottom) + 4.5rem));
  }

  .forum-page-head {
    margin-bottom: 0.85rem;
  }

  .forum-page-head h1 {
    font-size: 1.35rem;
    margin-bottom: 0.25rem;
  }

  .forum-page-head .forum-muted {
    font-size: 0.82rem;
    line-height: 1.5;
  }

  .forum-card {
    padding: 0.85rem 0.8rem;
    margin-bottom: 0.75rem;
    border-radius: 12px;
  }

  .forum-card-head {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.35rem 0.5rem;
  }

  .forum-card-head h2 {
    font-size: 0.95rem;
  }

  .forum-dash-panel {
    padding: 0.8rem 0.7rem 0.6rem;
    min-height: 0;
  }

  .forum-grid-dashboard {
    gap: 0.75rem;
  }

  .forum-grid-2 {
    grid-template-columns: 1fr;
  }

  /* 底部快捷導覽 */
  .forum-mobile-bottomnav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 110;
    justify-content: space-around;
    align-items: stretch;
    gap: 0.15rem;
    padding: 0.35rem 0.5rem;
    padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
  }

  .forum-mobile-bottomnav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 3rem;
    padding: 0.25rem 0.15rem;
    border-radius: 10px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
    text-decoration: none;
    line-height: 1.2;
  }

  .forum-mobile-bottomnav a.is-active {
    color: var(--nav-active-text);
    background: var(--nav-active-bg);
  }

  .forum-mobile-bottomnav-icon {
    font-size: 1.05rem;
    line-height: 1;
  }

  /* 首頁排行：卡片列（取代橫向捲動表格） */
  .forum-table-wrap-dash {
    overflow: visible;
    border: none;
    background: transparent;
    margin: 0;
    padding: 0;
  }

  .forum-table-wrap-dash::after {
    display: none !important;
  }

  .forum-table-fund thead,
  .forum-table-cb thead {
    display: none;
  }

  .forum-table-fund tbody tr,
  .forum-table-cb tbody tr {
    display: block;
    background: var(--bg-warm);
    border: 1px solid var(--row-divider);
    border-radius: 10px;
    margin-bottom: 0.45rem;
    padding: 0.6rem 0.7rem;
  }

  .forum-table-fund tbody tr:last-child,
  .forum-table-cb tbody tr:last-child {
    margin-bottom: 0;
  }

  .forum-table-fund td,
  .forum-table-cb td {
    display: inline;
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
    white-space: normal;
  }

  .forum-table-fund .col-rank,
  .forum-table-cb .col-rank {
    display: inline-block;
    min-width: 1.5rem;
    font-weight: 900;
    color: var(--muted);
    margin-right: 0.35rem;
  }

  .forum-table-fund .col-code {
    font-weight: 800;
    color: var(--heading);
    margin-right: 0.25rem;
  }

  .forum-table-fund .col-name {
    font-weight: 600;
    color: var(--text-soft);
  }

  .forum-table-fund .col-amount,
  .forum-table-fund .col-concentration {
    display: block;
    text-align: right;
    font-size: 0.84rem;
    margin-top: 0.2rem;
  }

  .forum-table-fund .col-amount::before {
    content: "買超 ";
    color: var(--muted);
    font-weight: 600;
  }

  .forum-table-fund tbody[data-amount-label] .col-amount::before {
    content: attr(data-amount-label) " ";
    color: var(--muted);
    font-weight: 600;
  }

  .forum-table-fund[data-amount-label] .col-amount::before {
    content: attr(data-amount-label) " ";
    color: var(--muted);
    font-weight: 600;
  }

  .forum-table-fund .col-concentration.is-high {
    color: #dc2626;
    font-weight: 800;
  }

  .forum-table-fund.is-flow-sell .col-concentration.is-high {
    color: #059669;
    font-weight: 800;
  }

  .forum-table-fund .col-concentration::before {
    content: "集中度 ";
    color: var(--muted);
    font-weight: 600;
  }

  .forum-table-cb .col-name {
    font-weight: 800;
    color: var(--heading);
    margin-right: 0.35rem;
  }

  .forum-table-cb .col-code {
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 700;
  }

  .forum-table-cb .col-vol,
  .forum-table-cb .col-px,
  .forum-table-cb .col-prem {
    display: inline-block;
    font-size: 0.8rem;
    margin-top: 0.35rem;
    margin-right: 0.65rem;
  }

  .forum-table-cb .col-vol::before {
    content: "量 ";
    color: var(--muted);
    font-weight: 600;
  }

  .forum-table-cb .col-px::before {
    content: "收 ";
    color: var(--muted);
    font-weight: 600;
  }

  .forum-table-cb .col-prem::before {
    content: "溢價 ";
    color: var(--muted);
    font-weight: 600;
  }

  /* 其他頁面表格仍可橫向滑動 */
  .forum-table-wrap:not(.forum-table-wrap-dash) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.15rem;
    padding: 0 0.15rem 0.35rem;
  }

  .forum-table-wrap:not(.forum-table-wrap-dash)::after {
    content: "← 左右滑動查看更多 →";
    display: block;
    text-align: center;
    font-size: 0.72rem;
    color: var(--muted);
    padding: 0.35rem 0 0.15rem;
  }

  .forum-table-wrap .forum-admin-table {
    min-width: 640px;
  }

  .forum-btn,
  .forum-btn-inline {
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .forum-sidebar-foot .forum-btn {
    min-height: 2.75rem;
  }

  .forum-post-title {
    font-size: 1rem;
    line-height: 1.45;
  }

  .forum-post-card {
    padding: 0.95rem !important;
  }

  .forum-post-meta {
    flex-wrap: wrap;
    gap: 0.35rem 0.5rem;
  }

  .forum-post-admin-actions {
    gap: 0.4rem;
  }

  .forum-admin-chip {
    min-height: 2.35rem;
    padding: 0.35rem 0.8rem;
  }

  .forum-admin-inline-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .forum-article-head h1 {
    font-size: 1.28rem;
  }

  .forum-paywall-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .forum-paywall-actions .forum-btn {
    width: 100%;
  }

  .forum-login-card {
    max-width: none;
  }

  .forum-admin-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .forum-admin-tab {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .forum-image-upload {
    flex-direction: column;
    align-items: stretch;
  }

  .forum-md-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .forum-md-toolbar-group {
    flex-shrink: 0;
  }

  .forum-md-btn,
  .forum-md-select,
  .forum-md-color {
    min-height: 44px;
    min-width: 44px;
  }

  .forum-upload-label {
    width: 100%;
    justify-content: center;
  }

  .forum-fund-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.15rem;
  }

  .forum-fund-tab {
    flex: 1 0 auto;
    min-height: 2.5rem;
    white-space: nowrap;
  }

  .forum-news-list-compact li {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  .forum-theme-switch {
    flex-wrap: wrap;
  }
}

/* JS 備援：html.forum-is-mobile 與 media query 雙軌 */
html.forum-is-mobile .forum-sidebar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  width: min(300px, 90vw);
  height: 100dvh;
}

html.forum-is-mobile body.forum-nav-open .forum-sidebar {
  display: flex;
}

html.forum-is-mobile .forum-shell {
  flex-direction: column;
}

html.forum-is-mobile .forum-main {
  width: 100%;
  padding-bottom: max(5rem, calc(env(safe-area-inset-bottom) + 4.5rem));
}

/* 頂部橫幅跑馬燈（手機版精簡） */
@media (max-width: 900px) {
  .forum-promo-link {
    gap: 0.55rem;
    padding: 0.5rem 2.5rem 0.5rem 0.85rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
  }

  .forum-promo-text {
    font-size: 0.85rem;
    padding-right: 2.5rem;
  }

  .forum-promo-cta {
    font-size: 0.8rem;
    padding: 0.24rem 0.6rem;
  }

  .forum-promo-close {
    width: 1.7rem;
    height: 1.7rem;
    right: 0.4rem;
  }
}
