/* Sticky Sidebar Layout */
.hdd-sticky-layout {
  display: flex;
  align-items: stretch;
  /* ensure columns are equal height so sticky has full height to work with */
  gap: 24px;
}

/* Sticky sidebar: 300px */
.hdd-sticky-sidebar {
  flex: 0 0 300px;
  width: 300px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  transition: top 0.3s ease;
}

/* Adjust for WP Admin Bar heights */
@media (min-width: 783px) {
  .admin-bar .hdd-sticky-sidebar {
    top: 32px;
  }

  /* Ensure direct ancestors don't clip vertical overflow, which breaks sticky */
  .hdd-sticky-layout>* {
    overflow-y: visible !important;
    align-self: stretch;
    /* stretch children to container height */
  }
}

@media (max-width: 782px) {
  .admin-bar .hdd-sticky-sidebar {
    top: 46px;
  }
}

/* Main content flexes to fill remaining width */
.hdd-main-content {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  /* Prevent horizontal scroll/whitespace */
  overflow-wrap: anywhere;
  /* Break long words/URLs if needed */
}

/* Ensure inner elements don't overflow the main content */
.hdd-main-content img,
.hdd-main-content iframe,
.hdd-main-content video,
.hdd-main-content .elementor-container,
.hdd-main-content .elementor-widget-container {
  max-width: 100%;
}

/* Safety: avoid layout overflow from the flex container itself */
.hdd-sticky-layout {
  overflow-x: hidden;
  overflow-y: visible;
  /* ensure sticky can calculate vertical offset */
}

/* Desktop: force fixed sidebar so it stays visible beyond shorter parents */
@media (min-width: 1025px) {
  .hdd-sticky-layout {
    align-items: stretch;
    overflow-y: visible;
    position: relative;
  }

  /* Reserve space for the fixed sidebar to avoid content jump */
  .hdd-main-content {
    margin-left: 324px;
    /* 300px sidebar + 24px gap */
  }

  .hdd-sticky-sidebar {
    position: fixed;
    top: 20px;
    left: auto;
    width: 300px;
    max-height: calc(100vh - 40px);
    overflow: auto;
    z-index: 5;
  }

  /* If WordPress admin bar is present on desktop */
  .admin-bar .hdd-sticky-sidebar {
    top: 32px;
  }

  /* Disable any animation class to prevent shifting */
  .hdd-sticky-sidebar.scrolled {
    animation: none !important;
  }
}

/* Basic widget area styling */
.hdd-sticky-sidebar .widget {
  /* background: var(--e-global-color-primary);
  border: 1px solid #e5e7eb; */
  border-radius: 8px;
  padding: 16px;
  margin: 0 0 16px;
}

.hdd-sticky-sidebar .widget-title {
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 1.3;
}

/* Placeholder when no widgets are assigned */
.hdd-sidebar-placeholder {
  border: 2px dashed #e5e7eb;
  color: #6b7280;
  padding: 16px;
  border-radius: 8px;
  background: #fafafa;
}

/* Responsive adjustments for mobile only - consolidated below */

/* Mobile: place sidebar at the bottom and ensure non-sticky */
@media (max-width: 782px) {
  .hdd-sticky-layout {
    flex-direction: column;
  }

  .hdd-sticky-sidebar {
    position: static;
    top: auto;
    max-height: none;
    overflow: visible;
    order: 2;
    /* Push to bottom after main content */
    width: 100%;
    margin-top: 16px;
  }
}

/* Animation for vertical centering on larger screens */
@keyframes centerSidebar {
  0% {
    top: 20px;
    /* Start close to the top */
  }

  100% {
    top: calc(50% - 250px);
    /* Center the sidebar vertically */
  }
}

/* Disable animation for tablet/desktop to keep sidebar fixed */
@media (min-width: 783px) {
  .hdd-sticky-sidebar.scrolled {
    animation: none !important;
  }
}

/* Example styles for menu when inside sticky sidebar */
#sticky-sidebar-layout #nav_menu-4 {
  background-color: transparent;
  /* per-item backgrounds instead */
  border-radius: 0;
  padding: 0;
}

#sticky-sidebar-layout #menu-side-bar-menu {
  list-style: none;
  margin: 0;
  padding: 0;
  background-color: transparent;
  /* each item will have its own bg */
}

#sticky-sidebar-layout #menu-side-bar-menu>.menu-item {
  margin-bottom: 10px;
  /* larger gap between main items */
}

#sticky-sidebar-layout #menu-side-bar-menu .menu-item a {
  color: white;
  text-decoration: none;
  padding: 10px;
  display: block;
  border-radius: 8px;
  background-color: var(--e-global-color-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Remove submenu bullet points */
#sticky-sidebar-layout #menu-side-bar-menu .sub-menu {
  list-style: none;
  padding-left: 20px;
}

#sticky-sidebar-layout #menu-side-bar-menu .menu-item a:hover {
  background-color: white;
  color: var(--e-global-color-primary);
  border-radius: 8px;
}

/* Keep caret visible when background is white */
#sticky-sidebar-layout #menu-side-bar-menu li.has-children>a:hover+.hdd-menu-toggle::after {
  border-top-color: var(--e-global-color-primary);
}

/* Do not show special style for active/current items */
#sticky-sidebar-layout #menu-side-bar-menu .menu-item.current-menu-item>a,
#sticky-sidebar-layout #menu-side-bar-menu .menu-item.current_page_item>a,
#sticky-sidebar-layout #menu-side-bar-menu .menu-item.current-menu-ancestor>a,
#sticky-sidebar-layout #menu-side-bar-menu .menu-item.current-menu-parent>a {
  background-color: var(--e-global-color-primary);
  color: #fff;
  border: 1px solid var(--e-global-color-primary);
}

/* Accordion behavior: hide submenus by default to prevent FOUC */
#sticky-sidebar-layout #menu-side-bar-menu li.has-children>.sub-menu {
  display: none;
  margin-top: 6px;
  /* gap so expanded submenu doesn't touch its parent */
  background: transparent;
  /* no panel background */
  border: 0;
  /* no panel border */
  border-radius: 0;
  padding: 0;
  /* spacing handled per-item */
}

/* Positioning for accordion row */
#sticky-sidebar-layout #menu-side-bar-menu li.has-children {
  position: relative;
}

/* Submenu items: primary text on white bg per item */
#sticky-sidebar-layout #menu-side-bar-menu .sub-menu .menu-item {
  margin-bottom: 2px;
}

#sticky-sidebar-layout #menu-side-bar-menu .sub-menu .menu-item a {
  background: #fff;
  color: var(--e-global-color-primary);
  border: 1px solid var(--e-global-color-primary);
  border-radius: 6px;
  display: block;
  padding: 8px 10px;
  position: relative;
}

/* Submenu hover: fill with primary */
#sticky-sidebar-layout #menu-side-bar-menu .sub-menu .menu-item a:hover {
  background: var(--e-global-color-primary);
  color: #fff;
  border-color: var(--e-global-color-primary);
}

/* Add room for the toggle on the right and define stacking context */
#sticky-sidebar-layout #menu-side-bar-menu li.has-children>a {
  position: relative;
  z-index: 0;
  padding-right: 42px;
}

/* Toggle button injected as LI child (sibling of anchor) */
#sticky-sidebar-layout #menu-side-bar-menu li.has-children>.hdd-menu-toggle {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  transition: transform .2s ease, background-color .2s ease, border-color .2s ease;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  /* ensure above anchor */
}

#sticky-sidebar-layout #menu-side-bar-menu li.has-children>.hdd-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.6);
}

/* Caret icon */
#sticky-sidebar-layout #menu-side-bar-menu li.has-children>.hdd-menu-toggle::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid #fff;
  transform: rotate(0deg);
  transition: transform .2s ease;
}

/* Open state: show submenu and rotate caret */
#sticky-sidebar-layout #menu-side-bar-menu li.has-children.is-open>.sub-menu {
  display: block;
}

#sticky-sidebar-layout #menu-side-bar-menu li.has-children.is-open>.hdd-menu-toggle::after {
  transform: rotate(180deg);
}