/* =========================================================================
 * DYNASCREW GLOBAL RESPONSIVE OVERRIDES
 * =========================================================================
 * This file systematically intercepts hardcoded inline styles (flex, grid, 
 * absolute widths) used across all page templates and forces them into 
 * responsive behaviors for tablets and mobile devices.
 * ========================================================================= */

@media (max-width: 1200px) {
    .container, .brochure-container {
        padding-left: 30px !important;
        padding-right: 30px !important;
    }
}

@media (max-width: 850px) {
    /* -----------------------------------------------------------
       GLOBAL FLEX & GRID COLLAPSE (Targeting Inline Styles)
       ----------------------------------------------------------- */
    
    /* Force common multi-column layout structures to stack */
    .container > div[style*="display: flex"],
    .brochure-container > div[style*="display: flex"],
    section > div > div[style*="display: flex"],
    section > div[style*="display: flex"],
    .callout-row,
    .callout-row[style*="display: flex"],
    .container > div > div[style*="display: flex"],
    .grid[style*="grid-template-columns:"],
    div[style*="grid-template-columns:"] {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
        height: auto !important;
    }

    /* Target direct inline flex children to take full width */
    div[style*="flex: 1"],
    div[style*="flex: 1.5"],
    div[style*="flex: 2"],
    div[style*="flex: 3"],
    div[style*="flex: 0 0"],
    .intro-left, .intro-right,
    .tech-col-left, .tech-col-right, .tech-col-center {
        flex: none !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 0 30px 0 !important;
    }

    /* Center alignments that look better stacked */
    .container > div[style*="display: flex"] > div,
    .brochure-container > div[style*="display: flex"] > div {
        text-align: center;
        align-items: center;
    }

    /* -----------------------------------------------------------
       SPECIFIC PAGE FIXES (Robostation, Tech, etc.)
       ----------------------------------------------------------- */
       
    /* Image bounding and scaling */
    img[style*="max-width: none"],
    img[style*="width: 140%"],
    img[style*="position: absolute"] {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        transform: none !important;
        margin: 20px auto !important;
        display: block;
    }
    
    /* Tech Page Process specific */
    .process-text-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
    .process-visual-strip {
        flex-direction: column;
        gap: 20px;
        padding: 20px;
    }
    .visual-step:not(:last-child)::after {
        display: none; /* Hide dashed connector lines on mobile */
    }

    /* Typography overrides for inline text */
    h1, h1[style*="font-size"] { font-size: 3rem !important; line-height: 1.1 !important; text-align: center; }
    h2, h2[style*="font-size"], .p6-title, .p7-title .main, .p8-title .main { font-size: 2.4rem !important; line-height: 1.2 !important; text-align: center; }
    h3, h3[style*="font-size"] { font-size: 1.8rem !important; line-height: 1.2 !important; text-align: center; }
    h4, h4[style*="font-size"] { font-size: 1.4rem !important; text-align: center; }
    p[style*="font-size: 1.1rem"], p[style*="font-size: 1.2rem"] { font-size: 1rem !important; }
    
    /* "How it Works" SVGs / Absolute annotations */
    div[style*="position: absolute"] > span[style*="font-size: 0.85rem"],
    .svg-anno {
        position: relative !important;
        display: block !important;
        top: auto !important; left: auto !important; right: auto !important; bottom: auto !important;
        margin: 10px auto !important;
        text-align: center !important;
    }
    
    /* Remove arbitrary margin-top/left on hero elements */
    img[style*="margin-top: -100px"] {
        margin-top: 0 !important;
    }
    img[style*="margin-left: -20%"] {
        margin-left: 0 !important;
    }
}

@media (max-width: 576px) {
    /* -----------------------------------------------------------
       SMARTPHONE TWEAKS
       ----------------------------------------------------------- */
       
    /* Process Grid */
    .process-text-grid {
        grid-template-columns: 1fr;
    }

    /* Product Grid */
    .product-grid-disp {
        grid-template-columns: 1fr;
    }

    /* Constrain massive dynamic images and cards on small phones */
    img[style*="max-height: 480px"],
    img[style*="height: 380px"],
    img[style*="height: 440px"] {
        max-height: 280px !important;
        height: auto !important;
        flex-grow: 0 !important;
        margin-bottom: 10px !important;
    }
    
    .b-card, .dd-card, .dd-list-item {
        padding: 20px !important;
    }

    /* Mobile Font Scaling */
    h1, h1[style*="font-size"], .fix-title-main { font-size: 2.3rem !important; margin-bottom: 20px !important; }
    h2, h2[style*="font-size"], .p6-title, .p7-title .main, .p8-title .main { font-size: 1.8rem !important; }
    h3, h3[style*="font-size"] { font-size: 1.4rem !important; }
    h4, h4[style*="font-size"] { font-size: 1.2rem !important; margin-bottom: 10px !important; }
    
    .p7-title .sub, .p8-title .sub { font-size: 1.4rem !important; }
    .label-text, .annotation-text { font-size: 0.7rem !important; }

    /* Adjust padding tighter for very small screens */
    .container, .brochure-container {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
    
    /* Section paddings */
    section[style*="padding: 100px 0"],
    section[style*="padding: 120px 0"],
    div[style*="padding: 100px 0"] {
        padding: 40px 0 !important;
    }
}

/* =========================================================================
 * MOBILE HEADER & HAMBURGER NAVIGATION
 * ========================================================================= */
@media (min-width: 993px) {
    .mobile-menu-toggle { display: none !important; }
    .mobile-menu-decorator { display: none !important; }
}

@media (max-width: 992px) {
    /* Header layout overrides */
    .site-header { position: relative; z-index: 1000; }
    .site-header .container { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; position: relative; }
    
    .header-cta { display: none !important; } /* Hide CTA button on mobile to save space */
    
    /* Hamburger Icon Styling */
    .mobile-menu-toggle {
        display: flex !important; flex-direction: column; justify-content: space-between;
        width: 30px; height: 21px; background: transparent; border: none; cursor: pointer; padding: 0; z-index: 1001;
    }
    .mobile-menu-toggle span {
        width: 100%; height: 3px; background: var(--text-dark, #111); border-radius: 10px; transition: all 0.3s ease;
    }
    
    /* Default Horizontal Menu -> Full Screen Overlay */
    .site-header .main-navigation {
        display: none !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: #ffffff;
        z-index: 999;
        padding: 100px 30px 40px 30px; /* Leave space for header */
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Rotating Decorative Graphic */
    .mobile-menu-decorator {
        display: block !important;
        position: absolute;
        bottom: -50px;
        right: -50px;
        width: 320px;
        height: auto;
        pointer-events: none;
        color: #eceef0;
        opacity: 1;
        animation: rotateSlowly 15s linear infinite;
    }
    
    @keyframes rotateSlowly {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }
    
    .site-header .main-navigation ul {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start;
        gap: 20px !important;
        margin: 0; padding: 0;
    }
    
    .site-header .main-navigation li { width: 100%; margin: 0 !important; }
    .site-header .main-navigation a { display: block; padding: 15px 0; font-size: 1.4rem; border-bottom: 1px solid #f0f0f0; font-weight: 500; }
    
    /* Menu Open State (Triggered by JS) */
    body.mobile-menu-open {
        overflow: hidden; /* Prevent background scrolling */
    }
    body.mobile-menu-open .site-header .main-navigation {
        display: block !important;
        animation: fadeInOverlay 0.3s ease forwards;
    }
    
    /* Hamburger to 'X' animation */
    .mobile-menu-toggle { position: relative; z-index: 1001; }
    body.mobile-menu-open .mobile-menu-toggle span:nth-child(1) { transform: rotate(45deg) translate(6px, 6px); }
    body.mobile-menu-open .mobile-menu-toggle span:nth-child(2) { opacity: 0; }
    body.mobile-menu-open .mobile-menu-toggle span:nth-child(3) { transform: rotate(-45deg) translate(6px, -7px); }
    
    @keyframes fadeInOverlay {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}
