/* US 10.10: Refactor UI/UX for Smaller Devices */

/* Prevent unexpected horizontal overflow */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Make all images scale safely */
img {
    max-width: 100%;
    height: auto;
}

/* Make form elements easier to tap on mobile */
input,
select,
textarea,
button,
.button,
a.button {
    max-width: 100%;
    box-sizing: border-box;
}

/* General responsive container safety */
.home-wrapper,
.customer-wrapper,
.marketplace-wrapper,
.product-page-wrapper,
.cart-wrapper,
.checkout-wrapper,
.products-wrapper,
.business-wrapper,
.admin-wrapper,
.inquiries-wrapper,
.auth-wrapper {
    width: 100%;
    box-sizing: border-box;
}

/* Medium screens: reduce spacing and prevent cards from feeling cramped */
@media (max-width: 900px) {
    .home-container,
    .customer-container,
    .marketplace-container,
    .product-page-container,
    .cart-container,
    .checkout-container,
    .products-container,
    .business-container,
    .admin-container,
    .inquiries-container,
    .auth-container {
        max-width: 100%;
    }

    .hero-section,
    .dashboard-grid,
    .features-grid,
    .steps-grid,
    .products-grid,
    .product-detail-card,
    .cart-layout,
    .checkout-layout,
    .business-grid,
    .admin-grid {
        grid-template-columns: 1fr !important;
    }

    .marketplace-header,
    .customer-header,
    .product-header,
    .cart-header,
    .checkout-header,
    .products-header,
    .business-header,
    .admin-header {
        align-items: flex-start;
    }
}

/* Small screens: mobile-first layout */
@media (max-width: 600px) {
    body {
        font-size: 15px;
    }

    .home-wrapper,
    .customer-wrapper,
    .marketplace-wrapper,
    .product-page-wrapper,
    .cart-wrapper,
    .checkout-wrapper,
    .products-wrapper,
    .business-wrapper,
    .admin-wrapper,
    .inquiries-wrapper,
    .auth-wrapper {
        padding: 20px 12px !important;
    }

    .home-container,
    .customer-container,
    .marketplace-container,
    .product-page-container,
    .cart-container,
    .checkout-container,
    .products-container,
    .business-container,
    .admin-container,
    .inquiries-container,
    .auth-container {
        width: 100%;
        max-width: 100%;
    }

    .hero-section,
    .customer-header,
    .marketplace-header,
    .product-header,
    .cart-header,
    .checkout-header,
    .products-header,
    .business-header,
    .admin-header,
    .info-section,
    .summary-card,
    .welcome-card,
    .table-card,
    .cart-card,
    .checkout-card,
    .product-detail-card,
    .feature-card,
    .dashboard-card,
    .step-card,
    .empty-box,
    .empty-cart,
    .empty-checkout {
        border-radius: 14px !important;
        padding: 20px !important;
    }

    .hero-section h1,
    .customer-header h1,
    .marketplace-header h1,
    .product-header h1,
    .cart-header h1,
    .checkout-header h1 {
        font-size: 26px !important;
        line-height: 1.25 !important;
    }

    .products-header h2,
    .section-title,
    .info-section h2,
    .summary-card h2 {
        font-size: 22px !important;
        line-height: 1.3 !important;
    }

    .hero-section p,
    .customer-header p,
    .marketplace-header p,
    .product-header p,
    .cart-header p,
    .checkout-header p,
    .products-header p,
    .info-section p,
    .dashboard-card p,
    .feature-card p,
    .step-card p {
        font-size: 14px !important;
        line-height: 1.6 !important;
    }

    /* Stack headers and actions */
    .marketplace-header,
    .customer-header,
    .product-header,
    .cart-header,
    .checkout-header,
    .products-header,
    .business-header,
    .admin-header,
    .hero-section {
        display: block !important;
    }

    .customer-actions,
    .header-actions,
    .hero-actions,
    .product-actions,
    .item-actions {
        display: flex !important;
        flex-direction: column !important;
        width: 100%;
        gap: 10px !important;
        margin-top: 16px;
    }

    /* Buttons become mobile friendly */
    .hero-btn,
    .header-btn,
    .header-link,
    .header-cart-btn,
    .search-btn,
    .clear-btn,
    .purchase-btn,
    .cart-action-btn,
    .login-btn,
    .checkout-btn,
    .place-order-btn,
    .small-btn,
    .remove-btn,
    .action-btn,
    .dashboard-card a,
    .feature-card a,
    .empty-cart a,
    .empty-checkout a {
        width: 100% !important;
        min-height: 46px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
    }

    /* Forms become single column */
    .search-form,
    .quantity-form,
    .checkout-form,
    .filter-form {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .search-form input,
    .search-form select,
    .quantity-form input,
    input,
    select,
    textarea {
        width: 100% !important;
        min-height: 44px;
        font-size: 15px !important;
    }

    /* Product cards and images */
    .products-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .product-image,
    .product-image-area,
    .item-image {
        width: 100% !important;
        height: auto !important;
        min-height: 220px !important;
    }

    .product-image img,
    .product-image-area img,
    .item-image img {
        width: 100% !important;
        height: auto !important;
        max-height: 260px;
        object-fit: cover;
    }

    .product-content,
    .product-info-area {
        padding: 18px !important;
    }

    .product-content h3,
    .product-info-area h2,
    .item-content h3 {
        font-size: 21px !important;
        line-height: 1.3 !important;
    }

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

    /* Cart and checkout items become single column */
    .cart-item,
    .checkout-item {
        grid-template-columns: 1fr !important;
    }

    /* Tables should scroll instead of breaking layout */
    .table-card {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

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

    th,
    td {
        padding: 12px 10px !important;
        font-size: 13px !important;
    }

    /* Pagination is easier to use */
    .pagination-wrapper {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .pagination {
        width: 100%;
        justify-content: center;
    }

    .pagination a,
    .pagination span {
        min-width: 40px;
        min-height: 40px;
    }
}

/* Very small devices */
@media (max-width: 390px) {
    .home-wrapper,
    .customer-wrapper,
    .marketplace-wrapper,
    .product-page-wrapper,
    .cart-wrapper,
    .checkout-wrapper,
    .products-wrapper,
    .business-wrapper,
    .admin-wrapper,
    .inquiries-wrapper,
    .auth-wrapper {
        padding: 16px 10px !important;
    }

    .hero-section,
    .customer-header,
    .marketplace-header,
    .product-header,
    .cart-header,
    .checkout-header,
    .products-header,
    .business-header,
    .admin-header,
    .info-section,
    .summary-card,
    .welcome-card,
    .table-card,
    .cart-card,
    .checkout-card,
    .feature-card,
    .dashboard-card,
    .step-card {
        padding: 16px !important;
    }

    .hero-section h1,
    .customer-header h1,
    .marketplace-header h1,
    .product-header h1,
    .cart-header h1,
    .checkout-header h1 {
        font-size: 24px !important;
    }
}
