/* ========================================
   Mega Menu Styles - Phase 0.2
   ======================================== */

/* Body padding for fixed header */
body {
    padding-top: 70px;
}

/* Base Header Styles */
.header-v2 {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1000;
    background: var(--header-bg, #ffffff);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

[data-theme="dark"] .header-v2 {
    --header-bg: #1a1a1a;
    --header-text: #ffffff;
    --header-border: #333333;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 70px;
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 20px;
    color: var(--primary-color, #2563eb);
}

.logo-icon {
    font-size: 28px;
    line-height: 1;
}

.logo-title a {
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s;
}

.logo-title a:hover {
    opacity: 0.8;
}

/* Main Navigation */
.main-nav {
    display: flex;
    align-items: center;
    gap: 32px;
    flex: 1;
    justify-content: center;
}

.nav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 4px;
}

.nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 24px 18px;
    color: var(--text-color, #374151);
    font-weight: 500;
    font-size: 15px;
    text-decoration: none;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-color, #2563eb);
    border-bottom-color: var(--primary-color, #2563eb);
}

/* Mega Menu Container */
.mega-menu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 900px;
    max-width: 1200px;
    background: var(--dropdown-bg, #ffffff);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    margin-top: 8px;
}

[data-theme="dark"] .mega-menu {
    --dropdown-bg: #2a2a2a;
    --column-border: #404040;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.nav-item.has-megamenu:hover .mega-menu {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.mega-menu-content {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    padding: 32px;
}

/* Mega Menu Columns */
.mega-menu-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.column-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color, #111827);
    margin: 0 0 8px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--column-border, #e5e7eb);
}

.column-icon {
    font-size: 18px;
    line-height: 1;
}

.column-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.column-links li a {
    display: block;
    padding: 8px 12px;
    color: var(--text-secondary, #6b7280);
    font-size: 14px;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s;
}

.column-links li a:hover {
    background: var(--hover-bg, #f3f4f6);
    color: var(--primary-color, #2563eb);
    transform: translateX(4px);
}

[data-theme="dark"] .column-links li a:hover {
    background: var(--hover-bg, #3a3a3a);
}

.view-all-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    margin-top: 8px;
    color: var(--primary-color, #2563eb);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s;
}

.view-all-link:hover {
    background: var(--primary-bg, #eff6ff);
    transform: translateX(4px);
}

/* Featured Column */
.featured-column {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 8px;
    padding: 16px;
}

[data-theme="dark"] .featured-column {
    background: linear-gradient(135deg, #1e3a5f 0%, #2a4a6f 100%);
}

.featured-tools {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.featured-tool {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--card-bg, #ffffff);
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.featured-tool:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .featured-tool {
    --card-bg: #333333;
}

.tool-icon {
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}

.tool-info {
    flex: 1;
}

.tool-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color, #111827);
    margin-bottom: 4px;
}

.tool-usage {
    font-size: 12px;
    color: var(--text-tertiary, #9ca3af);
}

/* Tool Badges */
.tool-badges {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tool-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    background: var(--card-bg, #ffffff);
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.tool-badge:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.badge-icon {
    font-size: 24px;
    line-height: 1;
}

.badge-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color, #111827);
}

.badge-count {
    font-size: 11px;
    color: var(--text-tertiary, #9ca3af);
}

/* Simple Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 280px;
    background: var(--dropdown-bg, #ffffff);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    margin-top: 8px;
    padding: 16px;
}

.nav-item.has-dropdown:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color, #111827);
    margin: 0 0 12px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--column-border, #e5e7eb);
}

.dropdown-icon {
    font-size: 18px;
    line-height: 1;
}

.dropdown-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.dropdown-links li a {
    display: block;
    padding: 10px 12px;
    color: var(--text-secondary, #6b7280);
    font-size: 14px;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s;
}

.dropdown-links li a:hover {
    background: var(--hover-bg, #f3f4f6);
    color: var(--primary-color, #2563eb);
}

/* Header Controls & Nav Actions */
.header-controls,
.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.language-button,
.language-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--button-bg, #f3f4f6);
    border: none;
    border-radius: 8px;
    color: var(--text-color, #374151);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.language-button:hover,
.language-selector:hover {
    background: var(--button-hover-bg, #e5e7eb);
}

.language-icon,
.flag-icon {
    font-size: 16px;
    line-height: 1;
}

.current-language {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.language-selector-wrapper {
    position: relative;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--button-bg, #f3f4f6);
    border: none;
    border-radius: 8px;
    color: var(--text-color, #374151);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--button-hover-bg, #e5e7eb);
    transform: rotate(15deg);
}

/* Mobile Menu Toggle (Hidden on Desktop) */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    z-index: 1001;
    position: relative;
    justify-content: center;
    align-items: center;
}

.mobile-menu-toggle span {
    width: 100%;
    height: 3px;
    background: var(--text-color, #374151);
    border-radius: 2px;
    transition: all 0.3s;
    pointer-events: none; /* 让点击穿透到按钮 */
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translateY(10px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translateY(-10px);
}

.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

/* ========================================
   Responsive Design - Tablet
   ======================================== */
@media (max-width: 1024px) {
    .mega-menu {
        min-width: 700px;
        max-width: 900px;
    }
    
    .mega-menu-content {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
        padding: 24px;
    }
    
    .nav-menu {
        gap: 2px;
    }
    
    .nav-link {
        padding: 24px 14px;
        font-size: 14px;
    }
}

/* ========================================
   Responsive Design - Mobile
   ======================================== */
@media (max-width: 768px) {
    .header-container {
        height: 60px;
        padding: 0 16px;
        position: relative;
        overflow: visible; /* Ensure button isn't clipped */
    }
    
    /* Logo adjustments for mobile */
    .logo {
        flex: 0 1 auto;
        max-width: calc(100% - 60px); /* Reserve space for menu button */
        z-index: 1;
    }
    
    .logo-title {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    
    .mobile-menu-toggle {
        display: flex !important;
        position: fixed !important;
        right: 16px !important;
        top: 14px !important; /* (60px - 32px) / 2 = 14px */
        pointer-events: auto !important;
        touch-action: manipulation !important;
        z-index: 1002 !important; /* Higher than everything */
    }
    
    .nav-actions {
        display: none; /* Hide desktop nav actions on mobile */
    }
    
    .main-nav {
        /* Reset desktop flex properties */
        display: flex !important;
        flex: none !important;
        flex-direction: column !important;
        /* Set as fixed positioned overlay */
        position: fixed !important;
        top: 60px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: calc(100vh - 60px) !important;
        max-height: calc(100vh - 60px) !important;
        background: var(--dropdown-bg, #ffffff);
        pointer-events: none !important; /* Don't block clicks when hidden */
        visibility: hidden !important; /* Completely hide when not active */
        align-items: stretch !important;
        justify-content: flex-start !important; /* Force top alignment */
        gap: 0;
        padding: 16px 24px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease, visibility 0s 0.3s;
        z-index: 1000 !important;
    }
    
    .main-nav.active {
        transform: translateX(0) !important;
        pointer-events: auto !important; /* Enable clicks when active */
        visibility: visible !important; /* Show when active */
        transition: transform 0.3s ease, visibility 0s 0s;
        overflow-y: auto !important; /* Force scrolling when active */
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .nav-menu {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px;
        width: 100%;
        list-style: none;
        margin: 0;
        padding: 0;
    }
    
    .nav-item {
        display: block !important;
        width: 100%;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    .nav-link {
        padding: 16px;
        border-bottom: none;
        border-radius: 8px;
        color: var(--text-color, #374151) !important;
    }
    
    .nav-link.active {
        background: var(--primary-color, #2563eb);
        color: #ffffff !important;
    }
    
    .nav-link:hover {
        background: var(--hover-bg, #f3f4f6);
    }
    
    /* Mobile Mega Menu */
    .mega-menu,
    .dropdown-menu {
        position: static !important;
        transform: none !important;
        box-shadow: none;
        border-radius: 8px;
        margin: 8px 0;
        min-width: auto;
        max-width: 100%;
        width: 100%;
        opacity: 1 !important;
        visibility: visible !important;
        display: none;
        background: var(--dropdown-bg, #f9fafb);
        padding: 16px;
        transition: none !important;
    }
    
    .nav-item.has-megamenu.expanded .mega-menu,
    .nav-item.has-dropdown.expanded .dropdown-menu {
        display: block !important;
    }
    
    .mega-menu-content {
        display: block !important;
        grid-template-columns: 1fr !important;
        gap: 16px;
        padding: 0;
    }
    
    .mega-menu-column {
        width: 100%;
        margin-bottom: 16px;
    }
    
    .column-links {
        width: 100%;
    }
    
    .featured-column {
        order: -1;
    }
    
    /* Mobile nav actions - move to mobile menu */
    .main-nav .nav-actions {
        display: flex;
        position: static;
        padding: 16px;
        border-top: 1px solid var(--border-color, #e5e7eb);
    }
    
    .language-selector {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .theme-toggle {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
}

/* ========================================
   Accessibility
   ======================================== */
.nav-link:focus,
.featured-tool:focus,
.tool-badge:focus {
    outline: 2px solid var(--primary-color, #2563eb);
    outline-offset: 2px;
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .header-v2 {
        position: static;
        box-shadow: none;
    }
    
    .mega-menu,
    .dropdown-menu,
    .mobile-menu-toggle,
    .mobile-menu-overlay {
        display: none !important;
    }
}
