/* 
   ISPHILO FRAGANCE - RESPONSIVE STYLES
   Premium Luxury Fragrance Design System
   Mobile-First & Adaptive CSS Rules
*/

/* 0. iOS Specific Fixes & Enhancements */
html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    height: -webkit-fill-available;
}

body {
    padding-bottom: env(safe-area-inset-bottom, 20px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
    position: relative;
}

header {
    padding-top: env(safe-area-inset-top, 0px);
}

/* Fix for iOS input appearance and zoom */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="search"],
textarea,
select {
    font-size: 16px !important; /* Prevents auto-zoom on focus in iOS Safari */
    -webkit-appearance: none;
    border-radius: 8px;
    max-width: 100%;
}

/* Remove tap highlight color */
a, button, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}

/* Fix for sticky elements on iOS */
.top-bar, header, .mobile-sticky-nav, .sticky-checkout-cta {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Improved scrolling for iOS */
.nav-menu, .category-tabs, .table-responsive, .product-thumbnails, .scroll-x {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
}

/* 0.3 iOS Button Reset */
button, input[type="submit"], .btn {
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

/* 1. Global Mobile Adjustments (Up to 1024px) */
@media (max-width: 1024px) {
    .nav-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 400px;
        height: 100vh;
        height: 100dvh;
        background: var(--pure-black);
        flex-direction: column;
        padding: 100px 40px;
        transition: 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
        z-index: 999;
        gap: 20px;
        align-items: flex-start;
        text-align: left;
        overflow-y: auto;
        box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    }

    .container {
        padding: 0 var(--space-sm);
    }

    header {
        height: 60px;
        top: 35px;
        width: 100%;
        border-radius: 0;
    }

    .nav-container {
        padding: 0 15px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .nav-menu.active {
        right: 0;
    }

    .nav-menu li {
        width: 100%;
    }

    .nav-menu li a {
        color: var(--pure-white);
        font-size: 20px;
        font-family: 'Playfair Display', serif;
        letter-spacing: 1px;
        border-bottom: 1px solid rgba(255,255,255,0.05);
        display: block;
        padding: 15px 0;
    }

    .mobile-menu-toggle {
        display: flex !important;
        color: var(--pure-black);
        font-size: 22px;
        z-index: 1000;
    }

    .hero-content {
        padding: 0 var(--space-md);
        text-align: center;
    }

    .hero-title {
        font-size: var(--fs-3xl);
    }
}

/* 2. Tablet Adjustments (Up to 768px) */
@media (max-width: 768px) {
    .section {
        padding: var(--space-lg) 0;
    }

    .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }

    .product-card {
        margin-bottom: 20px;
    }

    .product-info {
        padding: 15px 10px;
    }

    .product-name {
        font-size: 13px;
        height: 40px;
        line-height: 1.4;
    }

    .footer-grid {
        grid-template-columns: 1fr !important;
        text-align: center;
        gap: 40px;
    }

    .footer-brand {
        align-items: center;
    }

    .footer-social {
        justify-content: center;
    }

    /* Cart & Checkout */
    .checkout-grid {
        grid-template-columns: 1fr !important;
        gap: 30px;
    }

    .checkout-form-section, .checkout-summary-section {
        padding: 25px 20px !important;
    }

    .payment-options {
        grid-template-columns: 1fr !important;
    }

    /* Admin Responsiveness */
    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100% !important;
        height: auto !important;
        position: relative !important;
    }

    .admin-main {
        padding: 20px !important;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* 3. Small Mobile Adjustments (Up to 480px) */
@media (max-width: 480px) {
    .hero-title {
        font-size: 1.8rem;
    }

    .hero-actions {
        flex-direction: column;
        width: 100%;
    }

    .hero-actions .btn {
        width: 100%;
    }

    .product-grid {
        grid-template-columns: 1fr !important;
    }

    .section-title {
        font-size: 1.5rem;
    }

    /* Cart/Checkout Mobile Polish */
    .cart-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .cart-item img {
        width: 100% !important;
        height: 200px !important;
    }

    .cart-item-info {
        width: 100%;
    }

    .sticky-checkout-cta {
        padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    }
}

/* 4. Large Desktop / 4K / Ultrawide Adjustments */
@media (min-width: 2000px) {
    .container {
        max-width: 1800px;
    }

    .hero-title {
        font-size: 5rem;
    }

    .section-title {
        font-size: 4rem;
    }
}

/* 6. Page-Specific Responsive Polish */

/* Shop Page Filters */
@media (max-width: 768px) {
    .shop-hero-section {
        padding-top: 100px !important;
        padding-bottom: 30px !important;
    }
    .shop-filters > div {
        flex-direction: column;
        align-items: stretch !important;
        gap: 15px;
    }
    .category-tabs {
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        padding: 5px 0 15px 0;
        display: flex;
        gap: 10px;
        -webkit-overflow-scrolling: touch;
    }
    .category-tab {
        flex: 0 0 auto;
        padding: 10px 20px;
        font-size: 11px;
    }
}

/* Product Details Page */
@media (max-width: 1024px) {
    .product-details-grid {
        grid-template-columns: 1fr !important;
        gap: 40px !important;
    }
    .product-gallery {
        max-width: 600px;
        margin: 0 auto;
    }
}

@media (max-width: 480px) {
    .product-main-image {
        aspect-ratio: 1/1;
    }
    .purchase-actions {
        flex-direction: column;
        gap: 15px;
    }
    .quantity-control {
        width: 100% !important;
        justify-content: center;
    }
    .add-to-cart-btn {
        width: 100%;
        padding: 20px !important;
    }
    .product-title {
        font-size: 24px !important;
    }
}

/* Login/Register Forms */
@media (max-width: 480px) {
    .auth-container {
        padding: 40px 20px !important;
    }
    .auth-card {
        padding: 30px 20px !important;
        border: none !important;
        box-shadow: none !important;
    }
}

/* 7. Utility Classes for Cross-Device Stabilization */
.no-scroll {
    overflow: hidden !important;
}

.touch-scroll {
    -webkit-overflow-scrolling: touch;
}

.full-height {
    height: 100vh;
    height: 100dvh;
}

/* Fix for CLS (Cumulative Layout Shift) */
img {
    height: auto;
    max-width: 100%;
}

.aspect-ratio-1 { aspect-ratio: 1 / 1; }
.aspect-ratio-16-9 { aspect-ratio: 16 / 9; }

/* Safe Area Utility */
.safe-padding-top { padding-top: env(safe-area-inset-top); }
.safe-padding-bottom { padding-bottom: env(safe-area-inset-bottom); }
.safe-margin-top { margin-top: env(safe-area-inset-top); }
.safe-margin-bottom { margin-bottom: env(safe-area-inset-bottom); }

    .cart-table thead {
        display: none;
    }

    .cart-table tr {
        display: flex;
        flex-direction: column;
        border-bottom: 1px solid var(--gray-light);
        padding: 20px 0;
    }

    .cart-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        text-align: right;
        border: none !important;
    }

    .cart-table td::before {
        content: attr(data-label);
        font-weight: 700;
        text-align: left;
        font-family: 'Montserrat', sans-serif;
        font-size: 10px;
        text-transform: uppercase;
        opacity: 0.7;
    }

    .cart-table td.product-info-cell {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 15px;
    }

    .cart-table td.product-info-cell::before {
        display: none;
    }

    .cart-item-img {
        width: 80px !important;
        height: 80px !important;
    }
}

/* 3. Mobile Adjustments (Up to 480px) */
@media (max-width: 480px) {
    .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .hero-title {
        font-size: 2rem;
    }

    .container {
        padding: 0 15px;
    }

    .section-title {
        font-size: 1.8rem !important;
    }

    .header-actions {
        gap: 5px;
    }

    .header-action-box {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    .cart-pill {
        padding: 4px 8px;
        font-size: 11px;
    }

    .btn {
        width: 100%;
        padding: 14px 20px;
        font-size: 10px;
        letter-spacing: 1px;
    }

    .top-bar {
        font-size: 8px !important;
    }
}

/* 4. Global Mobile UI Overrides (Consolidated) */
@media (max-width: 992px) {
    /* Mobile Engagement Enhancements */
    .section-title {
        font-size: 1.8rem !important;
        line-height: 1.2;
    }

    .hero-title {
        font-size: 2.2rem !important;
        margin-bottom: 15px;
    }

    .hero-description {
        font-size: 0.9rem !important;
        line-height: 1.6;
        margin-bottom: 25px;
    }

    /* Enhanced Product Grid for Mobile */
    .product-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
        padding: 15px 10px !important;
    }

    .product-card {
        background: #fff;
        border: none !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05) !important;
        border-radius: 12px !important;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        transition: transform 0.3s ease;
    }

    .product-card:active {
        transform: scale(0.98);
    }

    .product-image {
        border-radius: 12px 12px 0 0 !important;
    }

    .product-info {
        padding: 12px !important;
        text-align: left !important;
    }

    .product-name {
        font-size: 13px !important;
        font-weight: 700 !important;
        margin-bottom: 6px !important;
        color: var(--pure-black);
    }

    .product-price {
        font-size: 14px !important;
        color: var(--primary-red) !important;
    }

    .btn-add-to-cart {
        width: 100% !important;
        border-radius: 8px !important;
        padding: 10px !important;
        font-size: 10px !important;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-top: 12px !important;
    }

    /* Better mobile spacing for hero */
    .hero {
        padding: 120px 20px 60px !important;
    }

    .hero-title {
        font-size: 2.5rem !important;
        line-height: 1.1 !important;
    }

    /* Sticky Bottom Mobile Nav */
    .mobile-sticky-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: #fff;
        box-shadow: 0 -2px 20px rgba(0,0,0,0.08);
        z-index: 10001;
        padding: 12px 0;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        justify-content: space-around;
        align-items: center;
        border-top: 1px solid rgba(0,0,0,0.05);
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        color: var(--pure-black);
        text-decoration: none;
        font-size: 10px;
        font-weight: 600;
        text-transform: uppercase;
        opacity: 0.7;
        transition: all 0.3s ease;
    }

    .mobile-nav-item:active, .mobile-nav-item.active {
        opacity: 1;
        color: var(--primary-red);
    }

    .mobile-nav-item i {
        font-size: 20px;
    }

    /* Adjust body padding for sticky nav to prevent content cutoff */
    body {
        padding-bottom: calc(75px + env(safe-area-inset-bottom)) !important;
    }
}

/* 5. iOS & Safari Specific Fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix for 100vh jumping on iOS Safari */
    .nav-menu {
        height: -webkit-fill-available;
    }
    
    /* Smooth scrolling for iOS */
    body {
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent text size adjustment on orientation change */
    html {
        -webkit-text-size-adjust: 100%;
    }
}

/* 6. Admin Dashboard Mobile Fixes */
@media (max-width: 992px) {
    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100% !important;
        height: auto !important;
        position: static !important;
        padding: 10px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--shopify-border);
    }

    .admin-sidebar-nav {
        display: flex !important;
        overflow-x: auto;
        padding-bottom: 10px;
        gap: 5px;
    }

    .admin-sidebar-item {
        flex: 0 0 auto;
        padding: 0 !important;
    }

    .admin-sidebar-link {
        padding: 8px 12px !important;
    }

    .admin-sidebar-link i {
        margin-right: 5px !important;
    }

    .admin-main {
        margin-left: 0 !important;
        padding: 20px 15px !important;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    .admin-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start !important;
    }

    .admin-header-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
}

@media (max-width: 576px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    .admin-topbar {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start !important;
    }
}
