/* ============================================
   TEMU-STYLE E-COMMERCE APP
   ============================================ */

:root {
    --primary: #F84C1E;
    --primary-dark: #D63E15;
    --bg: #F5F5F5;
    --white: #FFFFFF;
    --text-dark: #222222;
    --text-gray: #666666;
    --text-light: #999999;
    --border: #EEEEEE;
    --success: #00C853;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-dark);
    line-height: 1.4;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   VIEWS SYSTEM
   ============================================ */

#app {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
}

.view {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    overflow: hidden;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ============================================
   HEADER
   ============================================ */

.header {
    background: var(--white);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 600px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.cart-btn {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.cart-icon {
    font-size: 1.5rem;
}

.cart-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ============================================
   PRODUCTS GRID
   ============================================ */

.products-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    padding-bottom: 20px;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-width: 600px;
    margin: 0 auto;
}

.product-card {
    background: var(--white);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

.product-card:active {
    transform: scale(0.98);
}

.product-card-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--border);
}

.product-card-info {
    padding: 8px 10px 12px;
}

.product-card-price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.product-card-title {
    font-size: 0.8rem;
    color: var(--text-gray);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

/* ============================================
   PRODUCT VIEW HEADER
   ============================================ */

.product-header {
    background: var(--white);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.back-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dark);
}

.product-header-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 10px;
}

/* ============================================
   PRODUCT CONTENT
   ============================================ */

.product-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 80px;
}

/* ============================================
   CAROUSEL
   ============================================ */

.carousel {
    position: relative;
    background: var(--white);
    overflow: hidden;
    touch-action: pan-y pinch-zoom;
}

.carousel-track {
    display: flex;
    transition: transform 0.3s ease-out;
    will-change: transform;
}

.carousel-slide {
    min-width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.carousel-slide img,
.carousel-slide video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}

.carousel-slide video {
    pointer-events: auto;
}

.carousel-dots {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
}

.carousel-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(0,0,0,0.2);
    transition: all 0.3s;
}

.carousel-dot.active {
    background: var(--primary);
    width: 18px;
    border-radius: 3px;
}

.carousel-counter {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(0,0,0,0.5);
    color: white;
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 12px;
}

/* ============================================
   PRODUCT INFO
   ============================================ */

.product-info {
    padding: 16px;
    background: var(--white);
    margin-top: 8px;
}

.product-price {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.product-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 12px;
    line-height: 1.4;
}

.product-desc {
    font-size: 0.9rem;
    color: var(--text-gray);
    margin-bottom: 16px;
    line-height: 1.5;
}

.product-details {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.detail-tag {
    background: var(--bg);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    color: var(--text-gray);
}

/* ============================================
   PRODUCT FOOTER
   ============================================ */

.product-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.add-cart-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s;
}

.add-cart-btn:active {
    background: var(--primary-dark);
}

.add-cart-btn.added {
    background: var(--success);
}

/* ============================================
   CART VIEW
   ============================================ */

.cart-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    padding-bottom: 140px;
}

.cart-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cart-item {
    background: var(--white);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    gap: 12px;
}

.cart-item-image {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg);
}

.cart-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.cart-item-title {
    font-size: 0.9rem;
    color: var(--text-dark);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cart-item-variant {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.cart-item-price {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    margin-top: auto;
}

.cart-item-remove {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px;
}

.cart-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.cart-empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* ============================================
   CART FOOTER
   ============================================ */

.cart-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.cart-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 1rem;
}

.cart-total span:last-child {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.checkout-btn {
    width: 100%;
    padding: 14px;
    background: #25D366;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.checkout-btn:active {
    background: #128C7E;
}

.checkout-btn:disabled {
    background: var(--text-light);
    cursor: not-allowed;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (min-width: 480px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .carousel-slide {
        aspect-ratio: 4/3;
    }
}
