/* ============================================================
   TOPNAV — mobile-first, three zones, auto-overflow.
   Single source of truth (2026-05-01 rebuild). Pages MUST NOT
   redefine .topnav, .topnav__*, or .nav-btn rules inline — those
   conflict and were the cause of the previous five-patch chase.
   ============================================================ */

body { padding-top: 0; }

.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(11, 13, 26, 0.85);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 56px;
}

@media (min-width: 768px) {
  .topnav { padding: 12px 20px; gap: 16px; }
}

/* ── Three zones ───────────────────────────────────────── */
.topnav__left,
.topnav__nav,
.topnav__right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topnav__left  { flex: 0 0 auto; }
.topnav__nav   { flex: 1 1 auto; justify-content: flex-end; position: relative; }
.topnav__right { flex: 0 0 auto; }

/* ── Brand ─────────────────────────────────────────────── */
.topnav__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text, #e7e9f4);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.topnav__brand-icon {
  width: 24px; height: 24px;
  border-radius: 7px;
  background: linear-gradient(135deg, #7c6dfa, #22d4fd);
  flex-shrink: 0;
}
.topnav__brand-sub {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 400;
  font-size: 12px;
  color: var(--mute, #a4a8c0);
}

@media (max-width: 480px) {
  .topnav__brand-sub { display: none; }
  .topnav__brand-name { font-size: 14px; }
}

/* ── Chips (status indicators, NOT navigation) ─────────── */
.topnav__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--mute, #a4a8c0);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.topnav__chip--credits {
  background: rgba(124, 109, 250, 0.10);
  color: #b6acff;
  font-weight: 500;
}
.topnav__chip--credits:hover { background: rgba(124, 109, 250, 0.18); }
.topnav__chip-icon { font-size: 12px; line-height: 1; }
.topnav__chip-value { font-weight: 600; color: var(--text, #e7e9f4); }
.topnav__chip-label { color: var(--mute, #a4a8c0); }

@media (max-width: 1024px) { .topnav__chip--storage { display: none; } }
@media (max-width: 480px)  { .topnav__chip-label { display: none; } }

/* ── Buttons ──────────────────────────────────────────── */
.topnav__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: var(--text, #e7e9f4);
  font-size: 13px;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.topnav__btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
}
.topnav__btn[aria-current="page"] {
  background: rgba(124, 109, 250, 0.14);
  border-color: rgba(124, 109, 250, 0.36);
  color: #d4ccff;
}
.topnav__icon-btn { width: 36px; padding: 0; }
.topnav__btn--signout { color: #ff8593; }
.topnav__btn--signout:hover {
  background: rgba(255, 92, 122, 0.10);
  border-color: rgba(255, 92, 122, 0.32);
}

/* ── More button + overflow panel ──────────────────────── */
.topnav__more svg { transition: transform 0.15s; }
.topnav__more[aria-expanded="true"] svg { transform: rotate(180deg); }
.topnav__more-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: #131626;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}
.topnav__more-panel[hidden] { display: none; }
.topnav__more-panel .topnav__btn {
  width: 100%;
  justify-content: flex-start;
  border: 0;
  background: transparent;
  height: 40px;
}
.topnav__more-panel .topnav__btn:hover { background: rgba(255, 255, 255, 0.06); }

/* ── Feature gates ─────────────────────────────────────── */
.member-feature { display: none; }
.admin-only     { display: none; }
body.is-admin .member-feature,
body.is-admin .admin-only,
body.is-member .member-feature { display: inline-flex; }
body.is-admin .topnav__more-panel .member-feature,
body.is-admin .topnav__more-panel .admin-only,
body.is-member .topnav__more-panel .member-feature { display: flex; }

/* ── Mobile: replace nav zone with hamburger + drawer ──── */
.topnav__hamburger {
  display: none;
  width: 40px; height: 40px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 10px;
  padding: 0;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  color: var(--text, #e7e9f4);
}
.topnav__hamburger span {
  width: 18px; height: 2px;
  background: currentColor;
  border-radius: 2px;
}

@media (max-width: 768px) {
  .topnav__nav { display: none; }
  .topnav__right .topnav__btn--signout { display: none; }
  .topnav__hamburger { display: inline-flex; }
}

/* ── Mobile drawer ─────────────────────────────────────── */
.topnav-drawer { position: fixed; inset: 0; z-index: 100; }
.topnav-drawer[hidden] { display: none; }
.topnav-drawer__backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.topnav-drawer__panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(82vw, 320px);
  background: #0b0d1a;
  border-left: 1px solid rgba(255, 255, 255, 0.10);
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.topnav-drawer:not([hidden]) .topnav-drawer__panel { transform: translateX(0); }
.topnav-drawer__close {
  align-self: flex-end;
  width: 40px; height: 40px;
  background: transparent;
  border: 0;
  color: var(--mute, #a4a8c0);
  font-size: 24px;
  cursor: pointer;
}
.topnav-drawer__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}
.topnav-drawer__nav .topnav__btn {
  width: 100%;
  justify-content: flex-start;
  height: 44px;
  border: 0;
  background: transparent;
  font-size: 15px;
}
.topnav-drawer__nav .topnav__btn:hover { background: rgba(255, 255, 255, 0.06); }

/* ── Light theme overrides ─────────────────────────────── */
/* `data-theme` is set on the <html> root by /js/theme.js — selectors
   below use the bare attribute selector so they match the documentElement
   regardless of whether body also carries the attribute. */
[data-theme="light"] .topnav {
  background: rgba(247, 248, 252, 0.85);
  border-bottom-color: rgba(20, 22, 43, 0.10);
}
[data-theme="light"] .topnav__btn {
  border-color: rgba(20, 22, 43, 0.12);
  color: #14162b;
}
[data-theme="light"] .topnav__btn:hover {
  background: rgba(20, 22, 43, 0.05);
  border-color: rgba(20, 22, 43, 0.22);
}
[data-theme="light"] .topnav__chip {
  /* Base chip bg in dark theme is white-on-dark glass; on light bg the
     same translucent white is invisible — give it a subtle dark tint. */
  background: rgba(20, 22, 43, 0.04);
}
[data-theme="light"] .topnav__chip--credits {
  /* Keep the violet accent — it reads on both backgrounds. */
  background: rgba(124, 109, 250, 0.12);
  color: #5a4be0;
}
[data-theme="light"] .topnav__chip--credits:hover {
  background: rgba(124, 109, 250, 0.20);
}
[data-theme="light"] .topnav__hamburger {
  border-color: rgba(20, 22, 43, 0.12);
  color: #14162b;
}
[data-theme="light"] .topnav__more-panel,
[data-theme="light"] .topnav-drawer__panel {
  background: #ffffff;
  border-color: rgba(20, 22, 43, 0.10);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .topnav__more-panel .topnav__btn:hover,
[data-theme="light"] .topnav-drawer__nav .topnav__btn:hover {
  background: rgba(20, 22, 43, 0.05);
}
