/* --- 全局設定 --- */
:root {
    --primary: #ff6b81;
    --bg-color: #f4f6f8;
    --text-main: #333;
    --text-sub: #888;
}

body {
    background-color: var(--bg-color);
    font-family: "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding-bottom: 80px;
    /* 增加底部留白，避免被導航擋住 */
    color: var(--text-main);
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    background: #fff;
    min-height: 100vh;
}

/* --- 通用元件 --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: #fff;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    z-index: 50;
    font-size: 1.1rem;
    font-weight: bold;
}

.icon-btn {
    border: none;
    background: none;
    font-size: 1.2rem;
    color: #333;
    padding: 5px;
}

.section-title {
    padding: 20px 0px 10px;
    font-size: 0.95rem;
    color: var(--text-sub);
    font-weight: bold;
}

.form-content-wrapper {
    padding: 20px;
}

/* 解決表單貼邊問題 */

/* --- Header --- */
.app-header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
}

#header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

/* --- 商品列表 (改為雙欄排版) --- */
.category-scroll {
    padding: 10px 15px;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 40;
    white-space: nowrap;
    /* 確保不換行 */
}

/* 隱藏捲軸 */
.category-scroll::-webkit-scrollbar {
    display: none;
}

.cat-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid #eee;
    background: #fff;
    white-space: nowrap;
    font-size: 0.9rem;
    transition: 0.2s;
    color: #555;
}

.cat-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* 改用 Grid 網格佈局，一行兩個 (1fr 1fr) */
.product-list-layout {
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* 關鍵：切成兩欄 */
    gap: 15px;
    /* 卡片之間的間距 */
}

.product-card {
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    height: 100%;
    /* 確保卡片高度一致 */
}

/* 圖片高度調整，配合雙欄變小一點 */
.product-img {
    width: 100%;
    height: 150px;
    /* 從 220px 改為 150px，比例較剛好 */
    object-fit: cover;
}

.product-info {
    padding: 10px;
    flex: 1;
    /* 讓內容撐開，使按鈕對齊底部 */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.product-title {
    font-size: 0.95rem;
    /* 字體稍微縮小適配雙欄 */
    margin: 0 0 5px;
    font-weight: bold;
    line-height: 1.4;
    /* 超過兩行顯示省略號 (選用) */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

.buy-btn {
    width: 100%;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 6px;
    font-weight: bold;
    font-size: 0.9rem;
}

/* --- 訂購表單 --- */
.selected-product-card {
    display: flex;
    gap: 15px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
    margin-bottom: 20px;
    align-items: center;
}

.selected-product-card img {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
}

.form-block {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 5px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: #555;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    box-sizing: border-box;
}

.row-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.qty-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.qty-control button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: #fff;
    color: #555;
}

.qty-control input {
    width: 50px;
    text-align: center;
    border: none;
    font-size: 1.1rem;
    padding: 0;
}

.payment-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.pay-item input {
    display: none;
}

.pay-content {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px 5px;
    text-align: center;
    color: #888;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
}

.pay-item input:checked+.pay-content {
    border-color: var(--primary);
    color: var(--primary);
    background: #fff0f3;
}

.submit-btn {
    width: 100%;
    padding: 15px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 30px;
    font-size: 1.1rem;
    font-weight: bold;
    margin-top: 30px;
    box-shadow: 0 4px 10px rgba(255, 107, 129, 0.4);
}

/* --- 會員中心 (重構) --- */
.profile-header {
    position: relative;
    text-align: center;
    margin-bottom: 20px;
}

.profile-bg {
    height: 120px;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
}

.profile-avatar-area {
    margin-top: -50px;
    /* 往上疊 */
    display: flex;
    flex-direction: column;
    align-items: center;
}

#profile-picture {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    border: 4px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: #eee;
}

#profile-name {
    margin: 10px 0 5px;
    font-size: 1.3rem;
}

#profile-status {
    color: #888;
    font-size: 0.9rem;
    background: #eee;
    padding: 2px 10px;
    border-radius: 10px;
}

.profile-menu {
    margin: 0 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #f5f5f5;
    cursor: pointer;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:active {
    background: #fafafa;
}

.icon-box {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    color: #fff;
}

.color-blue {
    background: #4facfe;
}

.color-green {
    background: #43e97b;
}

.color-orange {
    background: #ff9a44;
}

.menu-text {
    flex: 1;
    font-size: 1rem;
    color: #333;
}

.arrow {
    color: #ccc;
    font-size: 0.9rem;
}

/* --- 歷史訂單 (更新版) --- */
.history-container {
    padding: 15px;
}

.history-card {
    background: #fff;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    border: 1px solid #eee;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}

.h-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed #eee;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.h-date {
    color: #999;
    font-size: 0.85rem;
}

/* 狀態標籤基礎樣式 */
.status-tag {
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: bold;
}

/* 三種狀態的顏色定義 */
.status-pending {
    background: #fff0f0;
    color: #ff4757;
    border: 1px solid #ffccc7;
}

/* 待付款 (紅/橘) */
.status-paid {
    background: #f6ffed;
    color: #52c41a;
    border: 1px solid #b7eb8f;
}

/* 已付款 (綠) */
.status-done {
    background: #f5f5f5;
    color: #8c8c8c;
    border: 1px solid #d9d9d9;
}

/* 已完成 (灰) */

.h-body h4 {
    margin: 0 0 5px;
    font-size: 1rem;
    color: #333;
}

.h-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.h-price {
    font-weight: bold;
    font-size: 1.1rem;
    color: #333;
}

/* 若是待付款，顯示去付款按鈕 */
.pay-now-btn {
    font-size: 0.85rem;
    background: #ff4757;
    color: white;
    padding: 5px 12px;
    border-radius: 4px;
    border: none;
}

/* --- 底部導航 --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    max-width: 600px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    height: 60px;
    z-index: 100;
}

.nav-item {
    flex: 1;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #aaa;
}

.nav-item i {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.nav-item.active {
    color: var(--primary);
}

/* --- Loading --- */
.loading-overlay {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 999;
    justify-content: center;
    align-items: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

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

input,
select,
textarea {
    -webkit-appearance: none;
    /* 關鍵：移除 iOS 預設樣式 */
    appearance: none;
    border-radius: 6px;
    /* 強制統一圓角 */
}

/* 2. 特別針對日期 (Date) 與時間 (Time) 輸入框修正 */
input[type="date"],
input[type="time"] {
    background-color: #fff;
    /* 強制白色背景，解決灰色區塊問題 */
    min-height: 48px;
    /* 強制最小高度，避免在 iOS 上看起來比文字框扁 */

    /* 確保文字垂直置中 */
    display: block;
    line-height: normal;

    /* 讓 iOS 的日期文字顏色深一點，避免看起來像無效狀態 */
    color: #333;
}

/* 3. 解決 iOS 上 Placeholder 有時候會跑位的問題 */
input::placeholder {
    line-height: normal;
}

/* --- 新增庫存顯示樣式 --- */

/* 讓價格與庫存顯示在同一排，左右對齊 */
.price-stock-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

/* 庫存文字基本樣式 */
.stock-label {
    font-size: 13px;
    color: #888;
}

/* 庫存少於 5 的警示樣式 */
.stock-label.low-stock {
    color: #e65100;
    /* 橘紅色 */
    font-weight: bold;
}

/* 已售完文字樣式 */
.stock-label.sold-out {
    color: #999;
}

/* 已售完的按鈕樣式 (灰色、無法點擊) */
.buy-btn.disabled {
    background-color: #ccc;
    pointer-events: none;
    /* 禁止滑鼠點擊 */
}

/* (選填) 圖片上的 SOLD OUT 遮罩 */
.img-wrapper {
    position: relative;
}

.img-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 18px;
    border-radius: 8px 8px 0 0;
    /* 配合卡片圓角 */
}

/* 訂單編號樣式 */
.order-no {
    font-weight: bold;
    color: #666;
    font-size: 0.85rem;
}

/* 日期樣式 */
.order-date {
    font-size: 0.75rem;
    color: #999;
    margin-bottom: 5px;
}

/* 狀態標籤美化 */
.status-tag.status-pending {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

textarea {
    width: 100%;
}

/* 填寫訂單頁的商品說明 */
.form-product-description {
    font-size: 14px;
    color: #888;
    line-height: 1.6;
    margin-top: 8px;
    word-break: break-all;
    /* 防止長英文/網址撐破排版 */
    white-space: pre-wrap;
    /* 保留資料庫中的換行符號 */
}

/* RWD 微調 */
@media (max-width: 480px) {
    .selected-product-card {
        align-items: flex-start !important;
        /* 確保圖片跟文字對齊 */
    }

    .form-product-description {
        font-size: 13px;
        margin-top: 6px;
    }
}

/* 確保卡片內的圖片與文字比例協調 */
.selected-product-card img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
}

.img-wrapper {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    /* 確保圖片不超出圓角 */
}

.product-img {
    height: 200px;
    /* 固定高度，或使用 aspect-ratio */
    object-fit: cover;
}

/* 調整輪播按鈕大小 */
.carousel-control-prev-icon,
.carousel-control-next-icon {
    width: 20px;
    height: 20px;
}

/* 產品卡片輪播樣式 */
.img-wrapper {
    position: relative;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    overflow: hidden;
    background: #f8f9fa;
}

.product-img {
    height: 220px;
    /* 固定高度 */
    object-fit: cover;
    /* 自動裁切填滿 */
    width: 100%;
}

.carousel-control-prev,
.carousel-control-next {
    width: 10%;
    /* 縮小控制按鈕點擊區域 */
}

/* 售完遮罩要蓋在輪播最上方 */
.img-overlay {
    z-index: 10;
}