/* ==========================================
   GLOBAL RESPONSIVE FIXES FOR ALL DEVICES
   Applied to entire application
   =========================================== */

/* ==========================================
   VIEWPORT AND CONTAINER CONSTRAINTS
   =========================================== */
html {
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
}

/* Prevent any element from breaking the layout (mobile only for aggressive rules) */
@media (max-width: 768px) {
    img, picture, video, canvas, svg {
        max-width: 100% !important;
        height: auto !important;
        display: block;
    }
}

/* ==========================================
   IMAGE RESPONSIVENESS (scoped for mobile)
   =========================================== */
/* Desktop: natural image sizing with proper object-fit */
img {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

.hero-image,
.split-image,
.gallery-item {
    max-width: 100%;
    height: auto;
    object-fit: cover;
}

/* Mobile: force full responsive */
@media (max-width: 768px) {
    img {
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain;
    }

    .hero-image,
    .split-image,
    .gallery-item,
    .card img,
    [class*="image-"] {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
        object-fit: cover;
    }
}

/* Logo and avatar images (all screen sizes) */
[class*="logo"],
[class*="avatar"],
.rounded-full img {
    max-width: 100%;
    height: auto;
    object-fit: cover;
}

/* ==========================================
   CONTAINER AND GRID FIXES
   Keep desktop Bootstrap container widths intact.
   =========================================== */
@media (max-width: 991.98px) {
    .container,
    .container-fluid,
    [class*="container"] {
        width: 100%;
        max-width: 100%;
        padding-left: 1rem;
        padding-right: 1rem;
        margin-left: auto;
        margin-right: auto;
        overflow-x: hidden;
    }

    /* Grid rows */
    .row,
    [class*="grid"] {
        margin-left: 0;
        margin-right: 0;
        max-width: 100%;
    }
}

/* ==========================================
   TEXT AND CONTENT OVERFLOW PREVENTION
   =========================================== */
p, h1, h2, h3, h4, h5, h6, span, div, a, li, td, th {
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

/* ==========================================
   RESPONSIVE BREAKPOINTS
   =========================================== */

/* Mobile First - Small devices (phones, less than 576px) */
@media (max-width: 575.98px) {
    body {
        font-size: 14px;
    }
    
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.125rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.875rem; }
    
    /* Force all cards to stack */
    [class*="grid"],
    .grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Full width buttons */
    .btn,
    button,
    a.btn {
        width: 100%;
        display: block;
        margin-bottom: 0.5rem;
    }
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .container {
        max-width: 540px;
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .container {
        max-width: 720px;
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    /* Restore button natural width */
    .btn {
        width: auto;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .container {
        max-width: 960px;
    }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
}

/* ==========================================
   IFRAME AND EMBED RESPONSIVENESS
   =========================================== */
iframe,
embed,
object,
video {
    max-width: 100% !important;
    height: auto !important;
}

/* Responsive embed containers (16:9 aspect ratio) */
.embed-responsive,
.video-responsive {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    overflow: hidden;
}

.embed-responsive::before {
    display: block;
    content: "";
    padding-top: 56.25%; /* 16:9 aspect ratio */
}

.embed-responsive iframe,
.embed-responsive embed,
.embed-responsive object,
.embed-responsive video {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ==========================================
   TABLE RESPONSIVENESS
   =========================================== */
@media (max-width: 767.98px) {
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Stack table on mobile */
    table.table-responsive-mobile {
        border: 0;
    }
    
    table.table-responsive-mobile thead {
        display: none;
    }
    
    table.table-responsive-mobile tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #ddd;
        border-radius: 0.5rem;
        padding: 0.5rem;
    }
    
    table.table-responsive-mobile td {
        display: block;
        text-align: right;
        padding: 0.5rem;
        border: none;
    }
    
    table.table-responsive-mobile td::before {
        content: attr(data-label);
        float: left;
        font-weight: bold;
    }
}

/* ==========================================
   FORM RESPONSIVENESS
   =========================================== */
@media (max-width: 767.98px) {
    input,
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        width: 100%;
        max-width: 100%;
    }
    
    .form-group,
    .form-control,
    .input-group {
        width: 100%;
        max-width: 100%;
    }
}

/* ==========================================
   NAVIGATION RESPONSIVENESS
   =========================================== */
@media (max-width: 767px) {
    .scroller-container {
        max-height: 80vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 991.98px) {
    .navbar-nav {
        width: 100%;
    }
    
    .nav-item {
        width: 100%;
    }
}

/* ==========================================
   UTILITY CLASSES
   =========================================== */

/* Hide on mobile */
@media (max-width: 575.98px) {
    .d-mobile-none {
        display: none !important;
    }
}

/* Hide on tablet and up */
@media (min-width: 576px) {
    .d-mobile-only {
        display: none !important;
    }
}

/* Responsive text alignment */
@media (max-width: 575.98px) {
    .text-mobile-center {
        text-align: center !important;
    }
}

/* Responsive padding */
@media (max-width: 575.98px) {
    .p-mobile-1 { padding: 0.25rem !important; }
    .p-mobile-2 { padding: 0.5rem !important; }
    .p-mobile-3 { padding: 1rem !important; }
    .p-mobile-4 { padding: 1.5rem !important; }
}

/* ==========================================
   TOUCH DEVICE OPTIMIZATIONS
   =========================================== */
@media (hover: none) and (pointer: coarse) {
    /* Increase tap target size */
    button,
    a,
    input[type="button"],
    input[type="submit"],
    .btn {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 0.75rem 1rem;
    }
    
    /* Remove hover effects on touch devices */
    *:hover {
        transition: none !important;
    }
    
    /* Add active states instead */
    *:active {
        opacity: 0.8;
    }
}

/* ==========================================
   PRINT STYLES
   =========================================== */
@media print {
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    .no-print {
        display: none !important;
    }
}
