/* 
 * DILG Cebu Province Website
 * Dynamic Drop-right Submenu Styles
 */

/* Prevent horizontal scrolling when submenus expand */
body {
  overflow-x: hidden;
  
  /* Ensure submenus can be accessed via keyboard navigation */
  .has-dropdown:focus-within > .dropdown-menu,
  .has-dropright:focus-within > .dropdown-menu,
  .has-drop-right:focus-within > .drop-right-menu {
    display: block;
  }
}

/* Add JavaScript-free viewport edge detection via CSS */
@media (min-width: 769px) {
  /* For very wide menus or menus near the right edge */
  @supports (position: fixed) {
    /* This creates a safe zone for menus that might overflow */
    .has-dropright:hover > .dropdown-menu,
    .has-drop-right:hover > .drop-right-menu {
      max-width: calc(100vw - 50px);
      overflow-x: auto;
    }
  }

  /* Drop-right submenu styles */
  .has-drop-right {
    position: relative;
  }

  .drop-right-menu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    min-width: 200px;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
    z-index: 120;
    list-style: none;
    padding: 0;
  }

  .has-drop-right:hover .drop-right-menu {
    display: block;
  }

  /* Base styles for dropdown menus */
  .dropdown-menu {
    position: absolute;
    z-index: 1000;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
    list-style: none;
    padding: 0;
    margin: 0;
  }

  /* When the drop-right menu should be visible (using pure CSS) */
  .has-dropright:hover > .dropdown-menu,
  .has-dropright:focus-within > .dropdown-menu {
    display: block;
  }

  /* Auto-positioning for submenus that would overflow the viewport */
  .has-dropright.viewport-edge > .dropdown-menu {
    left: auto;
    right: 100%;
  }

  .has-drop-right.viewport-edge .drop-right-menu {
    left: auto;
    right: 100%;
  }
}

/* Improved styling for deeper nested menus (3+ levels) */
.drop-right-menu .drop-right-menu {
  z-index: 130; /* Increase z-index for deeper levels to ensure proper stacking */
}

.drop-right-menu .drop-right-menu .drop-right-menu {
  z-index: 140; /* Further increase for even deeper levels */
}

/* Positioning for standard drop-right menus */
.has-dropright > .dropdown-menu {
  top: 0;
  left: 100%;
  margin-top: 0;
  margin-left: 0;
}

/* Ensure proper arrow direction for edge-positioned menus */
.has-dropright.viewport-edge > .dropdown-toggle::after {
  transform: rotate(180deg);
}

/* Arrow indicator for has-drop-right items */
.has-drop-right > a::after {
  display: inline-block;
  margin-left: 0.255em;
  vertical-align: 0.255em;
  content: "";
  border-top: 0.3em solid transparent;
  border-right: 0;
  border-bottom: 0.3em solid transparent;
  border-left: 0.3em solid;
}

/* Ensure proper arrow direction for edge-positioned menus with has-drop-right */
.has-drop-right.viewport-edge > a::after {
  transform: rotate(180deg);
}

/* Add subtle visual cues for menu depth */
.drop-right-menu {
  border-left: 1px solid rgba(0,0,0,0.1);
}

/* Improve menu item spacing for better readability */
.drop-right-menu li {
  padding: 2px 0;
}

.drop-right-menu li a {
  padding: 8px 15px;
  display: block;
  white-space: nowrap;
  transition: background-color 0.2s ease;
}

.drop-right-menu li a:hover {
  background-color: rgba(0,0,0,0.05);
}

/* Transition effects for smoother animations */
.has-dropright > .dropdown-menu,
.has-drop-right .drop-right-menu {
  transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.has-dropright:hover > .dropdown-menu,
.has-dropright:focus-within > .dropdown-menu,
.has-drop-right:hover .drop-right-menu,
.has-drop-right:focus-within .drop-right-menu {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Allow full text display in menu items */
.dropdown-menu li a,
.drop-right-menu li a {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  max-width: none;
}

/* Ensure menus don't get too tall on smaller screens */
@media (max-height: 700px) {
  .drop-right-menu {
    max-height: 80vh;
    overflow-y: auto;
  }
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
  .has-dropright > .dropdown-menu {
    position: static;
    margin-left: 1rem;
    box-shadow: none;
    border: none;
    background-color: transparent;
  }
  
  .has-dropright.drop-left > .dropdown-menu {
    right: auto;
    left: auto;
  }
  
  /* Mobile adjustments for drop-right menus */
  .drop-right-menu {
    position: static;
    margin-left: 1rem;
    box-shadow: none;
    border: none;
    width: 100%;
    background-color: transparent;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
  }
  
  /* Improved indentation for nested mobile menus */
  .drop-right-menu .drop-right-menu {
    margin-left: 1.5rem;
  }
  
  .drop-right-menu .drop-right-menu .drop-right-menu {
    margin-left: 2rem;
  }
  
  /* Mobile accordion animation for drop-right menus */
  .has-drop-right.open > .drop-right-menu {
    max-height: 80vh;
  }
  
  /* Mobile accordion style for top-menu dropdowns using pure CSS */
  .main-navigation .main-menu .has-dropdown > .dropdown-menu {
    display: none;
  }

  /* Show submenu on tap/focus for mobile */
  .main-navigation .main-menu .has-dropdown:focus-within > .dropdown-menu {
    display: block;
  }

  /* Optional: rotate arrow indicator for focus state */
  .main-navigation .main-menu .has-dropdown > a::after {
    transition: transform 0.3s ease;
  }
  .main-navigation .main-menu .has-dropdown:focus-within > a::after {
    transform: rotate(90deg);
  }
  
  /* Support for tap-to-expand on mobile */
  .main-navigation .main-menu .has-dropdown > a,
  .has-dropright > a,
  .has-drop-right > a {
    position: relative;
  }
  
  /* Add a larger tap area for mobile navigation */
  .main-navigation .main-menu .has-dropdown > a::before,
  .has-dropright > a::before,
  .has-drop-right > a::before {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    width: 50px;
    height: 100%;
    z-index: 1;
  }
}

/* Helper for consistent root menu padding */
.root-menu-padding > .dropdown-menu,
.root-menu-padding > .drop-right-menu {
  margin-left: 1rem;
}

/* Ensure dropdown toggles have proper cursor */
.has-dropright > .dropdown-toggle,
.has-drop-right > a {
  cursor: pointer;
}

/* Add a subtle indicator for items with submenus */
.has-dropright > .dropdown-toggle::after,
.has-dropright > a::after {
  display: inline-block;
  margin-left: 0.255em;
  vertical-align: 0.255em;
  content: "";
  border-top: 0.3em solid transparent;
  border-right: 0;
  border-bottom: 0.3em solid transparent;
  border-left: 0.3em solid;
}

/* Grey out and disable links with href="#" */
.main-menu .dropdown-menu a[href="#"],
.main-menu .drop-right-menu a[href="#"] {
  color: #aaa;          /* Change text color to grey */
  opacity: 0.6;         /* Reduce opacity for visual cue */
  pointer-events: none; /* Disable clicking */
  cursor: default;      /* Change cursor to default arrow */
}

/* Optional: Disable hover effects */
.main-menu .dropdown-menu a[href="#"]:hover,
.main-menu .drop-right-menu a[href="#"]:hover {
  background: none;
}

/* Safety rule to ensure dropdown appears on mobile when JS toggles .open */
@media (max-width: 768px) {
  .has-dropdown.open > .dropdown-menu {
    display: block;
  }
}