/* ============================================================
   TSB Mobile Responsiveness Fix - Comprehensive
   Fixes breakpoint mismatches, layout issues, touch targets,
   performance, and accessibility for all mobile devices
   ============================================================ */

/* ============================================================
   0. GLOBAL MOBILE FOUNDATIONS
   ============================================================ */

/* Smooth scrolling on iOS */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Prevent horizontal overflow globally */
body {
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Accessibility: Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .carousel-slide {
        transition: opacity 0.01ms !important;
    }
    
    .fade-in {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
}

/* ============================================================
   1. NAVIGATION BREAKPOINT FIX
   Unify hamburger breakpoint to 968px across all stylesheets
   ============================================================ */

/* Show hamburger and hide nav menu at 968px (matching critical CSS) */
@media (max-width: 968px) {
    .nav-menu {
        position: fixed;
        left: -100%;
        top: 70px;
        flex-direction: column;
        background-color: white;
        width: 100%;
        text-align: center;
        transition: 0.3s ease;
        box-shadow: 0 10px 27px rgba(0, 0, 0, 0.1);
        padding: 2rem 0;
        gap: 1.5rem !important;
        z-index: 999;
    }

    .nav-menu.active {
        left: 0;
    }

    .nav-toggle {
        display: flex !important;
        flex-direction: column;
        cursor: pointer;
        padding: 0.5rem;
        z-index: 1001;
    }

    .nav-toggle .bar {
        width: 25px;
        height: 3px;
        background-color: var(--text-primary);
        margin: 3px 0;
        transition: 0.3s;
        border-radius: 2px;
    }

    .nav-toggle.active .bar:nth-child(2) {
        opacity: 0;
    }

    .nav-toggle.active .bar:nth-child(1) {
        transform: translateY(9px) rotate(45deg);
    }

    .nav-toggle.active .bar:nth-child(3) {
        transform: translateY(-9px) rotate(-45deg);
    }
    
    /* Dropdown menus in mobile nav */
    .nav-dropdown {
        width: 100%;
        text-align: center;
    }
    
    .dropdown-trigger {
        justify-content: center;
        width: 100%;
    }
    
    .dropdown-menu {
        position: static !important;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        box-shadow: none !important;
        border: none !important;
        background: var(--background-light) !important;
        border-radius: 8px !important;
        margin-top: 0.5rem;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        padding: 0 !important;
    }
    
    .nav-dropdown.open .dropdown-menu {
        max-height: 200px;
        padding: 0.5rem 0 !important;
    }
    
    .dropdown-menu a {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    
    .dropdown-menu a:hover {
        padding-left: 1rem;
    }
    
    .btn-nav-cta {
        margin-top: 0.5rem;
        text-align: center;
        width: auto;
        display: inline-block !important;
    }
    
    /* Hero layout adjustments */
    .hero-container {
        grid-template-columns: 1fr !important;
        gap: 2.5rem;
        text-align: center;
    }
    
    .hero-content {
        order: 1;
    }
    
    .hero-image {
        order: 2;
    }
    
    .hero-buttons {
        justify-content: center;
    }
    
    /* Contact content stacking */
    .contact-content {
        grid-template-columns: 1fr !important;
        gap: 3rem;
    }
    
    /* About content stacking */
    .about-content {
        grid-template-columns: 1fr !important;
        gap: 2rem;
    }
    
    /* Contact grid stacking */
    .contact-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem;
    }
}

/* ============================================================
   2. TABLET OPTIMIZATIONS (769px - 968px)
   ============================================================ */
@media (min-width: 769px) and (max-width: 968px) {
    .expertise-grid,
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .diff-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stories-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .footer-grid {
        grid-template-columns: 2fr 1fr 1fr !important;
        gap: 2rem;
    }
    
    .hero-buttons {
        flex-direction: row;
        justify-content: center;
    }
    
    .btn {
        width: auto;
        max-width: none;
    }
}

/* ============================================================
   3. MOBILE PHONE OPTIMIZATIONS (768px and below)
   ============================================================ */
@media (max-width: 768px) {
    /* Ensure adequate touch targets throughout */
    a, button, .faq-question, .nav-link, .btn {
        min-height: 44px;
    }
    
    /* Fix expertise/products grid for small screens */
    .expertise-grid,
    .products-grid {
        grid-template-columns: 1fr !important;
    }
    
    .diff-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Fix stories grid */
    .stories-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Hero section mobile fixes */
    .hero {
        min-height: auto !important;
        padding-top: 90px !important;
        padding-bottom: 2rem !important;
    }
    
    .hero-title {
        font-size: 2rem !important;
        line-height: 1.2 !important;
    }
    
    .hero-subtitle {
        font-size: 1rem !important;
        line-height: 1.6 !important;
    }
    
    .hero-buttons {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }
    
    .btn {
        width: 100%;
        max-width: 300px;
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }
    
    /* Hero carousel mobile */
    .hero-carousel {
        height: 280px !important;
        border-radius: 12px;
    }
    
    .hero-image img {
        height: 280px !important;
    }
    
    /* About image mobile fix - use cover instead of contain */
    .about-image img {
        height: 300px !important;
        object-fit: cover !important;
        width: 100% !important;
        border-radius: 12px !important;
    }
    
    .about-image {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
    }
    
    /* Timeline mobile fixes */
    .impact-timeline::before {
        left: 20px !important;
    }
    
    .timeline-item {
        flex-direction: column !important;
        padding-left: 3rem !important;
        align-items: flex-start !important;
    }
    
    .timeline-item:nth-child(even) {
        flex-direction: column !important;
    }
    
    .timeline-date {
        position: relative !important;
        left: auto !important;
        margin: 0 0 1rem 0 !important;
        width: auto !important;
        font-size: 0.85rem !important;
        padding: 0.5rem 1rem !important;
        display: inline-block !important;
    }
    
    .timeline-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1.5rem !important;
    }
    
    .timeline-content::before {
        display: none !important;
    }
    
    .timeline-content h4 {
        font-size: 1.25rem !important;
    }
    
    .timeline-content p {
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
    }
    
    /* Alternating timeline mobile */
    .timeline-alternating::before {
        left: 20px !important;
    }
    
    .timeline-item-alt::before {
        left: 20px !important;
        width: 16px !important;
        height: 16px !important;
    }
    
    .timeline-item-alt.left .timeline-content-wrapper,
    .timeline-item-alt.right .timeline-content-wrapper {
        flex-direction: column !important;
        padding-left: 3rem !important;
        padding-right: 0 !important;
        gap: 1.5rem !important;
    }
    
    .timeline-image {
        flex: 1 !important;
        max-width: 100% !important;
        min-width: auto !important;
    }
    
    .timeline-image img {
        height: 200px !important;
        border-radius: 12px !important;
    }
    
    .timeline-text {
        min-width: auto !important;
        padding: 1.5rem !important;
    }
    
    .timeline-text h3 {
        font-size: 1.15rem !important;
    }
    
    .timeline-text p {
        font-size: 0.95rem !important;
    }
    
    .timeline-badge {
        font-size: 0.8rem !important;
        padding: 0.4rem 1rem !important;
    }
    
    /* Impact flex container mobile */
    .impact-flex-container {
        flex-direction: column !important;
    }
    
    .impact-flex-container .impact-timeline {
        flex: 1 !important;
        max-width: 100% !important;
    }
    
    .impact-flex-container .impact-photos-sidebar {
        flex: 1 !important;
        max-width: 100% !important;
        position: static !important;
    }
    
    /* Team page mobile */
    .team-member,
    .team-member:nth-child(even) {
        flex-direction: column !important;
        text-align: center;
        padding: 2rem 1.5rem !important;
        gap: 1.5rem !important;
    }
    
    .team-photo {
        flex: 0 0 auto !important;
        width: 100% !important;
        max-width: 200px !important;
        margin: 0 auto !important;
    }
    
    .team-photo img {
        width: 180px !important;
        height: 180px !important;
    }
    
    .team-bio {
        text-align: center;
    }
    
    .team-bio h2 {
        font-size: 1.5rem !important;
    }
    
    .team-bio h3 {
        font-size: 0.9rem !important;
    }
    
    .team-bio p {
        font-size: 0.95rem !important;
        text-align: left;
    }
    
    .social-links {
        justify-content: center;
    }
    
    /* Footer mobile */
    .footer-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 2rem !important;
        text-align: left;
    }
    
    .footer-brand {
        grid-column: 1 / -1 !important;
        text-align: center !important;
        padding-right: 0 !important;
    }
    
    .footer-social {
        justify-content: center !important;
    }
    
    .footer-bottom-inner {
        flex-direction: column !important;
        gap: 1rem !important;
        text-align: center !important;
    }
    
    /* Contact page mobile */
    .hero-small {
        padding-top: 100px !important;
        padding-bottom: 2rem !important;
        min-height: auto !important;
    }
    
    .hero-small h1,
    .hero-small .hero-title {
        font-size: 1.75rem !important;
    }
    
    .hero-small .hero-subtitle {
        font-size: 0.95rem !important;
    }
    
    .contact-page {
        padding: 1.5rem 0 3rem 0 !important;
    }
    
    .contact-info-card,
    .contact-form-card {
        padding: 1.5rem !important;
    }
    
    /* Contact images mobile */
    .contact-images {
        grid-template-columns: 1fr !important;
    }
    
    .contact-images img {
        height: 180px !important;
    }
    
    .contact-images img:nth-child(2) {
        height: 200px !important;
    }
    
    /* Image grids mobile */
    .image-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
        padding: 0 !important;
    }
    
    .image-grid-two {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }
    
    .grid-image {
        height: 250px !important;
        object-fit: cover !important;
    }
    
    /* Section headers mobile */
    .section-header {
        margin-bottom: 2rem !important;
    }
    
    .section-header h2 {
        font-size: 1.75rem !important;
        line-height: 1.2 !important;
    }
    
    .section-header p {
        font-size: 0.95rem !important;
    }
    
    /* FAQ mobile */
    .faq-container {
        padding: 1rem 0 !important;
    }
    
    .faq-category-title {
        font-size: 1.4rem !important;
    }
    
    .faq-question {
        font-size: 1rem !important;
        padding: 1.25rem 1.5rem !important;
    }
    
    .faq-item.active .faq-answer {
        padding: 1.5rem !important;
    }
    
    .faq-item:hover {
        transform: none !important;
    }
    
    /* Prevent horizontal overflow */
    .container {
        overflow-x: hidden !important;
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }
    
    /* Ensure all images fit */
    img {
        max-width: 100% !important;
    }
    
    /* Story detail page mobile */
    .story-detail h1 {
        font-size: 1.6rem !important;
    }
    
    .story-detail-content {
        font-size: 1rem !important;
    }
    
    .story-detail-content h2 {
        font-size: 1.3rem !important;
    }
    
    .story-detail-content blockquote {
        padding: 1rem 1.25rem !important;
        margin: 1.5rem 0 !important;
    }
    
    /* Nav logo mobile */
    .nav-logo h2 {
        font-size: 1rem !important;
    }
    
    .nav-logo .logo-img {
        height: 38px !important;
    }
    
    .nav-container {
        height: 70px !important;
        padding: 0 1rem !important;
    }
}

/* ============================================================
   4. SMALL PHONE OPTIMIZATIONS (480px and below)
   ============================================================ */
@media (max-width: 480px) {
    .hero {
        padding-top: 80px !important;
    }
    
    .hero-title {
        font-size: 1.75rem !important;
    }
    
    .hero-small h1,
    .hero-small .hero-title {
        font-size: 1.5rem !important;
    }
    
    .hero-small {
        padding-top: 85px !important;
    }
    
    .section-header h2 {
        font-size: 1.5rem !important;
    }
    
    .hero-carousel {
        height: 220px !important;
    }
    
    .hero-image img {
        height: 220px !important;
    }
    
    .about-image img {
        height: 250px !important;
    }
    
    .nav-container {
        height: 65px !important;
        padding: 0 0.75rem !important;
    }
    
    .nav-logo h2 {
        font-size: 0.9rem !important;
    }
    
    .nav-logo .logo-img {
        height: 32px !important;
    }
    
    .nav-menu {
        top: 65px !important;
    }
    
    /* Cards more compact */
    .expertise-card,
    .product-card,
    .diff-item {
        padding: 1.5rem 1.25rem !important;
    }
    
    .timeline-content {
        padding: 1.25rem !important;
    }
    
    .team-member {
        padding: 1.5rem 1rem !important;
    }
    
    .team-photo img {
        width: 150px !important;
        height: 150px !important;
    }
    
    /* Footer compact */
    .footer {
        padding: 3rem 0 1.5rem !important;
    }
    
    .footer-grid {
        grid-template-columns: 1fr !important;
        text-align: center !important;
    }
    
    .footer-col a:hover {
        transform: none !important;
    }
    
    .footer-logo-img {
        height: 55px !important;
    }
    
    /* Buttons full width */
    .btn {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.875rem 1.25rem !important;
    }
    
    /* FAQ compact */
    .faq-category-title {
        font-size: 1.2rem !important;
    }
    
    .faq-question {
        font-size: 0.9rem !important;
        padding: 1rem 1.25rem !important;
    }
    
    .faq-item.active .faq-answer {
        padding: 1rem !important;
    }
    
    /* Story detail compact */
    .story-detail h1 {
        font-size: 1.4rem !important;
    }
    
    .story-detail-content h2 {
        font-size: 1.15rem !important;
    }
}

/* ============================================================
   5. EXTRA SMALL PHONES (375px and below)
   ============================================================ */
@media (max-width: 375px) {
    .hero-title {
        font-size: 1.5rem !important;
    }
    
    .section-header h2 {
        font-size: 1.35rem !important;
    }
    
    .nav-logo h2 {
        font-size: 0.85rem !important;
    }
    
    .nav-logo .logo-img {
        height: 28px !important;
    }
    
    .hero-carousel {
        height: 200px !important;
    }
    
    .hero-image img,
    .about-image img {
        height: 200px !important;
    }
    
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .team-photo img {
        width: 130px !important;
        height: 130px !important;
    }
}

/* ============================================================
   6. LANDSCAPE MOBILE FIXES
   ============================================================ */
@media (max-width: 968px) and (orientation: landscape) {
    .hero {
        min-height: auto !important;
        padding: 80px 0 2rem !important;
    }
    
    .hero-carousel {
        height: 200px !important;
    }
    
    .hero-image img {
        height: 200px !important;
    }
    
    .hero-container {
        gap: 2rem !important;
    }
}

/* ============================================================
   7. SAFE AREA INSETS (iPhone X+ notch support)
   ============================================================ */
@supports (padding: env(safe-area-inset-top)) {
    .navbar {
        padding-top: env(safe-area-inset-top);
    }
    
    .footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .nav-menu {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ============================================================
   8. HIGH-DPI / RETINA DISPLAY OPTIMIZATIONS
   ============================================================ */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ============================================================
   9. PRINT STYLES (for completeness)
   ============================================================ */
@media print {
    .navbar,
    .nav-toggle,
    .footer-social,
    .btn,
    .hero-carousel {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        color: #000;
    }
    
    a {
        color: #000;
        text-decoration: underline;
    }
}
