:root {
  --app-brand: #0284c7;
  --app-brand-dark: #0369a1;
  --app-nav-border: #e2e8f0;
}

.app-nav-root,
.app-nav-root * { box-sizing: border-box; }
.app-nav-root a { color: inherit; text-decoration: none; }
.app-nav-root button { font: inherit; }
.app-nav-root:empty { display: none; }

/* ══════════════ 安靜白頂列 ══════════════
   設計定案（2026-07）：導航是基礎設施不是主角。
   白底細線、灰字；品牌藍只留在 logo、當前頁底線與身分徽章。
   內容的顏色（乾坤、狀態、主要按鈕）才是畫面的主角。 */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: 58px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #ffffff;
  border-bottom: 1px solid var(--app-nav-border);
  transition: transform .28s ease;
}
/* 捲動讓位：往下捲隱藏、往上捲立刻回來（nav.js 控制） */
.app-topbar.nav-hidden { transform: translateY(-105%); }

.app-topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--app-brand-dark);
  font-size: .98rem;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
}
.app-topbar-brand i { color: var(--app-brand); }
.app-topbar-brand img { height: 32px; width: auto; display: block; }
.app-topbar-identity {
  flex-shrink: 0;
  width: 4px;
  height: 24px;
  border-radius: 999px;
  background: var(--pi, transparent);
}
/* 頁面標題：字級明顯大於導航項，讀起來是「標題」不是選單選項 */
.app-topbar-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  max-width: 300px;
  padding-right: 16px;
  border: 0;
  border-right: 1px solid #eef2f6;
  line-height: 1.22;
}
.app-topbar-title .t { display:flex; align-items:center; min-width:0; max-width:100%; color: #0f172a; font-size: 1.1rem; font-weight: 800; letter-spacing: .01em; white-space: nowrap; overflow: hidden; }
.app-topbar-current { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.app-topbar-crumb { flex-shrink:0; max-width:88px; overflow:hidden; color:#64748b !important; font-size:.78rem; font-weight:800; text-overflow:ellipsis; white-space:nowrap; border-bottom:1px solid #cbd5e1; }
.app-topbar-crumb:hover { color:var(--app-brand) !important; border-bottom-color:var(--app-brand); }
.app-topbar-crumb:focus-visible { outline:2px solid #7dd3fc; outline-offset:2px; border-radius:3px; }
.app-topbar-crumb-separator { flex-shrink:0; margin:0 5px; color:#cbd5e1; font-size:.82rem; }
.app-topbar-title .s { color: #94a3b8; font-size: .76rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-topbar-title .s.is-action {
  appearance:none;
  display:flex;
  align-items:center;
  gap:5px;
  min-width:0;
  max-width:100%;
  padding:0;
  border:0;
  border-bottom:1px dashed #cbd5e1;
  background:transparent;
  color:#475569;
  text-align:left;
  cursor:pointer;
}
.app-topbar-title .s.is-action span { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.app-topbar-title .s.is-action i { flex-shrink:0; color:var(--app-brand); font-size:.68rem; }
.app-topbar-title .s.is-action:hover { color:var(--app-brand-dark); border-bottom-color:var(--app-brand); }
.app-topbar-title .s.is-action:focus-visible { outline:2px solid #7dd3fc; outline-offset:2px; border-radius:3px; }
/* 可點擊標題（如 people 切換佛堂，開的是彈窗）：不用下拉箭頭，
   改用虛線底線表示「可更換的值」，hover 轉品牌藍 */
.app-topbar-title.is-action {
  appearance: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.app-topbar-title.is-action .t { border-bottom: 1px dashed #cbd5e1; align-self: flex-start; max-width: 100%; }
.app-topbar-title.is-action:hover .t { color: var(--app-brand); border-bottom-color: var(--app-brand); }
.app-topbar-title.is-action:focus-visible {
  outline: 2px solid #7dd3fc;
  outline-offset: 2px;
  border-radius: 4px;
}

/* 導航項：圖示＋文字，當前頁用底線標示 */
.app-topbar-nav { display: flex; align-items: stretch; gap: 2px; height: 100%; }
.app-nav-item {
  position: relative;
  height: 100%;
  padding: 0 13px;
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #74839a;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  transition: color .15s, background .15s;
}
.app-nav-item i { font-size: 15px; color: #9aa8ba; transition: color .15s; }
.app-nav-item:hover { background: #f8fafc; color: #0f172a; }
.app-nav-item:hover i { color: #64748b; }
.app-nav-item.active { color: var(--app-brand-dark); border-bottom-color: var(--app-brand); font-weight: 800; }
.app-nav-item.active i { color: var(--app-brand); }
.app-nav-item:focus-visible { outline: 2px solid var(--app-brand); outline-offset: -2px; }

.app-topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.app-topbar-action {
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: var(--app-brand);
  color: #fff;
  font-size: .88rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(15,23,42,.12);
}
.app-topbar-action:hover { background: var(--app-brand-dark); }

.app-more-wrap { position: relative; height: 100%; display: flex; align-items: stretch; }
.app-more-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1002;
  width: 240px;
  overflow: hidden;
  border: 1px solid var(--app-nav-border);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 16px 32px rgba(15,23,42,.14);
}
.app-more-user {
  padding: 12px 16px;
  border-bottom: 1px solid var(--app-nav-border);
  background: #f8fafc;
}
.app-more-user .name { color: #0f172a; font-size: .92rem; font-weight: 800; }
.app-more-user .role { margin-top: 2px; color: #64748b; font-size: .76rem; }
.app-more-link {
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  color: #0f172a;
  font-size: .9rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.app-more-link:last-child { border-bottom: 0; }
.app-more-link:hover { background: #f0f9ff; }
.app-more-link i { width: 18px; color: var(--app-brand); text-align: center; }
.app-more-link.logout,
.app-more-link.logout i { color: #b91c1c; }
.app-more-backdrop { position: fixed; inset: 0; z-index: 1001; }

.app-bottom-nav,
.app-more-sheet,
.app-more-sheet-backdrop { display: none; }

@media (max-width: 760px) {
  html, body { overscroll-behavior-y: none; }
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)) !important; }
  .app-topbar { height: 52px; padding: 0 14px; }
  .app-topbar-identity { height: 20px; }
  .app-topbar-nav { display: none; }
  .app-topbar-title { max-width: 46vw; padding-right: 10px; }
  .app-topbar-title .t { font-size: .9rem; }
  .app-topbar-crumb { max-width:54px; font-size:.7rem; }
  .app-topbar-crumb-separator { margin:0 3px; font-size:.72rem; }
  .app-topbar-right { margin-left: auto; }
  .app-topbar-action { min-width: 44px; height: 44px; padding: 0 12px; justify-content: center; font-size: .84rem; }

  /* 固定弹窗与抽屉必须盖过底部导航，否则 modal footer 会被 tab bar 遮住。 */
  .modal-backdrop,
  .modal-mask,
  .report-edit-backdrop,
  .drawer-backdrop { z-index: 1400 !important; }
  .mega-drawer { z-index: 1401 !important; }

  /* 手機導航交給底部分頁列（固定不讓位：拇指操作的主要入口） */
  .app-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    display: block;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--app-nav-border);
    background: #fff;
    box-shadow: 0 -3px 12px rgba(15,23,42,.07);
  }
  .app-bottom-nav-list { display: flex; }
  .app-bottom-nav-item {
    flex: 1;
    min-width: 0;
    padding: 6px 2px;
    border: 0;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    color: #94a3b8;
    font-size: .66rem;
    font-weight: 700;
    cursor: pointer;
  }
  .app-bottom-nav-item i { font-size: 19px; }
  .app-bottom-nav-item.active { color: var(--app-brand); }

  .app-more-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1101;
    display: block;
    background: rgba(15,23,42,.35);
  }
  .app-more-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1102;
    display: block;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-radius: 18px 18px 0 0;
    background: #fff;
    box-shadow: 0 -8px 30px rgba(15,23,42,.2);
  }
  .app-more-sheet-handle {
    width: 36px;
    height: 4px;
    margin: 10px auto;
    border-radius: 2px;
    background: #e2e8f0;
  }
}
