/*
 * Royal Integrated Company - Responsive Design System
 * Mobile-first responsive CSS for all pages
 * Version: 1.0
 */

/* ===== BASE RESPONSIVE SETUP ===== */

/* Prevent horizontal scroll — on html, not body.
   overflow-x: hidden on body breaks position:fixed elements in Chrome/Safari. */
html {
    overflow-x: hidden;
}

/* Do NOT set overflow on .container — it clips dropdown menus */

/* ===== NAVBAR & DROPDOWN STACKING ===== */

/* Navbar must be a positioned stacking context above all page content */
.navbar {
    z-index: 9999 !important;
    position: relative;
    overflow: visible !important;
}

/* Navbar's inner container must never clip dropdowns */
.navbar .container,
.navbar .container-fluid {
    overflow: visible !important;
}

/* Dropdowns — global base */
.dropdown-menu {
    z-index: 10000 !important;
    position: absolute !important;
}

/* ===== DESKTOP DROPDOWN FIX (≥ 992px) =====
   Problem: the fadeIn animation uses opacity 0→1 and transform, both of which
   create temporary stacking contexts that let content paint over the dropdown.
   Solution: keep the menu always display:block so it stays in the stacking order,
   hide it with visibility:hidden instead, and remove the animation entirely.
*/
@media (min-width: 992px) {
    .navbar .dropdown-menu {
        display: block !important;        /* always in stacking order */
        visibility: hidden !important;    /* hidden without stacking context side-effects */
        opacity: 1 !important;            /* no opacity animation */
        pointer-events: none !important;
        top: 100% !important;
        left: 0 !important;
        transform: none !important;
        animation: none !important;       /* kill the fadeIn that breaks z-index */
        z-index: 10000 !important;
    }

    .navbar .dropdown:hover > .dropdown-menu,
    .navbar .dropdown-menu.show {
        visibility: visible !important;
        pointer-events: auto !important;
    }
}

/* Hero sections must sit below the navbar at all times */
.hero-slider,
.page-hero,
.page-header {
    position: relative;
    z-index: 0 !important;
    isolation: isolate;   /* contain carousel / animation stacking contexts inside */
}

/* Contain Bootstrap carousel internal stacking contexts */
.carousel {
    position: relative;
    isolation: isolate;
}

/* Ensure images are responsive */
img {
    max-width: 100%;
    height: auto;
}

/* ===== MOBILE NAVIGATION (< 992px) ===== */
@media (max-width: 991px) {
    .navbar {
        padding: 0.5rem 0;
    }

    .navbar-brand img {
        height: 40px;
    }

    .navbar-collapse {
        background: white;
        padding: 20px;
        margin-top: 15px;
        border-radius: 10px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    }

    .navbar-nav {
        align-items: flex-start !important;
    }

    .nav-item {
        width: 100%;
        margin: 5px 0;
    }

    .nav-link {
        padding: 10px 15px !important;
        border-radius: 5px;
    }

    .nav-link:hover {
        background-color: #f8f4e3;
    }

    .dropdown-menu {
        border: none;
        box-shadow: none;
        padding-left: 20px;
        position: static !important;
        transform: none !important;
    }

    .btn-outline-dark, .btn-primary, .btn-outline-primary {
        width: 100%;
        margin: 10px 0 !important;
        text-align: center;
    }
}

/* ===== MOBILE DEVICES (< 768px) ===== */
@media (max-width: 768px) {

    /* Hero/Page Headers */
    .hero-slider, .page-header {
        height: 70vh !important;
        min-height: 500px !important;
    }

    .hero-content {
        bottom: 10%;
        width: 95%;
        padding: 0 15px;
    }

    .hero-content h1, .page-header h1 {
        font-size: clamp(1.8rem, 6vw, 2.5rem) !important;
        margin-bottom: 15px;
    }

    .hero-content p, .page-header p {
        font-size: clamp(0.9rem, 3vw, 1.1rem) !important;
        margin-bottom: 20px;
    }

    .hero-content .btn {
        padding: 10px 25px;
        font-size: 0.95rem;
    }

    .page-header {
        padding: 80px 0 60px !important;
    }

    /* Sections */
    .py-5 {
        padding: 3rem 0 !important;
    }

    .my-4 {
        margin: 2rem 0 !important;
    }

    /* Impact Section */
    .impact-section {
        padding: 40px 0 !important;
    }

    .impact-counter {
        font-size: 2.5rem !important;
    }

    .impact-title {
        font-size: 0.95rem !important;
    }

    /* Cards */
    .card:hover {
        transform: none !important;
    }

    .venture-card, .value-card, .project-card {
        margin-bottom: 20px;
    }

    /* Touch-Friendly Buttons */
    .btn {
        min-height: 44px;
        font-size: 1rem;
        padding: 12px 24px;
    }

    .btn-sm {
        min-height: 40px;
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .btn-lg {
        font-size: 1.1rem;
        padding: 14px 28px;
    }

    /* WhatsApp & Scroll Buttons */
    .whatsapp-float {
        bottom: 90px !important;
        right: 20px !important;
        width: 55px !important;
        height: 55px !important;
        font-size: 26px !important;
    }

    #scrollToTop {
        bottom: 20px !important;
        right: 20px !important;
        width: 45px !important;
        height: 45px !important;
    }

    /* Footer */
    footer .col-md-3,
    footer .col-md-2,
    footer .col-md-4,
    footer .col-lg-2,
    footer .col-lg-3,
    footer .col-lg-4,
    footer .col-xl-2,
    footer .col-xl-3 {
        text-align: center;
        margin-bottom: 30px;
    }

    footer .d-flex {
        flex-direction: column;
        text-align: center;
    }

    /* Brand Logos */
    .brand-logo svg {
        width: 150px;
        height: 60px;
    }

    /* Forms */
    .form-control, .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    textarea.form-control {
        min-height: 120px;
    }

    /* Timeline (About page) */
    .timeline::before {
        left: 20px !important;
    }

    .timeline-item {
        padding-left: 50px;
    }

    /* Product/Service Cards */
    .product-card, .service-card {
        margin-bottom: 30px;
    }

    /* Spacing adjustments */
    .g-4, .g-5 {
        --bs-gutter-y: 2rem;
    }

    /* Text centering on mobile */
    .text-md-start, .text-md-end {
        text-align: center !important;
    }

    /* Image ordering */
    .row .col-lg-6:first-child {
        order: 2;
    }

    .row .col-lg-6:last-child {
        order: 1;
    }
}

/* ===== SMALL MOBILE (< 576px) ===== */
@media (max-width: 576px) {
    body {
        font-size: 15px;
        line-height: 1.6;
    }

    h1 {
        font-size: 2rem !important;
    }

    h2 {
        font-size: 1.75rem !important;
    }

    h3 {
        font-size: 1.5rem !important;
    }

    h4 {
        font-size: 1.25rem !important;
    }

    h5 {
        font-size: 1.1rem !important;
    }

    .lead {
        font-size: 1.1rem !important;
    }

    .display-4 {
        font-size: 2.5rem !important;
    }

    /* Tighter padding */
    .container {
        padding-left: 15px;
        padding-right: 15px;
    }

    .card-body {
        padding: 20px !important;
    }

    /* Hero adjustments */
    .hero-slider, .page-header {
        height: 60vh !important;
        min-height: 450px !important;
    }
}

/* ===== TABLET (768px - 991px) ===== */
@media (min-width: 768px) and (max-width: 991px) {
    .hero-slider, .page-header {
        height: 80vh !important;
    }

    .impact-counter {
        font-size: 2.75rem !important;
    }

    .container {
        max-width: 720px;
    }

    /* Adjust columns for better tablet display */
    .col-md-6 {
        margin-bottom: 30px;
    }
}

/* ===== DESKTOP DROPDOWN FIX (992px+) ===== */
@media (min-width: 992px) {
    /* Ensure dropdowns work properly on desktop */
    .dropdown-menu {
        position: absolute !important;
        border: 1px solid rgba(0,0,0,.15);
        box-shadow: 0 0.5rem 1rem rgba(0,0,0,.175);
        padding-left: 0;
        z-index: 10000 !important;
    }

    /* Force navbar to front */
    .navbar {
        z-index: 9999 !important;
        position: relative !important;
    }

    .navbar-collapse {
        z-index: 9999 !important;
    }

    /* Ensure dropdown parent is positioned */
    .navbar .dropdown {
        position: relative;
        z-index: 9999;
    }
}

/* ===== LARGE TABLET / SMALL DESKTOP (992px - 1199px) ===== */
@media (min-width: 992px) and (max-width: 1199px) {
    .navbar-brand img {
        height: 45px;
    }

    .hero-content h1 {
        font-size: 3rem !important;
    }

    .container {
        max-width: 960px;
    }
}

/* ===== LANDSCAPE PHONE OPTIMIZATION ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .hero-slider, .page-header {
        height: 100vh !important;
        min-height: 400px !important;
    }

    .hero-content {
        bottom: 15%;
    }

    .hero-content h1, .page-header h1 {
        font-size: 2rem !important;
    }

    .hero-content p, .page-header p {
        font-size: 1rem !important;
        margin-bottom: 15px;
    }

    .navbar {
        padding: 0.3rem 0;
    }
}

/* ===== TOUCH TARGET IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Minimum 44x44px touch targets (Apple HIG) */
    a, button, .btn, .nav-link, .dropdown-item {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-link, .dropdown-item {
        width: 100%;
        justify-content: flex-start;
    }

    /* Icon buttons */
    .social-icon, .carousel-control-prev, .carousel-control-next {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus indicators for keyboard navigation */
@media (max-width: 768px) {
    a:focus, button:focus, .btn:focus {
        outline: 3px solid var(--primary-color, #9D1B1F);
        outline-offset: 2px;
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .navbar, .whatsapp-float, #scrollToTop, footer {
        display: none !important;
    }

    .hero-slider {
        height: auto !important;
    }

    body {
        background: white !important;
    }

    a {
        text-decoration: underline;
    }

    a[href^="http"]:after {
        content: " (" attr(href) ")";
    }
}

/* ===== DARK MODE SUPPORT (Optional) ===== */
@media (prefers-color-scheme: dark) {
    /* Add dark mode styles if needed in future */
}
