/* Mobile Fixes and Optimizations - Complete Rewrite */

/* Mobile Only Styles */
@media (max-width: 768px) {
    /* ===== GLOBAL RESET ===== */
    * {
        box-sizing: border-box !important;
        -webkit-tap-highlight-color: transparent !important;
    }
    
    html {
        overflow-x: hidden !important;
        width: 100% !important;
    }
    
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        position: relative !important;
        padding-top: 56px !important; /* For fixed header */
        padding-bottom: 56px !important; /* For bottom nav */
        min-height: 100vh !important;
    }
    
    /* ===== HEADER STYLES ===== */
    .header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 56px !important;
        background: white !important;
        z-index: 9999 !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
        width: 100% !important;
    }
    
    .nav {
        height: 56px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 1rem !important;
        max-width: 100% !important;
    }
    
    .logo {
        font-size: 1.4rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Hide all desktop navigation elements */
    .nav-menu,
    .nav-icons,
    .cart-icon,
    .mobile-menu-btn,
    #mobile-menu-btn,
    #cart-count,
    .cart-count {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
        position: absolute !important;
        left: -9999px !important;
    }
    
    /* ===== MAIN CONTENT ===== */
    main,
    .shop-main,
    .cart-page,
    .contact-page,
    .size-guide-page,
    .about-hero,
    .product-page {
        margin-top: 0 !important; /* Body already has padding-top */
        margin-bottom: 0 !important;
        padding: 1rem !important;
        padding-bottom: 2rem !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Container */
    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* ===== BOTTOM NAVIGATION ===== */
    .mobile-bottom-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 56px !important;
        background: white !important;
        border-top: 1px solid #e0e0e0 !important;
        display: flex !important;
        justify-content: space-around !important;
        align-items: center !important;
        z-index: 9999 !important;
        width: 100% !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05) !important;
    }
    
    .mobile-nav-item {
        flex: 1 !important;
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-decoration: none !important;
        color: #666 !important;
        position: relative !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        border: none !important;
        transition: all 0.2s ease !important;
    }
    
    .mobile-nav-item:active {
        background: rgba(0, 0, 0, 0.05) !important;
        transform: scale(0.95) !important;
    }
    
    .mobile-nav-item.active {
        color: #03C75A !important;
    }
    
    .mobile-nav-item.active::before {
        content: '' !important;
        position: absolute !important;
        top: 0 !important;
        left: 30% !important;
        right: 30% !important;
        height: 2px !important;
        background: #03C75A !important;
    }
    
    .mobile-nav-item > div {
        position: relative !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .mobile-nav-item svg {
        width: 22px !important;
        height: 22px !important;
        stroke-width: 2 !important;
        margin-bottom: 4px !important;
    }
    
    .mobile-nav-item span:not(.mobile-cart-count) {
        font-size: 11px !important;
        font-weight: 500 !important;
        line-height: 1 !important;
    }
    
    /* Mobile cart count */
    .mobile-cart-count {
        position: absolute !important;
        top: -6px !important;
        right: -6px !important;
        background: #FF5722 !important;
        color: white !important;
        width: 16px !important;
        height: 16px !important;
        border-radius: 50% !important;
        font-size: 10px !important;
        font-weight: 600 !important;
        display: none !important;
        align-items: center !important;
        justify-content: center !important;
        line-height: 1 !important;
        border: 1.5px solid white !important;
    }
    
    .mobile-cart-count:not(:empty) {
        display: flex !important;
    }
    
    /* ===== TYPOGRAPHY ===== */
    h1 { font-size: 1.8rem !important; }
    h2 { font-size: 1.5rem !important; }
    h3 { font-size: 1.3rem !important; }
    h4 { font-size: 1.1rem !important; }
    h5 { font-size: 1rem !important; }
    h6 { font-size: 0.9rem !important; }
    
    p, div, span {
        max-width: 100% !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }
    
    /* ===== SECTIONS ===== */
    section {
        padding: 2rem 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Hero sections */
    .hero,
    .shop-hero,
    .about-hero {
        padding: 2rem 1rem !important;
        min-height: auto !important;
    }
    
    .hero-content {
        padding: 0 !important;
        text-align: center !important;
    }
    
    .hero-title {
        font-size: 2rem !important;
        margin-bottom: 1rem !important;
    }
    
    .hero-description {
        font-size: 1rem !important;
        margin-bottom: 1.5rem !important;
    }
    
    /* ===== PRODUCT GRID ===== */
    .products-grid,
    .featured-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }
    
    .product-card {
        width: 100% !important;
        margin: 0 !important;
        border-radius: 8px !important;
        overflow: hidden !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
    }
    
    .product-card:active {
        transform: scale(0.98) !important;
    }
    
    .product-image {
        width: 100% !important;
        height: 180px !important;
        object-fit: cover !important;
    }
    
    .product-info {
        padding: 0.75rem !important;
    }
    
    .product-name {
        font-size: 0.9rem !important;
        margin-bottom: 0.3rem !important;
    }
    
    .product-price {
        font-size: 1rem !important;
        font-weight: 600 !important;
    }
    
    /* ===== BUTTONS ===== */
    .btn {
        padding: 0.8rem 1.5rem !important;
        font-size: 0.9rem !important;
        border-radius: 6px !important;
        width: 100% !important;
        max-width: 100% !important;
        white-space: normal !important;
        word-wrap: break-word !important;
        margin: 0.5rem 0 !important;
    }
    
    .hero-cta {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
        width: 100% !important;
    }
    
    /* ===== FORMS ===== */
    input,
    textarea,
    select {
        width: 100% !important;
        padding: 0.8rem !important;
        font-size: 16px !important; /* Prevent zoom on iOS */
        border-radius: 6px !important;
    }
    
    .form-group {
        margin-bottom: 1rem !important;
    }
    
    .form-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }
    
    /* ===== CART PAGE ===== */
    .cart-content {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }
    
    .cart-item {
        display: flex !important;
        flex-direction: column !important;
        padding: 1rem !important;
        background: white !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
    }
    
    .cart-item-image {
        width: 100% !important;
        height: 150px !important;
        object-fit: cover !important;
        margin-bottom: 1rem !important;
        border-radius: 6px !important;
    }
    
    .cart-item-details {
        text-align: center !important;
        margin-bottom: 1rem !important;
    }
    
    .quantity-control {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 1rem !important;
    }
    
    /* Empty cart */
    .empty-cart {
        padding: 3rem 1rem !important;
        text-align: center !important;
        min-height: 50vh !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* empty-cart가 show 클래스를 가질 때만 display: flex */
    .empty-cart.show {
        display: flex !important;
    }
    
    .empty-cart svg {
        width: 60px !important;
        height: 60px !important;
        margin-bottom: 1.5rem !important;
        stroke: #ccc !important;
    }
    
    .empty-cart h2 {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .empty-cart p {
        font-size: 0.9rem !important;
        margin-bottom: 1.5rem !important;
        color: #666 !important;
    }
    
    /* ===== FOOTER ===== */
    .footer {
        margin-bottom: 56px !important; /* Space for bottom nav */
        padding: 2rem 0 !important;
    }
    
    .footer-content {
        display: flex !important;
        flex-direction: column !important;
        text-align: center !important;
        gap: 2rem !important;
    }
    
    .footer-links {
        display: none !important; /* Hide on mobile to save space */
    }
    
    .footer-bottom {
        padding: 1rem !important;
        text-align: center !important;
        font-size: 0.8rem !important;
    }
    
    /* ===== FLOATING BUTTONS ===== */
    .floating-buttons {
        position: fixed !important;
        bottom: 70px !important;
        right: 1rem !important;
        z-index: 998 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .float-btn {
        width: 44px !important;
        height: 44px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2) !important;
        transition: all 0.2s ease !important;
    }
    
    .float-btn:active {
        transform: scale(0.9) !important;
    }
    
    .float-btn svg {
        width: 20px !important;
        height: 20px !important;
    }
    
    .float-btn.kakao svg {
        width: 18px !important;
        height: 18px !important;
    }
    
    /* Scroll to top button */
    .scroll-top-btn {
        width: 40px !important;
        height: 40px !important;
        background: rgba(0, 0, 0, 0.8) !important;
    }
    
    .scroll-top-btn svg {
        width: 18px !important;
        height: 18px !important;
        stroke: white !important;
    }
    
    /* ===== TOAST NOTIFICATIONS ===== */
    .toast {
        position: fixed !important;
        bottom: 80px !important;
        left: 1rem !important;
        right: 1rem !important;
        background: rgba(0, 0, 0, 0.9) !important;
        color: white !important;
        padding: 0.8rem !important;
        border-radius: 8px !important;
        text-align: center !important;
        z-index: 10000 !important;
        font-size: 0.9rem !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    }
    
    /* ===== MODALS ===== */
    .modal-content {
        width: calc(100% - 2rem) !important;
        margin: 1rem !important;
        padding: 1.5rem !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        border-radius: 12px !important;
    }
    
    /* ===== TABLES ===== */
    table {
        font-size: 0.85rem !important;
    }
    
    th, td {
        padding: 0.5rem !important;
    }
    
    .size-chart-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 0 -1rem !important;
        padding: 0 1rem !important;
    }
    
    /* ===== FAQ ===== */
    .faq-item {
        margin-bottom: 1rem !important;
    }
    
    .faq-question {
        font-size: 0.95rem !important;
        padding: 1rem !important;
    }
    
    .faq-answer {
        font-size: 0.9rem !important;
        padding: 0 1rem 1rem !important;
    }
    
    /* ===== ANIMATIONS ===== */
    @keyframes slideIn {
        from {
            opacity: 0;
            transform: translateY(10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    main {
        animation: slideIn 0.3s ease-out;
    }
    
    /* ===== UTILITIES ===== */
    .text-center { text-align: center !important; }
    .text-left { text-align: left !important; }
    .text-right { text-align: right !important; }
    
    /* Prevent text selection on interactive elements */
    button, a, .btn {
        -webkit-user-select: none !important;
        -moz-user-select: none !important;
        -ms-user-select: none !important;
        user-select: none !important;
    }
    
    /* ===== PRODUCT DETAIL PAGE ===== */
    .product-detail {
        padding: 1rem !important;
    }
    
    .product-images {
        margin-bottom: 2rem !important;
    }
    
    .main-image {
        width: 100% !important;
        height: 300px !important;
        object-fit: cover !important;
        border-radius: 8px !important;
    }
    
    .thumbnail-images {
        display: flex !important;
        gap: 0.5rem !important;
        overflow-x: auto !important;
        padding: 0.5rem 0 !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .thumbnail {
        width: 60px !important;
        height: 60px !important;
        flex-shrink: 0 !important;
        border-radius: 4px !important;
        object-fit: cover !important;
    }
    
    /* ===== SHOP PAGE FILTERS ===== */
    .filter-bar {
        padding: 1rem !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .filter-options {
        display: flex !important;
        gap: 0.5rem !important;
        min-width: max-content !important;
    }
    
    .filter-btn {
        padding: 0.5rem 1rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        border-radius: 20px !important;
        flex-shrink: 0 !important;
    }
    
    .sort-options {
        margin-top: 0.5rem !important;
    }
    
    .sort-options select {
        width: 100% !important;
        padding: 0.5rem !important;
        font-size: 0.9rem !important;
        border-radius: 6px !important;
    }
    
    /* ===== CONTACT PAGE ===== */
    .contact-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 2rem !important;
    }
    
    .contact-info,
    .contact-form-wrapper {
        width: 100% !important;
        padding: 1rem !important;
    }
    
    .contact-item {
        margin-bottom: 1.5rem !important;
    }
    
    .social-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .social-btn {
        width: 100% !important;
        padding: 0.8rem !important;
        font-size: 0.9rem !important;
    }
    
    /* ===== SIZE GUIDE PAGE ===== */
    .size-calculator {
        background: #f8f8f8 !important;
        padding: 1.5rem !important;
        border-radius: 8px !important;
        margin: 2rem 0 !important;
    }
    
    .calculator-form input {
        height: 48px !important;
        font-size: 16px !important;
        border: 2px solid #e0e0e0 !important;
        border-radius: 8px !important;
    }
    
    .calculator-form input:focus {
        border-color: #03C75A !important;
        box-shadow: 0 0 0 3px rgba(3, 199, 90, 0.1) !important;
    }
    
    .size-result {
        margin-top: 1.5rem !important;
        padding: 1.5rem !important;
        background: white !important;
        border-radius: 8px !important;
        text-align: center !important;
    }
    
    .recommended-size {
        font-size: 2rem !important;
        font-weight: 700 !important;
        color: #03C75A !important;
        margin: 0.5rem 0 !important;
    }
    
    /* ===== ABOUT PAGE ===== */
    .story-grid,
    .values-grid,
    .materials-grid,
    .team-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 2rem !important;
    }
    
    .story-content,
    .story-image {
        width: 100% !important;
    }
    
    .value-card,
    .material-item {
        padding: 1.5rem !important;
        margin-bottom: 1rem !important;
    }
    
    .process-timeline {
        padding: 0 !important;
    }
    
    .process-item {
        padding: 1rem !important;
        margin-bottom: 1.5rem !important;
    }
    
    /* ===== PREVENT LAYOUT BREAKING ===== */
    img, video, iframe {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Force all elements to respect viewport width */
    * {
        max-width: 100vw !important;
    }
    
    /* Fix any absolutely positioned elements */
    [style*="position: absolute"],
    [style*="position:absolute"] {
        max-width: 100% !important;
    }
}

/* High priority overrides */
@media screen and (max-width: 768px) {
    /* Ensure mobile nav is always visible */
    .mobile-bottom-nav {
        display: flex !important;
        visibility: visible !important;
    }
    
    /* Force hide desktop elements */
    .header .nav-icons,
    .header .cart-icon,
    .mobile-menu-btn {
        display: none !important;
    }
}
