/* Shared member topbar — Dashboard / 盤前 / ETF計劃 / 雷達 / 篩選器 / 停損計算器 / 術語表 / 交易方法 */
.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 40;
  overflow: visible;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: max-content;
  text-decoration: none;
  color: inherit;
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: max-content;
}
.brand-name {
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.2;
  white-space: nowrap;
  min-width: max-content;
}
.top-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.nav-link {
  text-decoration: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.nav-link:hover {
  color: var(--text);
  background: var(--s2);
}
.nav-link.active {
  color: var(--primary);
  background: color-mix(in oklab, var(--primary) 12%, transparent);
  border-color: color-mix(in oklab, var(--primary) 26%, transparent);
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.top-date {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Visually hidden, but still toggled by its label. Kept out of the hit area. */
.nav-check {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--s2, var(--surface));
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  touch-action: manipulation;
}
.nav-toggle-close { display: none; }
.nav-check:focus-visible ~ .nav-toggle {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}
.nav-check:checked ~ .nav-toggle .nav-toggle-open { display: none; }
.nav-check:checked ~ .nav-toggle .nav-toggle-close { display: inline; }

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    padding: 8px 12px;
  }
  .top-nav {
    order: 3;
    flex: 1 1 100%;
    width: auto;
    max-width: 100%;
    min-width: 0;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    touch-action: pan-x;
  }
  .nav-link {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 16px;
    position: relative;
    z-index: 1;
    touch-action: manipulation;
  }

  /* Links stay on screen. A closed「選單」button hid every other page. */
  .topbar:has(.nav-check) {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "brand actions"
      "nav nav";
    align-items: center;
    row-gap: 2px;
  }
  .topbar:has(.nav-check) .brand {
    grid-area: brand;
    min-width: max-content;
    position: relative;
    z-index: 2;
  }
  .topbar:has(.nav-check) .nav-toggle {
    display: none;
  }
  .topbar:has(.nav-check) .top-actions {
    grid-area: actions;
    justify-self: end;
    position: relative;
    z-index: 2;
  }
  .topbar:has(.nav-check) .top-nav {
    grid-area: nav;
    display: flex;
    position: static;
    flex: none;
    width: auto;
    max-width: none;
    max-height: none;
    flex-direction: row;
    align-items: center;
    padding: 0;
    background: transparent;
    border-bottom: 0;
    box-shadow: none;
    z-index: 1;
  }
}

@media (max-width: 640px) {
  .topbar:has(.nav-check) .top-date { display: none; }
}

@media (max-width: 420px) {
  .brand-name { font-size: 13px; }
}
