:root {
    /* 主色系（承襲 origin.php 的漸變色） */
    --primary-start: #14d3eb;
    --primary-end: #0cecbe;
    --primary-gradient: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);

    /* 中性色 */
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --border-light: #f0f0f0;

    /* 狀態色 */
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --info-color: #3b82f6;

    /* 間距 */
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* 圓角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* 陰影 */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.2);

    /* 動畫 */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    background: var(--primary-gradient);
    min-height: 100vh;
    padding: var(--spacing-md);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 600px;
    margin: 0 auto;
}

/* ============================================
   頂部導航
   ============================================ */
.header {
    background: var(--card-bg);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--card-bg);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-sm);
}

.site-title {
    font-size: 24px;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.user-actions {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

.cart-btn,
.login-btn,
.user-menu-btn {
    position: relative;
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-full);
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px;
    /* 禁止手機雙擊縮放 */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.cart-btn:hover,
.login-btn:hover,
.user-menu-btn:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

.cart-btn:active {
    transform: translateY(0);
}

.cart-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--error-color);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
}

.login-btn {
    background: var(--primary-gradient);
    color: white;
}

.login-btn:hover {
    opacity: 0.9;
    background: var(--primary-gradient);
}

/* 狀態提示 */
.status-banner {
    background: var(--info-color);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: 14px;
    text-align: center;
    margin-bottom: var(--spacing-md);
}

.status-banner.warning {
    background: var(--warning-color);
}

.status-banner.success {
    background: var(--success-color);
}

/* 搜尋框 */
.search-box {
    position: relative;
}

#searchInput {
    width: 100%;
    padding: 16px 50px 16px 46px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 16px;
    transition: var(--transition);
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary-start);
    box-shadow: 0 0 0 3px rgba(20, 211, 235, 0.1);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 18px;
}

.clear-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--border-color);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.clear-btn.show {
    display: flex;
}

.clear-btn:hover {
    background: #ccc;
}

/* ============================================
   產品列表 - 兩欄卡片式佈局
   ============================================ */
.products-section {
    background: var(--card-bg);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--spacing-sm);
}

#productsList {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* 手機固定 2 欄 */
    gap: var(--spacing-sm);
}

.product-item {
    background: var(--bg-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    width: 100%;
    /* 填滿格子寬度 */
    /* 固定寬度 */
    /* height: 410px; */
    /* 增加高度確保按鈕可見 */
    /* 固定高度 */
    justify-self: center;
    /* 置中對齊 */
}

.product-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.product-header {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.product-image {
    width: 100%;
    height: 220px;
    /* 增加圖片高度以適應直向照片 */
    object-fit: contain;
    background: #e0e0e0;
    flex-shrink: 0;
}

/* 虛擬圖片佔位符 */
.product-image-placeholder {
    width: 100%;
    height: 220px;
    /* 增加圖片高度以適應直向照片 */
    background: linear-gradient(135deg, #e0e0e0 0%, #f0f0f0 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 36px;
    flex-shrink: 0;
}

.product-info {
    padding: var(--spacing-xs);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.product-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price-row {
    display: flex;
    align-items: baseline;
    gap: 2px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.product-price {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 700;
}

.product-price-plus {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0 2px;
}

.product-proxy-price {
    font-size: 14px;
    color: #333;
    font-weight: 600;
}

.product-description {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}

/* 數量控制（登入後顯示） */
.quantity-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs);
    border-top: 1px solid var(--border-light);
    background: white;
    flex-shrink: 0;
    /* 確保不會被壓縮或隱藏 */
}

.qty-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-gradient);
    color: white;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    /* 禁止手機雙擊縮放 */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.qty-btn:hover {
    opacity: 0.85;
    transform: scale(1.05);
}

.qty-btn:active {
    transform: scale(0.95);
}

.qty-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.qty-display {
    min-width: 30px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================
   Loading & Empty States
   ============================================ */
.loading {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-start);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.no-results {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

/* ============================================
   Modal & Overlay
   ============================================ */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-xl);
    transform: translateY(100%);
    transition: transform var(--transition);
    z-index: 1000;
    max-height: 80vh;
    overflow-y: auto;
}

.modal.show {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.close-btn {
    background: var(--bg-color);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 20px;
}

.close-btn:hover {
    background: var(--border-color);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    min-height: 48px;
    width: 100%;
    /* 禁止手機雙擊縮放 */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--success-color);
    color: white;
    padding: 16px 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    z-index: 2000;
    opacity: 0;
    transition: all var(--transition);
    max-width: 90%;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.error {
    background: var(--error-color);
}

.toast.warning {
    background: var(--warning-color);
}

/* ============================================
   Responsive Design
   ============================================ */

/* 極窄螢幕優化 (300-400px) */
@media (max-width: 480px) {
    body {
        padding: var(--spacing-sm);
    }

    .header {
        padding: var(--spacing-md);
        border-radius: var(--radius-md) var(--radius-md) 0 0;
    }

    .site-title {
        font-size: 18px;
        flex-shrink: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-actions {
        gap: 6px;
        flex-shrink: 0;
    }

    .cart-btn,
    .login-btn,
    .user-menu-btn {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 40px;
    }

    /* 極窄螢幕：按鈕只顯示 icon */
    .cart-btn:not(.orders-btn),
    .user-menu-btn {
        width: 44px;
        padding: 10px;
        text-indent: -9999px;
        position: relative;
    }

    .cart-btn:not(.orders-btn)::after {
        content: '🛒';
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        text-indent: 0;
        font-size: 20px;
    }

    .user-menu-btn::after {
        content: '👤';
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        text-indent: 0;
        font-size: 20px;
    }

    /* 確保徽章可見 */
    .cart-badge {
        text-indent: 0;
    }

    .search-box {
        margin-top: var(--spacing-sm);
    }

    #searchInput {
        padding: 12px 44px 12px 40px;
        font-size: 15px;
    }

    .product-image,
    .product-image-placeholder {
        height: 155px;
        /* 保持直向圖片比例 */
    }

    .product-info {
        padding: 6px;
    }

    .product-name {
        font-size: 12px;
        flex-shrink: 0;
        margin-bottom: 2px;
    }

    .product-price-row {
        margin-bottom: 2px;
        flex-shrink: 0;
    }

    .product-price {
        font-size: 13px;
    }

    .product-proxy-price {
        font-size: 12px;
    }

    .product-description {
        font-size: 10px;
        -webkit-line-clamp: 1;
        margin-top: 2px;
    }

    .qty-btn {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }
}

@media (min-width: 768px) {
    body {
        padding: var(--spacing-lg);
    }

    .container {
        max-width: 700px;
    }

    .modal {
        left: 50%;
        right: auto;
        transform: translate(-50%, 100%);
        max-width: 500px;
        bottom: 20px;
        border-radius: var(--radius-xl);
    }

    .modal.show {
        transform: translate(-50%, 0);
    }

    /* 寬版自動填滿多欄 */
    #productsList {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    }
}

/* ============================================
   Image Viewer (Zoom)
   ============================================ */
.zoomable {
    cursor: zoom-in;
    transition: transform var(--transition-fast);
}

.zoomable:hover {
    transform: scale(1.02);
}

.image-viewer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    z-index: 11000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.image-viewer-backdrop.show {
    display: flex;
    opacity: 1;
}

.image-viewer-content {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.image-viewer-backdrop.show .image-viewer-content {
    transform: scale(1);
}

.image-viewer-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

.image-viewer-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 30px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 10px;
}

@media (max-width: 768px) {
    .image-viewer-close {
        top: 20px;
        right: 20px;
        background: rgba(0, 0, 0, 0.5);
        border-radius: 50%;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 800px;
    }
}

/* ============================================
   停售商品樣式 (Inactive Products)
   ============================================ */
.product-item.product-inactive {
    position: relative;
    opacity: 0.7;
}

.product-item.product-inactive .product-header {
    filter: grayscale(30%);
}

.product-inactive-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: var(--radius-md);
    pointer-events: none;
}

.product-inactive-overlay span {
    background: rgba(239, 68, 68, 0.95);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.quantity-control-disabled {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xs);
    border-top: 1px solid var(--border-light);
    background: #fef2f2;
    flex-shrink: 0;
}

.quantity-control-disabled span {
    color: #991b1b;
    font-size: 12px;
    font-weight: 600;
}

/* ============================================
   PWA Install Banner
   ============================================ */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 0;
}

.pwa-install-banner.show {
    transform: translateY(0);
}

.pwa-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    max-width: 600px;
    margin: 0 auto;
}

.pwa-banner-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.pwa-banner-text {
    flex: 1;
    min-width: 0;
}

.pwa-banner-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.pwa-banner-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.pwa-share-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-gradient);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    vertical-align: middle;
}

.pwa-banner-install {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.pwa-banner-install:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(20, 211, 235, 0.3);
}

.pwa-banner-install:active {
    transform: scale(0.98);
}

.pwa-banner-close {
    background: var(--bg-color);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    color: var(--text-muted);
}

.pwa-banner-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* 適配 iPhone 底部安全區 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .pwa-install-banner {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* 行動裝置微調 */
@media (max-width: 480px) {
    .pwa-banner-content {
        padding: 14px 16px;
        gap: 10px;
    }

    .pwa-banner-icon {
        font-size: 28px;
    }

    .pwa-banner-title {
        font-size: 14px;
    }

    .pwa-banner-desc {
        font-size: 12px;
    }

    .pwa-banner-install {
        padding: 8px 16px;
        font-size: 13px;
    }
}