/* ============================================
   Frontend CSS - 專業前台樣式
   ============================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f8fafc;
    --card: #fff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --accent: #f97316;
    --success: #10b981;
    --danger: #ef4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
                 "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    padding-top: 68px;
    padding-bottom: 64px;
}

a { color: inherit; }

/* ============================================
   Header
   ============================================ */
.site-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: #fff;
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    box-shadow: 0 1px 3px rgba(0,0,0,.03);
}

.site-header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
    height: 68px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 18px;
    white-space: nowrap;
}
.logo-mark { font-size: 22px; }

.site-nav {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.site-nav a {
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    transition: all .15s;
}
.site-nav a:hover { background: var(--bg); color: var(--primary); }

.site-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.site-search {
    display: flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.site-search input {
    border: none;
    background: transparent;
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
    width: 200px;
}
.site-search button {
    background: none;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-muted);
}
.site-search button:hover { color: var(--primary); }

.wallet-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.btn-login, .btn-register {
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}
.btn-login { color: var(--text); }
.btn-login:hover { background: var(--bg); }
.btn-register {
    background: var(--primary);
    color: #fff;
}
.btn-register:hover { background: var(--primary-dark); }

/* ============================================
   會員選單（修正 hover 收回問題）
   ============================================ */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    cursor: pointer;
    /* 增加底部熱區，讓滑鼠從頭像移到選單時不離開元素 */
    padding-bottom: 10px;
    margin-bottom: -10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0,0,0,.08);
    min-width: 160px;
    padding: 6px;
    z-index: 200;

    /* 用 opacity + visibility 取代 display，可以加過渡效果 */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity .18s ease, visibility .18s ease, transform .18s ease;

    /* 用 ::before 建立透明橋接區，覆蓋 margin-top 的縫隙 */
    margin-top: 8px;
}

.user-dropdown::before {
    content: "";
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
    background: transparent;
}

/* 由 JS 加上 .show class 來顯示 */
.user-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown a {
    display: block;
    padding: 8px 12px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    transition: background .12s;
}

.user-dropdown a:hover {
    background: var(--bg);
}

/* ============================================
   Main
   ============================================ */
.site-main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 20px;
}

.section-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title::before {
    content: "";
    width: 4px;
    height: 22px;
    background: var(--primary);
    border-radius: 2px;
}

/* Hero / 輪播 */
.hero-carousel {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 32px;
    background: #e2e8f0;
    min-height: 320px;
}
.carousel-slide {
    display: none;
    position: relative;
}
.carousel-slide.active { display: block; }
.carousel-slide img {
    width: 100%;
    height: 420px;
    object-fit: cover;
    display: block;
}
.carousel-caption {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 32px;
    background: linear-gradient(to top, rgba(0,0,0,.75), transparent);
    color: #fff;
}
.carousel-caption h2 { font-size: 26px; margin-bottom: 4px; }
.carousel-caption p { font-size: 15px; opacity: .9; }

.carousel-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px; height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,.9);
    border: none;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    z-index: 10;
}
.carousel-nav:hover { background: #fff; transform: translateY(-50%) scale(1.1); }
.carousel-nav.prev { left: 16px; }
.carousel-nav.next { right: 16px; }

.carousel-dots {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
}
.carousel-dots span {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: rgba(255,255,255,.5);
    cursor: pointer;
    transition: all .2s;
}
.carousel-dots span.active { background: #fff; width: 24px; border-radius: 5px; }

/* 廣告區 */
.ad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.ad-card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: all .2s;
    display: block;
}
.ad-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0,0,0,.08);
}
.ad-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}
.ad-card-body {
    padding: 12px 14px;
}
.ad-card-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}
.ad-card-tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #f1f5f9;
    color: var(--text-muted);
}
.ad-card-tag.paid { background: #fee2e2; color: #991b1b; }
.ad-card-tag.charity { background: #d1fae5; color: #065f46; }

/* 產品 / 公司卡片 */
.product-grid, .company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.product-card, .company-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
    transition: all .2s;
    text-decoration: none;
    color: inherit;
    display: block;
}
.product-card:hover, .company-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0,0,0,.06);
    border-color: transparent;
}
.product-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    background: #f8fafc;
}
.product-card-body { padding: 12px 14px; }
.product-card-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.product-card-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}
.product-card-company {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.company-card { padding: 20px; text-align: center; }
.company-card img {
    width: 72px; height: 72px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 12px;
    display: block;
    background: #f1f5f9;
}
.company-card-name { font-weight: 700; margin-bottom: 4px; }
.company-card-type { font-size: 13px; color: var(--text-muted); }

/* ============================================
   底部導航
   ============================================ */
.bottom-nav {
    display: none;
}
@media (max-width: 900px) {
    .site-nav, .site-search { display: none; }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: #fff;
        border-top: 1px solid var(--border);
        justify-content: space-around;
        padding: 6px 0;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0,0,0,.04);
    }
    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 11px;
        gap: 2px;
        padding: 6px 12px;
        flex: 1;
    }
    .bottom-nav a i { font-size: 20px; font-style: normal; }
    .bottom-nav a.active { color: var(--primary); }

    .hero-carousel, .carousel-slide img { min-height: 200px; height: 220px; }
    .carousel-caption { padding: 16px; }
    .carousel-caption h2 { font-size: 18px; }
    .carousel-caption p { font-size: 13px; }
    .carousel-nav { width: 36px; height: 36px; font-size: 16px; }

    .site-main { padding: 16px 12px; }
    .section-title { font-size: 18px; }
    .product-grid, .company-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .ad-grid { grid-template-columns: 1fr; }
    .product-card img { height: 120px; }
}

/* ============================================
   Footer
   ============================================ */
.site-footer {
    background: #0f172a;
    color: #cbd5e1;
    padding: 40px 20px 20px;
    margin-top: 60px;
}
.footer-cols {
    max-width: 1280px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 30px;
}
.footer-cols h4 {
    color: #fff;
    font-size: 15px;
    margin-bottom: 12px;
}
.footer-cols a, .footer-cols p {
    display: block;
    color: #94a3b8;
    text-decoration: none;
    font-size: 13px;
    margin-bottom: 6px;
}
.footer-cols a:hover { color: #fff; }
.footer-bottom {
    max-width: 1280px;
    margin: 30px auto 0;
    padding-top: 20px;
    border-top: 1px solid #1e293b;
    text-align: center;
    color: #64748b;
    font-size: 12px;
}

/* ============================================
   通用元件
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
}
.btn:hover { background: var(--bg); }
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); }

.card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 20px;
}
/* ============================================
   Toast 通知
   ============================================ */
.toast {
    position: fixed;
    left: 50%;
    bottom: 90px;
    transform: translateX(-50%) translateY(20px);
    background: #0f172a;
    color: #fff;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,.2);
    opacity: 0;
    transition: all .3s cubic-bezier(.2,.9,.3,1.2);
    z-index: 9999;
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast-success { background: #059669; }
.toast-error   { background: #dc2626; }
.toast-info    { background: #2563eb; }

/* ============================================
   搜尋建議
   ============================================ */
.search-suggest {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 6px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,.08);
    z-index: 500;
    max-height: 320px;
    overflow-y: auto;
}
.search-suggest a {
    display: block;
    padding: 10px 14px;
    color: #0f172a;
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid #f1f5f9;
}
.search-suggest a:last-child { border-bottom: none; }
.search-suggest a:hover { background: #f8fafc; }

/* ============================================
   分頁
   ============================================ */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 32px 0;
    flex-wrap: wrap;
}
.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #334155;
    text-decoration: none;
    font-size: 14px;
    transition: all .15s;
}
.pagination a:hover { background: #f1f5f9; color: #2563eb; border-color: #2563eb; }
.pagination .current {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
    font-weight: 600;
}
.pagination .disabled { opacity: .4; cursor: not-allowed; }

/* ============================================
   篩選列
   ============================================ */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 24px;
    align-items: center;
}
.filter-bar select,
.filter-bar input {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: #fff;
}
.filter-bar select:focus,
.filter-bar input:focus { border-color: #2563eb; }
.filter-bar .filter-label { font-size: 13px; color: #64748b; font-weight: 600; }

/* ============================================
   空狀態
   ============================================ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #64748b;
}
.empty-state .empty-icon {
    font-size: 56px;
    margin-bottom: 14px;
    display: block;
    opacity: .5;
}
.empty-state h3 {
    color: #0f172a;
    margin-bottom: 8px;
    font-size: 18px;
}

/* ============================================
   商品詳細頁
   ============================================ */
.product-detail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    background: #fff;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    padding: 32px;
    margin-bottom: 32px;
}
.product-detail-img {
    width: 100%;
    border-radius: 12px;
    background: #f8fafc;
    object-fit: contain;
    aspect-ratio: 1/1;
}
.product-detail-info h1 {
    font-size: 24px;
    color: #0f172a;
    margin-bottom: 12px;
    line-height: 1.3;
}
.product-detail-price {
    font-size: 32px;
    color: #f97316;
    font-weight: 700;
    margin: 16px 0;
}
.product-detail-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 0;
    border-top: 1px solid #f1f5f9;
    border-bottom: 1px solid #f1f5f9;
    margin-bottom: 20px;
}
.product-detail-meta > div {
    display: flex;
    gap: 12px;
    font-size: 14px;
    color: #475569;
}
.product-detail-meta > div > span:first-child {
    color: #94a3b8;
    min-width: 70px;
}
.qty-selector {
    display: inline-flex;
    align-items: center;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    margin-right: 12px;
}
.qty-selector button {
    width: 40px;
    height: 40px;
    background: #f8fafc;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #475569;
}
.qty-selector button:hover { background: #e2e8f0; }
.qty-selector input {
    width: 60px;
    height: 40px;
    border: none;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    outline: none;
}

@media (max-width: 768px) {
    .product-detail { grid-template-columns: 1fr; padding: 20px; gap: 20px; }
    .product-detail-price { font-size: 26px; }
}

/* ============================================
   廠商列表
   ============================================ */
.company-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.company-card-lg {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 20px;
    display: flex;
    gap: 14px;
    text-decoration: none;
    color: inherit;
    transition: all .2s;
}
.company-card-lg:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0,0,0,.06);
    border-color: transparent;
}
.company-card-lg img {
    width: 64px; height: 64px;
    border-radius: 12px;
    object-fit: cover;
    background: #f8fafc;
    flex-shrink: 0;
}
.company-card-lg-info { flex: 1; min-width: 0; }
.company-card-lg-name {
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.company-card-lg-type {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 6px;
}
.company-card-lg-desc {
    font-size: 13px;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ============================================
   媒合列表
   ============================================ */
.match-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.match-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 20px;
    text-decoration: none;
    color: inherit;
    transition: all .2s;
    display: block;
}
.match-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0,0,0,.06);
}
.match-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.match-card-keyword {
    font-size: 17px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 8px;
}
.match-card-meta {
    display: flex;
    gap: 12px;
    font-size: 13px;
    color: #64748b;
    margin-top: 10px;
    flex-wrap: wrap;
}
.match-card-desc {
    font-size: 13px;
    color: #94a3b8;
    margin-top: 8px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ============================================
   公告
   ============================================ */
.announcement-item {
    display: block;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 12px;
    text-decoration: none;
    color: inherit;
    transition: all .2s;
}
.announcement-item:hover {
    border-color: #2563eb;
    box-shadow: 0 4px 16px rgba(37,99,235,.08);
}
.announcement-item h3 {
    font-size: 16px;
    color: #0f172a;
    margin-bottom: 8px;
}
.announcement-item .meta {
    font-size: 12px;
    color: #94a3b8;
}
.announcement-item .excerpt {
    font-size: 14px;
    color: #64748b;
    margin-top: 8px;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   錢包
   ============================================ */
.wallet-card {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff;
    border-radius: 16px;
    padding: 28px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}
.wallet-card::after {
    content: "💰";
    position: absolute;
    right: -10px;
    bottom: -20px;
    font-size: 120px;
    opacity: .1;
}
.wallet-card-label { font-size: 13px; opacity: .85; margin-bottom: 6px; }
.wallet-card-balance {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 16px;
}
.wallet-card-actions {
    display: flex;
    gap: 10px;
}
.wallet-card-actions .btn {
    background: rgba(255,255,255,.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,.3);
}
.wallet-card-actions .btn:hover {
    background: rgba(255,255,255,.25);
}

/* ============================================
   模組選購
   ============================================ */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}
.module-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 24px;
    transition: all .2s;
    position: relative;
    overflow: hidden;
}
.module-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 40px rgba(0,0,0,.08);
}
.module-card.owned::before {
    content: "✓ 已擁有";
    position: absolute;
    top: 12px;
    right: 12px;
    background: #d1fae5;
    color: #065f46;
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.module-icon {
    font-size: 42px;
    margin-bottom: 12px;
    display: block;
}
.module-name {
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 8px;
}
.module-desc {
    font-size: 13px;
    color: #64748b;
    line-height: 1.6;
    margin-bottom: 16px;
    min-height: 42px;
}
.module-price {
    font-size: 24px;
    font-weight: 700;
    color: #f97316;
    margin-bottom: 16px;
}
.module-price small {
    font-size: 12px;
    color: #94a3b8;
    font-weight: normal;
}
.module-price .free { color: #10b981; }
