/*
 * 前台（顧客頁面）共用版型：頁首置中、頁尾、首頁輪播／布告欄／分類／橫向商品列、
 * 商品詳細介紹彈窗。只在顧客頁面引入，後台 /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;
}

.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);
}

/* 水果插圖是透明背景的 PNG，整顆顯示在淺色底上，不要放大裁切 */
.category-tile-shape.is-illustration {
    background-color: var(--sf-green-soft);
    border: 3px solid var(--sf-green);
}

.category-tile-shape.is-illustration img {
    width: 72%;
    height: 72%;
    object-fit: contain;
}

.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) {
    .category-tiles {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.6em 0.6em;
    }

    .category-tile {
        font-size: 0.9em;
        gap: 0.8em;
    }

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

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

/* ---------- 首頁：精選商品橫向滑動 ---------- */
.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%;
    }

    /* 卡片變窄後，加入購物車按鈕要能縮小，愛心按鈕才不會被擠出卡片外 */
    .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;
    }
}


/* ---------- 首頁：布告欄（後台「布告欄管理」的文字公告，一到兩則） ---------- */
.bulletin-board {
    padding: 0 0 3.5em;
    background-color: #fff;
}

.bulletin-board[hidden] {
    display: none;
}

.bulletin-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.75em;
    max-width: 45em;
    margin: 0 auto;
}

.bulletin-grid.bulletin-grid-2 {
    max-width: 67.5em;
    grid-template-columns: 1fr 1fr;
}

.bulletin-card {
    background: #fff;
    border-radius: 1em;
    box-shadow: 0 0.625em 2.1875em rgba(0, 0, 0, 0.08);
    overflow: hidden;
    border: 1px solid #f0f0f0;
    border-top: 4px solid var(--sf-green);
}

.bulletin-card .bulletin-body {
    padding: 2em 2.25em;
}

.bulletin-card .bulletin-icon {
    font-size: 1.3em;
    color: var(--sf-green);
    display: block;
    margin-bottom: 0.8em;
}

.bulletin-card .bulletin-text {
    font-size: 1.05em;
    line-height: 1.9;
    color: #444;
    overflow-wrap: anywhere;
}

.bulletin-card .bulletin-image {
    width: 100%;
    line-height: 0;
    background: #fafafa;
}

/* 不裁切，依原始比例縮放，避免把公告圖片重要內容切掉 */
.bulletin-card .bulletin-image img {
    width: 100%;
    height: auto;
    display: block;
}

@media (max-width: 768px) {
    .bulletin-grid.bulletin-grid-2 {
        grid-template-columns: 1fr;
    }

    .bulletin-card .bulletin-body {
        padding: 1.5em;
    }
}

/* ---------- 首頁：果園介紹 ---------- */
.farm-showcase {
    padding: 4em 0;
    background-color: var(--sf-green-soft);
}

.farm-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3em;
    align-items: center;
}

.farm-image img {
    width: 100%;
    height: auto;
    border-radius: 1em;
    box-shadow: 0 0.8em 2em rgba(0, 0, 0, 0.12);
    display: block;
}

.farm-text h3 {
    font-size: 1.6em;
    color: var(--sf-green-deep);
    margin-bottom: 0.8em;
}

.farm-text p {
    color: #555;
    line-height: 1.9;
    margin-bottom: 1.2em;
}

.farm-text .specialty-note {
    background: #fff8e1;
    border-left: 4px solid #f9a825;
    border-radius: 0 0.5em 0.5em 0;
    padding: 0.9em 1.1em;
    margin-bottom: 1.5em;
}

.farm-text .specialty-note p {
    margin: 0;
    color: #6d5200;
}

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

/* ---------- 商品卡片：描述只顯示 2 行，完整內容在詳細介紹彈窗看 ---------- */
.product-card {
    cursor: pointer;
}

.product-card .product-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.4em;
}

/* 「查看詳細介紹」是一顆真的 <button>：卡片本身是 <div>，鍵盤的 Tab 走不到，
   做成按鈕之後 Tab 走得到、Enter/Space 也能開啟彈窗（事件會冒泡到 common.js 的卡片點擊代理）。
   下面把瀏覽器預設的按鈕外觀清掉，維持一行小字的樣子 */
.product-detail-hint {
    color: var(--sf-green);
    font-size: 0.8em;
    font-weight: 600;
    margin: 0 0 0.8em;
    display: flex;
    align-items: center;
    gap: 0.3em;
    -webkit-appearance: none;
    appearance: none;
    border: 0;
    background: none;
    padding: 0;
    font-family: inherit;
    line-height: inherit;
    text-align: left;
    cursor: pointer;
}

.product-detail-hint i {
    font-size: 0.85em;
}

.product-detail-hint:focus-visible {
    outline: 2px solid var(--sf-green-deep);
    outline-offset: 3px;
    border-radius: 3px;
}

/* 已下架商品：仍顯示但不可購買。徽章放左上角，跟右上角的商品標籤分開，避免疊在一起 */
.product-card.unavailable {
    opacity: 0.55;
}

.product-card.unavailable .product-image img {
    filter: grayscale(70%);
}

.unavailable-badge {
    position: absolute;
    top: 0.625em;
    left: 0.625em;
    padding: 0.25em 0.625em;
    background-color: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 0.75em;
    border-radius: 0.25em;
    z-index: 2;
}

/* 水蜜桃內傷提醒 */
.peach-warning {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 6px 10px;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 4px;
    font-size: 12px;
    color: #8d6e00;
    line-height: 1.4;
}

.peach-warning i {
    color: #f9a825;
    flex-shrink: 0;
}

/* ---------- 商品詳細介紹彈跳視窗 ---------- */
body.modal-open-noscroll {
    overflow: hidden;
}

.product-detail-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    align-items: center;
    justify-content: center;
    padding: 1.5em;
}

.product-detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.product-detail-panel {
    position: relative;
    background: #fff;
    border-radius: 1em;
    max-width: 50em;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 1.5em 3em rgba(0, 0, 0, 0.25);
    animation: productDetailPopIn 0.25s ease;
}

@keyframes productDetailPopIn {
    from { opacity: 0; transform: translateY(0.8em) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.product-detail-close {
    position: absolute;
    top: 0.8em;
    right: 0.8em;
    width: 2.2em;
    height: 2.2em;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0.125em 0.5em rgba(0, 0, 0, 0.15);
    z-index: 2;
    transition: all 0.2s ease;
}

.product-detail-close:hover {
    background: #ff6b6b;
    color: #fff;
    transform: rotate(90deg);
}

.product-detail-body {
    display: flex;
    flex-direction: column;
}

.product-detail-image {
    position: relative;
    height: 16em;
    flex-shrink: 0;
    background-color: #f8f8f8;
    border-radius: 1em 1em 0 0;
    overflow: hidden;
}

/* 詳細介紹要看清楚完整商品照，不能像卡片縮圖一樣裁切掉邊緣 */
.product-detail-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.product-detail-info {
    padding: 1.5em;
}

.product-detail-info h2 {
    font-size: 1.5em;
    color: #333;
    margin-bottom: 0.5em;
    line-height: 1.4;
}

.product-detail-price {
    font-size: 1.6em;
    font-weight: 700;
    color: #ff6b6b;
    margin-bottom: 0.3em;
}

.product-detail-stock {
    font-size: 0.9em;
    color: #777;
    font-weight: 500;
    margin-bottom: 1em;
}

.product-detail-section-label {
    font-size: 0.85em;
    font-weight: 700;
    color: var(--sf-green);
    margin: 0 0 0.4em;
}

.product-detail-desc-text {
    color: #555;
    font-size: 0.95em;
    line-height: 1.7;
    white-space: pre-wrap;
}

.product-detail-actions {
    display: flex;
    align-items: center;
    gap: 0.8em;
    margin-top: 1.5em;
    padding-top: 1.2em;
    border-top: 1px solid #f0f0f0;
}

.product-detail-actions .add-to-cart-btn {
    max-width: none;
}

@media (min-width: 700px) {
    .product-detail-body {
        flex-direction: row;
    }

    .product-detail-image {
        height: auto;
        min-height: 20em;
        width: 45%;
        border-radius: 1em 0 0 1em;
    }

    .product-detail-info {
        width: 55%;
        overflow-y: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .product-detail-panel {
        animation: none;
    }
}

/* ---------- 商品詳細介紹彈窗：分頁、加入購物車固定在下方 ---------- */
.product-detail-tabs {
    display: flex;
    gap: 0.25em;
    border-bottom: 2px solid #eef2ee;
    margin-bottom: 0.8em;
}

.product-detail-tabs[hidden],
.product-detail-section-label[hidden],
.product-detail-desc-text[hidden] {
    display: none;
}

.product-detail-tab {
    -webkit-appearance: none;
    appearance: none;
    background: none;
    border: 0;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 0.5em 0.9em;
    font-family: inherit;
    font-size: 0.95em;
    color: #777;
    cursor: pointer;
}

.product-detail-tab.active {
    color: var(--sf-green-deep);
    font-weight: 700;
    border-bottom-color: var(--sf-green);
}

.product-detail-tab:focus-visible {
    outline: 2px solid var(--sf-green-deep);
    outline-offset: 2px;
}

/* 文字很長時，「加入購物車」固定在彈窗底部，不用捲到最下面才按得到 */
.product-detail-actions {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding-bottom: 0.25em;
    z-index: 1;
}

/* ---------- 商品頁：手機一排兩個 ---------- */
@media (max-width: 600px) {
    .products-display .product-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75em;
    }

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

    .products-display .product-info {
        padding: 0.7em 0.65em 0.85em;
    }

    .products-display .product-info h3 {
        font-size: 1em;
        margin-bottom: 0.35em;
    }

    .products-display .product-desc {
        font-size: 0.8em;
    }

    .products-display .product-price {
        font-size: 1.05em;
    }

    .products-display .peach-warning {
        font-size: 11px;
        padding: 4px 6px;
    }

    /* 卡片變窄後，加入購物車按鈕要能縮小，愛心按鈕才不會被擠出卡片外 */
    .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.4em;
        height: 2.4em;
    }

    /* ---------- 首頁分類：手機排成一排，左右滑動 ---------- */
    .category-tiles {
        display: flex;
        overflow-x: auto;
        gap: 1.1em;
        padding: 1.2em 0.25em 0.75em;
        scroll-snap-type: x proximity;
        scrollbar-width: thin;
    }

    .category-tile {
        flex: 0 0 auto;
        width: 5.8em;
        scroll-snap-align: start;
    }
}
