/* ==========================================================================
   product-sheet.css — การ์ดสินค้าแบบร้านออนไลน์บนมือถือ + หน้าสินค้าเต็มจอ (sheet)
   โหลดเฉพาะหน้าที่ประกาศ $page_css[] = '/css/product-sheet.css';
   เนื้อหาใน sheet ทั้งหมดก๊อปมาจาก HTML การ์ดที่อยู่ในหน้าอยู่แล้ว
   ไม่มีเนื้อหาใหม่ ไม่มี URL ใหม่ = SEO เดิมไม่เปลี่ยน
   ========================================================================== */

/* ==========================================================
   [1] กริดการ์ดบนมือถือ — 2 ใบต่อแถว
   ขอบเขต: การ์ดสินค้าจริง (แกลเลอรี + อุปกรณ์เสริม)
   ไม่รวมการ์ดเนื้อหา .content-cards-seo ที่มีปุ่มลิงก์ของตัวเองอยู่แล้ว
   ========================================================== */
@media (max-width: 520px) {
    .product-cards-seo:not(.content-cards-seo) .product-card-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

/* ==========================================================
   [2] กดการ์ดเปิดหน้าสินค้าเต็มจอ — ใช้เหมือนกันทั้งมือถือและคอม
   จึงไม่ต้องมีปุ่ม "อ่านเพิ่มเติม" ในการ์ดอีก (ทางเข้าซ้ำซ้อน)
   ซ่อนด้วย CSS เท่านั้น HTML ยังอยู่ในหน้าครบทุกบรรทัด (Googlebot อ่านได้เหมือนเดิม)
   ========================================================== */
.product-cards-seo:not(.content-cards-seo) .product-card-seo {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.product-cards-seo:not(.content-cards-seo) .product-card-details {
    display: none;
}

/* ==========================================================
   [2.1] การ์ดย่อบนมือถือ — เหลือ รูป / ชื่อ / ราคา
   ========================================================== */
@media (max-width: 767.98px) {
    .product-cards-seo:not(.content-cards-seo) .product-card-seo:hover {
        transform: none;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
        border-color: rgba(0, 188, 212, 0.18);
    }

    .product-cards-seo:not(.content-cards-seo) .product-card-seo:active {
        transform: scale(0.985);
    }

    .product-cards-seo:not(.content-cards-seo) .product-card-seo:hover .product-card-img {
        transform: none;
    }

    .product-cards-seo:not(.content-cards-seo) .product-card-body {
        padding: 8px 10px 10px;
        gap: 4px;
    }

    .product-cards-seo:not(.content-cards-seo) .product-card-title {
        font-size: 0.84rem;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .product-cards-seo:not(.content-cards-seo) .product-card-meta {
        font-size: 0.72rem;
    }

    .product-cards-seo:not(.content-cards-seo) .product-card-price {
        font-size: 0.95rem;
    }

    .product-cards-seo:not(.content-cards-seo) .product-card-desc {
        display: none;
    }
}

/* ==========================================================
   [3] หน้าสินค้าเต็มจอ (sheet) — เลื่อนเข้าจากขวา
   ========================================================== */
.psheet {
    position: fixed;
    inset: 0;
    z-index: 9990;
    display: none;
    background: #fff;
    transform: translateX(100%);
    transition: transform 0.28s ease;
}

.psheet.is-open {
    display: block;
}

.psheet.is-in {
    transform: translateX(0);
}

/* จอที่ 1 = ข้อมูลหลัก, จอที่ 2 = รายละเอียด (ทับซ้อนเข้ามาจากขวา) */
.psheet-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.psheet-screen--detail {
    transform: translateX(100%);
    transition: transform 0.26s ease;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
}

.psheet.show-detail .psheet-screen--detail {
    transform: translateX(0);
}

/* ---------- แถบหัว: ย้อนกลับ / ชื่อ / แชร์ ---------- */
.psheet-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.psheet-icon-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    line-height: 1;
    color: #0f172a;
    background: rgba(15, 23, 42, 0.06);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
}

.psheet-icon-btn:active {
    transform: scale(0.92);
    background: rgba(15, 23, 42, 0.12);
}

/* ปุ่มย้อนกลับ — ใหญ่และหนากว่าปุ่มอื่น เพราะเป็นทางออกหลักของหน้านี้ */
.psheet-icon-btn--back {
    width: 48px;
    height: 48px;
    font-size: 1.75rem;
    color: #0f172a;
    background: rgba(15, 23, 42, 0.08);
}

.psheet-icon-btn--back i {
    -webkit-text-stroke: 1px currentColor;
}

.psheet-bar-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- เนื้อหาที่เลื่อนได้ ---------- */
.psheet-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: 96px;
}

/* ---------- สไลด์รูป: เต็มความกว้าง ทีละรูป ปัดขวา→ซ้าย บอกตำแหน่งด้วยจุดด้านล่าง ---------- */
.psheet-gallery {
    position: relative;
    padding: 0 0 4px;
}

/* ปุ่มลูกศรเลื่อนรูป — จำเป็นบนคอมที่ปัดนิ้วไม่ได้ */
.psheet-nav {
    position: absolute;
    top: 0;
    bottom: 26px;
    /* เว้นแถวจุดด้านล่างไว้ ปุ่มจะอยู่กึ่งกลางรูปพอดี */
    margin: auto 0;
    z-index: 2;
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    line-height: 1;
    color: #0f172a;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 50%;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
}

.psheet-gallery.has-multi .psheet-nav {
    display: flex;
}

.psheet-nav:hover {
    background: #fff;
}

.psheet-nav:active {
    transform: scale(0.92);
}

.psheet-nav--prev {
    left: 10px;
}

.psheet-nav--next {
    right: 10px;
}

/* มือถือปัดนิ้วได้อยู่แล้ว ปุ่มบังรูปเปล่า ๆ */
@media (max-width: 767.98px) {
    .psheet-gallery.has-multi .psheet-nav {
        display: none;
    }
}

.psheet-slider {
    display: flex;
    gap: 0;
    padding: 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
}

.psheet-slider::-webkit-scrollbar {
    display: none;
}

.psheet-slide {
    flex: 0 0 100%;
    aspect-ratio: 1 / 1;
    max-height: 52vh;
    scroll-snap-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
    overflow: hidden;
}

.psheet-slide img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.psheet-slide-empty {
    font-size: 3rem;
    color: #cbd5e1;
}

.psheet-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    min-height: 8px;
}

.psheet-dot {
    width: 7px;
    height: 7px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.18);
    cursor: pointer;
    transition: width 0.2s ease, background 0.2s ease;
}

/* จุดเล็กเกินกว่าจะกดง่าย ขยายพื้นที่กดโดยไม่เปลี่ยนหน้าตา */
.psheet-dot {
    position: relative;
}

.psheet-dot::before {
    content: '';
    position: absolute;
    inset: -9px;
}

.psheet-dot.is-active {
    width: 18px;
    border-radius: 999px;
    background: #00bcd4;
}

.psheet-info {
    padding: 14px 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.psheet-price {
    font-size: 1.6rem;
    font-weight: 800;
    color: #10b981;
    letter-spacing: 0.2px;
    line-height: 1.2;
}

.psheet-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.4;
}

.psheet-meta {
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 500;
}

/* ป้ายข้อมูลสั้น ๆ ที่กรอกไว้ในแอดมิน เช่น รับน้ำหนัก / รหัสสินค้า / คลังเหลือ */
.psheet-specs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.psheet-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #0369a1;
    background: rgba(3, 105, 161, 0.08);
    border: 1px solid rgba(3, 105, 161, 0.18);
    border-radius: 999px;
}

.psheet-chip i {
    color: #00bcd4;
}

.psheet-desc {
    margin: 4px 0 0;
    font-size: 0.9rem;
    color: #334155;
    line-height: 1.6;
    white-space: pre-wrap;
}

.psheet-detail-body {
    padding: 14px 16px 18px;
}

.psheet-empty {
    padding: 30px 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 0.9rem;
}

/* ---------- แถบปุ่มล่างติดขอบจอ ---------- */
.psheet-footbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}

.psheet-btn {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 12px 10px;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 700;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    text-decoration: none !important;
    transition: filter 0.2s ease, transform 0.15s ease;
}

.psheet-btn:active {
    transform: scale(0.98);
}

.psheet-btn--ghost {
    color: #0369a1;
    background: rgba(3, 105, 161, 0.08);
    box-shadow: inset 0 0 0 1.5px rgba(3, 105, 161, 0.28);
}

.psheet-btn--calc {
    color: #fff;
    background: linear-gradient(135deg, #e67e22, #f39c12);
    box-shadow: 0 4px 12px rgba(230, 126, 34, 0.32);
}

/* ---------- จอคอม: กรอบเท่ากล่อง .detail-block-glass ของหมวดนั้น ไม่เต็มจอ ----------
   ตำแหน่ง/ขนาดจริงวัดจากกล่องที่กดการ์ด แล้วส่งมาเป็นตัวแปร --psheet-* โดย product-sheet.js */
@media (min-width: 768px) {
    .psheet {
        inset: auto;
        top: var(--psheet-top, 16px);
        left: var(--psheet-left, 16px);
        width: var(--psheet-w, calc(100vw - 32px));
        height: var(--psheet-h, calc(100vh - 32px));
        border-radius: 18px;
        overflow: hidden;
        box-shadow: 0 26px 70px rgba(15, 23, 42, 0.3);
        /* กรอบไม่เต็มจอแล้ว เลื่อนเข้าจากขวาจะโผล่นอกกรอบ ใช้จาง ๆ เข้าแทน */
        transform: none;
        opacity: 0;
        transition: opacity 0.2s ease;
    }

    .psheet.is-in {
        opacity: 1;
    }

    body.psheet-open::after {
        content: '';
        position: fixed;
        inset: 0;
        z-index: 9989;
        background: rgba(15, 23, 42, 0.42);
    }

    /* กรอบบนคอมกว้างกว่ามือถือมาก คุมความสูงรูปด้วยสัดส่วนของกรอบแทนสี่เหลี่ยมจัตุรัส */
    .psheet-slide {
        aspect-ratio: auto;
        height: calc(var(--psheet-h, 80vh) * 0.52);
        max-height: none;
    }

    .psheet-dots {
        margin-top: 12px;
    }

    /* ข้อความไม่ต้องลากยาวเต็มกรอบกว้าง ๆ อ่านยาก */
    .psheet-info,
    .psheet-detail-body {
        max-width: 920px;
        padding-left: 24px;
        padding-right: 24px;
    }

    .psheet-footbar {
        justify-content: center;
    }

    .psheet-footbar .psheet-btn {
        flex: 0 1 260px;
    }

    .psheet-title {
        font-size: 1.15rem;
    }
}

/* ==========================================================
   [4] บล็อกในจอรายละเอียด — ใช้สไตล์ .pc-* เดิมจาก style.css
   ปรับเฉพาะรูปเพิ่มเติมให้เลื่อนแนวนอน (ปัดขวา→ซ้าย) แทนกริด
   ========================================================== */
.psheet .pc-block {
    margin-bottom: 20px;
}

.psheet .pc-block-title {
    font-size: 0.95rem;
    margin-bottom: 10px;
}

.psheet .pc-catalog-btn {
    width: 100%;
    justify-content: center;
    padding: 12px 16px;
}

.psheet-video {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
}

.psheet-video iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ==========================================================
   [5] ตอนเปิดหน้าสินค้า: ล็อกการเลื่อนหน้าหลัก + ซ่อนปุ่มลอย
   ========================================================== */
body.psheet-open {
    overflow: hidden;
}

body.psheet-open .site-floating-dock {
    display: none !important;
}

/* ==========================================================
   [6] แจ้งเตือนสั้น ๆ (ใช้ตอนคัดลอกลิงก์เมื่อเครื่องไม่มีเมนูแชร์)
   ========================================================== */
.psheet-toast {
    position: fixed;
    left: 50%;
    bottom: 88px;
    transform: translateX(-50%) translateY(8px);
    z-index: 9996;
    max-width: 82vw;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    background: rgba(15, 23, 42, 0.92);
    border-radius: 999px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.psheet-toast.is-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
