/**
 * @file
 * CC Soccer Theme - Navigation styles.
 *
 * Horizontal main nav, account dropdown, mobile hamburger.
 * Targets actual Drupal markup: bare <ul>/<li> with block IDs.
 *
 * Main nav:    #block-ccsoccer-theme-main-menu
 * Account nav: #block-ccsoccer-theme-account-menu
 */

/* ============================================
   HEADER NAV CONTAINER
   ============================================ */

.site-header__nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  justify-content: flex-end;
}

/* Drupal wraps region blocks in an extra div */
.site-header__nav > div {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  justify-content: flex-end;
}

/* ============================================
   HIDE DRUPAL SITE BRANDING BLOCK
   (branding is hardcoded in page template)
   ============================================ */

#block-ccsoccer-theme-site-branding {
  display: none;
}

/* ============================================
   HIDE BLOCK TITLES (keep for accessibility)
   ============================================ */

.site-header__nav h2 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   HAMBURGER BUTTON (mobile only)
   ============================================ */

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--color-white);
}

.nav-toggle__icon {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-white);
  position: relative;
  transition: background var(--transition-base);
}

.nav-toggle__icon::before,
.nav-toggle__icon::after {
  content: '';
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-white);
  position: absolute;
  left: 0;
  transition: transform var(--transition-base);
}

.nav-toggle__icon::before { top: -7px; }
.nav-toggle__icon::after { top: 7px; }

.nav-toggle[aria-expanded="true"] .nav-toggle__icon {
  background: transparent;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__icon::before {
  transform: rotate(45deg);
  top: 0;
  background: var(--color-text);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__icon::after {
  transform: rotate(-45deg);
  top: 0;
  background: var(--color-text);
}

/* ============================================
   MAIN NAVIGATION - Horizontal links
   #block-ccsoccer-theme-main-menu
   ============================================ */

#block-ccsoccer-theme-main-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0;
}

#block-ccsoccer-theme-main-menu li {
  position: relative;
}

#block-ccsoccer-theme-main-menu li a {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  color: var(--color-gray-200);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  border-radius: var(--radius-md);
}

#block-ccsoccer-theme-main-menu li a:hover {
  color: var(--color-white);
  background: rgba(255, 255, 255, 0.1);
}

#block-ccsoccer-theme-main-menu li a.is-active {
  color: var(--color-white);
}

/* ============================================
   ANONYMOUS: Hide account menu
   ============================================ */

body:not(.user-logged-in) #block-ccsoccer-theme-account-menu {
  display: none;
}

/* Show Log In link only for anonymous users */
body.user-logged-in #block-ccsoccer-theme-main-menu li a[href*="/user/login"] {
  display: none;
}

/* ============================================
   REGISTER LINK - Button treatment
   ============================================ */

#block-ccsoccer-theme-main-menu li a[href="/register"] {
  background: var(--color-primary);
  color: var(--color-text-inverse) !important;
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-5);
  font-weight: var(--font-weight-semibold);
  margin-left: var(--space-2);
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

#block-ccsoccer-theme-main-menu li a[href="/register"]:hover {
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-primary);
  color: var(--color-text-inverse) !important;
}

/* ============================================
   DIVIDER between main nav and account menu
   ============================================ */

#block-ccsoccer-theme-account-menu {
  position: relative;
  margin-left: var(--space-4);
  padding-left: var(--space-3);
  align-self: center;
  min-height: 40px;
  min-width: 180px;
  z-index: var(--z-dropdown);
}

#block-ccsoccer-theme-account-menu::before {
  content: '';
  display: block;
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

/* ============================================
   ACCOUNT MENU - Dropdown
   #block-ccsoccer-theme-account-menu
   
   Shows "My account ▾" as trigger.
   Dropdown opens on hover/focus to show 
   all account links.
   ============================================ */

#block-ccsoccer-theme-account-menu > ul {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

/* First item ("My account") is the visible trigger */
#block-ccsoccer-theme-account-menu > ul > li:first-child > a {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  color: var(--color-gray-200);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

/* Dropdown arrow on trigger */
#block-ccsoccer-theme-account-menu > ul > li:first-child > a::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: var(--space-1);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform var(--transition-fast);
}

#block-ccsoccer-theme-account-menu > ul > li:first-child > a:hover {
  color: var(--color-white);
  background: rgba(255, 255, 255, 0.1);
}

/* All other account items - hidden by default */
#block-ccsoccer-theme-account-menu > ul > li:not(:first-child) {
  display: none;
}

/* Dropdown panel - always absolute so it never affects flex layout */
#block-ccsoccer-theme-account-menu > ul {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  min-width: 220px;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-lg);
}

/* Only show first item in collapsed state */
#block-ccsoccer-theme-account-menu > ul > li:first-child {
  display: block;
}

/* On hover/focus: show all items as dropdown */
#block-ccsoccer-theme-account-menu:hover > ul > li:not(:first-child),
#block-ccsoccer-theme-account-menu:focus-within > ul > li:not(:first-child) {
  display: block;
}

/* Dropdown container styling on hover */
#block-ccsoccer-theme-account-menu:hover > ul,
#block-ccsoccer-theme-account-menu:focus-within > ul {
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2) 0;
  z-index: var(--z-dropdown);
}

/* When dropdown is open: trigger gets dark text on white bg */
#block-ccsoccer-theme-account-menu:hover > ul > li:first-child > a,
#block-ccsoccer-theme-account-menu:focus-within > ul > li:first-child > a {
  color: var(--color-text);
  background: transparent;
}

/* Rotate arrow when open */
#block-ccsoccer-theme-account-menu:hover > ul > li:first-child > a::after,
#block-ccsoccer-theme-account-menu:focus-within > ul > li:first-child > a::after {
  transform: rotate(180deg);
}

/* Dropdown item links */
#block-ccsoccer-theme-account-menu > ul > li:not(:first-child) > a {
  display: block;
  padding: var(--space-2) var(--space-4);
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: var(--font-weight-normal);
  white-space: nowrap;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

#block-ccsoccer-theme-account-menu > ul > li:not(:first-child) > a:hover {
  background: var(--color-gray-100);
  color: var(--color-primary);
}

/* Tournament section separator.
 * Both items get border-top so either can appear alone.
 * When both appear, the adjacent sibling rule removes the border from
 * My Tournament Schedule (which immediately follows My Tournament Team). */
#block-ccsoccer-theme-account-menu > ul > li:has(a[href="/my-tournament-teams"]),
#block-ccsoccer-theme-account-menu > ul > li:has(a[href="/my-tournament-schedule"]) {
  border-top: 1px solid var(--border-color);
  margin-top: var(--space-1);
  padding-top: var(--space-1);
}

/* When both items appear together, remove duplicate border from schedule */
#block-ccsoccer-theme-account-menu > ul > li:has(a[href="/my-tournament-teams"]) + li:has(a[href="/my-tournament-schedule"]) {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* Log out link - subtle separator */
#block-ccsoccer-theme-account-menu > ul > li:last-child {
  border-top: 1px solid var(--border-color);
  margin-top: var(--space-1);
  padding-top: var(--space-1);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {

  /* Show hamburger */
  .nav-toggle {
    display: block;
  }

  /* Header: logo left, hamburger right, sits above overlay */
  .site-header {
    position: relative;
    z-index: 1000;
  }

  .site-header__inner {
    flex-wrap: nowrap;
  }

  /* --- OVERLAY PANEL --- */
  .site-header__nav {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 999;
    overflow-y: auto;
    padding: 80px var(--space-4) var(--space-4); /* top padding clears the header bar */
    flex: none;
    justify-content: flex-start;
  }

  .site-header__nav.is-open {
    display: block;
  }

  /* Drupal's wrapper div — stack everything vertically */
  .site-header__nav > div {
    display: block;
  }

  /* Hamburger sits above the overlay */
  .nav-toggle {
    position: relative;
    z-index: 1001;
  }

  /* When open, pin X to top-right of screen */
  .nav-toggle[aria-expanded="true"] {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
  }

  /* --- Main nav: vertical list --- */
  #block-ccsoccer-theme-main-menu ul {
    flex-direction: column;
    align-items: stretch;
  }

  #block-ccsoccer-theme-main-menu li a,
  #block-ccsoccer-theme-main-menu li a.is-active {
    padding: var(--space-3) 0;
    border-radius: 0;
    border-bottom: 1px solid var(--color-gray-100);
    font-size: var(--text-lg);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    background: none;
  }

  #block-ccsoccer-theme-main-menu li a:hover {
    background: none;
    color: var(--color-primary);
  }

  /* Register button — still prominent, full-width */
  /* Re-assert red background here because .is-active (same specificity) comes
     earlier in source order and would otherwise apply background:none */
  #block-ccsoccer-theme-main-menu li a[href="/register"],
  #block-ccsoccer-theme-main-menu li a[href="/register"].is-active {
    background: var(--color-primary) !important;
    color: var(--color-text-inverse) !important;
    border-radius: var(--radius-pill);
    margin: var(--space-4) 0;
    text-align: center;
    justify-content: center;
    border-bottom: none;
    font-size: var(--text-base);
  }

  /* --- Separator between nav sections --- */
  #block-ccsoccer-theme-account-menu {
    margin-left: 0;
    padding-left: 0;
    min-height: 0;
    min-width: 0;
    z-index: auto;
    border-top: 2px solid var(--border-color);
    margin-top: var(--space-2);
    padding-top: var(--space-2);
  }

  /* Hide the vertical divider */
  #block-ccsoccer-theme-account-menu::before {
    display: none;
  }

  /* Account menu: flat list, no dropdown, no absolute positioning */
  #block-ccsoccer-theme-account-menu > ul,
  #block-ccsoccer-theme-account-menu:hover > ul,
  #block-ccsoccer-theme-account-menu:focus-within > ul {
    position: static;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  /* All account items visible */
  #block-ccsoccer-theme-account-menu > ul > li,
  #block-ccsoccer-theme-account-menu > ul > li:first-child,
  #block-ccsoccer-theme-account-menu > ul > li:not(:first-child),
  #block-ccsoccer-theme-account-menu:hover > ul > li:not(:first-child),
  #block-ccsoccer-theme-account-menu:focus-within > ul > li:not(:first-child) {
    display: block;
    position: static;
    min-width: 0;
    background: none;
  }

  /* "My account" label styled as section header on mobile */
  #block-ccsoccer-theme-account-menu > ul > li:first-child > a {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2) 0 var(--space-1);
    /* pointer-events: none removed — was preventing tap on mobile */
  }

  /* Hide dropdown arrow on mobile */
  #block-ccsoccer-theme-account-menu > ul > li:first-child > a::after {
    display: none;
  }

  /* Account links */
  #block-ccsoccer-theme-account-menu > ul > li:not(:first-child) > a {
    display: block;
    padding: var(--space-3) 0;
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--text-base);
    font-weight: var(--font-weight-normal);
    border-bottom: 1px solid var(--color-gray-100);
    white-space: normal;
  }

  #block-ccsoccer-theme-account-menu > ul > li:not(:first-child) > a:hover {
    color: var(--color-primary);
  }

  /* Log out — subtle at bottom, with its own separator */
  #block-ccsoccer-theme-account-menu > ul > li:last-child {
    border-top: 1px solid var(--border-color);
    margin-top: var(--space-1);
    padding-top: var(--space-1);
  }

  #block-ccsoccer-theme-account-menu > ul > li:last-child > a {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    border-bottom: none;
  }
}
