/**
 * Bengal SSG Default Theme
 * Header & Navigation Styles
 */

/* ============================================
   SITE HEADER
   ============================================ */

header[role="banner"] {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  /* Glass effect */
  overflow: visible;
  /* allow dropdowns to overflow */
}

/* Fallback for browsers without backdrop-filter */
@supports not (backdrop-filter: blur(12px)) {
  header[role="banner"] {
    background-color: var(--color-bg-primary);
    border-bottom: 1px solid var(--color-border);
  }
}

[data-theme="dark"] header[role="banner"] {
  background-color: rgba(26, 26, 26, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

@supports not (backdrop-filter: blur(12px)) {
  [data-theme="dark"] header[role="banner"] {
    background-color: rgba(26, 26, 26, 0.95);
  }
}

header nav {
  padding-block: var(--space-2); /* Balanced tight padding */
}

header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
}

/* ============================================
   LOGO / SITE TITLE
   ============================================ */

.logo {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--color-text-primary);
  text-decoration: none;
  transition: color var(--transition-fast) var(--ease-out);
}

.logo:hover {
  color: var(--color-primary);
  text-decoration: none;
}

/* Brand presentation variants */
.brand-image {
  display: inline-block;
  height: 1.5em;
  vertical-align: middle;
}

.brand-text {
  display: inline-block;
  line-height: 1;
}

/* ============================================
   MAIN NAVIGATION
   ============================================ */

.nav-main {
  display: none;
}

@media (min-width: 768px) {
  .nav-main {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }
}

.nav-main ul {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-main a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast) var(--ease-out);
}

.nav-main a:hover {
  color: var(--color-primary);
  background-color: var(--color-bg-hover);
  text-decoration: none;
}

.nav-main a svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.nav-main li.active>a {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
  font-weight: var(--weight-semibold);
}

.nav-main li.active-trail>a {
  color: var(--color-primary);
}

/* ============================================
   SUBMENU / NESTED NAVIGATION
   ============================================ */

.nav-main li {
  position: relative;
}

.nav-main .submenu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 200px;
  padding-top: calc(var(--space-1) + var(--space-2));
  padding-bottom: var(--space-2);
  margin-top: calc(-1 * var(--space-1));
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-fast) var(--ease-out);
  z-index: var(--z-dropdown);

  /* Reset flex layout */
  display: block;
}

.nav-main li:hover>.submenu,
.nav-main li:focus-within>.submenu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

[data-theme="dark"] .nav-main .submenu {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.nav-main .submenu li {
  margin: 0;
  width: 100%;
}

.nav-main .submenu a {
  width: 100%;
  padding: var(--space-2) var(--space-4);
  border-radius: 0;
  font-size: var(--text-sm);
}

.nav-main .submenu li:first-child a {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.nav-main .submenu li:last-child a {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.nav-main .submenu li.active>a {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
  font-weight: var(--weight-semibold);
}

/* ============================================
   MOBILE NAVIGATION
   ============================================ */

.mobile-nav-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast) var(--ease-out);
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-toggle:hover {
  background-color: var(--color-bg-hover);
}

@media (min-width: 768px) {
  .mobile-nav-toggle {
    display: none;
  }
}

.mobile-nav-toggle svg {
  width: 24px;
  height: 24px;
}

/* Mobile Menu */
.mobile-nav {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-modal);
  display: none;
  background-color: var(--color-bg-primary);
  overflow-y: auto;
  touch-action: pan-y;
  overscroll-behavior: contain;
  /* Use smooth drawer animation */
  transform: translate3d(0, -100%, 0);
  transition: transform var(--transition-smooth);
  will-change: transform;
}

.mobile-nav.is-open {
  transform: translate3d(0, 0, 0);
  will-change: auto;
}

.mobile-nav.is-open {
  display: block;
  transform: translate3d(0, 0, 0);
  will-change: auto;
}

.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.mobile-nav-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast) var(--ease-out);
}

.mobile-nav-close:hover {
  background-color: var(--color-bg-hover);
}

.mobile-nav-close svg {
  width: 24px;
  height: 24px;
}

.mobile-nav ul {
  padding: var(--space-4);
  list-style: none;
}

.mobile-nav li {
  margin: 0;
}

.mobile-nav a {
  display: block;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast) var(--ease-out);
}

.mobile-nav a:hover {
  color: var(--color-primary);
  background-color: var(--color-bg-hover);
  text-decoration: none;
}

.mobile-nav li.active>a {
  color: var(--color-primary);
  background-color: var(--color-bg-secondary);
}

/* Mobile submenus - show as nested list */
.mobile-nav .submenu {
  display: none;
  padding-left: var(--space-6);
  margin-top: var(--space-2);
}

.mobile-nav li.has-submenu>a::after {
  content: '▼';
  margin-left: var(--space-2);
  font-size: var(--text-sm);
  opacity: 0.6;
  transition: transform var(--transition-fast);
}

.mobile-nav li.has-submenu.submenu-open>a::after {
  transform: rotate(180deg);
}

.mobile-nav li.has-submenu.submenu-open>.submenu {
  display: block;
}

/* Mobile Navigation Footer (Theme Controls) */
.mobile-nav-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}

.mobile-nav-footer .theme-controls {
  justify-content: center;
}

.mobile-nav-footer .theme-dropdown__button {
  width: 100%;
  justify-content: center;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
}

.mobile-nav-footer .theme-dropdown {
  /* Make this the positioning context */
  position: static;
}

.mobile-nav-footer .theme-dropdown__menu {
  /* Use fixed positioning to escape overflow constraints */
  position: fixed;
  left: 50%;
  right: auto;
  bottom: 80px;
  /* Position above the footer */
  top: auto;
  transform: translateX(-50%) translateY(8px);
  width: calc(100% - 2rem);
  max-width: 300px;
  /* Ensure dropdown appears above mobile nav overlay */
  z-index: calc(var(--z-modal) + 10);
  margin-bottom: 0;
  /* Smooth transition */
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  opacity: 0;
  visibility: hidden;
}

.mobile-nav-footer .theme-dropdown__menu.open {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}

/* (Removed legacy single-button theme toggle styles) */

/* Theme Controls (toggle + dropdown) */
.theme-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Desktop theme controls wrapper */
.theme-controls-desktop {
  display: none;
}

@media (min-width: 768px) {
  .theme-controls-desktop {
    display: block;
  }
}

.theme-dropdown {
  position: relative;
}

.theme-dropdown__button {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  background: linear-gradient(180deg,
      rgba(255, 255, 255, 0.92),
      rgba(242, 242, 242, 0.9));
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast) var(--ease-out), box-shadow 0.2s ease;
  /* Neumorphic shadow - refined depth */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.32),
    inset 0.5px 0.5px 1px rgba(255, 255, 255, 0.4),
    inset -0.5px -0.5px 1px rgba(0, 0, 0, 0.15),
    1px 1px 2px rgba(0, 0, 0, 0.08),
    -0.5px -0.5px 1px rgba(255, 255, 255, 0.3);
}

.theme-dropdown__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.theme-dropdown__icon svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  display: block;
  flex-shrink: 0;
}

/* Theme dropdown chevron icon (direct child SVG, not inside icon span) */
.theme-dropdown__button > svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  flex-shrink: 0;
  display: block;
}

.theme-dropdown__icon circle {
  transform-origin: center;
}

.theme-dropdown__button:hover {
  color: var(--color-primary);
  background: linear-gradient(180deg,
      rgba(255, 255, 255, 0.95),
      rgba(245, 245, 245, 0.92));
  border-color: var(--color-primary);
  /* Neumorphic hover - refined raised effect */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.35),
    inset 0.5px 0.5px 1.5px rgba(255, 255, 255, 0.5),
    inset -0.5px -0.5px 1.5px rgba(0, 0, 0, 0.12),
    2px 2px 6px rgba(0, 0, 0, 0.1),
    -1px -1px 3px rgba(255, 255, 255, 0.4);
}

.theme-dropdown__button:active {
  /* Neumorphic pressed state */
  transform: translateY(1px);
  box-shadow:
    inset 2px 2px 3px rgba(0, 0, 0, 0.18),
    inset -1px -1px 2px rgba(255, 255, 255, 0.25);
  background: linear-gradient(180deg,
      rgba(240, 240, 240, 0.95),
      rgba(230, 230, 230, 0.93));
}

.theme-dropdown__button[aria-expanded="true"] {
  color: var(--color-primary);
  background: linear-gradient(180deg,
      rgba(248, 248, 248, 0.96),
      rgba(238, 238, 238, 0.94));
  border-color: var(--color-primary);
  /* Neumorphic shadow when expanded */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.35),
    inset 0.5px 0.5px 1px rgba(255, 255, 255, 0.4),
    inset -0.5px -0.5px 1px rgba(0, 0, 0, 0.12),
    2px 2px 6px rgba(0, 0, 0, 0.1),
    -1px -1px 3px rgba(255, 255, 255, 0.3);
}

.theme-dropdown__menu {
  position: absolute;
  right: 0;
  margin-top: 0.5rem;
  min-width: 180px;
  padding: 0.25rem;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  /* Neumorphic shadow for dropdown */
  box-shadow:
    inset 0.5px 0.5px 1px rgba(255, 255, 255, 0.3),
    inset -0.5px -0.5px 1px rgba(0, 0, 0, 0.1),
    4px 4px 12px rgba(0, 0, 0, 0.12),
    -2px -2px 6px rgba(255, 255, 255, 0.2);
  list-style: none;
  display: none;
  z-index: var(--z-dropdown);
  transition: box-shadow 0.2s ease;
}

.theme-dropdown__menu.open {
  display: block;
}

/* Override for mobile nav footer - use visibility/opacity for smooth animation */
.mobile-nav-footer .theme-dropdown__menu {
  display: block;
}

.theme-dropdown__menu li {
  margin: 0;
}

.theme-dropdown__menu li.separator {
  height: 1px;
  background: var(--color-border-light);
  margin: 0.25rem 0.25rem;
}

.theme-dropdown__menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  padding: 0.5rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast) var(--ease-out), box-shadow 0.2s ease;
}

.theme-dropdown__menu button:hover,
.theme-dropdown__menu button:focus {
  background: var(--color-bg-secondary);
  color: var(--color-primary);
}

.theme-dropdown__menu button:active {
  /* Neumorphic pressed state for menu items */
  box-shadow:
    inset 1px 1px 2px rgba(0, 0, 0, 0.1),
    inset -0.5px -0.5px 1px rgba(255, 255, 255, 0.15),
    0.5px 0.5px 1px rgba(0, 0, 0, 0.05);
  background: var(--color-bg-tertiary);
}

.theme-dropdown__menu button.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: var(--weight-medium);
  position: relative;
}

.theme-dropdown__menu button.active::after {
  content: '✓';
  position: absolute;
  right: 0.5rem;
  color: var(--color-primary);
  font-size: var(--text-base);
}

/* ============================================
   DARK MODE - Theme Dropdown
   ============================================ */

[data-theme="dark"] .theme-dropdown__button {
  /* Neumorphic shadow for dark mode */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0.5px 0.5px 1px rgba(255, 255, 255, 0.08),
    inset -0.5px -0.5px 1px rgba(0, 0, 0, 0.4),
    1px 1px 3px rgba(0, 0, 0, 0.25),
    -0.5px -0.5px 1px rgba(255, 255, 255, 0.05);
  background: linear-gradient(180deg,
      rgba(38, 38, 38, 0.95),
      rgba(22, 22, 22, 0.95));
}

[data-theme="dark"] .theme-dropdown__button:hover {
  /* Neumorphic hover for dark mode */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0.5px 0.5px 1.5px rgba(255, 255, 255, 0.12),
    inset -0.5px -0.5px 1.5px rgba(0, 0, 0, 0.5),
    2px 2px 6px rgba(0, 0, 0, 0.35),
    -1px -1px 3px rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg,
      rgba(44, 44, 44, 0.96),
      rgba(27, 27, 27, 0.96));
}

[data-theme="dark"] .theme-dropdown__button:active {
  /* Neumorphic pressed state for dark mode */
  transform: translateY(1px);
  box-shadow:
    inset 2px 2px 3px rgba(0, 0, 0, 0.45),
    inset -1px -1px 2px rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg,
      rgba(30, 30, 30, 0.97),
      rgba(18, 18, 18, 0.97));
}

[data-theme="dark"] .theme-dropdown__button[aria-expanded="true"] {
  /* Neumorphic shadow when expanded - dark mode */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0.5px 0.5px 1px rgba(255, 255, 255, 0.12),
    inset -0.5px -0.5px 1px rgba(0, 0, 0, 0.4),
    2px 2px 6px rgba(0, 0, 0, 0.35),
    -1px -1px 3px rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg,
      rgba(48, 48, 48, 0.97),
      rgba(30, 30, 30, 0.97));
}

[data-theme="dark"] .theme-dropdown__menu {
  /* Neumorphic shadow for dark mode dropdown */
  box-shadow:
    inset 0.5px 0.5px 1px rgba(255, 255, 255, 0.08),
    inset -0.5px -0.5px 1px rgba(0, 0, 0, 0.4),
    4px 4px 12px rgba(0, 0, 0, 0.3),
    -2px -2px 6px rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .theme-dropdown__menu button:active {
  /* Neumorphic pressed state for menu items - dark mode */
  box-shadow:
    inset 1px 1px 2px rgba(0, 0, 0, 0.3),
    inset -0.5px -0.5px 1px rgba(255, 255, 255, 0.08),
    0.5px 0.5px 1px rgba(0, 0, 0, 0.15);
  background: var(--color-bg-tertiary);
}

/* ============================================
   PALETTE-SPECIFIC ACTIVE NAVIGATION STYLING
   ============================================ */

/* Brown Bengal - Warm amber active navigation */
[data-palette="brown-bengal"] .nav-main li.active>a,
[data-palette="brown-bengal"] .nav-main .submenu li.active>a {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="brown-bengal"] .nav-main li.active>a,
[data-theme="dark"][data-palette="brown-bengal"] .nav-main .submenu li.active>a {
  background-color: var(--color-primary-light);
}

/* Blue Bengal - Soft powder blue active navigation */
[data-palette="blue-bengal"] .nav-main li.active>a,
[data-palette="blue-bengal"] .nav-main .submenu li.active>a {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="blue-bengal"] .nav-main li.active>a,
[data-theme="dark"][data-palette="blue-bengal"] .nav-main .submenu li.active>a {
  background-color: var(--color-primary-light);
}

/* Silver Bengal - High contrast monochrome active navigation */
[data-palette="silver-bengal"] .nav-main li.active>a,
[data-palette="silver-bengal"] .nav-main .submenu li.active>a {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="silver-bengal"] .nav-main li.active>a,
[data-theme="dark"][data-palette="silver-bengal"] .nav-main .submenu li.active>a {
  background-color: var(--color-primary-light);
}

/* Charcoal Bengal - Dramatic slate active navigation */
[data-palette="charcoal-bengal"] .nav-main li.active>a,
[data-palette="charcoal-bengal"] .nav-main .submenu li.active>a {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="charcoal-bengal"] .nav-main li.active>a,
[data-theme="dark"][data-palette="charcoal-bengal"] .nav-main .submenu li.active>a {
  background-color: var(--color-primary-light);
}
