/* Small-screen & touch optimizations */

/* Mobile browser foundations */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Prevent iOS zoom on form focus */
input,
select,
textarea {
    font-size: 16px;
}

img,
video {
    max-width: 100%;
    height: auto;
}

.logo {
    flex: 0 1 auto;
    min-width: 0;
}

.logo a {
    display: flex;
    align-items: center;
    min-width: 0;
}

.logo a img {
    height: 56px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

/* Touch-friendly tap targets */
.btn,
.btn-add-cart,
.btn-primary,
.btn-secondary,
.cart-btn,
.phone-btn,
.mobile-menu-toggle,
.qty-btn,
.checkout-btn,
.btn-checkout,
.btn-back,
.view-btn,
.page-btn,
.availability-btn,
.btn-import {
    min-height: 44px;
}

button,
a.cart-btn,
a.phone-btn {
    -webkit-tap-highlight-color: transparent;
}

/* Header — tablet & mobile */
@media (max-width: 992px) {
    .header .social-links {
        display: none;
    }

    .header {
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .header-content {
        position: relative;
        flex-wrap: nowrap;
        gap: 8px;
        padding: 8px 0;
    }

    .logo {
        max-width: 38%;
    }

    .header-actions {
        margin-left: auto;
    }

    .main-nav {
        max-height: min(75vh, 520px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        z-index: 1001;
    }

    .main-nav a {
        padding: 14px 0;
        font-size: 16px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .dropdown-menu a {
        padding: 12px 16px;
        min-height: 44px;
    }

    .mobile-menu-toggle {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        background: var(--bg-light, #f5f5f5);
        border-radius: 6px;
        cursor: pointer;
    }

    body.nav-open {
        overflow: hidden;
        touch-action: none;
    }

    body.nav-open .main-nav {
        max-height: calc(100vh - 70px);
    }
}

@media (max-width: 768px) {
    .container {
        padding-left: 14px;
        padding-right: 14px;
    }

    .logo {
        max-width: 32%;
    }

    .logo a img {
        height: 44px !important;
    }

    .top-banner {
        font-size: 12px;
        padding: 8px 12px;
        line-height: 1.4;
    }

    .header-actions {
        gap: 6px;
        flex-shrink: 0;
        flex-wrap: nowrap;
        min-width: 0;
    }

    .phone-btn {
        padding: 10px 8px;
        min-width: 0;
        justify-content: center;
        font-size: 11px;
        gap: 5px;
        white-space: nowrap;
        flex-shrink: 0;
        letter-spacing: -0.2px;
    }

    .phone-btn .phone-label {
        white-space: nowrap;
    }

    #loginBtn,
    .btn-login {
        padding: 8px 12px;
        font-size: 13px;
    }

    #userMenu .btn-login span,
    #loginBtn span {
        display: none;
    }

    .cart-btn {
        padding: 10px 12px;
        min-width: 44px;
    }

    /* Hero */
    .hero {
        min-height: 360px;
        padding: 60px 16px;
    }

    .hero-content h2 {
        font-size: 28px;
        line-height: 1.2;
    }

    .hero-content p {
        font-size: 16px;
        margin-bottom: 24px;
    }

    .hero .btn-primary {
        padding: 14px 28px;
        font-size: 15px;
        width: 100%;
        max-width: 280px;
    }

    /* Sections */
    .products-section,
    .categories-section,
    .spotlight-section {
        padding: 36px 0;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 24px;
    }

    .section-header h2,
    .spotlight-section h2 {
        font-size: 22px;
    }

    .spotlight-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .spotlight-card {
        flex-direction: column;
    }

    .spotlight-image,
    .spotlight-info {
        width: 100%;
    }

    .spotlight-image {
        height: 200px;
        min-height: 200px;
    }

    .spotlight-info {
        padding: 16px;
    }

    .spotlight-info h3 {
        font-size: 16px;
    }

    .spotlight-info .price {
        font-size: 20px;
        margin-bottom: 12px;
    }

    .category-card {
        height: 160px;
    }

    .category-info {
        padding: 40px 12px 12px;
    }

    .category-info h3 {
        font-size: 14px;
    }

    /* Product grid — keep 2 columns on phones (not carousels) */
    .products-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px;
    }

    .products-carousel .products-grid {
        display: flex !important;
        grid-template-columns: unset !important;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 12px;
        padding-bottom: 4px;
        scrollbar-width: none;
    }

    .products-carousel .products-grid::-webkit-scrollbar {
        display: none;
    }

    .products-carousel .product-card {
        flex: 0 0 min(72vw, 200px);
        scroll-snap-align: start;
    }

    .categories-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px;
    }

    .product-image {
        height: 140px;
    }

    .product-info {
        padding: 10px;
    }

    .product-info h3 {
        font-size: 12px;
        min-height: auto;
        -webkit-line-clamp: 2;
    }

    .product-info .price {
        font-size: 15px;
        margin-bottom: 8px;
    }

    .btn-add-cart {
        font-size: 11px;
        padding: 10px 6px;
    }

    /* Carousel — swipe scroll, hide arrows */
    .products-carousel {
        margin: 0 -4px;
    }

    .carousel-btn {
        display: none;
    }

    /* Breadcrumb */
    .breadcrumb {
        padding: 10px 0;
        font-size: 12px;
    }

    .breadcrumb .container {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* WhatsApp float */
    .whatsapp-float {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: calc(16px + env(safe-area-inset-right));
        z-index: 999;
        width: 56px;
        height: 56px;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
        font-size: 0;
    }

    .whatsapp-float span {
        display: none;
    }

    .whatsapp-float i {
        font-size: 26px;
    }

    body {
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Login modal */
    #loginModal .modal-content {
        margin: 10px auto !important;
        padding: 20px 16px !important;
        max-width: calc(100% - 20px) !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 16px 12px;
    }

    .footer-section.footer-brand-col {
        grid-column: 1 / -1;
    }
}

@media (max-width: 480px) {
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }

    .logo {
        max-width: 28%;
    }

    .logo a img {
        height: 38px !important;
    }

    /* Shorter phone label on very narrow screens */
    .phone-btn .phone-label {
        font-size: 0;
        letter-spacing: 0;
    }

    .phone-btn .phone-label::after {
        content: '0115 668 313';
        font-size: 10px;
        white-space: nowrap;
    }

    .hero {
        min-height: 300px;
        padding: 48px 12px;
    }

    .hero-content h2 {
        font-size: 24px;
    }

    .hero-content p {
        font-size: 14px;
    }

    .section-header h2,
    .spotlight-section h2 {
        font-size: 20px;
    }

    .products-section,
    .categories-section,
    .spotlight-section {
        padding: 28px 0;
    }

    .category-card {
        height: 140px;
    }

    .product-image {
        height: 120px;
    }

    .footer-content {
        grid-template-columns: 1fr;
    }

    .footer-section h3 {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .progress-steps .step p {
        font-size: 10px;
    }

    .step-number {
        width: 36px !important;
        height: 36px !important;
        font-size: 14px !important;
    }

    .checkout-progress {
        padding: 16px 0;
    }
}

/* Products page — mobile filters */
.mobile-filter-toggle {
    display: none;
}

@media (max-width: 992px) {
    .mobile-filter-toggle {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        margin-bottom: 16px;
        padding: 12px 16px;
        background: var(--white);
        border: 1px solid var(--border-color, #ddd);
        border-radius: 8px;
        font-size: 15px;
        font-weight: 600;
        color: var(--primary-color, #1a365d);
        cursor: pointer;
        min-height: 44px;
        box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,0.08));
    }

    .filters-sidebar {
        display: none;
        margin-bottom: 16px;
    }

    .filters-sidebar.is-open {
        display: block;
    }

    .products-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }

    .view-options {
        width: 100%;
        justify-content: flex-end;
    }

    .view-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    .page-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Products page */
@media (max-width: 768px) {
    .products-page {
        padding: 24px 0 48px;
    }

    .page-layout {
        gap: 20px;
    }

    .filters-sidebar {
        padding: 16px;
    }

    .filter-section {
        margin-bottom: 20px;
        padding-bottom: 16px;
    }

    .products-content {
        padding: 16px;
    }

    .products-header h1 {
        font-size: 22px;
    }

    .products-grid.list-view .product-image {
        height: 200px;
    }
}

/* Cart */
@media (max-width: 768px) {
    .cart-page {
        padding: 24px 0 48px;
    }

    .cart-page h1 {
        font-size: 24px;
        margin-bottom: 24px;
    }

    .cart-items,
    .cart-summary {
        padding: 16px;
    }

    .cart-item {
        flex-direction: column;
        padding: 16px 0;
        gap: 12px;
    }

    .cart-item-image {
        width: 100%;
        height: 160px;
    }

    .cart-item-actions {
        flex-wrap: wrap;
        justify-content: space-between;
        width: 100%;
    }

    .shipping-note {
        font-size: 12px;
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }
}

/* Checkout */
@media (max-width: 768px) {
    .checkout-page {
        padding: 24px 0 48px;
    }

    .checkout-form-section h2 {
        font-size: 22px;
    }

    .form-section {
        padding: 16px;
    }

    .payment-option label {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px;
    }

    .order-summary-card {
        padding: 16px;
    }

    .security-badges {
        flex-direction: column;
    }

    .trust-signals {
        padding: 16px;
    }

    #guestCheckoutNotice {
        font-size: 12px !important;
        padding: 8px 10px !important;
    }
}

/* Contact, about, FAQ, pages */
@media (max-width: 768px) {
    .page-content {
        padding: 36px 0;
    }

    .page-content h1 {
        font-size: 26px;
        margin-bottom: 24px;
    }

    .contact-layout {
        gap: 24px;
    }

    .contact-info-section,
    .contact-form-section,
    .about-card,
    .policy-content {
        padding: 20px 16px;
    }

    .faq-question {
        padding: 16px 20px;
        font-size: 15px;
    }

    .faq-answer-content {
        padding: 0 20px 16px;
        font-size: 14px;
    }
}

/* Product import tool */
@media (max-width: 768px) {
    .import-layout {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .import-header {
        padding: 12px 16px;
    }

    .import-header h1 {
        font-size: 16px;
    }

    .import-card {
        padding: 16px;
    }

    .import-form-grid {
        grid-template-columns: 1fr;
    }

    .import-actions {
        flex-direction: column;
    }

    .import-actions .btn-import {
        width: 100%;
        justify-content: center;
    }

    .image-preview-item {
        width: 80px;
        height: 80px;
    }
}

/* Product detail page (inline layout classes) */
@media (max-width: 768px) {
    .product-detail-section {
        padding: 24px 0 !important;
    }

    .product-detail-container {
        padding: 0 12px !important;
    }

    .product-detail-grid {
        grid-template-columns: 1fr !important;
        padding: 16px !important;
        gap: 20px !important;
    }

    .main-image {
        height: 260px !important;
    }

    .thumbnail-images {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .thumbnail {
        height: 64px !important;
    }

    .product-info h1 {
        font-size: 22px !important;
    }

    .product-price {
        font-size: 28px !important;
    }

    .product-actions {
        flex-direction: column !important;
    }

    .btn-add-cart-detail {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .thumbnail-images {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .main-image {
        height: 220px !important;
    }
}

/* Order success */
@media (max-width: 768px) {
    .success-card,
    .order-details-card {
        padding: 20px 16px !important;
        margin: 0 12px;
    }
}

/* Checkout forms — mobile keyboards */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .form-group input,
    .form-group select,
    .form-group textarea,
    .checkout-form input,
    .checkout-form select,
    .checkout-form textarea,
    .contact-form input,
    .contact-form select,
    .contact-form textarea {
        width: 100%;
        box-sizing: border-box;
        min-height: 44px;
    }

    .qty-btn,
    .quantity-control button {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Prevent horizontal overflow */
table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

/* Modals & quick view on mobile */
@media (max-width: 768px) {
    .quick-view-modal .modal-content,
    .modal-content {
        width: calc(100% - 24px) !important;
        max-width: none !important;
        margin: 12px auto !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    .user-dropdown {
        right: 0 !important;
        left: auto !important;
        min-width: 160px !important;
    }
}
