/* ============================================
   FIX 1: PREVENT DUPLICATE ELEMENTS
   ============================================ */
@media (max-width: 768px) {

    /* === HEADER LAYOUT: MENU (L) - LOGO (C) - THEME (R) === */
    header {
        height: 70px;
        padding: 0 1.25rem;
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        background: rgba(0, 0, 0, 0.4) !important;
        backdrop-filter: blur(15px);
    }

    /* 1. LEFT: HAMBURGER TRIGGER */
    .mobile-menu-trigger {
        display: flex !important;
        align-items: center;
        width: 40px;
        height: 40px;
        z-index: 2000;
        /* Ensure above everything */
    }

    /* Modern Hamburger Button */
    .hamburger {
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 32px;
        height: 32px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        gap: 6px;
        position: relative;
    }

    /* Hamburger Lines (Modern Gap Style) */
    .hamburger span {
        width: 24px;
        height: 2px;
        background: #fff;
        border-radius: 4px;
        transition: all 0.3s cubic-bezier(0.68, -0.6, 0.32, 1.6);
        position: relative;
        transform-origin: center;
    }

    /* Animation State */
    .hamburger.active span:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }

    .hamburger.active span:nth-child(2) {
        opacity: 0;
        transform: translateX(-20px);
    }

    .hamburger.active span:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }

    /* Light Mode Hamburger */
    body.light .hamburger span {
        background: #1a1a2e;
    }

    /* 2. CENTER: LOGO */
    .header-left {
        flex: 1;
        /* Takes up remaining space to center logo */
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0;
        /* Reset margins */
        order: 0;
    }

    .logo {
        height: 42px !important;
        /* Slightly smaller for mobile balancing */
        width: auto;
    }

    /* 3. RIGHT: THEME TOGGLE */
    .header-right {
        display: flex !important;
        align-items: center;
        justify-content: flex-end;
        width: 40px;
    }

    /* Ensure switch is visible and correctly sized */
    header>.switch,
    .header-right .switch {
        display: inline-block !important;
        transform: scale(0.85);
        /* Slight scale down for mobile */
        margin: 0;
    }

    /* 4. HIDDEN NAV CONTAINER */
    .header-center {
        display: none !important;
    }

    /* Previne shrink */
}

.hamburger span {
    width: 100%;
    height: 3px;
    background: #fff;
    border-radius: 10px;
    transition: all 0.3s ease;
    position: relative;
    transform-origin: center;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(7px, 7px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-20px);
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

body.light .hamburger span {
    background: #1a1a1a;
}

/* ============================================
   FIX 3: DESKTOP - Default behavior
   ============================================ */

header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

nav {
    display: block;
    position: relative;
    width: auto;
    height: auto;
    background: transparent;
}

nav ul {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
}

/* ============================================
   FIX 4: MOBILE - Complete overhaul
   ============================================ */

@media (max-width: 768px) {

    /* === CRITICAL: Prevent horizontal scroll === */
    html,
    body {
        overflow-x: hidden !important;
        max-width: 100vw;
        position: relative;
    }

    /* Mobile header is shorter than desktop */
    html {
        scroll-padding-top: 80px !important;
    }

    * {
        max-width: 100%;
    }

    /* === HEADER FIXES === */
    /* Handled by new layout at top of file */
    header {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        box-sizing: border-box;
        z-index: 1000;
        /* ensure compatibility */
    }

    /* Switch and Hamburger styles REMOVED - handled by new layout */

    /* === NAVIGATION SLIDE-IN MENU (from LEFT) === */
    nav {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        /* Hidden to the LEFT by default */
        width: min(280px, 80vw) !important;
        /* Max 80% screen width */
        height: 100vh !important;
        height: 100dvh !important;
        /* Dynamic viewport height for iOS */
        background: linear-gradient(135deg, rgba(40, 0, 80, 0.98), rgba(90, 0, 150, 0.95)) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        /* Safari support */
        transition: left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
        z-index: 1500 !important;
        padding: 80px 0 20px 0 !important;
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.5) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        /* Smooth scroll on iOS */
        box-sizing: border-box;
        touch-action: pan-y;
    }

    body.light nav {
        background: linear-gradient(135deg, rgba(245, 240, 255, 0.98), rgba(230, 225, 250, 0.95)) !important;
    }

    /* Fix light mode nav text color - must be dark on light background */
    body.light nav a {
        color: #1a1a2e !important;
    }

    body.light nav a:hover,
    body.light nav a:active {
        color: var(--primary) !important;
    }

    /* Active state - slide in FROM LEFT */
    nav.active {
        left: 0 !important;
    }

    nav ul {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0 !important;
        padding: 0 1.5rem !important;
        width: 100% !important;
        margin: 0 !important;
        list-style: none !important;
    }

    nav li {
        width: 100% !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        margin: 0 !important;
    }

    body.light nav li {
        border-bottom: 1px solid rgba(100, 50, 150, 0.2) !important;
    }

    nav li:last-child {
        border-bottom: none !important;
    }

    nav a {
        display: block !important;
        padding: 1rem 0.75rem !important;
        font-size: 1rem !important;
        width: 100% !important;
        transition: all 0.3s ease !important;
        text-decoration: none !important;
        box-sizing: border-box;
    }

    nav a:hover,
    nav a:active {
        padding-left: 1.5rem !important;
        color: var(--primary) !important;
    }

    nav a::after {
        display: none !important;
    }

    /* === PREVENT BODY SCROLL WHEN MENU OPEN === */
    body.menu-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }

    /* === GENERAL MOBILE TYPOGRAPHY === */
    body {
        font-size: 14px;
        line-height: 1.6;
    }

    h2 {
        font-size: 1.6rem !important;
    }

    h3 {
        font-size: 1.2rem !important;
    }

    /* === HERO SECTION === */
    .hero {
        height: auto !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
        /* Dynamic viewport for iOS */
        padding: 100px 1rem 2rem !important;
        box-sizing: border-box;
    }

    .hero h2 {
        font-size: 1.5rem !important;
        margin-bottom: 0.75rem;
    }

    .hero p {
        font-size: 0.95rem !important;
        margin-bottom: 1.5rem;
        padding: 0 0.5rem;
    }

    .hero button {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .logo-bg {
        width: 250px !important;
        opacity: 0.15;
    }

    /* === CONTENT SECTIONS === */
    .content {
        width: 90% !important;
        max-width: 100% !important;
        padding: 1.25rem !important;
        margin: 1.5rem auto !important;
        box-sizing: border-box;
    }

    /* === MATERII GRID === */
    .materii {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    .materie-card {
        padding: 1rem;
        margin: 0 auto;
        max-width: 100%;
    }

    .materie-icon {
        font-size: 2.2rem !important;
        margin-bottom: 10px;
    }

    /* === TEAM SECTION === */
    .team,
    .leadership {
        gap: 1.25rem !important;
        justify-content: center;
    }

    .membru {
        width: 100% !important;
        max-width: 320px;
        padding: 1rem !important;
        margin: 0 auto;
        box-sizing: border-box;
    }

    /* === MOBILE MEMBER POPUP - Completely redesigned === */
    .hover-popup {
        display: none !important;
        /* Hide the hover popup completely on mobile */
    }

    /* Create a new popup approach for mobile - show info inline */
    .membru.show-popup {
        position: relative;
    }

    .membru.show-popup::after {
        content: '✕ Tap to close';
        position: absolute;
        top: -30px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--primary);
        color: #fff;
        padding: 4px 12px;
        border-radius: 12px;
        font-size: 0.75rem;
        white-space: nowrap;
        z-index: 100;
    }

    /* Mobile popup overlay for dimming */
    .member-popup-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.7);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 2000;
        pointer-events: none;
    }

    .member-popup-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Mobile Modal Popup - show centered */
    .mobile-popup-modal {
        display: none;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90%;
        max-width: 320px;
        max-height: 80vh;
        overflow-y: auto;
        background: linear-gradient(135deg, rgba(30, 10, 50, 0.98), rgba(60, 20, 100, 0.95));
        border: 2px solid rgba(192, 132, 252, 0.5);
        border-radius: 16px;
        padding: 1.5rem;
        z-index: 3000;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
        text-align: center;
        color: #fff;
    }

    .mobile-popup-modal.active {
        display: block;
    }

    .mobile-popup-modal img {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        border: 3px solid var(--primary);
        object-fit: cover;
        margin-bottom: 1rem;
    }

    .mobile-popup-modal h3 {
        color: #e8d7ff !important;
        font-size: 1.2rem;
        margin: 0 0 0.25rem 0;
        -webkit-text-fill-color: #e8d7ff;
    }

    .mobile-popup-modal h4 {
        color: #c9a8ff !important;
        font-size: 0.95rem;
        margin: 0 0 1rem 0;
        font-weight: 500;
        -webkit-text-fill-color: #c9a8ff;
    }

    .mobile-popup-modal p {
        color: #ddd !important;
        font-size: 0.9rem;
        line-height: 1.5;
        margin: 0;
        -webkit-text-fill-color: #ddd;
    }

    .mobile-popup-close {
        position: absolute;
        top: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        background: rgba(255, 255, 255, 0.1);
        border: none;
        border-radius: 50%;
        color: #fff;
        font-size: 1.2rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Light mode popup */
    body.light .mobile-popup-modal {
        background: linear-gradient(135deg, rgba(250, 248, 255, 0.98), rgba(240, 235, 255, 0.95));
        border-color: rgba(139, 92, 246, 0.4);
    }

    body.light .mobile-popup-modal h3 {
        color: #2d1b4e !important;
        -webkit-text-fill-color: #2d1b4e;
    }

    body.light .mobile-popup-modal h4 {
        color: #5b3d8a !important;
        -webkit-text-fill-color: #5b3d8a;
    }

    body.light .mobile-popup-modal p {
        color: #333 !important;
        -webkit-text-fill-color: #333;
    }

    body.light .mobile-popup-close {
        background: rgba(0, 0, 0, 0.1);
        color: #333;
    }
}

/* === STATS === */
.stats-container {
    grid-template-columns: 1fr !important;
    gap: 1.25rem;
}

.stat-box {
    padding: 1.25rem;
}

.stat-number {
    font-size: 2.2rem !important;
}

.stat-label {
    font-size: 0.95rem !important;
}

/* === PROJECTS BIRD === */
.loader {
    transform: scale(0.6) !important;
    transform-origin: center center;
    margin: 0 auto;
}

.proiecte-content {
    min-height: 200px;
    overflow: visible;
}

.coming-soon {
    font-size: 1.3rem !important;
    letter-spacing: 2px;
}

/* === CONTACT === */
.contact-card {
    padding: 1.5rem !important;
    margin: 1.5rem auto !important;
}

.contact-grid {
    grid-template-columns: 1fr !important;
    gap: 1.25rem;
}

.contact-item {
    grid-template-columns: 56px 1fr;
    padding: 1rem;
}

.contact-icon {
    width: 56px !important;
    height: 56px !important;
    font-size: 1.2rem;
}

.contact-link {
    font-size: 0.85rem;
    padding: 0.6rem 0.9rem;
}

/* === PARTENERI === */
.parteneri-logos {
    gap: 1.25rem;
}

.parteneri-logos img {
    max-width: 180px;
    padding: 12px;
}

/* === FOOTER === */
footer {
    padding: 1.25rem 1rem;
    font-size: 0.8rem;
}

/* === SCROLL TO TOP === */
#scrollTopBtn {
    bottom: 15px;
    right: 15px;
    padding: 8px 14px;
    font-size: 1.2rem;
    width: 44px;
    height: 44px;
}

/* === PROGRESS BAR === */
#progress-bar {
    height: 3px;
}

/* === COOKIE POPUP === */
.cookie-content {
    width: 90% !important;
    max-width: 340px !important;
    padding: 1.25rem !important;
}

.cookie-buttons {
    flex-direction: column;
    gap: 10px;
}

.cookie-buttons button {
    width: 100%;
    padding: 12px;
}

/* === PAGE LOADER === */
#page-loader .loader-logo {
    width: 100px !important;
}

#page-loader .loader-bar {
    width: 150px !important;
}

/* === PARTICLES - Performance handled by mobile-performance-fix.css === */

/* ============================================
   FIX 5: SMALL PHONES (max-width: 480px)
   ============================================ */

@media (max-width: 480px) {

    body {
        font-size: 13px;
    }

    h2 {
        font-size: 1.4rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    .logo {
        height: 45px !important;
    }

    .switch {
        font-size: 12px !important;
    }

    nav {
        width: min(260px, 85vw) !important;
    }

    .hero h2 {
        font-size: 1.3rem !important;
    }

    .hero p {
        font-size: 0.85rem !important;
    }

    .content {
        padding: 1rem !important;
    }

    .materie-icon {
        font-size: 2rem !important;
    }

    .stat-number {
        font-size: 2rem !important;
    }

    .coming-soon {
        font-size: 1.1rem !important;
    }

    .membru {
        max-width: 280px;
    }

    .parteneri-logos img {
        max-width: 140px;
        padding: 10px;
    }

    /* Particles handled by mobile-performance-fix.css */
}

/* ============================================
   FIX 6: LANDSCAPE MODE
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {

    .hero {
        min-height: auto !important;
        padding: 90px 1rem 2rem !important;
    }

    header {
        padding: 0.5rem 1rem !important;
        min-height: 50px;
    }

    .logo {
        height: 40px !important;
    }

    nav {
        padding-top: 60px !important;
    }
}

/* ============================================
   FIX 7: TOUCH IMPROVEMENTS
   ============================================ */

@media (hover: none) and (pointer: coarse) {

    /* Minimum tap targets 44x44px (Apple HIG) */
    nav a,
    .hero button,
    .materie-card,
    .contact-link,
    #scrollTopBtn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Active states */
    .membru:active {
        transform: scale(0.98);
    }

    .materie-card:active {
        transform: translateY(-2px);
    }

    /* Prevent text selection on interactive elements */
    button,
    .materie-card,
    .membru,
    .hamburger {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: rgba(192, 132, 252, 0.2);
    }

    /* On touch devices, popups are shown via JS tap (show-popup class) */
    /* Do NOT block the tap-based popup display */
}

/* ============================================
   FIX 8: iOS SPECIFIC FIXES (Safari)
   ============================================ */

@supports (-webkit-touch-callout: none) {

    /* iOS viewport fix */
    .hero {
        min-height: -webkit-fill-available !important;
    }

    /* iOS smooth scrolling */
    body {
        -webkit-overflow-scrolling: touch;
    }

    /* iOS input zoom prevention */
    input,
    select,
    textarea,
    button {
        font-size: 16px !important;
    }

    /* iOS safe area insets */
    @media (max-width: 768px) {
        header {
            padding-top: max(0.75rem, env(safe-area-inset-top)) !important;
            padding-left: max(1rem, env(safe-area-inset-left)) !important;
            padding-right: max(1rem, env(safe-area-inset-right)) !important;
        }

        nav {
            padding-top: max(80px, calc(80px + env(safe-area-inset-top))) !important;
        }
    }

    /* Fix iOS 100vh bug */
    @media (max-width: 768px) {

        .hero,
        nav {
            height: 100dvh !important;
            /* Dynamic viewport */
        }
    }
}

/* ============================================
   FIX 9: ANDROID CHROME FIXES
   ============================================ */

@media (max-width: 768px) {

    /* Prevent address bar issues */
    .hero {
        min-height: calc(100vh - 56px);
        /* Account for address bar */
    }

    /* Fix for Chrome URL bar collapse */
    @supports (height: 100dvh) {
        .hero {
            min-height: 100dvh;
        }
    }
}

/* ============================================
   FIX 10: PERFORMANCE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {

    /* Performance optimizations moved to mobile-performance-fix.css for single source of truth */
    /* - Particle animation duration
       - Background size
       - Header blur */

    /* GPU acceleration */
    .hamburger,
    nav,
    .menu-overlay {
        will-change: transform;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}

/* ============================================
   FIX 11: ACCESSIBILITY
   ============================================ */

@media (max-width: 768px) {

    /* Better focus indicators */
    a:focus,
    button:focus,
    .materie-card:focus {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }

    /* Skip to content link */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--primary);
        color: white;
        padding: 8px;
        text-decoration: none;
        z-index: 9999;
    }

    .skip-to-content:focus {
        top: 0;
    }

    /* High contrast mode support */
    @media (prefers-contrast: high) {
        nav li {
            border-bottom: 2px solid rgba(255, 255, 255, 0.3) !important;
        }
    }
}