/**
 * accessible-menu.css
 *
 * Styling for the Accessible Menu Drupal module.
 * All interactive states use :focus-visible for keyboard users.
 * Mobile breakpoint is controlled via a CSS custom property set by JS.
 */

/* ============================================================
   CUSTOM PROPERTIES (design tokens — override in your theme)
   ============================================================ */
:root {
  --am-font-family: inherit;
  --am-font-size: 1rem;
  --am-font-weight-normal: 400;
  --am-font-weight-bold: 600;

  /* Desktop nav */
  --am-nav-bg: transparent;
  --am-nav-color: #000000;
  --am-nav-hover-bg: rgba(0,0,0,0.05);
  --am-nav-hover-color: #000000;
  --am-nav-active-color: #f0c040;
  --am-nav-height: 3.25rem;
  --am-nav-focus-outline: 3px solid #f0c040;
  --am-nav-focus-outline-offset: -3px;

  /* Dropdown */
  --am-dropdown-bg: #ffffff;
  --am-dropdown-color: #1a2740;
  --am-dropdown-hover-bg: #f0f4f8;
  --am-dropdown-hover-color: #1a2740;
  --am-dropdown-border: 1px solid #d0d8e4;
  --am-dropdown-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  --am-dropdown-heading-color: #1a2740;
  --am-dropdown-heading-border: 2px solid #1a2740;

  /* Mobile toggle */
  --am-toggle-bg: transparent;
  --am-toggle-color: #ffffff;
  --am-toggle-padding: 0.5rem 0.75rem;

  /* Drawer */
  --am-drawer-width: 280px;
  --am-drawer-bg: #1a2740;
  --am-drawer-color: #ffffff;
  --am-drawer-link-hover-bg: #243450;
  --am-drawer-border-color: rgba(255, 255, 255, 0.12);
  --am-drawer-transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);

  /* Overlay */
  --am-overlay-bg: rgba(0, 0, 0, 0.45);
}

/* ============================================================
   UTILITY
   ============================================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   DESKTOP NAV WRAPPER
   ============================================================ */
.accessible-menu {
  position: relative;
  background: var(--am-nav-bg);
  font-family: var(--am-font-family);
  font-size: var(--am-font-size);
}

/* Mobile toggle hidden on desktop */
.accessible-menu__toggle {
  display: none;
}

/* ============================================================
   DESKTOP: TOP-LEVEL LIST
   ============================================================ */
.accessible-menu__list {
  display: flex;
  flex-wrap: nowrap;
  list-style: none;
  margin: 0;
  padding: 0;
  /* Distribute items equally across full width */
  justify-content: center;
}

.accessible-menu__item {
  position: relative;
  flex: 1 1 0%;
  display: flex;
  align-items: stretch;
}

/* ============================================================
   DESKTOP: TOP-LEVEL LINKS
   ============================================================ */
.accessible-menu__link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0 1rem;
  height: var(--am-nav-height);
  color: var(--am-nav-color);
  text-decoration: none;
  font-weight: var(--am-font-weight-bold);
  text-align: center;
  white-space: nowrap;
  gap: 0.35em;
  transition: background 0.15s ease, color 0.15s ease;
}

.accessible-menu__link:hover,
.accessible-menu__link:focus {
  background: var(--am-nav-hover-bg);
  color: var(--am-nav-hover-color);
}

.accessible-menu__link:focus-visible {
  outline: var(--am-nav-focus-outline);
  outline-offset: var(--am-nav-focus-outline-offset);
}

.accessible-menu__link.is-active,
.is-active-trail > .accessible-menu__link {
  color: var(--am-nav-active-color);
}

/* Down arrow indicator */
.accessible-menu__arrow {
  font-size: 0.65em;
  transition: transform 0.2s ease;
  display: inline-block;
}

.accessible-menu__item[aria-expanded="true"] .accessible-menu__arrow,
.accessible-menu__link[aria-expanded="true"] .accessible-menu__arrow {
  transform: none;
}

/* ============================================================
   DESKTOP: DROPDOWN SUBMENU — flat list
   ============================================================ */
.accessible-menu__submenu {
  position: absolute;
  top: 100%;
  left: 0;
  transform: none;
  min-width: 200px;
  background: var(--am-dropdown-bg);
  border: var(--am-dropdown-border);
  box-shadow: var(--am-dropdown-shadow);
  list-style: none;
  margin: 0;
  padding: 0.5rem 0;
  z-index: 1000;
}

/* When hidden attribute is removed, display flex for column layout */
.accessible-menu__submenu:not([hidden]) {
  display: block;
}

.accessible-menu__submenu-item {
  display: block;
}

.accessible-menu__submenu-link {
  display: block;
  padding: 0.55rem 1.25rem;
  color: var(--am-dropdown-color);
  text-decoration: none;
  transition: background 0.12s ease;
}

.accessible-menu__submenu-link:hover,
.accessible-menu__submenu-link:focus {
  background: var(--am-dropdown-hover-bg);
  color: var(--am-dropdown-hover-color);
}

.accessible-menu__submenu-link:focus-visible {
  outline: var(--am-nav-focus-outline);
  outline-offset: -2px;
}

.accessible-menu__submenu-link.is-active {
  font-weight: var(--am-font-weight-bold);
}

/* ============================================================
   DESKTOP: DROPDOWN SUBMENU — multi-column layout
   ============================================================ */
.accessible-menu__item.has-grandchildren {
  position: static;
}

.accessible-menu__submenu--columns {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  transform: none;
  width: 100%;
  background: var(--am-dropdown-bg);
  border: var(--am-dropdown-border);
  box-shadow: var(--am-dropdown-shadow);
  z-index: 1000;
}

.accessible-menu__submenu--columns:not([hidden]) {
  display: flex;
  flex-wrap: nowrap;
  padding: 1rem 0;
}

.accessible-menu__submenu-column {
  flex: 1 1 0%;
  min-width: 0;
  padding: 0 1rem;
  border-right: 1px solid var(--am-dropdown-border);
}

.accessible-menu__submenu-column:last-child {
  border-right: none;
}

/* Column heading = the child link that itself has grandchildren */
.accessible-menu__submenu-heading {
  display: block;
  padding: 0.55rem 1.25rem;
  color: var(--am-dropdown-color);
  font-weight: var(--am-font-weight-normal);
  text-decoration: none;
}

.accessible-menu__submenu-heading:hover,
.accessible-menu__submenu-heading:focus {
  background: var(--am-dropdown-hover-bg);
  color: var(--am-dropdown-hover-color);
}

.accessible-menu__submenu-heading:focus-visible {
  outline: var(--am-nav-focus-outline);
  outline-offset: -2px;
}

.accessible-menu__submenu-group {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ============================================================
   MOBILE TOGGLE BUTTON
   ============================================================ */
.accessible-menu__toggle {
  align-items: center;
  gap: 0.5rem;
  background: var(--am-toggle-bg);
  border: 2px solid transparent;
  color: var(--am-toggle-color);
  cursor: pointer;
  font-family: var(--am-font-family);
  font-size: var(--am-font-size);
  font-weight: var(--am-font-weight-bold);
  padding: var(--am-toggle-padding);
  height: var(--am-nav-height);
  transition: border-color 0.15s ease;
}

.accessible-menu__toggle:focus-visible {
  outline: var(--am-nav-focus-outline);
  outline-offset: var(--am-nav-focus-outline-offset);
}

/* Hamburger icon */
.accessible-menu__hamburger {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 22px;
  height: 16px;
}

.accessible-menu__hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.25s ease;
  transform-origin: center;
}

/* Animate hamburger to X when open */
.accessible-menu__toggle[aria-expanded="true"] .accessible-menu__hamburger span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.accessible-menu__toggle[aria-expanded="true"] .accessible-menu__hamburger span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}

.accessible-menu__toggle[aria-expanded="true"] .accessible-menu__hamburger span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ============================================================
   MOBILE OVERLAY
   ============================================================ */
.accessible-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--am-overlay-bg);
  z-index: 1099;
  cursor: pointer;
}

.accessible-menu-overlay.is-visible {
  display: block;
}

/* ============================================================
   MOBILE DRAWER
   ============================================================ */
.accessible-menu-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--am-drawer-width);
  max-width: 90vw;
  height: 100%;
  background: var(--am-drawer-bg);
  color: var(--am-drawer-color);
  z-index: 1100;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: var(--am-drawer-transition);
  font-family: var(--am-font-family);
  /* Focus trap boundary */
  outline: none;
}

.accessible-menu-drawer.is-open {
  transform: translateX(0);
}

/* Close button */
.accessible-menu-drawer__close {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--am-drawer-border-color);
  color: var(--am-drawer-color);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.accessible-menu-drawer__close:focus-visible {
  outline: var(--am-nav-focus-outline);
  outline-offset: -3px;
}

/* Drawer list */
.accessible-menu-drawer__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Depth indentation */
.accessible-menu-drawer__item--depth-1 { --am-indent: 0; }
.accessible-menu-drawer__item--depth-2 { --am-indent: 1; }
.accessible-menu-drawer__item--depth-3 { --am-indent: 2; }
.accessible-menu-drawer__item--depth-4 { --am-indent: 3; }

.accessible-menu-drawer__item {
  border-bottom: 1px solid var(--am-drawer-border-color);
}

/* Row that holds link + expand button */
.accessible-menu-drawer__item-row {
  display: flex;
  align-items: stretch;
}

/* Drawer links */
.accessible-menu-drawer__link {
  flex: 1;
  display: block;
  padding: 0.85rem 1rem 0.85rem calc(1rem + var(--am-indent, 0) * 1.25rem);
  color: var(--am-drawer-color);
  text-decoration: none;
  transition: background 0.12s ease;
}

.accessible-menu-drawer__link:hover,
.accessible-menu-drawer__link:focus {
  background: var(--am-drawer-link-hover-bg);
}

.accessible-menu-drawer__link:focus-visible {
  outline: var(--am-nav-focus-outline);
  outline-offset: -3px;
}

.accessible-menu-drawer__link.is-active {
  color: var(--am-nav-active-color);
  font-weight: var(--am-font-weight-bold);
}

/* Expand/collapse button */
.accessible-menu-drawer__expand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  background: transparent;
  border: none;
  border-left: 1px solid var(--am-drawer-border-color);
  color: var(--am-drawer-color);
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.12s ease, transform 0.2s ease;
}

.accessible-menu-drawer__expand:focus-visible {
  outline: var(--am-nav-focus-outline);
  outline-offset: -3px;
}

.accessible-menu-drawer__expand[aria-expanded="true"] {
  transform: rotate(180deg);
}

/* Sub list */
.accessible-menu-drawer__sub {
  list-style: none;
  margin: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.15);
}

/* ============================================================
   RESPONSIVE — MOBILE
   Uses a class toggled by JS at the configured breakpoint.
   ============================================================ */
.accessible-menu--mobile .accessible-menu__toggle {
  display: flex;
}

.accessible-menu--mobile .accessible-menu__list {
  display: none;
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .accessible-menu-drawer,
  .accessible-menu__hamburger span,
  .accessible-menu__arrow,
  .accessible-menu-drawer__expand {
    transition: none;
  }
}
