/* ========================================
   HYBRID NAVIGATION - COMPLETE SOLUTION
   Desktop: Dropdowns with nested sub-menus
   Mobile: Hamburger slides from LEFT
   ======================================== */

/* CRITICAL: Header must allow overflow for dropdowns */
header {
  overflow: visible !important;
  position: relative;
  z-index: 100;
}

/* Nav container - wrapper for dynamically loaded nav.
   Must be transparent to layout so nav behaves identically
   to being placed directly in the header. */
#nav-container {
  overflow: visible;
  position: relative;
  z-index: 10000;
}

/* Keep image grid below navigation */
.image-grid {
  position: relative;
  z-index: 1;
}

/* Main Navigation Container */
.main-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  padding: 1em;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 10px;
  margin: 20px auto;
  max-width: 900px;
  position: relative;
  z-index: 10000 !important;
  overflow: visible !important;
}

/* Mobile hamburger button - hidden on desktop */
.nav-toggle {
  display: none;
  background: white;
  border: 2px solid #667eea;
  border-radius: 8px;
  cursor: pointer;
  padding: 0.5em;
  position: absolute;
  left: 15px;
  z-index: 10002;
  width: 45px;
  height: 45px;
}

.nav-toggle span {
  display: block;
  width: 25px;
  height: 3px;
  background: #667eea;
  margin: 5px auto;
  transition: all 0.3s;
  border-radius: 2px;
}

/* Hamburger animation to X */
.nav-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.nav-toggle.active span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(6px, -6px);
}

/* Navigation items container */
.nav-items {
  display: flex;
  gap: 0;
  align-items: center;
  position: relative;
  z-index: 10001 !important;
}

/* Simple nav links (Dog AI, Daily Fact) */
.nav-link {
  color: white;
  text-decoration: none;
  padding: 10px 10px;
  border-radius: 5px;
  font-weight: 600;
  transition: all 0.3s;
  white-space: nowrap;
  display: block;
  font-size: 0.88em;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.2);
}

/* Dropdown containers */
.nav-dropdown {
  position: relative;
  z-index: 10002 !important;
}

/* Dropdown trigger button */
.nav-dropdown-btn {
  color: white;
  background: none;
  border: none;
  padding: 10px 10px;
  font-weight: 600;
  font-size: 0.88em;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 5px;
  transition: all 0.3s;
}

.nav-dropdown-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.nav-dropdown-btn::after {
  content: '\25BC';
  font-size: 0.7em;
  transition: transform 0.3s;
}

.nav-dropdown.active .nav-dropdown-btn::after {
  transform: rotate(180deg);
}

/* Dropdown menu - CRITICAL z-index */
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  margin-top: 5px;
  z-index: 10003 !important;
  overflow: visible;
}

.nav-dropdown.active .nav-dropdown-menu {
  display: block;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Dropdown menu links */
.nav-dropdown-menu a {
  display: block;
  padding: 12px 20px;
  color: #333;
  text-decoration: none;
  transition: background 0.2s;
  border-bottom: 1px solid #f0f0f0;
}

.nav-dropdown-menu a:last-child {
  border-bottom: none;
}

.nav-dropdown-menu a:hover {
  background: #f8f9fa;
  color: #667eea;
}

.nav-dropdown-menu a.active {
  background: #667eea;
  color: white;
}

/* ========================================
   DESKTOP NESTED SUB-MENUS
   Only applies above 768px
   ======================================== */

/* Sub-group container inside a dropdown menu */
.nav-subgroup {
  position: relative;
}

/* Sub-group trigger - looks like a menu item with arrow */
.nav-subgroup-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px 20px;
  color: #333;
  background: none;
  border: none;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  text-align: left;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.nav-subgroup:last-child .nav-subgroup-btn {
  border-bottom: none;
}

.nav-subgroup-btn:hover {
  background: #f0f2ff;
  color: #667eea;
}

.nav-subgroup-btn::after {
  content: '\25B6';
  font-size: 0.6em;
  color: #999;
  transition: color 0.2s;
  margin-left: 12px;
}

.nav-subgroup-btn:hover::after {
  color: #667eea;
}

/* Flyout sub-menu - appears to the right */
.nav-submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 220px;
  z-index: 10004 !important;
  margin-left: 2px;
}

.nav-subgroup:hover > .nav-submenu {
  display: block;
  animation: slideSide 0.2s ease;
}

@keyframes slideSide {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Sub-menu links */
.nav-submenu a {
  display: block;
  padding: 11px 18px;
  color: #333;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

.nav-submenu a:last-child {
  border-bottom: none;
}

.nav-submenu a:hover {
  background: #f0f2ff;
  color: #667eea;
}

.nav-submenu a.active {
  background: #667eea;
  color: white;
}

/* ========================================
   TABLET STYLES (max-width: 968px, min-width: 769px)
   Slightly smaller nav for tablets
   ======================================== */
@media (max-width: 968px) and (min-width: 769px) {
  .main-nav {
    max-width: 95%;
    padding: 0.6em;
  }

  .nav-link {
    padding: 8px 10px;
    font-size: 0.85em;
  }

  .nav-dropdown-btn {
    padding: 8px 10px;
    font-size: 0.85em;
  }

  .nav-subgroup-btn {
    padding: 10px 16px;
    font-size: 0.92em;
  }

  .nav-submenu a {
    padding: 10px 16px;
    font-size: 0.92em;
  }
}

/* ========================================
   MOBILE STYLES (max-width: 768px)
   Sub-groups become flat items - IDENTICAL
   to original mobile behaviour
   ======================================== */
@media (max-width: 768px) {
  /* Reduce header height on mobile */
  header {
    padding: 5px 10px;
  }
  
  /* Hide image grid on mobile to save space */
  .image-grid {
    display: none;
  }
  
  /* Smaller logo on mobile - aligned left */
  header img {
    max-height: 60px;
    width: auto;
    display: block;
    margin: 0;
  }
  
  .main-nav {
    padding: 10px;
    max-width: 100%;
    margin: 5px 0 0 0;
    background: transparent;
    border-radius: 0;
    min-height: 50px;
    position: relative;
  }

  /* Show hamburger button on LEFT */
  .nav-toggle {
    display: block;
    position: fixed;
    bottom: auto;
    top: auto;
    left: 10px;
    width: 40px;
    height: 40px;
    z-index: 10003;
  }

  /* Hide hamburger when menu is open (X not needed - overlay closes menu) */
  .nav-toggle.active {
    left: 240px;
    top: 10px;
    position: fixed;
    z-index: 10003;
  }
  
  .nav-toggle span {
    width: 22px;
    height: 2px;
    margin: 4px auto;
  }

  /* Mobile menu - slides from LEFT */
  .nav-items {
    display: flex;
    flex-direction: column;
    width: 280px;
    gap: 0;
    position: fixed;
    top: 0;
    left: -300px;
    height: 100vh;
    max-height: 100vh;
    background: white;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.2);
    z-index: 10001 !important;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    transition: left 0.3s ease;
    padding: 10px 0 200px 0;
    visibility: hidden;
  }

  /* Show nav items when menu is active - slides to left: 0 */
  .nav-items.active {
    left: 0;
    visibility: visible;
  }

  /* Dark overlay behind menu - ONLY COVERS RIGHT SIDE */
  .nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 280px;
    width: calc(100% - 280px);
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
  }

  .nav-overlay.active {
    display: block;
  }

  /* Mobile link styles - LEFT ALIGNED */
  .nav-link {
    width: 100%;
    text-align: left;
    color: #333 !important;
    border-radius: 0;
    border-bottom: 1px solid #f0f0f0;
    padding: 16px 20px;
    display: block;
    font-size: 16px;
    background: #ffffff !important;
  }

  .nav-link:hover,
  .nav-link.active {
    background: #f8f9fa !important;
    color: #667eea !important;
  }

  /* Mobile dropdown container - MUST fill width */
  .nav-dropdown {
    width: 100%;
    position: relative;
    z-index: auto;
  }

  /* Mobile dropdown button - LEFT ALIGNED */
  .nav-dropdown-btn {
    width: 100%;
    text-align: left;
    color: #333 !important;
    justify-content: space-between;
    border-radius: 0;
    border-bottom: 1px solid #f0f0f0;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    font-size: 16px;
    background: #ffffff !important;
  }

  .nav-dropdown-btn:hover {
    background: #f8f9fa !important;
    color: #667eea !important;
  }

  /* Mobile dropdown menu */
  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border-radius: 0;
    background: #f8f9fa !important;
    margin-top: 0;
    overflow: hidden;
  }

  /* Mobile dropdown items - INDENTED and LEFT ALIGNED */
  .nav-dropdown-menu a {
    padding: 14px 20px 14px 50px;
    font-size: 15px;
    display: block;
    color: #333 !important;
    text-align: left;
    background: #f8f9fa !important;
    border-bottom: 1px solid #e0e0e0;
  }
  
  .nav-dropdown-menu a:hover {
    background: #e9ecef !important;
    color: #667eea !important;
  }
  
  .nav-dropdown-menu a.active {
    background: #667eea !important;
    color: white !important;
  }

  /* ---- MOBILE: Sub-groups are collapsible sections ---- */
  .nav-subgroup {
    position: static;
  }

  /* Sub-group header - visible, tappable, styled as a section header */
  .nav-subgroup-btn {
    display: flex !important;
    width: 100%;
    text-align: left;
    color: #667eea !important;
    background: #eef0ff !important;
    border: none;
    border-bottom: 1px solid #d0d4ff;
    padding: 12px 20px 12px 36px;
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    justify-content: space-between;
    align-items: center;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  /* Chevron - points down, rotates up when open */
  .nav-subgroup-btn::after {
    content: '\25BC';
    font-size: 0.6em;
    color: #667eea;
    transition: transform 0.25s;
    margin-left: 8px;
    flex-shrink: 0;
  }

  .nav-subgroup-btn.active::after {
    transform: rotate(180deg);
  }

  /* Sub-menu hidden by default on mobile */
  .nav-submenu {
    display: none !important;
    position: static !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    min-width: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    animation: none !important;
  }

  /* Shown when JS adds .active */
  .nav-submenu.active {
    display: block !important;
  }

  /* Sub-menu links - deeper indent than group header */
  .nav-submenu a {
    padding: 13px 20px 13px 52px;
    font-size: 15px;
    display: block;
    color: #333 !important;
    text-align: left;
    background: #f8f9fa !important;
    border-bottom: 1px solid #e0e0e0;
    white-space: normal;
  }

  .nav-submenu a:hover {
    background: #e9ecef !important;
    color: #667eea !important;
  }

  .nav-submenu a.active {
    background: #667eea !important;
    color: white !important;
  }
}

/* ========================================
   MOBILE LANDSCAPE MODE - Extra compact
   ======================================== */
@media (max-width: 768px) and (orientation: landscape) {
  header {
    padding: 2px 5px;
  }
  
  header img {
    max-height: 40px;
    margin: 0;
  }
  
  .main-nav {
    min-height: 40px;
    margin: 2px 0 0 0;
  }
  
  .nav-toggle {
    width: 35px;
    height: 35px;
  }

  .nav-toggle.active {
    left: 240px;
    top: 5px;
  }
  
  .nav-toggle span {
    width: 20px;
    height: 2px;
    margin: 3px auto;
  }
}
