/* Mobile responsive adjustments (Lightbox) */
@media (max-width: 768px) {
    .lightbox-info {
        position: static;
        margin-bottom: 10px;
        transform: none;
        max-width: 90%;
    }

    .lightbox-info h3 {
        font-size: 1rem;
        white-space: normal;
    }

    .zoom-controls {
        bottom: 10px;
        padding: 8px;
    }

    .zoom-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }

    .lightbox-nav {
        width: 45px;
        height: 45px;
        font-size: 1.5rem;
    }

    .lightbox-close {
        width: 45px;
        height: 45px;
        font-size: 1.5rem;
    }
}

/* Mobile Styles - max-width: 480px */
@media (max-width: 480px) {
    /* Navigation improvements */
    .nav-container {
        padding: 0 15px;
        height: 55px;
        min-height: 55px;
    }
    /* Keep brand compact so it doesn't crowd menu */
    .brand { font-size: 0.95rem; line-height: 1.05; }
    .brand .brand-line { display: block; }
    
    .nav-toggle {
        padding: 4px;
        right: 15px;
    }
    
    .nav-toggle span {
        width: 20px;
        height: 2px;
    }
    
    .nav-menu {
        top: 55px;
        height: calc(100vh - 55px);
        padding: 1rem 0;
    }

    /* Improved section spacing */
    section {
        padding: 88px 12px 44px;
        min-height: auto;
        width: 100%;
        overflow-x: hidden;
        scroll-margin-top: 80px;
    }

    /* Hero section mobile optimization */
    .hero-content {
        gap: 1.5rem;
        padding: 1rem 0;
    }

    .hero-text {
        text-align: center;
        padding: 0 10px;
    }

    .hero-text h1 {
        font-size: 1.8rem;
        line-height: 1.2;
        margin-bottom: 0.8rem;
    }

    .hero-text h2 {
        font-size: 1.2rem;
        line-height: 1.3;
        margin-bottom: 1rem;
    }

    .hero-text p {
        font-size: 0.95rem;
        line-height: 1.5;
        margin-bottom: 1.5rem;
    }

    .hero-image {
        margin: 0 auto;
    }

    .hero-image img {
        width: 220px;
        height: 220px;
        margin: 0 auto;
    }

    /* Better button layout */
    .cta-buttons {
        flex-direction: column;
        align-items: center;
        gap: 12px;
        margin-top: 1rem;
        margin-bottom: 24px;
    }

    .btn {
        width: 100%;
        max-width: 300px;
        text-align: center;
        padding: 12px 20px;
        font-size: 16px;
        white-space: nowrap;
    }

    /* Typography improvements */
    .section-title {
        font-size: 1.8rem;
        line-height: 1.2;
        margin-bottom: 0.8rem;
        padding: 0;
        text-align: center;
        width: 100%;
        word-wrap: break-word;
    }

    .section-subtitle {
        font-size: 0.95rem;
        line-height: 1.4;
        padding: 0;
        margin-bottom: 2rem;
        text-align: center;
        width: 100%;
        word-wrap: break-word;
    }

    /* About stats mobile layout */
    .about-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-top: 2rem;
        padding: 0;
        width: 100%;
    }

    .stat {
        padding: 1.2rem 1rem;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .stat-number {
        font-size: 1.3rem;
    }

    .stat-label {
        font-size: 0.85rem;
    }

    /* Problem boxes mobile optimization */
    .problem-boxes {
        padding: 0;
        width: 100%;
    }

    .problem-box {
        padding: 1.5rem 1rem;
        max-width: 100% !important;
        width: 100%;
        margin: 0 0 1rem 0;
        align-self: center;
        box-sizing: border-box;
    }

    .problem-text {
        font-size: 0.95rem;
        line-height: 1.5;
    }

    /* Grid layouts mobile optimization */
    .services-grid,
    .projects-grid,
    .skills-container,
    .portfolio-folders {
        grid-template-columns: 1fr;
        gap: 1.2rem;
        padding: 0;
        width: 100%;
    }

    .service-card,
    .project-card,
    .skill-category,
    .folder-card {
        margin: 0;
        padding: 1.5rem 1rem;
        width: 100%;
        box-sizing: border-box;
    }

    /* Testimonials mobile improvements */
    .testimonials-grid {
        grid-template-columns: 1fr;
        gap: 1.2rem;
        padding: 0;
        width: 100%;
    }

    .testimonial-card {
        margin: 0;
        padding: 1.5rem 1rem;
        width: 100%;
        box-sizing: border-box;
    }

    .testimonials-categories {
        gap: 0.8rem;
        justify-content: center;
        flex-wrap: wrap;
        padding: 0 10px;
    }

    .category-filter {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
        min-width: auto;
    }

    /* Timeline mobile improvements */
    .timeline {
        padding: 0.5rem 0;
        margin: 0;
        width: 100%;
    }

    .timeline::before {
        left: 10px;
    }

    .timeline-item {
        flex-direction: column !important;
        margin-left: 25px;
        margin-bottom: 1.5rem;
    }

    .timeline-content {
        width: 100%;
        padding: 1.2rem;
        margin-right: 10px;
    }

    .timeline-dot {
        left: 10px;
        width: 12px;
        height: 12px;
    }

    /* Contact section mobile */
    .contact-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .contact-info,
    .contact-form {
        margin: 0;
        padding: 1.2rem;
        width: 100%;
        box-sizing: border-box;
    }

    .contact-item {
        padding: 0.8rem;
        margin-bottom: 1rem;
    }

    .form-group {
        margin-bottom: 1.2rem;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.75rem;
        font-size: 16px !important;
        border-radius: 8px;
    }

    /* Portfolio mobile improvements */
    .portfolio-tabs {
        gap: 0.8rem;
        flex-wrap: wrap;
        justify-content: center;
        padding: 0 10px;
    }

    .tab-btn {
        padding: 0.7rem 1.2rem;
        font-size: 0.9rem;
        min-width: 100px;
        flex: 1;
        max-width: 150px;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 1.2rem;
        padding: 0;
        width: 100%;
    }

    .gallery-item {
        margin: 0;
        width: 100%;
        box-sizing: border-box;
    }

    /* iOS safe area support */
    .nav-container {
        padding-top: env(safe-area-inset-top);
    }

    section {
        padding-bottom: env(safe-area-inset-bottom, 30px);
    }

    /* Prevent horizontal scroll on small screens */
    * {
        box-sizing: border-box;
        word-wrap: break-word;
        word-break: break-word;
        hyphens: auto;
    }
    
    /* Fix width constraints */
    .container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0;
        padding: 0 10px;
    }

    /* Better touch targets */
    button, .btn, a {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    /* Add more vertical rhythm and anchor offset for all sections */
    section + section { margin-top: 28px; }
    section { scroll-margin-top: 80px; }

    /* Section-specific spacing to avoid visual crowding */
    #services, #testimonials, #skills, #experience, #portfolio, #contact { padding-top: 64px; padding-bottom: 64px; }
    #projects { padding-top: 72px; padding-bottom: 64px; }

    /* Extra breathing room for hero CTA visibility */
    #home { padding-top: 90px; padding-bottom: calc(env(safe-area-inset-bottom, 24px) + 200px); }
}

/* Tablet Styles - max-width: 768px */
@media (max-width: 768px) {
    .nav-container {
        height: 60px;
    }
    
    /* Lightbox should stack info on top and media centered below */
    .lightbox-modal { align-items: flex-start; }
    .lightbox-content { 
        flex-direction: column; 
        justify-content: flex-start; 
        align-items: center; 
        padding-top: 10px;
    }
    .lightbox-info { 
        order: 0; 
        width: 100%; 
        text-align: center; 
        margin-bottom: 8px; 
    }
    .lightbox-viewer, 
    .lightbox-scroll-container, 
    .lightbox-video { 
        max-width: 100%; 
        max-height: calc(100dvh - 200px); 
    }

    .nav-toggle {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 44px;
        height: 44px;
        gap: 4px;
        position: relative; /* needed for absolute-positioned spans on active */
    }

    .nav-menu {
        position: fixed;
        top: 60px;
        right: -100%;
        width: 80%;
        max-width: 300px;
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px); /* Dynamic viewport height for mobile browsers */
        background: rgba(0, 0, 0, 0.98);
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
        transition: right 0.3s ease;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        padding: 20px;
        gap: 0;
        overflow-y: auto;
        z-index: 1000;
        display: none;              /* hide by default on mobile/tablet */
        visibility: hidden;
    }
    .nav-menu.active { right: 0; display: flex; visibility: visible; }

    /* Dropdown in mobile menu */
    .nav-menu .dropdown-menu {
        position: static;
        transform: none;
        width: 100%;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0 0 0 10px;
        display: none;
    }
    .nav-menu .dropdown-menu.open { display: block; }
    .nav-menu .dropdown-menu a { padding: 10px 0; color: #fff; }

    .nav-menu li {
        margin: 0.5rem 0;
        width: 100%;
    }

    .nav-link {
        padding: 1rem 2rem;
        display: block;
        width: 100%;
        font-size: 1rem;
        border-radius: 0;
    }

    .nav-link:after {
        display: none;
    }

    /* Align hamburger-to-X precisely */
    .nav-toggle.active span {
        position: absolute;
        left: 50%;
        top: 50%;
        width: 24px; /* consistent line length for X */
    }
    .nav-toggle.active span:nth-child(1) {
        transform: translate(-50%, -50%) rotate(45deg);
    }
    .nav-toggle.active span:nth-child(2) {
        opacity: 0;
    }
    .nav-toggle.active span:nth-child(3) {
        transform: translate(-50%, -50%) rotate(-45deg);
    }

    .hero-content {
        grid-template-columns: 1fr;
        gap: 2rem;
        text-align: center;
        padding-bottom: 24px;
    }

    .hero-text {
        order: 2;
    }

    .hero-image {
        order: 1;
    }

    .hero-text h1 {
        font-size: 2.8rem;
    }

    .hero-text h2 {
        font-size: 1.6rem;
    }

    .hero-image img {
        width: 300px;
        height: 300px;
    }

    .about-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    .services-grid,
    .projects-grid,
    .skills-container,
    .case-grid {
        grid-template-columns: 1fr;
    }

    .testimonials-grid {
        grid-template-columns: 1fr;
    }

    .portfolio-folders {
        grid-template-columns: repeat(2, 1fr);
    }

    .contact-content {
        grid-template-columns: 1fr;
    }

    .timeline::before {
        left: 20px;
    }

    .timeline-item {
        flex-direction: column !important;
        margin-left: 40px;
    }

    .timeline-content {
        width: 100%;
    }

    .timeline-dot {
        left: 20px;
    }
}
