/* ============================================
   MODERN NAVIGATION BAR - iSpirits Cloud
   Premium glassmorphism with dynamic island style
   ============================================ */

/* WCAG 2.5.5 tap target minimum (44×44px) on mobile.
   Added 2026-04-14 from launch readiness audit — fixes ~18 small
   tap target findings across the feature pages. Mobile-only so
   desktop compact toolbars aren't disrupted. Applies to anchor
   buttons, real buttons, role=button, and form input buttons.
   Icon buttons keep their size via min-width/min-height working
   with box-sizing. Uses :not() to exclude nav items which are
   already sized via var(--nav-height). */
@media (max-width: 768px) {
  button:not(.nav-menu-item):not(.nav-logo),
  a.btn, a.button, a[role="button"],
  [role="button"],
  input[type="button"],
  input[type="submit"],
  input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    box-sizing: border-box;
  }
}

/* CSS Variables for Navigation */
:root {
  --nav-height: 70px;
  --nav-bg: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(10, 18, 36, 0.88));
  --nav-border: rgba(79, 172, 254, 0.2);
  --nav-border-hover: rgba(148, 121, 255, 0.4);
  --nav-glow: rgba(79, 172, 254, 0.15);
  --nav-accent: #4FACFE;
  --nav-accent-2: #9479FF;
  --nav-text: rgba(248, 250, 252, 0.9);
  --nav-text-muted: rgba(148, 163, 184, 0.8);
  --nav-text-hover: #ffffff;
  --nav-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  --nav-z-index: 30000;
  /* Increased to avoid conflicts */
  --dropdown-bg: linear-gradient(145deg, rgba(15, 23, 42, 0.98), rgba(10, 18, 36, 0.95));
  --dropdown-shadow: 0 20px 48px rgba(0, 0, 0, 0.4);
}

/* Cozy mode: warm light nav chrome so the nav doesn't float as a midnight
   strip over the cream body. Additive override — nav CSS keeps using
   var(--nav-*) names and automatically switches to light values when
   data-ux-mode="cozy" is set on <html>. */
:root[data-ux-mode="cozy"] {
  --nav-bg: linear-gradient(145deg, hsla(30, 30%, 100%, 0.95), hsla(30, 25%, 98%, 0.92));
  --nav-border: hsla(200, 40%, 55%, 0.24);
  --nav-border-hover: hsla(250, 50%, 60%, 0.42);
  --nav-glow: hsla(200, 60%, 55%, 0.12);
  --nav-text: hsl(30, 10%, 18%);
  --nav-text-muted: hsl(30, 10%, 38%);
  --nav-text-hover: hsl(30, 10%, 10%);
  --nav-shadow: 0 8px 32px rgba(15, 23, 42, 0.1);
  --dropdown-bg: linear-gradient(145deg, hsla(30, 30%, 100%, 0.98), hsla(30, 25%, 98%, 0.95));
  --dropdown-shadow: 0 20px 48px rgba(15, 23, 42, 0.18);
}

/* Body padding helper */
/* Only apply the 70px top padding when the legacy fixed `.top-nav` is actually
   visible. When AppShell.js mounts the sidebar (body.product-page), the
   `.top-nav` is hidden (display:none) and the padding is dead space. */
body.has-top-nav:not(.product-page) {
  padding-top: var(--nav-height);
}

/* ============================================
   MAIN NAVIGATION CONTAINER
   ============================================ */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--nav-border);
  box-shadow:
    var(--nav-shadow),
    0 0 0 1px rgba(79, 172, 254, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  z-index: var(--nav-z-index);
  overflow: visible;
  transition: all 0.3s ease;
}

/* Animated gradient border at bottom */
.top-nav::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
      transparent 0%,
      rgba(79, 172, 254, 0.5) 20%,
      rgba(148, 121, 255, 0.6) 50%,
      rgba(79, 172, 254, 0.5) 80%,
      transparent 100%);
  opacity: 0.7;
}

/* Inner glow effect */
.top-nav::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: radial-gradient(ellipse 50% 100% at 50% 0%, rgba(79, 172, 254, 0.08), transparent 70%);
  pointer-events: none;
}

.nav-container {
  max-width: 1400px;
  height: 100%;
  margin: 0 auto;
  padding: 0 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  position: relative;
}

/* ============================================
   BRAND / LOGO
   ============================================ */
.nav-brand {
  flex-shrink: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--nav-text);
  padding: 0.5rem 1.25rem 0.5rem 0.5rem;
  border-radius: 16px;
  border: 1px solid rgba(79, 172, 254, 0.25);
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.12), rgba(148, 121, 255, 0.08));
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.brand-link::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 50%, rgba(79, 172, 254, 0.15), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.brand-link:hover {
  color: #ffffff;
  border-color: rgba(148, 121, 255, 0.45);
  transform: translateY(-2px);
  box-shadow:
    0 12px 32px rgba(79, 172, 254, 0.2),
    0 0 0 1px rgba(148, 121, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.brand-link:hover::before {
  opacity: 1;
}

.brand-logo {
  width: 32px;
  height: 32px;
  color: var(--nav-accent);
}

.brand-logo-img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(79, 172, 254, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.brand-link:hover .brand-logo-img {
  border-color: rgba(148, 121, 255, 0.5);
  box-shadow: 0 0 16px rgba(79, 172, 254, 0.3);
}

.brand-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--nav-accent), var(--nav-accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  position: relative;
  z-index: 1;
}

/* ============================================
   NAVIGATION LINKS
   ============================================ */
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem;
  background: rgba(5, 10, 20, 0.5);
  border-radius: 16px;
  border: 1px solid rgba(79, 172, 254, 0.12);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.15);
  flex: 1;
  justify-content: center;
  max-width: max-content;
  margin: 0 auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  min-height: 44px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--nav-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.25s ease;
  position: relative;
  white-space: nowrap;
}

.nav-link::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.15), rgba(148, 121, 255, 0.1));
  opacity: 0;
  transition: opacity 0.25s ease;
}

.nav-link:hover {
  color: var(--nav-text-hover);
  transform: translateY(-1px);
}

.nav-link:hover::before {
  opacity: 1;
}

.nav-link.active {
  color: #ffffff;
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.25), rgba(148, 121, 255, 0.2));
  border: 1px solid rgba(79, 172, 254, 0.35);
  box-shadow:
    0 4px 16px rgba(79, 172, 254, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: linear-gradient(90deg, var(--nav-accent), var(--nav-accent-2));
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(79, 172, 254, 0.5);
}

.nav-link.active:hover {
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.3), rgba(148, 121, 255, 0.25));
}

.nav-link.active .nav-icon {
  filter: grayscale(0%) brightness(1.1);
}

/*
  Cozy "More" dropdown (CM-01/CM-02).
  Keeps Wisdom/Habits/Progress/iSpirit reachable in cozy mode without
  bloating the 4-tab primary row.
*/
.nav-more {
  position: relative;
}
.nav-more-trigger {
  background: none;
  font-family: inherit;
  cursor: pointer;
}
.nav-more-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  padding: 0.5rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(79, 172, 254, 0.25);
  border-radius: 14px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.4);
  display: none;
  z-index: 1000;
}
.nav-more-menu.show {
  display: block;
}
.nav-more-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  min-height: 44px;
  border-radius: 10px;
  color: rgba(248, 250, 252, 0.9);
  font-size: 0.95rem;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-more-item:hover,
.nav-more-item:focus-visible {
  background: rgba(79, 172, 254, 0.15);
  color: #ffffff;
  outline: none;
}
.nav-more-item.active {
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.25), rgba(148, 121, 255, 0.2));
  color: #ffffff;
}
.nav-more-item .nav-icon {
  font-size: 1.1rem;
}

/*
  CM-07: active-tab underline is absolutely positioned and already
  does not contribute to layout (::after bottom:-10px). But the
  active border adds 2px of height via `border: 1px`. Compensate
  with negative margin so the row doesn't jump when a tab activates.
*/
.top-nav .nav-link.active {
  margin-top: -1px;
  margin-bottom: -1px;
}

/* Cozy mobile "More" subhead */
.mobile-menu-subhead {
  padding: 0.75rem 1rem 0.35rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(148, 163, 184, 0.85);
  font-weight: 700;
}

.nav-icon {
  font-size: 1.1rem;
  line-height: 1;
  position: relative;
  z-index: 1;
  filter: grayscale(30%);
  transition: filter 0.25s ease;
}

.nav-link:hover .nav-icon {
  filter: grayscale(0%);
}

.nav-text {
  white-space: nowrap;
  position: relative;
  z-index: 1;
  letter-spacing: 0.01em;
}

/* ============================================
   RIGHT ACTIONS (User Menu)
   ============================================ */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* User Menu */
.user-menu {
  position: relative;
}

.user-button {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 1rem 0.45rem 0.45rem;
  border: 1px solid rgba(79, 172, 254, 0.25);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.1), rgba(148, 121, 255, 0.06));
  color: var(--nav-text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.user-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 70% 50%, rgba(148, 121, 255, 0.12), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.user-button:hover {
  border-color: rgba(148, 121, 255, 0.45);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(79, 172, 254, 0.15);
}

.user-button:hover::before {
  opacity: 1;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid rgba(79, 172, 254, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.user-button:hover .user-avatar {
  border-color: rgba(148, 121, 255, 0.5);
}

.user-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
  z-index: 1;
  font-weight: 600;
}

/* ============================================
   USER DROPDOWN
   ============================================ */
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 260px;
  background: var(--dropdown-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(79, 172, 254, 0.25);
  border-radius: 18px;
  box-shadow:
    var(--dropdown-shadow),
    0 0 0 1px rgba(79, 172, 254, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  padding: 0.6rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.25s ease;
  z-index: 31000;
}

.user-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Also show on hover for desktop */
.user-menu:hover .user-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1rem;
  border-radius: 14px;
  background: rgba(79, 172, 254, 0.08);
  border: 1px solid rgba(79, 172, 254, 0.12);
  margin-bottom: 0.5rem;
}

.dropdown-avatar {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid rgba(79, 172, 254, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.dropdown-user-info {
  flex: 1;
  overflow: hidden;
}

.dropdown-user-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--nav-text-hover);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 0.15rem;
}

.dropdown-user-email {
  font-size: 0.8rem;
  color: var(--nav-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(79, 172, 254, 0.2), transparent);
  margin: 0.5rem 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  padding: 0.8rem 1rem;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--nav-text-muted);
  font-size: 0.95rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropdown-item:hover {
  background: rgba(79, 172, 254, 0.12);
  color: var(--nav-text-hover);
  transform: translateX(4px);
}

.dropdown-icon {
  font-size: 1.15rem;
  width: 1.4rem;
  text-align: center;
  filter: grayscale(30%);
  transition: filter 0.2s ease;
}

.dropdown-item:hover .dropdown-icon {
  filter: grayscale(0%);
}

/* ============================================
   MOBILE MENU TOGGLE
   ============================================ */
.mobile-menu-toggle {
  display: none !important;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(79, 172, 254, 0.2);
  border-radius: 12px;
  background: rgba(5, 10, 20, 0.6);
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-menu-toggle:hover {
  background: rgba(79, 172, 254, 0.15);
  border-color: rgba(79, 172, 254, 0.35);
}

.hamburger-line {
  width: 20px;
  height: 2px;
  background: var(--nav-text);
  border-radius: 2px;
  transition: all 0.3s ease;
}

.hamburger-line:not(:last-child) {
  margin-bottom: 4px;
}

.mobile-menu-toggle.active .hamburger-line:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.mobile-menu-toggle.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active .hamburger-line:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* ============================================
   MOBILE MENU OVERLAY
   ============================================ */
.mobile-menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 10, 20, 0.92);
  z-index: 99999;
  isolation: isolate;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-menu-overlay.active {
  display: block !important;
  opacity: 1;
  visibility: visible;
}

.mobile-menu-content {
  position: absolute;
  top: 0;
  right: 0;
  width: min(320px, 85vw);
  height: 100%;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.98), rgba(10, 18, 36, 0.95));
  border-left: 1px solid rgba(79, 172, 254, 0.2);
  box-shadow: -12px 0 45px rgba(79, 172, 254, 0.15);
  padding: 1.5rem;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.mobile-menu-overlay.active .mobile-menu-content {
  transform: translateX(0);
}

.mobile-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(79, 172, 254, 0.15);
}

.mobile-menu-close {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(79, 172, 254, 0.2);
  border-radius: 12px;
  background: rgba(79, 172, 254, 0.1);
  color: var(--nav-text);
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-menu-close:hover {
  background: rgba(148, 121, 255, 0.2);
  border-color: rgba(148, 121, 255, 0.35);
  color: var(--nav-text-hover);
}

.mobile-menu-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mobile-nav-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  text-decoration: none;
  color: var(--nav-text-muted);
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border: 1px solid transparent;
}

.mobile-nav-link:hover {
  background: rgba(79, 172, 254, 0.12);
  color: var(--nav-text-hover);
  border-color: rgba(79, 172, 254, 0.2);
}

.mobile-nav-link.active {
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.2), rgba(148, 121, 255, 0.15));
  color: #ffffff;
  border-color: rgba(79, 172, 254, 0.3);
}

.mobile-menu-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(79, 172, 254, 0.2), transparent);
  margin: 1rem 0;
}

.mobile-menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mobile-action-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.1rem;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--nav-text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}

.mobile-action-link:hover {
  background: rgba(79, 172, 254, 0.12);
  color: var(--nav-text-hover);
}

.action-icon {
  font-size: 1.15rem;
  width: 1.5rem;
  text-align: center;
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* Large Tablet */
@media (max-width: 1100px) {
  .nav-container {
    padding: 0 1.25rem;
    gap: 1.5rem;
  }

  .nav-links {
    gap: 0.15rem;
    padding: 0.35rem;
  }

  .nav-link {
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
  }
}

/* Tablet */
@media (max-width: 1024px) {
  .nav-container {
    padding: 0 1rem;
  }

  .nav-text {
    font-size: 0.75rem;
  }

  .nav-icon {
    font-size: 1.1rem;
  }

  .nav-link {
    padding: 0.45rem 0.55rem;
    gap: 0.2rem;
  }

  .user-name {
    display: none;
  }

  .user-button {
    padding: 0.4rem;
    border-radius: 12px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --nav-height: 60px;
  }

  .nav-links,
  .nav-actions {
    display: none;
  }

  .mobile-menu-toggle {
    display: flex !important;
  }

  .mobile-menu-overlay {
    display: block;
  }

  /* Remove backdrop-filter on nav for mobile to avoid WebKit compositing bug
     where two position:fixed + backdrop-filter elements render in wrong z-order */
  .top-nav {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(10, 15, 30, 0.97);
  }

  .brand-text {
    font-size: 1rem;
  }

  .brand-link {
    padding: 0.4rem 1rem 0.4rem 0.4rem;
  }

  .brand-logo-img {
    width: 34px;
    height: 34px;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  :root {
    --nav-height: 56px;
  }

  .nav-container {
    padding: 0 0.75rem;
  }

  .brand-text {
    display: none;
  }

  .brand-link {
    padding: 0.35rem;
    border-radius: 12px;
  }

  .brand-logo-img {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles for keyboard navigation */
.nav-link:focus-visible,
.user-button:focus-visible,
.dropdown-item:focus-visible,
.mobile-menu-toggle:focus-visible,
.mobile-nav-link:focus-visible,
.mobile-action-link:focus-visible {
  outline: 2px solid var(--nav-accent);
  outline-offset: 2px;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {

  .top-nav,
  .mobile-menu-overlay {
    display: none;
  }
}

/* ============================================
   GLOBAL MOBILE HELPERS (applied when nav is present)
   ============================================ */

/* Prevent horizontal overflow on any page with the nav */
body.has-top-nav {
  overflow-x: hidden;
}

/* Ensure all page containers don't exceed viewport.
   The :not() list is for FIXED OVERLAY UI that is a direct body child but is not
   a page container — clamping it does real damage.
   .page-guide added 2026-07-30: it is a 82x44 fixed pill whose panel is an
   absolutely-positioned 400x359 CHILD. `overflow-x: hidden` here made
   `overflow-y: visible` compute to `auto` (CSS spec: when one axis is hidden the
   other cannot stay visible), turning the pill into a scroll container — so the
   panel opened correctly and was then clipped to the pill's own 44px box.
   scrollHeight 410 vs clientHeight 44, and every hit-test inside the panel's
   rect returned the page BEHIND it.
   That is why the button looked dead on click: the handler ran, the class
   toggled, the panel had opacity 1 and a real rect — getBoundingClientRect
   reports layout size regardless of ancestor clipping, so every "is it visible"
   check said yes. Only hit-testing exposed it. Reported twice before being
   found, because the first investigation fixed a real-but-unrelated drag-slop
   bug on a page that does not carry has-top-nav. */
body.has-top-nav>main,
body.has-top-nav>div:not(#mobileMenuOverlay):not(.mobile-menu-overlay):not(.page-guide) {
  max-width: 100%;
  overflow-x: hidden;
}

/* ============================================
   BODY OFFSET (prevent content hiding under fixed nav)
   ============================================ */
/* Only apply the 70px top padding when the legacy fixed `.top-nav` is actually
   visible. When AppShell.js mounts the sidebar (body.product-page), the
   `.top-nav` is hidden (display:none) and the padding is dead space. */
body.has-top-nav:not(.product-page) {
  padding-top: var(--nav-height);
}

/* ============================================
   EXPLORE DROPDOWN (desktop nav)
   ============================================ */
.nav-dropdown-wrap {
  position: relative;
}

.nav-dropdown-trigger {
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  font-family: inherit;
}

.nav-chevron {
  font-size: 0.6rem;
  margin-left: 0.15rem;
  opacity: 0.6;
  transition: transform 0.2s ease;
}

.nav-dropdown-wrap.open .nav-chevron {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 170px;
  background: var(--dropdown-bg);
  border: 1px solid var(--nav-border);
  border-radius: 14px;
  box-shadow: var(--dropdown-shadow);
  padding: 6px;
  z-index: calc(var(--nav-z-index) + 10);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.nav-dropdown-wrap.open .nav-dropdown-menu {
  display: flex;
  flex-direction: column;
  animation: navDropIn 0.15s ease-out;
}

@keyframes navDropIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.nav-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s ease;
  white-space: nowrap;
  width: 100%;
  box-sizing: border-box;
}

.nav-dropdown-item:hover {
  background: rgba(79, 172, 254, 0.12);
  color: var(--nav-text-hover);
}

.nav-dropdown-item.active {
  background: rgba(79, 172, 254, 0.18);
  color: var(--nav-accent);
}

/* Hide dropdown on mobile — items show in mobile menu instead */
@media (max-width: 768px) {
  .nav-dropdown-wrap {
    display: none;
  }
}

/* Mobile section label */
.mobile-menu-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(148, 163, 184, 0.5);
  padding: 0.4rem 1rem 0.2rem;
}

/* ============================================
   UNIVERSAL DASHBOARD FOOTER
   ============================================ */
.dashboard-footer {
  margin-top: auto;
  padding: 2rem 1.5rem 2.5rem;
  border-top: 1px solid rgba(79, 172, 254, 0.08);
  background: rgba(5, 10, 20, 0.4);
}

.dashboard-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.dashboard-footer-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  color: rgba(148, 163, 184, 0.85);
}

.dashboard-footer-brand img {
  opacity: 0.5;
  border-radius: 4px;
}

.dashboard-footer-links {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* A-03: tap targets must be ≥44px tall and have at least 4.5:1 contrast.
   Old style: 0.8rem text, rgba(148,163,184,0.5) color, no padding
   → ~20px tall and ~3.5:1 contrast. */
.dashboard-footer-links a {
  font-size: 0.85rem;
  color: rgba(203, 213, 225, 0.95);
  text-decoration: none;
  transition: color 0.2s ease, background 0.2s ease;
  padding: 0.75rem 1rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
}

.dashboard-footer-links a:hover {
  color: #ffffff;
  background: rgba(79, 172, 254, 0.12);
}

@media (max-width: 480px) {
  .dashboard-footer-inner {
    flex-direction: column;
    text-align: center;
  }
}

/* ==========================================================================
   Mobile Bottom Nav (UI review M10) — bottom tab bar for 55+ users.
   Replaces the hamburger experience on small screens with always-visible
   tabs that the Android app already uses. Hidden above 768px.
   ========================================================================== */

.mobile-bottom-nav {
  /* Hidden by default; opt in at ≤768px. */
  display: none;
}

body.has-mobile-bottom-nav {
  /* Reserve space so fixed composer/CTA rows on the last screen don't
     slide under the bottom bar. env(safe-area-inset-bottom) handles the
     iOS home-indicator on newer iPhones. */
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    background: rgba(5, 10, 20, 0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid hsla(var(--primary-hue, 250), 60%, 75%, 0.18);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
  }

  .mbn-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    min-height: 60px;
    text-decoration: none;
    color: rgba(248, 250, 252, 0.55);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    border-radius: 10px;
    transition: color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
  }

  .mbn-tab:hover {
    color: rgba(248, 250, 252, 0.8);
  }

  .mbn-tab:active {
    transform: scale(0.96);
    background-color: hsla(var(--primary-hue, 250), 60%, 70%, 0.12);
  }

  .mbn-tab:focus-visible {
    outline: 2px solid var(--color-primary, hsl(250, 100%, 75%));
    outline-offset: -2px;
  }

  .mbn-tab.is-active {
    color: hsl(var(--primary-hue, 250), 100%, 80%);
    background-color: hsla(var(--primary-hue, 250), 60%, 70%, 0.15);
  }

  .mbn-icon {
    font-size: 1.5rem;
    line-height: 1;
  }

  .mbn-label {
    font-size: 0.7rem;
    line-height: 1;
  }

  /* Hide the existing mobile hamburger trigger — the bottom bar replaces
     it as the primary navigation. The hamburger's secondary-menu overlay
     is still reachable from the "More" tab. */
  body.has-mobile-bottom-nav .mobile-menu-toggle {
    display: none !important;
  }

  /* On pages with a fixed composer (chat) or a footer CTA row, add a
     bit more bottom padding so the composer still clears the bottom bar. */
  body.has-mobile-bottom-nav .chat .composer,
  body.has-mobile-bottom-nav .chat-inner {
    padding-bottom: 12px;
  }

  /* Lift the chat composer ABOVE the bottom nav. The composer is
     position:fixed; bottom:0 by default — even with a higher z-index
     the opaque nav background visually covers the input box. Match the
     nav's rendered height (88px = 6 top + 74 tab + 6 bottom + 1 border
     + 1 sub-pixel) plus the iOS safe-area inset that the nav itself
     scales with. */
  body.has-mobile-bottom-nav .composer {
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  }
}

/* Landing, login, register, welcome pages opt out. */
body.no-bottom-nav .mobile-bottom-nav,
body.is-landing .mobile-bottom-nav {
  display: none !important;
}