/* ============================================================
   M3U-EDIT.COM v2 — Premium Header
   Location: assets/css/header.css
   ============================================================ */

/* ---------- HEADER BASE ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(var(--bg-rgb, 255, 255, 255), 0.85);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
}

[data-theme="dark"] .site-header {
  background: rgba(15, 23, 42, 0.85);
}

.site-header .container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: 68px;
}

/* ---------- LOGO ---------- */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.logo:hover { color: var(--text); text-decoration: none; }

.logo-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-radius: 10px;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.logo-text {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ---------- MAIN NAV (desktop) ---------- */
.nav-main {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
}

.nav-main > a,
.nav-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.15s;
  cursor: pointer;
  background: transparent;
  border: none;
  font-family: inherit;
}

.nav-main > a:hover,
.nav-dropdown-trigger:hover {
  background: var(--bg-secondary);
  color: var(--text);
  text-decoration: none;
}

.nav-main > a.active,
.nav-dropdown-trigger.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(139,92,246,0.1));
  color: var(--primary);
}

.nav-icon {
  font-size: 14px;
  line-height: 1;
}

.caret {
  font-size: 10px;
  margin-left: 2px;
  opacity: 0.6;
  transition: transform 0.2s;
}

.nav-dropdown:hover .caret { transform: rotate(180deg); }

/* ---------- DROPDOWN MEGA MENU ---------- */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  min-width: 720px;
  max-width: 95vw;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 8px 24px rgba(0, 0, 0, 0.08);
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 200;
}

[data-theme="dark"] .nav-dropdown-menu {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.3);
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.nav-dropdown-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.nav-dropdown-section {
  display: flex;
  flex-direction: column;
}

.nav-dropdown-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 0 8px;
}

.nav-dropdown-section a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.12s;
}
.nav-dropdown-section a:hover {
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(139,92,246,0.08));
  color: var(--primary);
  transform: translateX(2px);
  text-decoration: none;
}
.nav-dropdown-section a span:first-child {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-dropdown-footer {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- HEADER ACTIONS (right) ---------- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Theme toggle */
.theme-toggle {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"]  .theme-toggle .icon-moon { display: none; }

/* ---------- USER MENU ---------- */
.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.user-menu-trigger:hover {
  border-color: var(--primary);
  background: var(--bg-secondary);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.credits-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(var(--primary-rgb), 0.10);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}
.credits-pill svg { width: 13px; height: 13px; flex-shrink: 0; }
[data-theme="dark"] .credits-pill {
  background: rgba(var(--primary-rgb), 0.22);
  color: var(--primary-light, #a5b4fc);
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
  transition: all 0.18s;
  z-index: 200;
}

.user-menu:hover .user-menu-dropdown,
.user-menu:focus-within .user-menu-dropdown {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.user-menu-header {
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.user-menu-dropdown a {
  display: block;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.12s;
}
.user-menu-dropdown a:hover {
  background: var(--bg-secondary);
  text-decoration: none;
}
.user-menu-dropdown .divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* ---------- MOBILE MENU TOGGLE ---------- */
.mobile-menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}

/* ---------- MOBILE MENU OVERLAY ---------- */
.mobile-menu {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 300;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s;
}

.mobile-menu.open {
  opacity: 1;
  visibility: visible;
}

.mobile-menu-inner {
  position: absolute;
  top: 0;
  right: 0;
  width: min(320px, 85vw);
  height: 100%;
  background: var(--bg);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.mobile-menu.open .mobile-menu-inner {
  transform: translateX(0);
}

.mobile-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.mobile-menu-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.mobile-menu-nav {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mobile-link {
  display: block;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 10px;
  transition: background 0.12s;
}
.mobile-link:hover {
  background: var(--bg-secondary);
  text-decoration: none;
}

.mobile-submenu {
  border-radius: 10px;
  overflow: hidden;
}
.mobile-submenu summary {
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mobile-submenu summary::-webkit-details-marker { display: none; }
.mobile-submenu summary::after {
  content: '▾';
  font-size: 12px;
  transition: transform 0.2s;
  opacity: 0.5;
}
.mobile-submenu[open] summary::after { transform: rotate(180deg); }

.mobile-submenu-content {
  display: flex;
  flex-direction: column;
  padding: 4px 0 4px 12px;
  border-left: 2px solid var(--border);
  margin-left: 14px;
}
.mobile-submenu-content a {
  padding: 9px 14px;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
}
.mobile-submenu-content a:hover {
  background: var(--bg-secondary);
  color: var(--text);
  text-decoration: none;
}

.mobile-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 4px;
}

/* ---------- HELPERS ---------- */
.show-mobile-only { display: none; }

/* ---------- RESPONSIVE BREAKPOINTS ---------- */
@media (max-width: 1024px) {
  .nav-main {
    display: none;
  }
  .mobile-menu-toggle {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  .header-inner {
    height: 60px;
    gap: 8px;
  }
  .logo-text {
    display: none; /* logo icon only on small screens */
  }
  .hide-mobile { display: none; }
  .show-mobile-only { display: inline; }
  .credits-pill {
    display: none;
  }
}

/* Body padding so sticky header doesn't overlap fixed elements */
body { padding-top: 0; }

/* ---------- QC PASS: primary CTA prominence in the header ---------- */
.header-actions .btn-primary {
  box-shadow: 0 4px 14px -4px rgba(var(--primary-rgb), 0.50);
}

/* ============================================================
   MOBILE DRAWER — polish pass
   Fixes the old "narrow dropdown over the hero" bug at the CSS
   layer too (the JS now opens this drawer instead of .nav-main).
   Touch-friendly items, clear active state, backdrop blur, body
   scroll-lock, and no horizontal overflow. Works in both themes.
   ============================================================ */

/* Lock the page behind the open drawer (set by main.js) */
body.mobile-menu-open { overflow: hidden; }

/* Softer, more premium dimmed backdrop */
.mobile-menu { backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }

/* Roomier panel on phones; never let it cause sideways scroll */
.mobile-menu-inner {
  width: min(360px, 88vw);
  max-width: 100vw;
  overflow-x: hidden;
}

/* Stacked, touch-friendly rows with aligned icon + label */
.mobile-link {
  display: flex;
  align-items: center;
  min-height: 46px;
}

/* Clear active/current highlight */
.mobile-link.active,
.mobile-link[aria-current="page"] {
  background: rgba(var(--primary-rgb), 0.12);
  color: var(--primary);
}
[data-theme="dark"] .mobile-link.active,
[data-theme="dark"] .mobile-link[aria-current="page"] {
  background: rgba(var(--primary-rgb), 0.24);
  color: var(--text);
}

/* Comfortable login / sign-up buttons at the foot of the drawer */
.mobile-menu-nav .btn-block {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-actions .btn-primary:hover {
  box-shadow: 0 8px 20px -6px rgba(var(--primary-rgb), 0.62);
  transform: translateY(-1px);
}
