/* Mobile Navigation Fixes for Cultura Racional Website
====================================================== */

/* Fix language selector overflow and positioning */
@media (max-width: 767px) {
    /* Make header a flex row so brand stays left and toggle stays right */
    .navbar-header {
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: justify;
        -ms-flex-pack: justify;
        -webkit-justify-content: space-between;
        justify-content: space-between;
        width: 100%;
        position: relative;
    }
    .navbar-brand { -webkit-order: 1; order: 1; }
    .navbar-toggle {
        -webkit-order: 2; order: 2;
        margin-left: auto;
        float: right !important;
        margin-right: 0; /* flush to container padding */
        z-index: 1100; /* above dropdown */
    }
    /* Prevent horizontal scrolling on small screens */
    html, body {
        overflow-x: hidden;
    }
    
    /* ONLY fix language selector positioning - keep original sizes */
    .navbar .idiomas .langs {
        text-align: right;
        overflow: visible;
    }
    
    /* Ensure language selector stays within viewport */
    .navbar .container {
    padding-left: 10px;  /* slightly tighter gutters */
    padding-right: 10px;
    }
    
    .navbar .row { margin-left: 0; margin-right: 0; }
    .row { margin-left: 0; margin-right: 0; }
    .container { padding-left: 10px; padding-right: 10px; }
    
    /* Mobile menu fixes - compact dropdown only */
    .navbar-collapse {
        max-height: none !important;
        overflow-y: visible !important;
    overflow-x: hidden !important; /* avoid horizontal scroll */
        border: none;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        padding: 0;
        background-color: #fff;
        border-radius: 5px;
        margin-top: 10px;
        width: auto !important;
        float: right !important;
        position: absolute;
        right: 15px;
        top: 100%;
        z-index: 1000;
    max-width: calc(100vw - 20px); /* keep within viewport */
    box-sizing: border-box;
    }
    
    /* Menu items styling - smaller text only in dropdown */
    .navbar-nav > li > a {
        font-size: 14px !important;
        padding: 10px 15px !important;
        line-height: 1.2 !important;
        white-space: nowrap;
        color: #333 !important;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .navbar-nav > li:last-child > a {
        border-bottom: none;
    }
    
    .navbar-nav > li > a:hover,
    .navbar-nav > li > a:focus {
        background-color: #f8f8f8 !important;
        color: #333 !important;
    }
    
    /* Ensure all menu items are visible without scrolling */
    .navbar-nav {
        margin: 0;
        padding: 5px 0;
        float: none;
        width: auto;
        min-width: 200px;
    }
    
    .navbar-nav > li {
        float: none;
        margin: 0;
    }
    
    /* ONLY essential positioning fixes */
    .navbar-header {
        position: relative;
    }
    
    .navbar {
        position: relative;
    }
    
    .navbar-collapse.collapse {
        display: none !important;
    }
    
    .navbar-collapse.collapse.in {
        display: block !important;
    }
}

/* Tablet fixes */
@media (min-width: 768px) and (max-width: 991px) {
    /* No restrictive header styling */
}

/* Small mobile devices */
@media (max-width: 480px) {
    
    /* Adjust menu for very small screens */
    .navbar-nav {
        min-width: 180px;
    }
    
    .navbar-collapse {
        right: 10px;
    }
}

/* Fix for very wide menu items on mobile */
@media (max-width: 767px) {
    .navbar-nav > li > a {
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    
    /* Mobile background image fix - very specific to avoid header conflicts */
    body .row .col-md-12 section.intro#intro {
        background-size: contain !important;
        background-repeat: no-repeat !important;
        background-position: center top !important;
    }
    
    /* Fix white space inside intro section */
    section.intro .intro-section {
        padding: 5px 15px !important;
    }
    
    section.intro .container {
        padding-top: 5px !important;
        padding-bottom: 5px !important;
    }
    
    section.intro {
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;
    }
    
    /* Mobile features section - 3 columns layout */
    .features .row {
        display: flex;
        align-items: stretch; /* equal height columns so we can center the middle */
        justify-content: space-between;
        flex-wrap: nowrap;
    margin-left: 0;   /* neutralize Bootstrap negative margins to avoid overflow */
    margin-right: 0;
    }
    
    /* Left column - 3 icons stacked vertically */
    .features .col-md-4:nth-child(1) {
        order: 1;
        width: 30%;
        flex: 1 1 30%;
        max-width: 30%;
    }
    
    /* Center image */
    .features .col-md-4:nth-child(2) {
        order: 2;
        width: 40%;
        flex: 1 1 40%;
        max-width: 40%;
        text-align: center;
        display: flex;              /* vertically center content within equal-height column */
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    
    /* Right column - 3 icons stacked vertically */
    .features .col-md-4:nth-child(3) {
        order: 3;
        width: 30%;
        flex: 1 1 30%;
        max-width: 30%;
    }

    /* Remove column side paddings to keep total width <= 100% */
    .features .col-md-4 {
        padding-left: 0 !important;
        padding-right: 0 !important;
        box-sizing: border-box;
    }
    
    /* Stack features vertically in each column and center-align */
    .features-left,
    .features-right {
        display: flex;
        flex-direction: column;
        align-items: center; /* center column content */
    margin-top: 0 !important; /* remove large desktop offset on mobile */
    }
    
    .features-left .feature,
    .features-right .feature {
        width: 100%;
        max-width: none; /* allow full width for single-line captions */
        margin-bottom: 10px !important; /* tighter spacing per card */
        text-align: center;
    }

    /* Remove default margins on the anchor wrapper to avoid extra gaps */
    .features .feature a {
        margin: 0 !important;
        display: block;
    }
    
    /* Center icons and put text below - tighter spacing */
    .feature .icon-container {
        text-align: center;
        margin-bottom: 2px; /* was 6px; ~60% reduction */
        min-height: 60px; /* matches icon size for vertical rhythm */
    }

    /* Match base selector specificity so min-height override applies on mobile */
    .features .feature .icon-container {
        min-height: 60px !important; /* override style_light.css (80px) */
    }
    /* Remove desktop floats so text stays below the icon */
    .features .features-left .icon-container,
    .features .features-right .icon-container {
        float: none !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* Make icons smaller (80px -> 60px) and override base CSS */
    .features .feature .icon-container .icon {
        width: 60px !important;
        height: 60px !important;
        line-height: 60px !important;
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        margin: 0 auto;
        display: block;
    }
    
    .feature .fetaure-details {
        text-align: center;
        display: block;
        width: 100%;
    }
    /* Fallback spelling used in some markup */
    .feature .feature-details {
        text-align: center;
        display: block;
        width: 100%;
    }
    /* Ensure caption sits below any floated elements, just in case */
    .features .feature .fetaure-details,
    .features .feature .feature-details { /* fallback for correct spelling */
        clear: both;
    }
    
    /* Icon caption: multi-line normal wrapping, centered, no hyphenation */
    .features .feature .fetaure-details h4,
    .features .feature .feature-details h4 {
        font-size: 11px; /* readable on mobile */
        line-height: 1.25;
        margin: 0;
        padding: 2px 4px; /* remove vertical padding to tighten gap */
        text-align: center;
        letter-spacing: normal;
        display: block;
        white-space: normal;       /* allow normal line breaks */
        word-break: normal;        /* break at natural points */
        overflow-wrap: normal;     /* no forced break */
        hyphens: none;             /* do not hyphenate */
        max-width: 100%;
    }
    
    /* Adjust center image */
    .image-features {
        max-width: 100%;
        margin: 0;
        /* padding: 20px; */
    }
    
    .image-features img {
        max-width: 100%;
        height: auto;
    }

    /* Remove extra space from stray headings placed outside caption block */
    .features .feature > h4.main-color {
        display: none !important;
        margin: 0 !important;
        padding: 0 !important;
        height: 0 !important;
        line-height: 0 !important;
    }
}

/* Ensure dropdown menus work properly on touch devices */
@media (max-width: 767px) {
    .navbar-nav .open .dropdown-menu {
        position: static;
        float: none;
        width: auto;
        margin-top: 0;
        background-color: transparent;
        border: 0;
        box-shadow: none;
    }
    
    .navbar-nav .open .dropdown-menu > li > a {
        padding: 5px 15px 5px 25px;
        color: #333;
    }
    
    .navbar-nav .open .dropdown-menu > li > a:hover,
    .navbar-nav .open .dropdown-menu > li > a:focus {
        color: #333;
        background-color: transparent;
    }
}

/* Remove large top space before services container */
    section.services#services,
    section.services {
        padding-top: 40px !important;
        padding-bottom: 30px !important;
    }

/* Footer spacing fix on mobile */
@media (max-width: 767px) {
    /* Add space between stacked service cards */
    section.services .service { margin-bottom: 15px !important; }

    /* Make header logo ~20% smaller on phones */
    .navbar-brand img {
        width: 75% !important;
        height: auto !important;
    }

    .footer {
        padding-top: 30px !important; /* reduce from 100px */
    }
}

/* Inner pages top spacing fix on mobile */
@media (max-width: 767px) {
    /* Many inner pages use a top-level section with large default padding (100px). Trim it. */
    section:not(.intro):not(.features) {
        padding-top: 20px !important;
    }

    /* Remove helper margin that adds extra gap before headings on inner pages */
    .margin-titulo {
        margin-top: 0 !important;
    }
}

/* Smartphone landscape: keep mobile layout when height is small */
@media (orientation: landscape) and (max-height: 480px) {
    /* Prevent horizontal scroll */
    html, body { overflow-x: hidden; }

    /* Tight gutters */
    .row { margin-left: 0; margin-right: 0; }
    .container { padding-left: 10px; padding-right: 10px; }

    /* Anchor dropdown to the navbar container for right alignment */
    .navbar .container { position: relative; }

    /* Keep language selector aligned to the right */
    .navbar .idiomas .langs { text-align: right; overflow: visible; }

    /* Navbar dropdown bounds */
    .navbar-collapse {
        max-height: none !important;
        overflow-y: visible !important;
        overflow-x: hidden !important;
        max-width: calc(100vw - 20px);
        box-sizing: border-box;
        position: absolute; /* position as a dropdown */
        right: 10px;
        left: auto !important;
        top: 100%;
        width: auto !important;
        float: right !important;
        border: none;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        background-color: #fff;
        border-radius: 5px;
        margin-top: 10px;
        z-index: 1000;
    }
    /* Keep brand left and toggle right in landscape as well */
    .navbar-header {
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: justify;
        -ms-flex-pack: justify;
        -webkit-justify-content: space-between;
        justify-content: space-between;
        width: 100%;
        position: relative;
    }
    .navbar-brand { -webkit-order: 1; order: 1; }
    .navbar-toggle {
        -webkit-order: 2; order: 2;
        margin-left: auto;
        float: right !important;
        margin-right: 0;
        z-index: 1100;
    }
    /* Show hamburger and keep menu collapsed */
    .navbar-toggle { display: block !important; }
    .navbar-collapse.collapse { display: none !important; }
    .navbar-collapse.collapse.in { display: block !important; }
    .navbar-nav { float: none !important; margin: 0; padding: 5px 0; min-width: 200px; }
    .navbar-nav > li { float: none; margin: 0; }
    .navbar-nav > li > a { font-size: 14px !important; padding: 10px 15px !important; line-height: 1.2 !important; white-space: nowrap; border-bottom: 1px solid #f0f0f0; }

    /* Features 3-column layout */
    .features .row {
        display: flex;
        align-items: stretch;
        justify-content: space-between;
        flex-wrap: nowrap;
        margin-left: 0;
        margin-right: 0;
    }
    .features .col-md-4:nth-child(1) { order: 1; width: 30%; flex: 1 1 30%; max-width: 30%; }
    .features .col-md-4:nth-child(2) { order: 2; width: 40%; flex: 1 1 40%; max-width: 40%; text-align: center; display: flex; flex-direction: column; justify-content: center; align-items: center; }
    .features .col-md-4:nth-child(3) { order: 3; width: 30%; flex: 1 1 30%; max-width: 30%; }
    .features .col-md-4 { padding-left: 0 !important; padding-right: 0 !important; box-sizing: border-box; }

    .features-left, .features-right { display: flex; flex-direction: column; align-items: center; margin-top: 0 !important; }
    .features-left .feature, .features-right .feature { width: 100%; max-width: none; margin-bottom: 10px !important; text-align: center; }
    .features .feature a { margin: 0 !important; display: block; }
    .feature .icon-container { text-align: center; margin-bottom: 2px; min-height: 60px; }
    .features .feature .icon-container { min-height: 60px !important; }
    /* Remove desktop floats so text stays below the icon */
    .features .features-left .icon-container,
    .features .features-right .icon-container { float: none !important; margin-left: 0 !important; margin-right: 0 !important; }
    .features .feature .icon-container .icon { width: 60px !important; height: 60px !important; line-height: 60px !important; background-size: contain; background-repeat: no-repeat; background-position: center; margin: 0 auto; display: block; }
    .feature .fetaure-details { text-align: center; display: block; width: 100%; }
    /* Ensure caption sits below any floated elements, just in case */
    .features .feature .fetaure-details,
    .features .feature .feature-details { /* fallback for correct spelling */
        clear: both;
    }
    .features .feature .fetaure-details h4 { font-size: 11px; line-height: 1.25; margin: 0; padding: 0 4px; text-align: center; letter-spacing: normal; display: block; white-space: normal; word-break: normal; overflow-wrap: normal; hyphens: none; max-width: 100%; }
    .features .feature > h4.main-color { display: none !important; margin: 0 !important; padding: 0 !important; height: 0 !important; line-height: 0 !important; }
    .image-features { max-width: 100%; margin: 0; }
    .image-features img { display: block; width: 100%; height: auto; }

    /* Make hero image full width in landscape */
    body .row .col-md-12 section.intro#intro,
    .col-md-12.text-center > section.intro#intro,
    section.intro#intro {
        background-size: cover !important;
        background-repeat: no-repeat !important;
        background-position: center center !important;
    }
    .col-md-12.text-center { padding-left: 0 !important; padding-right: 0 !important; }

    /* Section spacing like portrait mobile */
    section:not(.intro):not(.features) { padding-top: 20px !important; }
    .margin-titulo { margin-top: 0 !important; }
    .footer { padding-top: 30px !important; }
    .navbar-brand img { width: 75% !important; height: auto !important; }
    /* Preserve spacing between service cards on phone landscape */
    section.services .service { margin-bottom: 15px !important; }
}
