/* Mobile-Safe Responsive System - NO HORIZONTAL SCROLL */

/* Critical: Prevent ALL horizontal overflow */
html {
    overflow-x: hidden;
    width: 100%;
}

body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* Ensure all containers are mobile-safe */
* {
    box-sizing: border-box;
}

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

/* Mobile-Safe Grid System */
.grid {
    display: grid;
    gap: var(--spacing-md);
    width: 100%;
}

.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Mobile: Everything stacks */
@media (max-width: 768px) {
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
        gap: var(--spacing-sm);
    }
    
    .grid-2.mobile-2col {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-sm);
    }
}

/* Tablet: 2 columns max */
@media (min-width: 769px) and (max-width: 1023px) {
    .grid-3,
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile-Safe Flex */
.flex {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.flex-nowrap {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Hide horizontal scrollbar but keep functionality for intentional carousels */
.flex-nowrap::-webkit-scrollbar {
    display: none;
}

.flex-nowrap {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Mobile Spacing System */
.section {
    padding: var(--spacing-xl) var(--spacing-md);
    width: 100%;
}

@media (min-width: 768px) {
    .section {
        padding: var(--spacing-2xl) var(--spacing-lg);
    }
}

/* Mobile-Safe Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Mobile-Safe Video Embeds */
.video-wrapper {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    max-width: 100%;
}

.video-wrapper iframe,
.video-wrapper video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Mobile-Safe Tables */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    min-width: 100%;
}

@media (max-width: 768px) {
    table {
        min-width: 600px;
    }
}

/* Mobile Page Structure */
.page {
    display: none;
    width: 100%;
    min-height: 100vh;
    overflow-x: hidden;
}

.page.active {
    display: block;
}

/* Mobile Header */
.header {
    width: 100%;
    padding: var(--spacing-md);
    background: white;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

@media (max-width: 768px) {
    .header {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* Mobile Navigation */
.nav-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: var(--spacing-md);
}

.nav-mobile-menu {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 99;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

.nav-mobile-menu.active {
    display: block;
}

/* Mobile Content Wrapper */
.content-wrapper {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    padding: 0;
}

/* Mobile Cards - Always Stack */
@media (max-width: 768px) {
    .card-grid {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-md);
        width: 100%;
    }
    
    .card {
        width: 100%;
        margin: 0;
    }
}

/* Mobile Buttons */
@media (max-width: 768px) {
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-sm);
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
    }
    
    .btn-group-horizontal {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .btn-group-horizontal .btn {
        flex: 1;
        min-width: 0;
    }
}

/* Mobile Modals */
@media (max-width: 768px) {
    .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 0;
        min-height: 100vh;
        border-radius: 0;
    }
    
    .modal {
        padding: 0;
    }
}

/* Mobile Form Elements */
@media (max-width: 768px) {
    .form-row {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-md);
    }
    
    .form-col-half,
    .form-col-third {
        width: 100%;
    }
}

/* Mobile Text Wrapping */
.text-wrap {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

/* Mobile Utilities */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
    
    .mobile-hide {
        display: none !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Prevent Text Selection Issues on Mobile */
button,
.btn,
.card {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Mobile Touch Targets */
@media (max-width: 768px) {
    button,
    .btn,
    a {
        min-height: 44px;
        min-width: 44px;
    }
    
    .btn {
        padding: var(--spacing-md) var(--spacing-lg);
    }
}

/* Safe Area Insets for Notched Devices */
@supports (padding: max(0px)) {
    .page {
        padding-left: max(var(--spacing-md), env(safe-area-inset-left));
        padding-right: max(var(--spacing-md), env(safe-area-inset-right));
    }
    
    .header {
        padding-top: max(var(--spacing-md), env(safe-area-inset-top));
    }
}

/* Debug: Outline Elements Exceeding Viewport (Remove in Production) */
/*
@media (max-width: 768px) {
    * {
        outline: 1px solid red !important;
    }
    *[style*="width"] {
        outline: 2px solid orange !important;
    }
}
*/
