/* SA Mega Menu — multi-level hover dropdown
 * Designed to fit topbar; mega panel anchored under trigger button.
 * Uses CSS variables from base theme (--c-primary, --c-sidebar-to, etc.)
 * Mobile: panel becomes full-width fixed overlay.
 */
.sa-megamenu-wrap {
  position: relative;
  display: inline-block;
  margin-left: 4px;
  margin-right: 4px;
}
.sa-megamenu-trigger {
  background: var(--c-table-head, #f5f3ff);
  border: 1px solid var(--c-input-border, #e5e7eb);
  color: var(--c-primary, #166534);
  border-radius: 8px;
  padding: 4px 10px;
  transition: all .15s ease;
}
.sa-megamenu-trigger:hover,
.sa-megamenu-trigger[aria-expanded="true"] {
  background: var(--c-primary, #166534);
  color: #fff;
  border-color: var(--c-primary, #166534);
}
.sa-megamenu-trigger i { font-size: 1rem; }

.sa-megamenu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 720px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 12px 40px rgba(0,0,0,.15), 0 4px 12px rgba(0,0,0,.06);
  z-index: 1050;
  display: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .18s ease, transform .18s ease;
}
.sa-megamenu-wrap.open .sa-megamenu-panel {
  display: block;
  animation: sa-megamenu-fade .18s ease forwards;
}
@keyframes sa-megamenu-fade {
  to { opacity: 1; transform: translateY(0); }
}
.sa-megamenu-head {
  background: linear-gradient(135deg, var(--c-primary, #166534), var(--c-sidebar-to, #14532d));
  color: #fff;
  padding: 12px 18px;
  font-weight: 800;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 14px 14px 0 0;
}
.sa-megamenu-cog {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: .9rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.sa-megamenu-cog:hover { background: rgba(255,255,255,.15); color: #fff; }

.sa-megamenu-body {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 22px;
}
.sa-megamenu-group {
  min-width: 0;
}
.sa-megamenu-group-title {
  font-size: .68rem;
  font-weight: 800;
  color: var(--c-primary, #166534);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin: 0 0 6px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--c-primary, #166534);
  border-bottom-color: rgba(22,101,52,.15);
}
.sa-megamenu-list,
.sa-megamenu-sublist {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sa-megamenu-item {
  position: relative;
}
.sa-megamenu-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: .82rem;
  font-weight: 600;
  color: #334155;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.sa-megamenu-link:hover,
.sa-megamenu-link:focus {
  background: rgba(22,101,52,.08);
  color: var(--c-primary, #166534);
  text-decoration: none;
}
.sa-megamenu-link i:first-child {
  color: var(--c-primary, #166534);
  font-size: .9rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.sa-megamenu-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sa-megamenu-chev {
  font-size: .7rem !important;
  color: #94a3b8 !important;
  margin-left: auto;
}

/* Sub-menu (level 2+): expand on hover — flyout to right */
.sa-megamenu-item.has-children > .sa-megamenu-sublist {
  display: none;
  position: absolute;
  left: 100%;
  top: -4px;
  min-width: 200px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 6px;
  z-index: 1;
}
.sa-megamenu-item.has-children:hover > .sa-megamenu-sublist,
.sa-megamenu-item.has-children:focus-within > .sa-megamenu-sublist {
  display: block;
}
/* Indicator on parent when sub is open */
.sa-megamenu-item.has-children:hover > .sa-megamenu-link,
.sa-megamenu-item.has-children:focus-within > .sa-megamenu-link {
  background: rgba(22,101,52,.10);
}

/* Avoid sub flying off right edge — flip to left if near edge */
.sa-megamenu-group:nth-child(n+3) .sa-megamenu-item.has-children > .sa-megamenu-sublist {
  left: auto;
  right: 100%;
}

/* Mobile / narrow viewport: panel goes full width */
@media (max-width: 768px) {
  .sa-megamenu-panel {
    position: fixed;
    top: 56px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
  }
  .sa-megamenu-body {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  /* Sub-menus on mobile expand inline rather than flyout */
  .sa-megamenu-item.has-children > .sa-megamenu-sublist {
    position: static;
    box-shadow: none;
    border: none;
    border-left: 2px solid rgba(22,101,52,.15);
    border-radius: 0;
    padding-left: 8px;
    margin-left: 12px;
  }
}
