/* =============================================================
   MEGA DROPDOWN — .hdr-mega-dd
   Opens to the LEFT on all devices to stay within viewport.
   Breakpoints: 1024px (tablet-lg), 768px (tablet), 480px (mobile)
   ============================================================= */

/* ── 1. TRIGGER (parent nav item) ─────────────────────────── */
.hdr-mega-dd {
  position: static; /* allows dropdown to be positioned relative to navbar */
}

/* ── 2. DROPDOWN PANEL ────────────────────────────────────── */
.hdr-mega-dd .mega-panel {
  /* Positioning — anchored to right edge of trigger, opens left */
  position: absolute;
  top: 100%;
  right: 0;
  left: auto;

  /* Sizing */
  width: 860px;
  max-width: calc(100vw - 20px); /* never overflow viewport */

  /* Appearance */
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);

  /* Layering */
  z-index: 9999;

  /* Spacing */
  padding: 28px 24px;

  /* Hidden by default */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px);

  /* Smooth open/close */
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

/* ── 3. OPEN STATE ────────────────────────────────────────── */
/* Triggered by JS adding .is-open, or CSS :hover/:focus-within */
.hdr-mega-dd:hover .mega-panel,
.hdr-mega-dd:focus-within .mega-panel,
.hdr-mega-dd.is-open .mega-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* ── 4. INNER GRID — multi-column layout ─────────────────── */
.mega-panel__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* 4 columns on desktop */
  gap: 8px 20px;
}

/* ── 5. COLUMN HEADING ────────────────────────────────────── */
.mega-panel__col-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9ca3af;
  padding: 0 10px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid #f3f4f6;
  white-space: nowrap;
}

/* ── 6. MENU ITEMS ────────────────────────────────────────── */
.mega-panel__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: #374151;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
  min-height: 44px; /* touch-friendly minimum */
  cursor: pointer;
}

.mega-panel__item:hover,
.mega-panel__item:focus {
  background: #f0f4ff;
  color: #4f46e5;
  transform: translateX(-2px); /* subtle left nudge on hover */
  outline: none;
}

/* Keyboard focus ring for accessibility */
.mega-panel__item:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}

/* Item icon */
.mega-panel__item-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  border-radius: 6px;
  font-size: 15px;
  transition: background 0.18s ease;
}

.mega-panel__item:hover .mega-panel__item-icon,
.mega-panel__item:focus .mega-panel__item-icon {
  background: #e0e7ff;
}

/* Item label + description */
.mega-panel__item-text {
  display: flex;
  flex-direction: column;
}

.mega-panel__item-label {
  font-weight: 600;
  font-size: 13.5px;
  color: inherit;
}

.mega-panel__item-desc {
  font-size: 11.5px;
  color: #9ca3af;
  font-weight: 400;
  margin-top: 1px;
}

/* ── 7. OPTIONAL FOOTER BANNER inside panel ──────────────── */
.mega-panel__footer {
  margin-top: 20px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mega-panel__footer-text {
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
}

.mega-panel__footer-btn {
  flex-shrink: 0;
  background: #ffffff;
  color: #4f46e5;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.18s ease;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.mega-panel__footer-btn:hover {
  background: #e0e7ff;
}

/* ── 8. DIVIDER between columns ──────────────────────────── */
.mega-panel__divider {
  width: 1px;
  background: #f3f4f6;
  margin: 0 4px;
}

/* ── 9. EDGE-CASE: panel near left screen edge ───────────── */
/* JS can add .edge-left when trigger is near left edge */
.hdr-mega-dd.edge-left .mega-panel {
  right: auto;
  left: 0;
}

/* ── 10. REDUCED MOTION ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .hdr-mega-dd .mega-panel {
    transition: opacity 0.1s ease, visibility 0.1s ease;
    transform: none;
  }
}

/* =============================================================
   TABLET-LG  ≤ 1024px
   3 columns, slightly narrower panel
   ============================================================= */
@media (max-width: 1024px) {
  .hdr-mega-dd .mega-panel {
    width: 680px;
    padding: 22px 18px;
  }

  .mega-panel__grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px 16px;
  }
}

/* =============================================================
   TABLET  ≤ 768px
   2 columns, full-width panel, anchored to right edge of screen
   ============================================================= */
@media (max-width: 768px) {
  .hdr-mega-dd {
    position: relative; /* re-scope so panel aligns to trigger */
  }

  .hdr-mega-dd .mega-panel {
    /* Stretch edge-to-edge with small gutters */
    position: fixed;
    top: auto;
    right: 10px;
    left: 10px;
    width: auto;
    max-width: 100%;

    padding: 18px 14px;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  }

  .mega-panel__grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 12px;
  }

  .mega-panel__col-title {
    font-size: 10px;
    padding-bottom: 6px;
  }

  .mega-panel__item {
    padding: 8px 8px;
    font-size: 13px;
  }

  .mega-panel__item-icon {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .mega-panel__footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    padding: 12px 14px;
  }
}

/* =============================================================
   MOBILE  ≤ 480px
   Single column, full-width, stacked vertically
   ============================================================= */
@media (max-width: 480px) {
  .hdr-mega-dd .mega-panel {
    right: 6px;
    left: 6px;
    padding: 14px 10px;
    border-radius: 8px;
    /* Scrollable if content is tall */
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mega-panel__grid {
    grid-template-columns: 1fr; /* single column stack */
    gap: 2px 0;
  }

  .mega-panel__col-title {
    margin-top: 12px;
    font-size: 10px;
  }

  /* First column title needs no top margin */
  .mega-panel__col-title:first-child {
    margin-top: 0;
  }

  .mega-panel__item {
    padding: 10px 8px;
    font-size: 14px;
    min-height: 48px; /* larger touch target on mobile */
    border-radius: 6px;
  }

  .mega-panel__item:hover,
  .mega-panel__item:focus {
    transform: none; /* no horizontal nudge on touch */
  }

  .mega-panel__item-icon {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .mega-panel__item-desc {
    display: none; /* hide descriptions to save space */
  }

  .mega-panel__divider {
    display: none;
  }

  .mega-panel__footer {
    margin-top: 12px;
    padding: 10px 12px;
  }

  .mega-panel__footer-btn {
    width: 100%;
    justify-content: center;
  }
}

/* =============================================================
   ACCESSIBILITY — skip animation for keyboard users until open
   ============================================================= */
.hdr-mega-dd .mega-panel[aria-hidden="true"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.hdr-mega-dd .mega-panel[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}
