/* ==========================================================================
   mss-Style Top Navigation - Authenticated App
   Mega-menu pattern: single shared panel per nav group, hover-driven via JS
   ========================================================================== */
/* --------------------------------------------------------------------------
   Floating nav pill wrapper (replaces AppBar background)
   -------------------------------------------------------------------------- */
.nav-pill {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 1232px; /* match MudContainer MaxWidth.Large inner content width */
  margin: 0 auto;
  height: 100%;
  /* background and backdrop-filter live on ::before so that position:fixed
     children (mobile nav) are not trapped inside this containing block */
  border: 1px solid rgba(0, 0, 0, 0.07);
  border-radius: 16px;
  padding: 0 4px 0 20px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
  gap: 2px;
  overflow: visible;
  position: relative;
  transition: border-bottom-left-radius 0.12s ease, border-bottom-right-radius 0.12s ease, border-bottom-color 0.12s ease;
}

/* Glassmorphic fill on a pseudo-element so the pill does NOT create a
   new CSS containing block (which backdrop-filter on the element itself would).
   border-radius: inherit tracks the pill's transition automatically. */
.nav-pill::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(20px);
  z-index: -1;
  pointer-events: none;
  transition: background 0.2s ease, backdrop-filter 0.2s ease, -webkit-backdrop-filter 0.2s ease;
}

.nav-pill:hover::before {
  background: rgb(255, 255, 255);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

html.dark-mode .nav-pill {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.35);
}

html.dark-mode .nav-pill::before {
  background: rgba(15, 23, 42, 0.85);
}

html.dark-mode .nav-pill:hover::before {
  background: rgb(15, 23, 42);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Desktop: JS adds .pill-mega-open; Mobile: :has() detects rendered mobile nav */
.nav-pill.pill-mega-open,
.nav-pill:has(.mss-mobile-nav) {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}

html.dark-mode .nav-pill.pill-mega-open,
html.dark-mode .nav-pill:has(.mss-mobile-nav) {
  border-bottom-color: transparent;
}

/* --------------------------------------------------------------------------
   Top Nav Container (inside MudAppBar)
   -------------------------------------------------------------------------- */
.mss-topnav {
  display: flex;
  align-items: center;
  gap: 0;
  height: 100%;
  margin-left: 1rem;
  flex: 1;
  overflow: visible;
}

/* --------------------------------------------------------------------------
   Individual Nav Item (link or dropdown trigger)
   -------------------------------------------------------------------------- */
.mss-topnav__item {
  display: flex;
  align-items: center;
  height: 100%;
  cursor: pointer;
  position: relative;
}
.mss-topnav__item > .mss-topnav__label {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  height: 100%;
  font-size: 0.875rem;
  font-weight: 600;
  color: #0F172A;
  text-decoration: none;
  white-space: nowrap;
  border-radius: 6px;
  transition: color 0.15s ease, background-color 0.15s ease;
  user-select: none;
}
.mss-topnav__item > .mss-topnav__label:hover {
  color: #087CFA;
  background-color: rgba(8, 124, 250, 0.06);
}
.mss-topnav__item > .mss-topnav__label .mss-chevron {
  font-size: 0.6rem;
  transition: transform 0.2s ease;
  opacity: 0.6;
  margin-top: 1px;
}
.mss-topnav__item {
  /* JS adds this class when the panel for this item is open */
}
.mss-topnav__item.mega-open > .mss-topnav__label {
  color: #087CFA;
  background-color: rgba(8, 124, 250, 0.06);
}
.mss-topnav__item.mega-open > .mss-topnav__label .mss-chevron {
  transform: rotate(180deg);
}
.mss-topnav__item.disabled > .mss-topnav__label {
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Mega Panel - single shared panel, JS shows/hides via .active class
   Always display:grid (position:absolute - no layout impact).
   Uses opacity/visibility/transform transitions for smooth open AND close.
   -------------------------------------------------------------------------- */
.mss-mega-panel {
  position: absolute;
  top: 100%; /* flush with pill bottom - no gap so it looks connected */
  left: -1px;
  right: -1px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.07);
  border-top: none; /* pill's bottom border acts as the junction */
  border-radius: 0 0 16px 16px; /* only round the bottom corners */
  box-shadow: 0 24px 60px -8px rgba(0, 0, 0, 0.14), 0 8px 20px -4px rgba(0, 0, 0, 0.06);
  padding: 12px;
  z-index: 9999;
  /* Always display:grid - toggling opacity/visibility instead of display
     gives smooth transitions in both directions */
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  /* Hidden by default */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, visibility 0.18s ease, transform 0.18s ease;
}
.mss-mega-panel.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Mega Card (item inside the mega panel)
   -------------------------------------------------------------------------- */
.mss-mega-card {
  display: flex;
  align-items: flex-start; /* align to top so description sits below title */
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: #0F172A;
  transition: background-color 0.12s ease;
  cursor: pointer;
  min-height: 72px;
}
.mss-mega-card:hover {
  background-color: #F4F4F5;
  text-decoration: none;
}
.mss-mega-card .mss-card__icon {
  width: 34px;
  height: 34px;
  min-width: 34px;
  background: rgba(8, 124, 250, 0.08);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #087CFA;
  margin-top: 2px; /* slight offset to align with title text */
}
.mss-mega-card .mss-card__content {
  flex: 1;
  min-width: 0;
}
.mss-mega-card .mss-card__content .mss-card__title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0F172A;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mss-mega-card .mss-card__content .mss-card__description {
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.4;
  margin-top: 2px;
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.mss-mega-card .mss-card__arrow {
  color: #087CFA;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-top: 4px;
}
.mss-mega-card:hover .mss-card__arrow {
  opacity: 1;
  transform: translateX(2px);
}
.mss-mega-card.disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Mobile Nav Panel
   -------------------------------------------------------------------------- */
.mss-mobile-nav {
  /* Pill-width, connected below the pill - mirrors .mss-mega-panel layout */
  position: absolute;
  top: 100%;
  left: -1px;
  right: -1px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.07);
  border-top: none;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 24px 60px -8px rgba(0, 0, 0, 0.14), 0 8px 20px -4px rgba(0, 0, 0, 0.06);
  z-index: 9990;
  max-height: calc(100dvh - var(--mud-appbar-height, 80px) - 16px);
  overflow-y: auto;
  padding: 8px 0 16px;
  animation: mss-mobile-in 0.18s ease;
}

@keyframes mss-mobile-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.mss-mobile-nav__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #0F172A;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.mss-mobile-nav__link:hover {
  background-color: #F4F4F5;
}
.mss-mobile-nav__link.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.mss-mobile-nav__group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #0F172A;
  cursor: pointer;
  transition: background-color 0.15s ease;
  user-select: none;
}
.mss-mobile-nav__group-header:hover {
  background-color: #F4F4F5;
}
.mss-mobile-nav__group-header .mss-mobile-chevron {
  font-size: 0.7rem;
  opacity: 0.5;
  transition: transform 0.2s ease;
}
.mss-mobile-nav__group-header .mss-mobile-chevron.open {
  transform: rotate(180deg);
}

.mss-mobile-nav__children {
  background: #F8FAFC;
  border-left: 3px solid #087CFA;
  margin: 0 12px;
  border-radius: 0 6px 6px 0;
}
.mss-mobile-nav__children .mss-mobile-nav__link {
  padding: 10px 16px;
  font-size: 0.825rem;
  font-weight: 500;
}

.mss-mobile-nav__divider {
  height: 1px;
  background: #e2e8f0;
  margin: 8px 20px;
}

.mss-mobile-nav__section-label {
  padding: 8px 20px 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #94a3b8;
}

/* --------------------------------------------------------------------------
   Dark Mode Overrides
   -------------------------------------------------------------------------- */
html.dark-mode .mss-topnav__item > .mss-topnav__label {
  color: #F4F4F5;
}
html.dark-mode .mss-topnav__item > .mss-topnav__label:hover {
  color: #087CFA;
  background-color: rgba(8, 124, 250, 0.1);
}
html.dark-mode .mss-topnav__item.mega-open > .mss-topnav__label {
  color: #087CFA;
  background-color: rgba(8, 124, 250, 0.1);
}
html.dark-mode .mss-mega-panel {
  background: rgba(15, 23, 42, 0.97);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 60px -8px rgba(0, 0, 0, 0.5), 0 8px 20px -4px rgba(0, 0, 0, 0.3);
}
html.dark-mode .mss-mega-card {
  color: #F4F4F5;
}
html.dark-mode .mss-mega-card:hover {
  background-color: rgba(255, 255, 255, 0.05);
}
html.dark-mode .mss-mega-card .mss-card__content .mss-card__title {
  color: #F4F4F5;
}
html.dark-mode .mss-mega-card .mss-card__content .mss-card__description {
  color: #94a3b8;
}
html.dark-mode .mss-mega-card .mss-card__icon {
  background: rgba(8, 124, 250, 0.15);
}
html.dark-mode .mss-mobile-nav {
  background: rgba(15, 23, 42, 0.97);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 60px -8px rgba(0, 0, 0, 0.5), 0 8px 20px -4px rgba(0, 0, 0, 0.3);
}
html.dark-mode .mss-mobile-nav__link {
  color: #F4F4F5;
}
html.dark-mode .mss-mobile-nav__link:hover {
  background-color: rgba(255, 255, 255, 0.05);
}
html.dark-mode .mss-mobile-nav__group-header {
  color: #F4F4F5;
}
html.dark-mode .mss-mobile-nav__group-header:hover {
  background-color: rgba(255, 255, 255, 0.05);
}
html.dark-mode .mss-mobile-nav__children {
  background: rgba(255, 255, 255, 0.03);
}
html.dark-mode .mss-mobile-nav__divider {
  background: rgba(255, 255, 255, 0.08);
}
html.dark-mode .mss-mobile-nav__section-label {
  color: #64748B;
}
