/* ===================================
   Responsive Design Enhancement (2026 Best Practices)
   Mobile-first approach with em-based breakpoints
   Standard breakpoints: 30em (480px), 48em (768px), 64em (1024px), 80em (1280px), 120em (1920px)
   =================================== */

/* ===================================
   CSS Variables for Responsive Design
   =================================== */
:root {
    --header-height: 80px;
    
    /* Breakpoint values for JavaScript/container queries */
    --bp-xs: 20rem;   /* 320px */
    --bp-sm: 30rem;   /* 480px */
    --bp-md: 48rem;   /* 768px */
    --bp-lg: 64rem;   /* 1024px */
    --bp-xl: 80rem;   /* 1280px */
    --bp-2xl: 120rem; /* 1920px */
}

/* ===================================
   Base Responsive Behavior
   =================================== */

/* Ensure smooth scrolling and proper scroll offset for fixed header */
html {
    scroll-behavior: smooth;
    scroll-padding-top: var(--header-height);
}

/* Respect user's motion preferences (accessibility) */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* All sections and headings should account for fixed header when jumped to */
.section,
.hero,
[id] {
    scroll-margin-top: var(--header-height);
}

/* First section on any page needs additional top padding for visual separation */
.section:first-of-type,
#about,
#capabilities,
#portfolio,
#services,
#technologies,
#contact,
#application,
#careers {
    padding-top: clamp(1.5rem, 3vw, 2.5rem);
}

/* Additional safety: ensure section titles and headings have a margin above
   them when targeted by fragment links. Add a small buffer so decorative
   ::after rules don't overlap the header. */
.section .section-title,
.section h1,
.section h2,
.section h3,
[id].section-title,
[id] {
    scroll-margin-top: calc(var(--header-height) + 12px);
}

/* Container Query Support (2026 best practice) */
.card-container,
.grid-container,
.feature-container {
    container-type: inline-size;
    container-name: card;
}

/* Example: Cards adapt based on their container width, not viewport */
@container card (min-width: 25rem) {
    .card {
        display: flex;
        flex-direction: row;
    }
}

@container card (min-width: 40rem) {
    .card {
        gap: 2rem;
    }
}

/* ===================================
   Mobile Devices (up to 30em / 480px)
   Base mobile styles - smallest screens first
   =================================== */
@media (max-width: 30em) {
    :root {
        --header-height: 56px;
    }

    body {
        font-size: clamp(0.9375rem, 3vw, 1rem); /* 15-16px */
        padding-top: var(--header-height);
    }

    /* Reduce first section padding on smallest screens for tighter layout */
    .section:first-of-type,
    #about,
    #capabilities,
    #portfolio,
    #services,
    #technologies,
    #contact,
    #application,
    #careers {
        padding-top: 1rem;
    }

    /* Apply touch-target minimums to primary interactive controls only on small devices.
       Avoid applying to all anchors to prevent breaking inline nav and footer layouts. */
    .btn,
    button,
    .menu-toggle,
    .cta-nav,
    input[type="submit"],
    input[type="button"] {
        min-height: var(--touch-target-min);
        /* Do not enforce min-width globally as it breaks inline flows */
        min-width: 0;
    }

    h1 { 
        font-size: clamp(1.75rem, 7vw, 2.25rem);
        line-height: 1.2;
    }
    
    h2 { 
        font-size: clamp(1.5rem, 6vw, 1.875rem);
        line-height: 1.25;
    }
    
    h3 { 
        font-size: clamp(1.25rem, 5vw, 1.5rem);
        line-height: 1.3;
    }

    .container {
        padding: 0 clamp(0.75rem, 3vw, 1rem);
    }

    /* Hero section mobile */
    .hero {
        min-height: calc(100vh - var(--header-height));
        padding-top: calc(var(--header-height) + 1rem);
        padding-bottom: 2rem;
    }

    /* Ensure hero content is centered on small screens and remains centered
       where intended across breakpoints (fixes unexpected left-shift) */
    .hero-content,
    .hero-title,
    .hero-subtitle {
        margin-left: auto;
        margin-right: auto;
        /* Restrict title line length on very small screens only */
        max-width: 20ch;
        text-align: center;
    }

    .hero-title {
        font-size: clamp(1.75rem, 7vw, 2.25rem);
        line-height: 1.2;
        margin-bottom: clamp(0.75rem, 3vw, 1rem);
    }

    .hero-subtitle {
        font-size: clamp(0.9375rem, 4vw, 1.0625rem);
        margin-bottom: clamp(1.25rem, 4vw, 1.5rem);
        padding: 0 0.5rem;
        line-height: 1.5;
    }

    .hero-buttons {
        padding: 0 0.5rem;
        gap: clamp(0.75rem, 2vw, 1rem);
        width: 100%;
    }

    .hero-buttons .btn,
    .secondary-buttons .btn {
        width: 100%;
        max-width: min(280px, 90vw);
        margin: 0 auto;
        padding: clamp(0.875rem, 3vw, 1rem) clamp(1.25rem, 4vw, 1.5rem);
        font-size: clamp(0.875rem, 3vw, 1rem);
    }

    .secondary-buttons {
        gap: clamp(0.75rem, 2vw, 1rem);
        width: 100%;
        flex-direction: column;
    }

    /* Section titles mobile */
    .section .section-title {
        font-size: clamp(1.5rem, 6vw, 1.875rem);
        padding-bottom: 0.75rem;
        line-height: 1.2;
    }

    .section .section-title::after {
        width: 60px;
        height: 3px;
    }

    .section .section-subtitle {
        font-size: clamp(0.9375rem, 3.5vw, 1.0625rem);
        line-height: 1.5;
    }

    /* Footer mobile */
    .footer-content {
        text-align: center;
    }

    .footer-section {
        align-items: center;
        text-align: center;
    }

    .footer-section:first-child {
        align-items: center;
    }

    .footer-logo {
        margin: 0 auto 1rem;
        height: 60px;
    }

    .footer-description {
        text-align: center;
        max-width: 100%;
    }

    .footer-section h3 {
        text-align: center;
    }

    .footer-links,
    .footer-contact {
        text-align: center;
    }

    .footer-contact li {
        justify-content: center;
    }

    .footer-social {
        justify-content: center;
    }

    .footer-legal {
        flex-direction: column;
        gap: 0.5rem;
    }

    .footer-legal .divider {
        display: none;
    }

    /* Mobile-only touch-target improvements for footer controls */
     /* Allow footer contact rows to remain compact on very small screens while
         keeping primary interactive controls touch-friendly elsewhere. This
         prevents an oversized minimum height from forcing large gaps in the
         footer on narrow viewports. */
     .footer-contact li { min-height: auto; }
    .footer-social a { min-width: var(--touch-target-min); min-height: var(--touch-target-min); }
}

/* ===================================
   Small Tablets / Large Phones (30em - 48em / 480px - 768px)
   =================================== */
@media (min-width: 30em) and (max-width: 48em) {
    :root {
        --header-height: 64px;
    }
    
    body {
        padding-top: var(--header-height);
    }

    h1 { 
        font-size: clamp(2.25rem, 5vw, 2.75rem);
        line-height: 1.15;
    }
    
    h2 { 
        font-size: clamp(1.75rem, 4vw, 2.125rem);
        line-height: 1.2;
    }

    .hero {
        min-height: calc(100vh - var(--header-height));
        padding-top: calc(var(--header-height) + 1.5rem);
    }

    .hero-title {
        font-size: clamp(2.25rem, 5vw, 2.75rem);
        line-height: 1.15;
    }

    .hero-subtitle {
        font-size: clamp(1rem, 3vw, 1.125rem);
        line-height: 1.6;
    }

    .hero-buttons .btn,
    .secondary-buttons .btn {
        max-width: 320px;
        margin: 0 auto;
    }

    /* Section titles */
    .section .section-title {
        font-size: clamp(1.75rem, 4vw, 2.125rem);
    }

    /* Footer tablet */
    .footer-content {
        text-align: center;
    }

    .footer-section {
        align-items: center;
        text-align: center;
    }

    .footer-section:first-child {
        align-items: center;
    }

    .footer-logo {
        margin: 0 auto 1rem;
    }

    .footer-description {
        text-align: center;
    }

    .footer-section h3 {
        text-align: center;
    }

    .footer-links,
    .footer-contact {
        text-align: center;
    }

    .footer-contact li {
        justify-content: center;
    }

    .footer-social {
        justify-content: center;
    }
}

/* ===================================
   Tablets (48em - 64em / 768px - 1024px)
   =================================== */
@media (min-width: 48em) and (max-width: 64em) {
    :root {
        --header-height: 72px;
    }    
    body {
        padding-top: var(--header-height);
    }
    .hero-title {
        font-size: clamp(3rem, 5vw, 3.5rem);
        line-height: 1.1;
    }

    /* keep primary button above secondary group */
    .hero-buttons {
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .secondary-buttons {
        flex-direction: row;
        gap: var(--spacing-md);
    }

    .hero-buttons .btn,
    .secondary-buttons .btn {
        width: auto;
        max-width: none;
    }

    .secondary-buttons {
        flex-direction: row;
        justify-content: center;
    }

    /* Footer tablet landscape */
    .footer-section:first-child {
        flex-direction: row;
        align-items: center;
    }

    .footer-logo {
        margin: 0 1rem 0 0;
    }

    .footer-description {
        text-align: left;
    }
}

/* ===================================
   Desktop (64em and up / 1024px and up)
   =================================== */
@media (min-width: 64em) {
    :root {
        --header-height: 80px;
    }    
    body {
        padding-top: var(--header-height);
    }
    /* Ensure hero buttons are horizontal on desktop */
    /* primary above secondary on desktop as well */
    .hero-buttons {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: var(--spacing-md);
    }

    .secondary-buttons {
        flex-direction: row;
        gap: var(--spacing-md);
        display: flex;
    }

    .hero-buttons .btn,
    .secondary-buttons .btn {
        width: auto;
        max-width: none;
        display: inline-block;
    }

    /* Desktop: center hero content both vertically and horizontally
       Use CSS Grid to guarantee perfect centering across wide viewports */
    .hero {
        display: grid;
        place-items: center;
        min-height: calc(100vh - var(--header-height));
        padding-top: calc(var(--header-height) + 1rem);
        padding-bottom: 2rem;
    }

    .hero > .container {
        width: 100%;
        display: grid;
        place-items: center;
    }

    .hero-content {
        justify-self: center;
        align-self: center;
        max-width: 64rem;
        width: 100%;
        padding: 0 var(--spacing-md);
    }

    .secondary-buttons {
        flex-direction: row;
        gap: var(--spacing-md);
    }

    /* Footer desktop */
    .footer-section:first-child {
        flex-direction: row;
        align-items: center;
        text-align: left;
    }

    .footer-logo {
        margin: 0 1rem 0 0;
    }

    .footer-description {
        text-align: left;
    }

    .footer-section h3 {
        text-align: left;
    }

    .footer-links,
    .footer-contact {
        text-align: left;
    }

    .footer-contact li {
        justify-content: flex-start;
    }

    .footer-social {
        justify-content: flex-start;
    }
}

/* ===================================
   Large Screens (90em and up / 1440px and up)
   =================================== */
@media (min-width: 90em) {
    .container {
        max-width: 1320px;
    }

    .hero-title {
        font-size: clamp(4rem, 6vw, 4.5rem);
        line-height: 1.1;
    }

    .hero-subtitle {
        font-size: clamp(1.25rem, 2vw, 1.5rem);
        line-height: 1.6;
    }
}

/* ===================================
   Touch Device Optimizations
   =================================== */
@media (hover: none) and (pointer: coarse) {
    .btn,
    a.btn,
    button,
    input[type="button"],
    input[type="submit"],
    select,
    .nav-link {
        min-height: 44px;
        min-width: 44px;
    }

    .nav-link {
        display: flex;
        align-items: center;
    }

    .btn:hover,
    .card:hover,
    .service-card:hover,
    .feature-card:hover,
    .portfolio-item:hover,
    .tech-card:hover {
        transform: none;
    }

    .footer-logo:hover {
        transform: none;
        box-shadow: none;
    }
    
    input,
    textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    select {
        font-size: 16px; /* Prevents iOS zoom on focus */
        transition: none !important;
        -webkit-tap-highlight-color: transparent;
    }

    /* Prevent ALL visual style changes on select tap — the native picker
       provides its own feedback.  Any border-color, box-shadow or
       background-color snap causes a repaint that blinks on mobile. */
    select:hover,
    select:focus,
    .form-group select:hover,
    .form-group select:focus,
    .form-group-country select:hover,
    .form-group-country select:focus,
    .phone-row .country-code-select:hover,
    .phone-row .country-code-select:focus {
        border-color: var(--gray-200) !important;
        box-shadow: none !important;
        background-color: transparent !important;
        outline: none !important;
        transition: none !important;
    }

    /* Error-state selects: keep the error look unchanged on focus/hover
       to prevent the red→gray visual snap.  Specificity must beat the
       JS-injected .input-error:focus rule in seg_common.js. */
    .form-group select.input-error:hover,
    .form-group select.input-error:focus,
    .form-group-country select.input-error:hover,
    .form-group-country select.input-error:focus,
    .phone-row select.input-error:hover,
    .phone-row select.input-error:focus {
        border-color: #ef4444 !important;
        box-shadow: 0 0 0 3px rgba(239,68,68,0.1) !important;
        background-color: transparent !important;
        outline: none !important;
        transition: none !important;
    }

    /* Dark mode: same neutralization but with dark-theme border */
    html[data-theme="dark"] select:hover,
    html[data-theme="dark"] select:focus,
    html[data-theme="dark"] .form-group select:hover,
    html[data-theme="dark"] .form-group select:focus,
    html[data-theme="dark"] .phone-row .country-code-select:hover,
    html[data-theme="dark"] .phone-row .country-code-select:focus {
        border-color: rgba(255,255,255,0.06) !important;
        box-shadow: none !important;
        background-color: rgba(255,255,255,0.02) !important;
        outline: none !important;
        transition: none !important;
    }

    html[data-theme="dark"] .form-group select.input-error:hover,
    html[data-theme="dark"] .form-group select.input-error:focus,
    html[data-theme="dark"] .phone-row select.input-error:hover,
    html[data-theme="dark"] .phone-row select.input-error:focus {
        border-color: #ef4444 !important;
        box-shadow: 0 0 0 3px rgba(239,68,68,0.1) !important;
        background-color: rgba(255,255,255,0.02) !important;
        outline: none !important;
        transition: none !important;
    }

    .form-group {
        margin-bottom: 1.5rem;
    }
}

/* ===================================
   Landscape Mode Adjustments
   =================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .hero {
        min-height: auto;
        padding: calc(var(--header-height) + 2rem) 0 2rem;
    }

    .hero-title {
        font-size: 2rem;
        margin-bottom: 1rem;
    }

    .hero-subtitle {
        margin-bottom: 1rem;
    }
}

/* ===================================
   Print Styles
   =================================== */
@media print {
    *,
    *::before,
    *::after {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    .navbar,
    .menu-toggle,
    .hero-background,
    .scroll-indicator,
    .footer-social,
    .no-print,
    nav,
    .nav,
    .btn,
    .hero-cta,
    .back-to-top,
    .notification,
    .theme-toggle {
        display: none !important;
    }

    .hero {
        min-height: auto;
        padding: 2rem 0;
        background: none;
        color: #000;
    }

    .hero-title,
    .hero-subtitle {
        color: #000;
    }

    body {
        padding-top: 0;
    }
    
    a,
    a:visited {
        text-decoration: underline;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    h2,
    h3 {
        page-break-after: avoid;
    }
}

/* ===================================
   Landscape Mobile Orientation
   =================================== */
@media (max-width: 48em) and (orientation: landscape) {
    .hero {
        min-height: auto;
        padding-top: calc(var(--header-height) + 1rem);
        padding-bottom: 2rem;
    }
    
    .section {
        padding-top: var(--spacing-lg);
        padding-bottom: var(--spacing-lg);
    }
}

/* ===================================
   Dark Mode Preference
   =================================== */
@media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
        --bg-primary: var(--dark-bg);
        --bg-secondary: var(--dark-secondary);
        --text-primary: #E6EEF8;
        --text-secondary: #B7C6D9;
        --border-color: var(--dark-tertiary);
    }
}

/* ===================================
   Accessibility Enhancements
   =================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-primary {
        border: 2px solid currentColor;
    }

    .nav-link {
        text-decoration: underline;
    }
    
    /* Ensure sufficient contrast */
    :root {
        --primary-color: #0000FF;
        --text-primary: #000000;
        --border-color: #000000;
    }
    
    .btn {
        border-width: 2px;
    }
    
    a {
        text-decoration: underline;
    }
}

/* ===================================
   Container Queries (2026 Feature)
   =================================== */
@supports (container-type: inline-size) {
    .card-container {
        container-type: inline-size;
        container-name: card;
    }
    
    @container card (min-width: 400px) {
        .card {
            padding: var(--spacing-xl);
        }
    }
    
    @container card (min-width: 600px) {
        .card {
            display: grid;
            grid-template-columns: auto 1fr;
            gap: var(--spacing-lg);
        }
    }
}