/*
 * 前台（顧客頁面）共用版型：頁首置中、頁尾、首頁輪播／分類／橫向商品列。
 * 只在顧客頁面引入（index、products、about、contact、cart、payment、
 * order-success、orders、profile、messages、knowledge），後台 /admin/ 不引入，
 * 所以這裡的覆寫不會影響管理系統的頁首頁尾。
 * 一定要放在 style.css / common.css 之後引入，才能覆寫原本的規則。
 */

:root {
    --sf-green: #4caf50;
    --sf-green-deep: #2e7d32;
    --sf-green-soft: #f1f8f1;
    --sf-footer-bg: #1f2a24;
    --sf-footer-text: #c9d3cc;
}

/* ---------- 頁首（桌面版）：Logo 置中、導覽列在下一排置中 ---------- */
/* 手機版原本就是「左漢堡、中 Logo、右購物車」，不需要改，只動 769px 以上 */
@media (min-width: 769px) {
    header {
        padding: 0.9em 0 0;
        border-top: 4px solid var(--sf-green);
    }

    header .container {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        grid-template-areas:
            ". logo right"
            "nav nav nav";
        align-items: center;
        row-gap: 0.4em;
    }

    header .logo-container {
        grid-area: logo;
        justify-self: center;
        margin: 0;
        max-width: none;
    }

    header .header-right {
        grid-area: right;
        justify-self: end;
        margin-left: 0;
    }

    header nav {
        grid-area: nav;
        justify-content: center;
        border-top: 1px solid #eee;
    }

    header nav ul li a {
        display: inline-block;
        font-size: 1em;
        padding: 0.75em 0;
        letter-spacing: 0.08em;
    }

    header nav ul li a::after {
        bottom: 0.35em;
    }

    /* 隨捲動縮放：頁面最上方比較大，往下捲（body.header-compact，由 common.js 切換）縮小 */
    header,
    header .logo-image,
    header .logo h1,
    header .logo p,
    header nav ul li a {
        transition: all 0.3s ease;
    }

    header .logo-image {
        height: 4em;
    }

    header .logo h1 {
        font-size: 2em;
    }

    body.header-compact header {
        padding-top: 0.35em;
    }

    body.header-compact header .logo-image {
        height: 2.4em;
    }

    body.header-compact header .logo h1 {
        font-size: 1.4em;
        margin-bottom: 0;
    }

    body.header-compact header .logo p {
        font-size: 0;
        opacity: 0;
    }

    body.header-compact header nav ul li a {
        padding: 0.45em 0;
        font-size: 0.95em;
    }
}

@media (min-width: 769px) and (prefers-reduced-motion: reduce) {
    header,
    header .logo-image,
    header .logo h1,
    header .logo p,
    header nav ul li a {
        transition: none;
    }
}

/* ---------- 頁尾 ---------- */
footer.site-footer {
    background-color: var(--sf-footer-bg);
    color: var(--sf-footer-text);
    padding: 3.5em 0 0;
    border-bottom: 8px solid var(--sf-green);
}

.site-footer .footer-content {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2em;
    margin-bottom: 2.5em;
    text-align: center;
}

.site-footer .footer-section h3 {
    font-size: 1.1em;
    color: #fff;
    margin-bottom: 1em;
    letter-spacing: 0.08em;
}

.site-footer .footer-section p {
    color: var(--sf-footer-text);
    font-size: 0.95em;
    margin-bottom: 0.5em;
}

.site-footer .footer-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.site-footer .footer-links li {
    margin-bottom: 0.55em;
}

.site-footer .footer-links a {
    color: var(--sf-footer-text);
    font-size: 0.95em;
}

.site-footer .footer-links a:hover {
    color: var(--sf-green);
}

.site-footer .social-links {
    justify-content: center;
}

.site-footer .social-links a {
    margin: 0 0.3em;
}

/* ---------- 官方 LINE（頁尾第一欄、聯絡我們頁） ---------- */
/* LINE 品牌綠 #06C755 */
.social-links a.social-line:hover {
    background-color: #06C755;
}

.line-official {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.7em;
    margin-top: 1.4em;
}

.line-official-qr {
    width: 120px;
    height: 120px;
    padding: 6px;
    background-color: #fff;
    border-radius: 10px;
}

.line-official-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45em;
    padding: 0.6em 1.3em;
    border-radius: 999px;
    background-color: #06C755;
    color: #fff;
    font-weight: 600;
    font-size: 0.92em;
    white-space: nowrap;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.line-official-btn:hover,
.line-official-btn:focus-visible {
    background-color: #05a648;
    color: #fff;
}

.line-official-btn i {
    font-size: 1.25em;
}

.site-footer .footer-section .line-official-id {
    margin: 0;
    font-size: 0.85em;
    letter-spacing: 0.03em;
}

/* 聯絡我們頁：靠左排，QR Code 要有邊框才看得出範圍（背景是白的） */
.line-official.line-official-inline {
    align-items: flex-start;
    margin-top: 0.8em;
}

.line-official-inline .line-official-qr {
    border: 1px solid #e3e8e4;
}

.contact-item-line .contact-icon {
    color: #06C755;
}

/* 聯絡資訊的信箱是一長串不能斷行的字，很窄的手機（320px）上會把整欄撐出螢幕 */
.contact-details,
.contact-text {
    min-width: 0;
}

.contact-text p {
    overflow-wrap: anywhere;
}

/* 手機：自己螢幕上的 QR Code 掃不到，不顯示；點按鈕直接開 LINE 加好友 */
@media (max-width: 768px) {
    .line-official-qr {
        display: none;
    }

    .line-official-btn {
        padding: 0.75em 1.5em;
        font-size: 1em;
    }

    /* 聯絡我們頁的欄位比較窄 */
    .line-official-inline .line-official-btn {
        padding: 0.65em 1.1em;
        font-size: 0.95em;
    }
}

.site-footer .copyright {
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding: 1.5em 0 1.75em;
    font-size: 0.88em;
    color: #9aa59e;
}

.site-footer .copyright p {
    margin-bottom: 0.35em;
}

.site-footer .footer-company {
    color: #dfe7e1;
    letter-spacing: 0.05em;
}

@media (max-width: 992px) {
    .site-footer .footer-content {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .site-footer .footer-content {
        grid-template-columns: 1fr;
        gap: 1.75em;
    }
}

/* ---------- 首頁：區塊標題色帶 ---------- */
.section-band {
    background-color: var(--sf-green-deep);
    color: #fff;
    text-align: center;
    padding: 1.4em 1em;
    margin-bottom: 2.5em;
}

.section-band h2 {
    font-size: clamp(1.4rem, 3vw, 2rem);
    font-weight: 600;
    letter-spacing: 0.2em;
    margin: 0;
    color: #fff;
}

.home-band-section,
.home-band-section.featured-products {
    padding: 0 0 3.5em;
    margin-bottom: 0;
    background-color: #fff;
}

/* ---------- 首頁：圖片輪播 ---------- */
.home-carousel {
    position: relative;
    overflow: hidden;
    background-color: var(--sf-green-soft);
    aspect-ratio: 12 / 5;
    touch-action: pan-y;
    user-select: none;
}

.home-carousel[hidden] {
    display: none;
}

.home-carousel-track {
    display: flex;
    height: 100%;
    transition: transform 0.6s ease;
}

.home-carousel.is-dragging .home-carousel-track {
    transition: none;
}

.home-carousel-slide {
    flex: 0 0 100%;
    height: 100%;
}

.home-carousel-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    -webkit-user-drag: none;
}

.home-carousel-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 2.75em;
    height: 2.75em;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.85);
    color: var(--sf-green-deep);
    font-size: 1em;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 2;
}

.home-carousel-arrow:hover {
    background-color: #fff;
}

.home-carousel-arrow.prev { left: 1.25em; }
.home-carousel-arrow.next { right: 1.25em; }

.home-carousel-dots {
    position: absolute;
    bottom: 1em;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 0.6em;
    z-index: 2;
}

.home-carousel-dots button {
    width: 0.7em;
    height: 0.7em;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.home-carousel-dots button.active {
    background-color: var(--sf-green);
}

@media (max-width: 768px) {
    /* 手機改成比較高的比例，左右會裁掉一些，重要文字要放在圖片中間 */
    .home-carousel {
        aspect-ratio: 16 / 9;
    }

    .home-carousel-arrow {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .home-carousel-track {
        transition: none;
    }
}

/* ---------- 首頁：商品分類入口（水滴形圖片） ---------- */
/* 分類數量由後台決定：桌面一排 6 個、平板 4 個、手機 3 個 */
.category-tiles {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2.25em 1.5em;
    max-width: 1000px;
    margin: 0 auto;
    /* 水滴尖端轉 45 度後會超出方框，留一點上緣空間不要貼到色帶 */
    padding-top: 1.5em;
}

.category-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1em;
    color: #333;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-align: center;
    line-height: 1.35;
}

.category-tile:hover {
    color: var(--sf-green-deep);
}

.category-tile-shape {
    width: 7.5em;
    height: 7.5em;
    border-radius: 0 50% 50% 50%;
    transform: rotate(45deg);
    overflow: hidden;
    background-color: var(--sf-green);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.3s ease;
}

.category-tile:hover .category-tile-shape {
    box-shadow: 0 6px 16px rgba(46, 125, 50, 0.3);
}

.category-tile-shape img {
    width: 150%;
    height: 150%;
    max-width: none;
    object-fit: cover;
    transform: rotate(-45deg);
}

.category-tile-shape i {
    transform: rotate(-45deg);
    color: #fff;
    font-size: 2.4em;
}

@media (max-width: 992px) {
    .category-tiles {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 600px) {
    /* 手機：分類排成一排左右滑。以前一排 3 個、18 個分類要 6 排，
       精選商品被擠到很下面。右邊露出半個，提示可以往右滑 */
    .category-tiles {
        display: flex;
        gap: 1.1em;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* 水滴轉 45 度後四個角會超出方框，左右上下都要留空間，不然捲動區會把尖端切掉 */
        padding: 1.4em 1em 0.6em;
        margin: 0 -1em;
    }

    .category-tiles::-webkit-scrollbar {
        display: none;
    }

    .category-tile {
        /* 一個畫面放 4.4 個：最右邊固定露出半個，看得出來可以往右滑 */
        flex: 0 0 calc((100% - 4 * 1.1em) / 4.4);
        scroll-snap-align: start;
        font-size: 0.85em;
        gap: 0.9em;
    }

    .category-tile-shape {
        width: 4.8em;
        height: 4.8em;
    }

    .category-tile-shape i {
        font-size: 2em;
    }
}

/* ---------- 商品頁：手機一排兩個 ---------- */
/* 以前手機一排只有一個，12 個商品要滑好幾個畫面；
   一排兩個時卡片變窄，文字、按鈕都要跟著縮小，愛心按鈕才不會被擠出去 */
@media (max-width: 767px) {
    .products-display .product-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75em;
    }

    .products-display .product-image {
        height: 9.5em;
    }

    .products-display .product-info {
        padding: 0.75em 0.7em 0.9em;
    }

    .products-display .product-info h3 {
        font-size: 0.92em;
        line-height: 1.4;
        margin-bottom: 0.35em;
    }

    .products-display .product-desc {
        font-size: 0.78em;
        line-height: 1.5;
    }

    .products-display .product-detail-hint {
        font-size: 0.75em;
    }

    .products-display .product-price {
        font-size: 1.05em;
        margin: 0.3em 0 0.1em;
    }

    .products-display .stock-info {
        font-size: 0.72em;
    }

    .products-display .product-actions {
        gap: 0.4em;
    }

    .products-display .add-to-cart-btn {
        min-width: 0;
        padding: 0.6em 0.3em;
        font-size: 0.8em;
        white-space: nowrap;
    }

    .products-display .wish-btn {
        flex-shrink: 0;
        width: 2.3em;
        height: 2.3em;
    }

    .products-display .product-tag,
    .products-display .unavailable-badge {
        font-size: 0.7em;
    }
}

/* ---------- 首頁：精選商品橫向滑動 ---------- */
.product-slider {
    position: relative;
}

.product-slider .product-grid {
    display: flex;
    gap: 1.25em;
    overflow-x: auto;
    /* 商品不夠多、不需要滑動時置中；不支援 safe 的瀏覽器會照原本靠左 */
    justify-content: safe center;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    padding: 0.25em 0.25em 1em;
    margin-bottom: 1.5em;
    scrollbar-width: thin;
}

.product-slider .product-grid > .product-card {
    flex: 0 0 calc((100% - 3 * 1.25em) / 4);
    scroll-snap-align: start;
    height: auto;
}

.product-slider .product-grid > .loading-indicator,
.product-slider .product-grid > .no-products,
.product-slider .product-grid > .error-message {
    flex: 1 0 100%;
}

.product-slider-arrow {
    position: absolute;
    top: 40%;
    transform: translateY(-50%);
    width: 2.5em;
    height: 2.5em;
    border: none;
    border-radius: 50%;
    background-color: var(--sf-green-deep);
    color: #fff;
    cursor: pointer;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.product-slider-arrow[hidden] {
    display: none;
}

.product-slider-arrow.prev { left: -1.25em; }
.product-slider-arrow.next { right: -1.25em; }

@media (max-width: 1199px) {
    .product-slider .product-grid > .product-card {
        flex-basis: calc((100% - 2 * 1.25em) / 3);
    }
}

@media (max-width: 767px) {
    .product-slider .product-grid {
        gap: 0.9em;
    }

    /* 手機一次看到兩張多一點，提示可以往右滑 */
    .product-slider .product-grid > .product-card {
        flex-basis: 44%;
    }

    /* 只有一個精選商品時，44% 寬的卡片縮在中間、左右空很多，放大一點 */
    .product-slider .product-grid > .product-card:only-child {
        flex-basis: 62%;
    }

    /* 卡片變窄後，加入購物車按鈕要能縮小，愛心按鈕才不會被擠出卡片外 */
    .product-slider .product-info {
        padding: 0.9em 0.75em 1em;
    }

    .product-slider .add-to-cart-btn {
        min-width: 0;
        padding: 0.65em 0.3em;
        font-size: 0.8em;
        white-space: nowrap;
    }

    .product-slider .wish-btn {
        flex-shrink: 0;
        width: 2.5em;
        height: 2.5em;
    }

    .product-slider-arrow {
        display: none;
    }
}

/* ---------- 栽培小知識（knowledge.html）：分類分頁 + 文章卡片 + 單篇文章 ---------- */
.knowledge-page {
    padding-bottom: 4em;
    background-color: #fff;
}

.knowledge-intro {
    text-align: center;
    color: #666;
    max-width: 640px;
    margin: 0 auto 1.8em;
    line-height: 1.8;
}

.knowledge-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4em 1.6em;
    border-bottom: 1px solid #e6ece7;
    margin-bottom: 2em;
}

.knowledge-tabs:empty {
    display: none;
}

.knowledge-tabs a {
    color: #555;
    text-decoration: none;
    padding: 0.6em 0.2em;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    letter-spacing: 0.05em;
    transition: color 0.2s, border-color 0.2s;
}

.knowledge-tabs a:hover,
.knowledge-tabs a.active {
    color: var(--sf-green-deep);
    border-bottom-color: var(--sf-green);
}

.knowledge-tabs .count {
    color: #999;
    font-size: 0.85em;
}

.knowledge-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.8em;
}

.knowledge-grid > .loading-indicator,
.knowledge-grid > .no-products,
.knowledge-grid > .error-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3em 1em;
    color: #777;
}

.knowledge-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #edf1ee;
    border-radius: 10px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.knowledge-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 24px rgba(46, 125, 50, 0.12);
}

.knowledge-card-image {
    display: block;
    aspect-ratio: 4 / 3;
    background-color: var(--sf-green-soft);
    overflow: hidden;
}

.knowledge-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.knowledge-card:hover .knowledge-card-image img {
    transform: scale(1.04);
}

.knowledge-card-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 3em;
    color: #a5d6a7;
}

.knowledge-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.6em;
    padding: 1.2em 1.3em 1.3em;
    flex: 1;
}

.knowledge-card-category {
    align-self: flex-start;
    display: inline-block;
    font-size: 0.8em;
    color: var(--sf-green-deep);
    background-color: var(--sf-green-soft);
    border-radius: 999px;
    padding: 0.2em 0.8em;
    text-decoration: none;
}

.knowledge-card-title {
    font-size: 1.15em;
    font-weight: 600;
    color: #2c3e2f;
    line-height: 1.5;
}

.knowledge-card-excerpt {
    color: #666;
    font-size: 0.93em;
    line-height: 1.7;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.knowledge-card-meta {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85em;
    color: #999;
    padding-top: 0.8em;
    border-top: 1px solid #f0f0f0;
}

.knowledge-read-more {
    color: var(--sf-green-deep);
    font-weight: 600;
}

.knowledge-more {
    text-align: center;
    margin-top: 2.2em;
}

/* .btn 會設定 display，要明確蓋回去 hidden 才有效 */
.knowledge-more .btn[hidden],
.knowledge-article[hidden] {
    display: none;
}

/* 單篇文章 */
.knowledge-article {
    max-width: 780px;
    margin: 0 auto;
}

.knowledge-back {
    display: inline-block;
    color: var(--sf-green-deep);
    text-decoration: none;
    margin-bottom: 1.5em;
}

.knowledge-article-header {
    text-align: center;
    margin-bottom: 1.8em;
}

.knowledge-article-header h1 {
    font-size: clamp(1.5rem, 3.5vw, 2.1rem);
    color: #2c3e2f;
    line-height: 1.45;
    margin: 0.5em 0 0.4em;
}

.knowledge-article-date {
    color: #999;
    font-size: 0.9em;
    margin: 0;
}

.knowledge-cover,
.knowledge-section figure {
    margin: 0 0 1.6em;
}

.knowledge-cover img,
.knowledge-section figure img {
    width: 100%;
    border-radius: 10px;
    display: block;
}

/* 封面固定 4:3 裁切，直式照片才不會佔滿整個畫面 */
.knowledge-cover img {
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.knowledge-section figure img {
    max-height: 560px;
    object-fit: cover;
}

.knowledge-summary {
    font-size: 1.05em;
    color: #555;
    line-height: 1.9;
    background-color: var(--sf-green-soft);
    border-left: 4px solid var(--sf-green);
    border-radius: 0 8px 8px 0;
    padding: 1em 1.3em;
    margin: 0 0 2em;
}

.knowledge-section {
    margin-bottom: 2.2em;
}

.knowledge-section h2 {
    font-size: 1.3em;
    color: var(--sf-green-deep);
    border-bottom: 2px solid var(--sf-green-soft);
    padding-bottom: 0.4em;
    margin: 0 0 0.9em;
}

.knowledge-section p {
    color: #444;
    line-height: 1.95;
    margin: 0 0 1em;
}

.knowledge-cta {
    text-align: center;
    background-color: var(--sf-green-soft);
    border-radius: 10px;
    padding: 1.6em 1em;
    margin: 2.5em 0;
}

.knowledge-cta p {
    margin: 0 0 1em;
    color: #555;
}

.knowledge-related h2 {
    text-align: center;
    font-size: 1.3em;
    letter-spacing: 0.15em;
    color: #2c3e2f;
    margin: 0 0 1.2em;
}

@media (max-width: 992px) {
    .knowledge-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .knowledge-grid {
        grid-template-columns: 1fr;
        gap: 1.3em;
    }

    .knowledge-tabs {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 1.2em;
    }

    .knowledge-tabs a {
        white-space: nowrap;
    }
}
