/* =========================================
   1. 核心佈局與鎖定設定
   ========================================= */
html, body {
    height: 100%;
    overflow: hidden;
    margin: 0;
    background-color: #f8f9fa;
}

body {
    display: flex;
    flex-direction: column;
    visibility: hidden;
}

/* 上方固定區 */
.fixed-section {
    flex-shrink: 0;
    z-index: 1020;
    background: white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    position: relative;
}

/* 下方滾動區 */
.scrollable-section {
    flex-grow: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 80px;
    padding-top: 15px;
}

/* =========================================
   2. Navbar & Auth UI
   ========================================= */
.navbar { padding: 8px 0; }

.nav-icon-link {
    color: rgba(255,255,255,0.8);
    font-size: 1.2rem;
    margin-left: 15px;
    position: relative;
    text-decoration: none;
    transition: color 0.2s;
    cursor: pointer;
}

.nav-icon-link:hover { color: white; }

.nav-icon-link .badge {
    font-size: 0.6rem;
    position: absolute;
    top: -5px;
    right: -8px;
    border: 2px solid #212529;
}

.navbar-divider {
    border-left: 1px solid rgba(255,255,255,0.3);
    height: 24px;
    margin: 0 15px;
    display: inline-block;
}

.btn-auth {
    border-radius: 50px;
    padding: 5px 18px;
    font-size: 0.9rem;
    transition: all 0.3s;
    border: 1px solid rgba(255,255,255,0.4);
    color: white;
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-auth:hover {
    background: white;
    color: #212529;
    border-color: white;
}

/* =========================================
   3. Modal 樣式 (登入/註冊)
   ========================================= */
.auth-modal-header {
    background: linear-gradient(135deg, #0d6efd 0%, #052c65 100%);
    color: white;
    border-radius: 10px 10px 0 0;
    padding: 25px 20px;
    text-align: center;
}

.auth-modal-content {
    border: none;
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
}

.nav-pills-custom {
    background: #f1f3f5;
    padding: 5px;
    border-radius: 50px;
    display: inline-flex;
}

.nav-pills-custom .nav-link {
    border-radius: 50px;
    color: #6c757d;
    padding: 8px 30px;
    font-weight: 600;
    transition: all 0.2s;
}

.nav-pills-custom .nav-link.active {
    background-color: white;
    color: #0d6efd;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.form-floating > .form-control {
    border-radius: 10px;
    border: 1px solid #dee2e6;
}

.form-floating > .form-control:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13,110,253,0.1);
}

/* =========================================
   4. 商品卡片與輪播
   ========================================= */
.carousel-promo-img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.5s, filter 0.3s;
}

.carousel-item:hover .carousel-promo-img {
    transform: scale(1.02);
    filter: brightness(0.95);
}

.product-card {
    transition: transform 0.3s, box-shadow 0.3s;
    border: none;
    overflow: hidden;
    height: 100%;
    background: white;
    cursor: pointer;
    position: relative;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important;
}

.product-img-wrapper {
    position: relative;
    height: 200px;
    overflow: hidden;
    background: #eee;
}

.product-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s;
}

.product-card:hover img { transform: scale(1.1); }

.badge-category {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    z-index: 2;
}

.filter-sidebar {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    position: sticky;
    top: 10px;
}

.category-item {
    cursor: pointer;
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #555;
    transition: all 0.2s;
}

.category-item:hover {
    background-color: #f1f3f5;
    color: #000;
    transform: translateX(5px);
}

.category-item.active {
    background-color: #0d6efd;
    color: white;
    transform: translateX(5px);
}

.category-item.active .badge {
    background-color: rgba(255,255,255,0.3) !important;
    color: white !important;
}

/* =========================================
   5. 商品詳情 Modal
   ========================================= */

/* 手機與通用設定 */
#productDetailModal .col-lg-6.bg-light {
    justify-content: flex-start !important;
    display: flex;
    flex-direction: column;
}

/* 電腦版左側固定設定 */
@media (min-width: 992px) {
    #productDetailModal .col-lg-6.bg-light {
        position: sticky;       /* 黏性定位 */
        top: 0;                 /* 貼齊 Modal 頂部 */
        align-self: flex-start; /* 關鍵：不要隨右邊拉長而變高 */
        height: auto;           /* 高度由內容決定 */
        max-height: 100%;       /* 確保不超過視窗 */
        overflow-y: auto;       /* 如果左側內容本身太長，允許左側內部滾動 */
        z-index: 10;
    }
}

.modal-product-img {
    width: 100%;
    height: 350px;
    object-fit: contain;
    background-color: #fff;
    border-radius: 8px;
}

.thumbnail-container {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 0;
    width: 100%;
    scrollbar-width: thin;
}

.thumbnail-item {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    overflow: hidden;
    padding: 1px;
    background: #fff;
    opacity: 1 !important;
    transition: all 0.2s;
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

.thumbnail-item.active {
    border-color: #0d6efd;
    box-shadow: 0 0 0 2px rgba(13,110,253,0.1);
}

.thumbnail-item:hover {
    transform: translateY(-2px);
    border-color: #0d6efd;
}

#productDetailModal .carousel-indicators { display: none; }

.badge-colorful {
    background: linear-gradient(45deg, #0d6efd, #0dcaf0);
    color: white;
    font-size: 0.9rem;
    padding: 6px 15px;
    border-radius: 20px;
    border: none;
}

.quote-box-colorful {
    background: white;
    border: 2px dashed #b6d4fe;
    border-radius: 12px;
    padding: 15px;
    margin-top: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
}

.price-colorful {
    font-size: 1.6rem;
    font-weight: 800;
    color: #dc3545;
}

/* 規格清單列表樣式 (List Style) */
.spec-list {
    max-height: 190px;
    overflow-y: auto;
    margin-bottom: 10px;
    padding-right: 5px;
}

.spec-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed #eee;
}

.spec-row:last-child { border-bottom: none; }

.spec-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.spec-name {
    font-weight: bold;
    color: #333;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.spec-price {
    color: #dc3545;
    font-size: 0.9rem;
    font-weight: bold;
}

/* 列表內的小型數量選擇器 */
.spec-qty-control {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    overflow: hidden;
}

.spec-btn-action {
    width: 30px;
    height: 30px;
    border: none;
    background: #f8f9fa;
    color: #333;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.spec-btn-action:hover:not(:disabled) { background: #e2e6ea; }
.spec-btn-action:disabled { color: #ccc; cursor: not-allowed; background: #f8f9fa; }

.spec-input-qty {
    width: 40px;
    border: none;
    text-align: center;
    font-weight: bold;
    font-size: 0.95rem;
    color: #0d6efd;
    background: white;
    padding: 0;
}

/* 缺貨狀態文字 */
.out-of-stock-text {
    color: #adb5bd;
    font-size: 0.85rem;
    font-weight: bold;
    padding: 5px 10px;
    border: 1px dashed #dee2e6;
    border-radius: 4px;
    background: #f8f9fa;
}

.btn-add-colorful {
    background: linear-gradient(90deg, #0d6efd, #0a58ca);
    border: none;
    color: white;
    transition: all 0.3s;
}

.btn-add-colorful:hover:not(:disabled) {
    background: linear-gradient(90deg, #0a58ca, #0d6efd);
    transform: scale(1.02);
    box-shadow: 0 5px 15px rgba(13, 110, 253, 0.4);
}

.line-float-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: #06c755;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 6px 15px rgba(0,0,0,0.3);
    z-index: 2000;
    cursor: pointer;
    transition: transform 0.2s;
    animation: pulse-green 2s infinite;
}

.line-float-btn:hover { transform: scale(1.1); }
.line-float-btn i { font-size: 2.5rem; }

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(6, 199, 85, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(6, 199, 85, 0); }
    100% { box-shadow: 0 0 0 0 rgba(6, 199, 85, 0); }
}

/* =========================================
   Media Queries (手機版優化)
   ========================================= */
@media (max-width: 768px) {
    .thumbnail-container { display: none !important; }

    /* Modal 內的輪播指示器 */
    #productDetailModal .carousel-indicators { display: flex !important; margin-bottom: 0; }
    #productDetailModal .carousel-indicators [data-bs-target] { background-color: #0d6efd; height: 4px; }

    /* 圖片高度調整 */
    .modal-product-img { height: 250px; }
    .carousel-promo-img { height: 160px; }
    .product-img-wrapper { height: 130px; }

    /* 卡片內容調整 */
    .card-body { padding: 0.5rem !important; }
    .card-title { font-size: 0.9rem; margin-bottom: 0.2rem !important; }
    .row.g-4 { --bs-gutter-x: 0.5rem; --bs-gutter-y: 0.5rem; }
    .container { padding-left: 10px; padding-right: 10px; }

    /* Navbar 調整 */
    .btn-auth span { display: none; }
    .navbar-divider { margin: 0 8px; }

    /* Modal Padding 調整 */
    #productDetailModal .col-lg-6.bg-light { padding: 1.5rem !important; } /* 增加內距讓畫面不貼邊 */
    #productDetailModal .col-lg-6.bg-white { padding: 1.5rem !important; }

    /* ★★★ 手機版標題區域優化 (重點修改) ★★★ */
    .mobile-title-area {
        display: flex;
        flex-direction: column;       /* 強制垂直排列 */
        align-items: flex-start;      /* 靠左對齊 */
        /* margin-bottom: 20px;
        padding-bottom: 15px;         增加底部留白 */
        border-bottom: 1px solid #e9ecef; /* 加一條淡淡的分隔線 */
    }

    /* 分類標籤樣式微調 */
    .mobile-title-area .badge {
        font-size: 0.9rem;            /* 字體適中 */
        margin-bottom: 8px;           /* 與標題拉開距離 */
        padding: 6px 12px;            /* 增加標籤厚度 */
        align-self: flex-start;
    }

    /* 標題樣式微調 */
    .mobile-title-area h3 {
        font-size: 1.5rem;            /* 標題字體大小 */
        line-height: 1.4;             /* 增加行高，避免多行時太擠 */
        color: #212529 !important;    /* 加深顏色增加對比 */
        margin-bottom: 0;
        font-weight: 700;
    }

    .desktop-title-area { display: none; }
}

@media (min-width: 769px) {
    .mobile-title-area { display: none; }
    .desktop-title-area { display: block; }
}

@media (max-width: 992px) {
    .filter-sidebar { display: none; }
}