/* Topbar — sticky chrome at the top of every authenticated page.
 * Contains: brand badge + wordmark, env pill, live status chip,
 * tab strip, user-menu chip + popover, hamburger (mobile only).
 *
 * The user-pop is anchored to .user-trigger so it lives here even
 * though it visually floats below the bar.
 */

/* Bar geometry — `--topbar-h` is the *total* sticky height (declared
   in the theme), the chips inside are 32px and live in `--chip-h`.
   The bar uses min-height (not fixed height) so any rogue oversized
   child grows the bar instead of overflowing; `align-items: center`
   then puts every chip on the bar's vertical centerline. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  min-height: var(--topbar-h);
  box-sizing: border-box;
  background: linear-gradient(180deg,
    rgba(var(--bg-rgb), 0.85) 0%,
    rgba(var(--bg-rgb), 0.7) 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  /* Glow stripe under the topbar — matches the gold accent without
     a hard rule. */
  box-shadow:
    0 1px 0 rgba(var(--accent-rgb), 0.10),
    0 8px 30px -20px var(--shadow-strong);
}
/* Slow gold shimmer that sweeps the bottom edge — barely there, but
   the bar feels like it's breathing. 12s loop so it's never
   distracting; just present. */
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(var(--accent-rgb), 0.0) 25%,
    rgba(var(--accent-rgb), 0.7) 50%,
    rgba(var(--accent-rgb), 0.0) 75%,
    transparent 100%);
  background-size: 200% 100%;
  animation: topbar-shimmer 12s ease-in-out infinite;
  pointer-events: none;
}
@keyframes topbar-shimmer {
  0%, 100% { background-position: -100% 0; opacity: 0.4; }
  50%      { background-position:  100% 0; opacity: 1; }
}

.topbar .left,
.topbar nav,
.topbar .right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar a { color: inherit; text-decoration: none; }

/* --- brand: badge + wordmark + env slug ------------------------- */
.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--chip-h);
  padding: 0 6px 0 2px;
  border-radius: 999px;
  transition: background 0.15s ease;
}
.topbar .brand:hover { background: rgba(var(--accent-rgb), 0.06); }
.topbar .brand:hover .badge::before { opacity: 1; }
.topbar .brand .badge {
  position: relative;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  isolation: isolate;
}
/* Slowly-rotating conic halo behind the mascot. Heartbeat, not flash. */
.topbar .brand .badge::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background:
    conic-gradient(from 0deg,
      rgba(var(--accent-rgb), 0.0) 0deg,
      rgba(var(--accent-rgb), 0.45) 90deg,
      rgba(var(--accent-rgb), 0.0) 200deg,
      rgba(var(--accent-rgb), 0.0) 360deg);
  filter: blur(3px);
  opacity: 0.7;
  animation: brand-halo-spin 8s linear infinite;
  z-index: -1;
  transition: opacity 0.2s ease;
}
.topbar .brand .badge::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--accent-rgb), 0.32) 0%, transparent 70%);
  z-index: -1;
}
.topbar .brand .badge img {
  width: 26px; height: 26px;
  filter: drop-shadow(0 0 5px rgba(var(--accent-rgb), 0.5));
  transition: transform 0.2s ease;
}
.topbar .brand:hover .badge img { transform: scale(1.04); }
@keyframes brand-halo-spin { to { transform: rotate(360deg); } }

.topbar .brand .name {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 16px;
  color: var(--text);
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
/* The dot in `labrador.` glows softly so the wordmark feels alive
   without competing with the cursor on the home hero. */
.topbar .brand .name .accent {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(var(--accent-rgb), 0.55);
}
.topbar .brand .env {
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(var(--slate-rgb), 0.25);
  border: 1px solid rgba(var(--slate-rgb), 0.5);
  color: var(--slate-text);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* --- live status chip ------------------------------------------ */
.topbar .live {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(var(--positive-rgb), 0.10);
  border: 1px solid rgba(var(--positive-rgb), 0.32);
  color: var(--positive);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-sizing: border-box;
  overflow: hidden;
}
/* Slow router-LED sweep across the chip's bottom — feels like a
   transmitting status light. */
.topbar .live::after {
  content: "";
  position: absolute;
  left: -40%; right: 0;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(var(--positive-rgb), 0.0) 30%,
    rgba(var(--positive-rgb), 0.95) 50%,
    rgba(var(--positive-rgb), 0.0) 70%,
    transparent 100%);
  animation: live-sweep 4.5s ease-in-out infinite;
}
.topbar .live .dot {
  width: 7px; height: 7px;
  background: var(--positive);
  border-radius: 50%;
  box-shadow:
    0 0 8px rgba(var(--positive-rgb), 0.85),
    0 0 18px rgba(var(--positive-rgb), 0.35);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes live-sweep {
  0%   { transform: translateX(0%); opacity: 0; }
  15%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateX(220%); opacity: 0; }
}

/* --- center tab strip ------------------------------------------ */
/* Text-only tabs with a gold underline on the active tab. Scales to
   many entries (doghouse, marketplace, tokens, …) without crowding
   the bar. Each tab is 32px tall to share the topbar's baseline with
   brand/live/user-trigger. */
.topbar .tabs {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 32px;
}
/* Subway-track line that runs the length of the tab strip — the
   active underline rides on top of it so visited/active stations
   feel connected. */
.topbar .tabs::before {
  content: "";
  position: absolute;
  left: 12px; right: 12px;
  bottom: -13px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--line) 15%,
    var(--line) 85%,
    transparent 100%);
  pointer-events: none;
}
.topbar .tabs .tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 14px;
  box-sizing: border-box;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.01em;
  border-radius: 6px;
  position: relative;
  transition: color 0.15s ease, background 0.12s ease;
  text-decoration: none;
}
.topbar .tabs .tab .ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  font-size: 11px;
  color: var(--text-soft);
  transition: color 0.15s ease, transform 0.18s ease, text-shadow 0.2s ease;
}
.topbar .tabs .tab:hover { color: var(--text); }
.topbar .tabs .tab:hover .ico {
  color: var(--accent);
  transform: translateX(-1px);
}
.topbar .tabs .tab.active { color: var(--accent); }
.topbar .tabs .tab.active .ico {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(var(--accent-rgb), 0.7);
}
.topbar .tabs .tab.active::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px;
  bottom: -13px;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--accent) 20%,
    var(--accent-bright) 50%,
    var(--accent) 80%,
    transparent 100%);
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.7);
}
/* "Station" dot on the track underneath each non-active tab. */
.topbar .tabs .tab:not(.active)::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--line-soft);
  transition: background 0.15s ease;
}
.topbar .tabs .tab:not(.active):hover::before {
  background: rgba(var(--accent-rgb), 0.5);
}

/* --- generic topbar nav links (legacy CTA / secondary) --------- */
.topbar nav a {
  font-size: 14px;
  color: var(--text-muted);
  transition: color 0.15s ease, background 0.15s ease;
}
.topbar nav a:hover { color: var(--text); }
.topbar nav a.secondary {
  padding: 7px 12px;
  border-radius: 6px;
}
.topbar nav a.secondary:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}
.topbar nav a.cta {
  padding: 8px 16px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 14px -4px rgba(var(--accent-rgb), 0.5);
  transition: all 0.15s ease;
}
.topbar nav a.cta:hover {
  color: var(--bg);
  background: var(--accent-bright);
  box-shadow: 0 6px 20px -4px rgba(var(--accent-rgb), 0.7);
  transform: translateY(-1px);
}

/* --- user menu (chip + popover) -------------------------------- */
/* Chip-style trigger with avatar + name + caret, opens a small
   popover with the identity card and actions. The chip is the only
   place logout lives now; the popover keeps room for usage and
   future settings shortcuts. */
.user-menu { position: relative; display: inline-flex; align-items: center; }
.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--chip-h);
  padding: 0 12px 0 3px;
  margin: 0;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text);
  font: inherit;
  line-height: 1;
  vertical-align: middle;
  -webkit-appearance: none;
  appearance: none;
}
.user-trigger:hover {
  border-color: rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.04);
}
.user-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.08);
}
.user-trigger .avatar {
  position: relative;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  flex: 0 0 auto;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.user-trigger:hover .avatar {
  transform: scale(1.06);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.18);
}
/* Status bead inside the avatar — same color language as the live
   chip. Today always green = online; later, gold = throttled, red
   = expired. */
.user-trigger .avatar::after {
  content: "";
  position: absolute;
  right: 0; bottom: 0;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--positive);
  box-shadow:
    0 0 0 2px var(--surface-elevated),
    0 0 6px rgba(var(--positive-rgb), 0.7);
  animation: pulse 2.4s ease-in-out infinite;
}
.user-trigger .who-name {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-trigger .caret {
  display: inline-flex;
  align-items: center;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1;
  transition: transform 0.15s ease;
}
.user-trigger[aria-expanded="true"] .caret {
  transform: rotate(180deg);
  color: var(--accent);
}

.user-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  background: linear-gradient(180deg, var(--surface-userpop-top) 0%, var(--surface-userpop-bot) 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow:
    0 14px 40px -10px var(--shadow-deep),
    0 0 0 1px rgba(var(--accent-rgb), 0.06);
  padding: 6px;
  z-index: 30;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}
.user-pop.open {
  opacity: 1;
  transform: translateY(0);
}
.user-pop-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.user-pop-head .avatar.lg {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  flex: 0 0 auto;
}
.user-pop-head .meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.user-pop-head .meta strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-pop-head .meta .email {
  color: var(--text-soft);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-pop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: color 0.12s ease, background 0.12s ease;
}
.user-pop-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.user-pop-item.logout:hover { color: var(--negative-soft); }
.user-pop-item .ico {
  width: 18px;
  color: var(--accent);
  font-size: 13px;
  text-align: center;
}
.user-pop-item .badge-soon {
  margin-left: auto;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(155, 182, 208, 0.1);
  color: var(--slate-soft);
  border: 1px solid rgba(var(--slate-rgb), 0.3);
}
.user-pop form.inline { margin: 0; }

/* --- hamburger (mobile only) ----------------------------------- */
.hamburger {
  display: none;
  width: 32px; height: 32px;
  padding: 0;
  box-sizing: border-box;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.hamburger span {
  display: block;
  width: 16px; height: 2px;
  background: var(--text);
  border-radius: 2px;
}
.hamburger:hover { border-color: var(--accent); }
.hamburger:hover span { background: var(--accent); }

/* --- pulse keyframe used by avatar bead, eyebrow dot, etc. ---- */
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

/* --- mobile breakpoint (700px) --------------------------------- */
/* The center tab strip + user menu fold into the drawer below the
   hamburger threshold; the brand stays as the home link. */
@media (max-width: 700px) {
  .topbar .live,
  .topbar .brand .env { display: none; }
  .topbar .tabs,
  .topbar .user-menu { display: none; }
  .hamburger { display: inline-flex; }
  /* The hamburger is the only child in `.right` on mobile, but the
     wordmark next to it has its optical center a hair above the box
     center because of font ascender bias. Nudging the hamburger up
     1px lines up the visual midline with the wordmark. */
  .hamburger { margin-top: -1px; }
  .topbar { padding: 8px 14px; gap: 10px; }
  .topbar .brand .name { font-size: 15px; }
}
