/* ============================================
   MOBILE OPTIMIZATIONS
   320px, 375px, 425px breakpoints
   ============================================ */

/* ============================================
   BASE MOBILE FIXES (ALL MOBILE DEVICES)
   ============================================ */

@media (max-width: 768px) {
    /* Prevent horizontal scroll via #page-wrap and banner fix; body overflow-x visible so fixed FAB stays viewport-fixed */
    html {
        overflow-x: hidden;
    }
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: visible;
    }
    #page-wrap {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Container padding */
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    /* Section padding */
    .section {
        padding: 24px 0;
    }
    
    /* Better touch targets */
    button,
    .btn,
    a.btn,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Prevent iOS zoom on input focus */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Navigation height fix */
    .nav-wrapper {
        height: 56px;
    }
    
    /* Mobile banner */
    .banner-image {
        height: auto;
        max-height: 350px;
    }
    
    /* Hero section */
    .hero-text-section {
        padding: var(--space-8) 0;
    }
    
    .hero-title {
        font-size: 28px;
    }
    
    .hero-description {
        font-size: 14px;
    }
    
    /* Product grid - 2 columns */
    .product-grid,
    .featured-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    /* Product cards compact */
    .product-card,
    .featured-product-card {
        border-radius: var(--radius-md);
        border-width: 2px;
    }
    
    .product-info,
    .featured-product-info {
        padding: 10px;
    }
    
    .product-name,
    .featured-product-name {
        font-size: 13px;
        margin-bottom: 4px;
        min-height: auto;
    }
    
    .product-author {
        font-size: 11px;
        margin-bottom: 6px;
    }
    
    .product-category,
    .featured-product-category {
        font-size: 10px;
        margin-bottom: 3px;
    }
    
    .product-price,
    .featured-product-price {
        gap: 4px;
    }
    
    .current-price {
        font-size: 16px;
    }
    
    .original-price {
        font-size: 12px;
    }
    
    .discount-badge {
        font-size: 9px;
        padding: 2px 5px;
    }
    
    .featured-product-badge {
        font-size: 9px !important;
        padding: 2px 6px !important;
    }
    
    .add-to-cart-btn,
    .featured-add-to-cart,
    .bestseller-add-to-cart {
        padding: 8px 12px;
        font-size: 12px;
        width: calc(100% - 20px);
        margin: 0 10px 10px;
    }
    
    /* Category grid */
    .category-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .category-card h3 {
        font-size: 13px;
    }
    
    /* Feature cards — three in one row on mobile */
    .features-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-2);
    }
    
    .feature-card {
        padding: var(--space-3);
        min-width: 0;
    }
    
    .feature-icon {
        width: 32px;
        height: 32px;
        margin-bottom: var(--space-2);
    }
    
    .feature-icon svg {
        width: 16px;
        height: 16px;
    }
    
    .feature-title {
        font-size: 11px;
        margin-bottom: var(--space-1);
        line-height: 1.2;
    }
    
    .feature-description {
        font-size: 10px;
        line-height: 1.3;
    }
    
    /* Testimonials */
    .testimonials-grid {
        grid-template-columns: 1fr;
        gap: var(--space-5);
    }
    
    .testimonial-card {
        padding: var(--space-5);
    }
    
    .testimonial-rating {
        font-size: 14px;
        margin-bottom: var(--space-3);
    }
    
    .testimonial-text {
        font-size: 13px;
        margin-bottom: var(--space-4);
    }
    
    .testimonial-author strong {
        font-size: 14px;
    }
    
    /* Section headers */
    .section-header {
        margin-bottom: var(--space-6);
    }
    
    .section-title {
        font-size: 20px;
        margin-bottom: var(--space-2);
    }
    
    .section-title::after {
        width: 40px;
        height: 2px;
        bottom: -6px;
    }
    
    .section-subtitle {
        font-size: 13px;
        margin-top: var(--space-3);
    }
    
    /* Bestsellers */
    .bestsellers-header {
        margin-bottom: var(--space-5);
    }
    
    .bestseller-card {
        width: 180px;
    }
    
    .bestseller-rank {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }
    
    /* Footer */
    .footer {
        padding: var(--space-8) 0 var(--space-5);
        margin-top: var(--space-10);
    }
    
    .footer-grid {
        grid-template-columns: 1fr;
        gap: var(--space-5);
    }
    
    .footer-logo {
        font-size: 20px;
    }
    
    .footer-title {
        font-size: 15px;
        margin-bottom: var(--space-3);
    }
    
    .footer-description,
    .footer-links a {
        font-size: 13px;
    }
    
    /* CTA Section */
    .cta-card {
        padding: var(--space-8);
    }
    
    .cta-title {
        font-size: 20px;
        margin-bottom: var(--space-3);
    }
    
    .cta-description {
        font-size: 14px;
        margin-bottom: var(--space-5);
    }
    
    /* Social FAB (decoupled, in .social-fab-wrapper) */
    .social-fab-toggle {
        width: 44px;
        height: 44px;
    }
    
    .social-fab-item {
        width: 44px;
        height: 44px;
    }
    
    /* Notifications */
    #notificationContainer {
        top: 60px;
        right: var(--space-3);
        left: var(--space-3);
    }
    
    .notification {
        min-width: auto;
        width: 100%;
        font-size: 13px;
        padding: var(--space-3) var(--space-4);
    }
}

/* ============================================
   PRODUCT DETAIL PAGE - MOBILE
   ============================================ */

@media (max-width: 768px) {
    .product-detail {
        padding: var(--space-6) 0;
    }
    
    .product-detail-container {
        grid-template-columns: 1fr;
        gap: var(--space-6);
    }
    
    .product-details-content h1 {
        font-size: 22px;
    }
    
    .book-author {
        font-size: 15px;
    }
    
    .book-illustrator {
        font-size: 13px;
    }
    
    .product-rating {
        padding: var(--space-3);
        gap: var(--space-2);
    }
    
    .stars {
        font-size: 14px;
    }
    
    .rating-count {
        font-size: 11px;
    }
    
    .product-price-section .current-price {
        font-size: 24px;
    }
    
    .product-price-section .original-price {
        font-size: 14px;
    }
    
    .book-details {
        padding: var(--space-4);
        margin: var(--space-5) 0;
    }
    
    .book-details h3 {
        font-size: 15px;
        margin-bottom: var(--space-3);
    }
    
    .book-details-grid {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }
    
    .format-selector {
        margin: var(--space-5) 0;
    }
    
    .format-selector label {
        font-size: 15px;
        margin-bottom: var(--space-3);
    }
    
    .format-options {
        grid-template-columns: 1fr;
    }
    
    .format-option {
        padding: var(--space-3);
    }
    
    .format-name {
        font-size: 14px;
    }
    
    .quantity-selector {
        margin: var(--space-4) 0;
    }
    
    .quantity-selector label {
        font-size: 15px;
    }
    
    .quantity-input {
        width: 80px;
        padding: 8px 10px;
        font-size: 15px;
    }
    
    .action-buttons {
        margin: var(--space-5) 0;
    }
    
    .product-description {
        margin-top: var(--space-5);
        padding: var(--space-4);
    }
    
    .product-description h3 {
        font-size: 16px;
        margin-bottom: var(--space-3);
    }
    
    .product-description p {
        font-size: 13px;
    }
    
    .main-image {
        max-height: 400px;
    }
    
    .image-thumbnails {
        display: flex;
        gap: var(--space-2);
        overflow-x: auto;
        scrollbar-width: thin;
        padding: var(--space-2) 0;
    }
    
    .image-thumbnail {
        min-width: 70px;
        height: 70px;
        flex-shrink: 0;
    }
}

/* ============================================
   CATEGORY/SHOP PAGE - MOBILE
   ============================================ */

@media (max-width: 768px) {
    .page-header {
        padding: var(--space-6) 0 var(--space-5);
    }
    
    .page-title {
        font-size: 22px;
    }
    
    .page-description {
        font-size: 13px;
    }
    
    .catalog-layout {
        grid-template-columns: 1fr;
    }
    
    .mobile-filter-trigger {
        margin-bottom: var(--space-4);
    }
    
    .product-count-text {
        font-size: 13px;
    }
    
    .mobile-filter-btn {
        font-size: 13px;
        padding: 8px 14px;
    }
}

/* ============================================
   SMALL MOBILE (375px and below)
   ============================================ */

@media (max-width: 375px) {
    /* Even tighter spacing */
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }
    
    .section {
        padding: 20px 0;
    }
    
    /* Hero */
    .hero-title {
        font-size: 24px;
    }
    
    .hero-description {
        font-size: 13px;
    }
    
    /* Product cards - keep 2 columns but tighter */
    .product-grid,
    .featured-products-grid {
        gap: 10px;
    }
    
    .product-name,
    .featured-product-name {
        font-size: 12px;
    }
    
    .current-price {
        font-size: 15px;
    }
    
    .add-to-cart-btn,
    .featured-add-to-cart,
    .bestseller-add-to-cart {
        font-size: 11px;
        padding: 7px 10px;
    }
    
    /* Section headers */
    .section-title {
        font-size: 18px;
    }
    
    .section-subtitle {
        font-size: 12px;
    }
    
    /* Bestsellers even smaller */
    .bestseller-card {
        width: 160px;
    }
    
    /* Age selector */
    .age-heart {
        width: 90px;
        height: 90px;
    }
    
    .age-emoji {
        font-size: 32px;
    }
    
    .age-range {
        font-size: 13px;
    }
    
    .age-label {
        font-size: 12px;
    }
    
    /* Product detail */
    .product-details-content h1 {
        font-size: 20px;
    }
    
    .product-price-section .current-price {
        font-size: 22px;
    }
    
    .main-image {
        max-height: 350px;
    }
}

/* ============================================
   EXTRA SMALL MOBILE (320px)
   ============================================ */

@media (max-width: 320px) {
    /* Minimal spacing */
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .section {
        padding: 16px 0;
    }
    
    /* Hero ultra compact */
    .hero-title {
        font-size: 22px;
    }
    
    .hero-description {
        font-size: 12px;
    }
    
    /* Product grid */
    .product-grid,
    .featured-products-grid {
        gap: 8px;
    }
    
    .product-info,
    .featured-product-info {
        padding: 8px;
    }
    
    .product-name,
    .featured-product-name {
        font-size: 11px;
    }
    
    .product-author {
        font-size: 10px;
    }
    
    .current-price {
        font-size: 14px;
    }
    
    .original-price {
        font-size: 11px;
    }
    
    .add-to-cart-btn,
    .featured-add-to-cart,
    .bestseller-add-to-cart {
        font-size: 10px;
        padding: 6px 8px;
        width: calc(100% - 16px);
        margin: 0 8px 8px;
    }
    
    /* Section headers */
    .section-title {
        font-size: 16px;
    }
    
    .section-subtitle {
        font-size: 11px;
    }
    
    /* Feature cards */
    .feature-title {
        font-size: 14px;
    }
    
    .feature-description {
        font-size: 12px;
    }
    
    /* Bestsellers */
    .bestseller-card {
        width: 140px;
    }
    
    /* Age selector compact */
    .age-heart {
        width: 80px;
        height: 80px;
    }
    
    .age-emoji {
        font-size: 28px;
    }
    
    .age-range {
        font-size: 12px;
    }
    
    .age-label {
        font-size: 11px;
    }
    
    /* Footer */
    .footer-logo {
        font-size: 18px;
    }
    
    .footer-title {
        font-size: 14px;
    }
    
    .footer-description,
    .footer-links a {
        font-size: 12px;
    }
    
    /* Product detail */
    .product-details-content h1 {
        font-size: 18px;
    }
    
    .book-author {
        font-size: 14px;
    }
    
    .product-price-section .current-price {
        font-size: 20px;
    }
    
    .main-image {
        max-height: 300px;
    }
}

/* ============================================
   LANDSCAPE MODE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce vertical padding in landscape */
    .section {
        padding: 16px 0;
    }
    
    .hero-text-section {
        padding: var(--space-6) 0;
    }
    
    .banner-image {
        max-height: 250px;
    }
    
    /* Navigation compact */
    .nav-wrapper {
        height: 48px;
    }
    
    /* Modal/drawer optimizations */
    .mobile-search-overlay {
        padding-top: 60px;
    }
}

/* ============================================
   UTILITIES
   ============================================ */

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile {
        display: block !important;
    }
}

/* Hide on desktop */
@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
    
    .show-desktop {
        display: block !important;
    }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    /* Reduce animation complexity on mobile */
    * {
        animation-duration: 0.2s !important;
    }
    
    /* Optimize images */
    img {
        image-rendering: -webkit-optimize-contrast;
    }
    
    /* Better scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   BOTTOM BAR — Cart + Social same row, iOS theme
   ============================================ */

.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    flex-direction: row;
    min-height: 56px;
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0));
    background: rgba(255, 247, 250, 0.97);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    box-shadow: 0 -1px 0 rgba(241, 241, 241, 0.8);
    border-radius: 16px 16px 0 0;
    transition: transform 0.35s cubic-bezier(0.34, 1.1, 0.64, 1);
    transform: translateY(100%);
}

.bottom-bar.visible {
    transform: translateY(0);
}

/* Cart popup hidden when empty (social still shows) */
#cartPopup.cart-popup-inline.cart-popup-empty {
    display: none !important;
}

#cartPopup.cart-popup-inline {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px 0 0;
    gap: 14px;
    background: transparent;
    color: var(--color-text-primary, #2B2D42);
    border: none;
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    max-width: none;
    bottom: auto;
    left: auto;
    right: auto;
    transition: none;
    min-height: 44px;
}

#cartPopup.cart-popup-inline.visible {
    bottom: auto;
}

.cart-popup-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.cart-popup-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cart-popup-icon-check {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-success, #10B981);
}

.cart-popup-icon-cart {
    background: var(--color-primary-pale, var(--color-primary-light));
    color: var(--color-primary, #F66FA1);
}

#cartPopup.cart-popup-inline .cart-popup-icon[hidden],
.cart-popup-icon[hidden] {
    display: none !important;
}

#cartPopupText {
    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 14px;
    font-weight: 400;
    color: var(--color-text-primary, #2B2D42);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-popup-viewbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: #fff;
    font-family: var(--font-heading, 'Poppins', sans-serif);
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.02em;
    text-decoration: none;
    background: var(--color-primary, #F66FA1);
    border: none;
    border-radius: var(--radius-btn, 12px);
    padding: 10px 18px;
    min-height: 44px;
    flex-shrink: 0;
    transition: background 0.3s ease, transform 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 8px rgba(246, 111, 161, 0.2);
}

.cart-popup-viewbtn:hover,
.cart-popup-viewbtn:active {
    background: var(--color-primary-dark, #E2558C);
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
}

/* Just-added state (cart icon visible) */
#cartPopup.cart-popup-inline.cart-popup-just-added .cart-popup-icon-check {
    display: none !important;
}

#cartPopup.cart-popup-inline.cart-popup-just-added .cart-popup-icon-cart {
    display: flex !important;
}

#cartPopup.cart-popup-inline.cart-popup-just-added .cart-popup-icon-cart[hidden] {
    display: flex !important;
}

#cartPopup.cart-popup-inline.cart-popup-warning .cart-popup-icon-check {
    background: rgba(230, 81, 0, 0.2);
    color: #E65100;
}

@media (max-width: 480px) {
    .bottom-bar {
        min-height: 52px;
        padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0));
    }
    #cartPopup.cart-popup-inline { padding: 0; gap: 12px; min-height: 44px; }
    #cartPopupText { font-size: 13px; }
    .cart-popup-viewbtn { font-size: 13px; padding: 10px 16px; min-height: 44px; }
}

@media (max-width: 320px) {
    .bottom-bar { padding-top: 8px; }
    #cartPopupText { font-size: 12px; }
    .cart-popup-viewbtn { font-size: 12px; padding: 10px 12px; min-height: 42px; }
}

/* Social icons: decoupled, always visible on mobile */
.social-fab-wrapper {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 10001;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0 12px;
    padding-bottom: env(safe-area-inset-bottom, 12px);
    pointer-events: none;
}

.social-fab-wrapper .social-fab-container {
    pointer-events: auto;
}

.social-fab-wrapper-standalone .social-fab-container {
    margin-left: 0;
}

/* Bottom cart bar: no social inside, leaves room for social on right */
.bottom-bar.bottom-bar-cart {
    right: 64px;
    max-width: calc(100% - 64px);
}

@media (max-width: 480px) {
    .bottom-bar.bottom-bar-cart {
        right: 56px;
        max-width: calc(100% - 56px);
    }
}

/* Show bottom bar and social wrapper only on mobile/tablet */
@media (min-width: 769px) {
    .bottom-bar,
    .social-fab-wrapper {
        display: none !important;
    }
}