/* ============================================================
   M3U-EDIT.COM v2 — Global Navigation Polish
   Location: assets/css/navigation.css

   Loaded site-wide after header.css (see layouts/header.php).
   This file LAYERS on top of header.css — no destructive overrides.
   Adds:
     - Skip-to-content link (a11y)
     - .user-menu.is-open + .user-menu-dropdown.open click-state
       (fixes the missing CSS rule that main.js click handler relied on)
     - Tools mega menu: 5-column grid layout for the real
       editing/validation/conversion/enrichment/analysis categories
     - .mega-item card styling (icon + name + optional badge)
     - Mobile drawer: search box + accordion-per-category tools list
     - Theme-toggle row inside drawer
   ============================================================ */

/* ---------- SKIP TO CONTENT ----------
   Visually hidden until focused via Tab. WCAG 2.4.1 compliance.
   ----------------------------------------------------- */
.skip-link {
  position: fixed;
  top: -100px;
  left: 12px;
  z-index: 9999;
  padding: 10px 18px;
  background: var(--primary, #6366f1);
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
  border-radius: 10px;
  text-decoration: none;
  box-shadow: 0 8px 24px -6px rgba(99, 102, 241, 0.45);
  transition: top 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 12px;
  outline: 3px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
  color: #ffffff;
  text-decoration: none;
}

/* ============================================================
   USER MENU — click-based open state
   ============================================================
   main.js already toggles `.open` on the dropdown when the user
   clicks the trigger, but header.css only had a `:hover` rule
   (no `.open` rule), so the click did nothing visually. Adding
   the missing rule here.
   ----------------------------------------------------- */
.user-menu-dropdown.open,
.user-menu.is-open .user-menu-dropdown {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  transform: translateY(0) !important;
}

/* On touch devices, kill the :hover open so a single tap doesn't
   show both hover + click state simultaneously. */
@media (hover: none) {
  .user-menu:hover .user-menu-dropdown:not(.open) {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-8px);
  }
}

/* ============================================================
   TOOLS MEGA MENU
   5 columns matching the real categories returned by
   tools_catalog_grouped(). Layout collapses gracefully if a
   category has zero tools (the helper drops empty categories).
   ============================================================ */

/* Override the existing 4-column header.css grid */
.nav-dropdown-menu {
  min-width: 920px;
  max-width: 95vw;
  padding: 24px 24px 0;
}

.nav-dropdown-grid {
  display: grid !important;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

@media (max-width: 1180px) {
  .nav-dropdown-menu { min-width: 760px; }
  .nav-dropdown-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.nav-dropdown-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.nav-dropdown-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 0 10px;
  margin-bottom: 6px;
}
.nav-dropdown-title .mega-cat-icon { font-size: 13px; line-height: 1; }

/* ---- The mega-menu item card ---- */
.mega-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition:
    background-color 160ms ease,
    transform 160ms cubic-bezier(0.16, 1, 0.3, 1),
    color 160ms ease;
  position: relative;
  min-width: 0;
}
.mega-item:hover {
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(139,92,246,0.06));
  transform: translateX(2px);
  text-decoration: none;
  color: var(--text);
}
.mega-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.mega-item-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(139,92,246,0.10));
  border-radius: 8px;
  flex-shrink: 0;
  transition: transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.mega-item:hover .mega-item-icon {
  transform: rotate(-6deg) scale(1.08);
}

.mega-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* Optional tier badge in the mega menu item — only renders for
   premium / login_required / coming_soon (not free) */
.mega-item-badge {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.mega-item-badge--free    { background: rgba(16,185,129,0.14);  color: var(--success); }
.mega-item-badge--mixed   { background: rgba(99,102,241,0.14);  color: var(--primary); }
.mega-item-badge--paid    { background: rgba(245,158,11,0.16);  color: var(--warning); }
.mega-item-badge--soon    { background: rgba(156,163,175,0.18); color: var(--text-muted); }

/* Coming-soon items: render but not clickable, dimmed */
.mega-item.is-coming-soon {
  pointer-events: none;
  opacity: 0.55;
}

/* ---- Footer of the mega menu ---- */
.nav-dropdown-footer {
  margin-top: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.nav-dropdown-footer-note {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.nav-dropdown-footer .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  border-radius: 8px;
}
.nav-dropdown-footer .btn-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #ffffff;
  box-shadow: 0 6px 16px -6px rgba(99, 102, 241, 0.50);
}
.nav-dropdown-footer .btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px -6px rgba(99, 102, 241, 0.60);
  color: #ffffff;
  text-decoration: none;
}

/* ============================================================
   MOBILE DRAWER — search input + accordion-per-category
   ============================================================ */

.mobile-menu-search {
  position: relative;
  margin: 4px 0 14px;
}
.mobile-menu-search input[type="search"] {
  width: 100%;
  padding: 12px 14px 12px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.mobile-menu-search input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
}
.mobile-menu-search input[type="search"]::placeholder {
  color: var(--text-muted);
}
.mobile-menu-search .mobile-menu-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Category accordion inside the drawer */
.mobile-tools-categories {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 8px;
}
.mobile-tools-cat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.mobile-tools-cat-summary {
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.mobile-tools-cat-summary::-webkit-details-marker { display: none; }
.mobile-tools-cat-summary::marker { display: none; content: ''; }
.mobile-tools-cat-summary::after {
  content: '▾';
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.mobile-tools-cat[open] .mobile-tools-cat-summary::after {
  transform: rotate(180deg);
}
.mobile-tools-cat-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: auto;
  margin-right: 6px;
}

.mobile-tools-cat-body {
  display: flex;
  flex-direction: column;
  padding: 4px 8px 10px;
  gap: 2px;
}
.mobile-tools-cat-body .mobile-tool-link {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  min-height: 44px;
}
.mobile-tools-cat-body .mobile-tool-link:hover,
.mobile-tools-cat-body .mobile-tool-link:focus-visible {
  background: var(--bg-secondary);
  color: var(--primary);
}
.mobile-tools-cat-body .mobile-tool-icon {
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(139,92,246,0.10));
  border-radius: 8px;
}
.mobile-tools-cat-body .mobile-tool-badge {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

/* When a category is filtered out by search, hide it */
.mobile-tools-cat.is-hidden { display: none; }
.mobile-tool-link.is-hidden { display: none; }

/* Search empty state */
.mobile-tools-empty {
  display: none;
  padding: 24px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--bg-card);
}
.mobile-tools-empty.is-visible { display: block; }

/* ---- Theme toggle row inside drawer ---- */
.mobile-theme-toggle-row {
  margin: 12px 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease;
}
.mobile-theme-toggle-row:hover {
  border-color: var(--primary);
  background: var(--bg-secondary);
}
.mobile-theme-toggle-row .mobile-theme-icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.mobile-theme-toggle-row .mobile-theme-label-dark { display: inline; }
.mobile-theme-toggle-row .mobile-theme-label-light { display: none; }
[data-theme="dark"] .mobile-theme-toggle-row .mobile-theme-label-dark { display: none; }
[data-theme="dark"] .mobile-theme-toggle-row .mobile-theme-label-light { display: inline; }

/* ============================================================
   ACTIVE LINK INDICATOR — gradient underline on the active page
   (header.css already has a base style; this strengthens it)
   ============================================================ */
.site-header .nav-main > a.active,
.site-header .nav-dropdown-trigger.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(139,92,246,0.10));
  color: var(--primary);
  font-weight: 700;
}

/* ============================================================
   QC PASS — center the Tools mega menu under the nav bar.
   It was positioned left:50% relative to the off-center Tools
   trigger (.nav-dropdown:position:relative), so a ~920px menu
   anchored to a left-of-center trigger looked shifted/uneven.
   Re-anchoring to .nav-main (which is page-centered via
   justify-content:center) centers the menu under the whole nav.
   The menu stays a DOM child of .nav-dropdown, so :hover still
   bridges trigger → menu. Vertical offset is unchanged.
   ============================================================ */
.site-header .nav-main { position: relative; }
.site-header .nav-dropdown { position: static; }

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .skip-link,
  .mega-item,
  .mega-item-icon,
  .mobile-tools-cat-summary::after,
  .mobile-theme-toggle-row {
    transition: none !important;
    animation: none !important;
  }
  .mega-item:hover { transform: none !important; }
}
