/* ==========================================================================
   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 .product-card-seo:not(.content-video-card) {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.product-cards-seo .product-card-details {
    display: none;
}

/* การ์ดเนื้อหาที่ไม่มีปุ่มลิงก์ไปหน้าเว็บ — แถวปุ่มเหลือแต่ details ที่ซ่อนไปแล้ว
   ถ้าไม่ซ่อนด้วยจะเหลือเส้นประกับช่องว่างสูง 44px ค้างท้ายการ์ด */
.product-cards-seo .product-card-actions:not(:has(.product-card-link-btn)) {
    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-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: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    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;
}

/* Font Awesome ชุด fas ต้องน้ำหนัก 900 ไม่งั้นไอคอนไม่ขึ้น */
.psheet-icon-btn i {
    font-weight: 900;
    -webkit-text-stroke: 0;
}

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

.psheet-icon-btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}

.psheet-icon-btn--back {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    color: #0f172a;
    background: rgba(15, 23, 42, 0.06);
}

.psheet-icon-btn--back i {
    font-weight: 900;
    -webkit-text-stroke: 0;
}

.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 {
    /* รูปจากฐานส่วนใหญ่เป็น 1:1 — อย่าบังคับกว้าง×สูงเต็มกรอบ ไม่งั้นเฟี้ยน */
    width: auto;
    height: auto;
    max-width: 100%;
    max-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-info ในจอเดียวกัน — เลื่อนลงมาอ่านได้เลย ไม่ต้องกดเข้าจอที่ 2 */
.psheet-detail-body {
    padding: 4px 16px 18px;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    margin-top: 2px;
}

.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;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    padding-bottom: calc(8px + 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-footbar .psheet-icon-btn {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
}

.psheet-icon-btn--buy {
    color: #fff;
    background: #34a853;
}

.psheet-icon-btn--buy:hover {
    background: #2e9e4f;
}

.psheet-btn {
    flex: 0 1 180px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px;
    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:disabled {
    opacity: 0.55;
    cursor: default;
    transform: none;
}

.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, #2e9e4f, #34a853);
    box-shadow: 0 4px 12px rgba(52, 168, 83, 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);
    }

    /* กรอบบนคอมกว้าง — สไลด์ยังเต็มความกว้างเพื่อปัดได้ แต่จำกัดความสูง ไม่ยืดรูป 1:1 */
    .psheet-slide {
        aspect-ratio: auto;
        height: calc(var(--psheet-h, 80vh) * 0.52);
        max-height: none;
    }

    /* รูปเดียวจากฐาน: ช่องจัตุรัสอยู่กลาง ไม่ดึงเต็มความกว้างกรอบ */
    .psheet-gallery:not(.has-multi) .psheet-slider {
        justify-content: center;
    }

    .psheet-gallery:not(.has-multi) .psheet-slide {
        flex: 0 0 auto;
        width: min(100%, calc(var(--psheet-h, 80vh) * 0.52));
        aspect-ratio: 1 / 1;
        height: auto;
        max-height: calc(var(--psheet-h, 80vh) * 0.52);
    }

    .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 160px;
    }

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

/* ==========================================================
   [7] แผ่นข้อมูลสินค้าสำหรับปุ่ม "บันทึกรูป"
   วางไว้นอกจอให้เบราว์เซอร์จัดหน้าจริง (html2canvas ต้องการกล่องที่มีขนาด)
   แล้วถ่ายเป็น PNG — ผู้ใช้ไม่เห็นกล่องนี้บนหน้าเว็บ
   ขนาด = A4 แนวตั้งที่ 96dpi (794 × 1123 px) เนื้อหายาวเกินก็ยืดลงได้
   ========================================================== */
.psheet-doc {
    position: fixed;
    top: 0;
    left: -20000px;
    z-index: -1;
    width: 794px;
    min-height: 1123px;
    padding: 45px;
    background: #fff;
    color: #1f2937;
    font-family: 'Sarabun', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* เนื้อหายืดเต็มที่เหลือ ท้ายกระดาษจึงไปติดขอบล่างเสมอ ไม่ลอยกลางหน้าตอนข้อมูลน้อย */
.psheet-doc-main {
    flex: 1 1 auto;
    padding-bottom: 26px;
}

.psheet-doc * {
    box-sizing: border-box;
}

.psheet-doc-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 12px;
    border-bottom: 3px solid #0ea5e9;
}

.psheet-doc-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    flex: 0 0 auto;
}

.psheet-doc-brand {
    flex: 1 1 auto;
    min-width: 0;
}

.psheet-doc-brand strong {
    display: block;
    font-size: 23px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

.psheet-doc-brand span {
    display: block;
    font-size: 13px;
    color: #64748b;
}

.psheet-doc-head-right {
    flex: 0 0 auto;
    text-align: right;
}

.psheet-doc-head-right b {
    display: block;
    font-size: 17px;
    color: #0369a1;
}

.psheet-doc-head-right span {
    display: block;
    font-size: 13px;
    color: #64748b;
}

.psheet-doc-figs {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
}

/* ช่องรูปเป็นสี่เหลี่ยมจัตุรัสชัด ๆ — html2canvas อ่าน width/height คงที่ได้ดีกว่า aspect-ratio */
.psheet-doc-fig {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}

.psheet-doc-figs.is-one .psheet-doc-fig {
    width: 380px;
    height: 380px;
}

.psheet-doc-figs.is-two .psheet-doc-fig {
    width: 340px;
    height: 340px;
}

.psheet-doc-fig img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

.psheet-doc-title {
    margin-top: 18px;
}

.psheet-doc-title h1 {
    margin: 0;
    font-size: 25px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.3;
}

.psheet-doc-meta {
    margin-top: 3px;
    font-size: 14px;
    color: #64748b;
}

.psheet-doc-price {
    margin-top: 6px;
    font-size: 26px;
    font-weight: 700;
    color: #059669;
}

.psheet-doc-chips {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.psheet-doc-chips span {
    font-size: 13px;
    padding: 3px 12px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
}

.psheet-doc-block {
    margin-top: 20px;
}

.psheet-doc-block h2,
.psheet-doc-detail .pc-block-title {
    margin: 0 0 6px;
    padding-left: 10px;
    font-size: 17px;
    font-weight: 700;
    color: #0369a1;
    border-left: 4px solid #0ea5e9;
    line-height: 1.4;
}

.psheet-doc-detail .pc-block {
    margin-top: 18px;
}

.psheet-doc-detail .pc-block:first-child {
    margin-top: 0;
}

/* ไอคอน bootstrap เป็นฟอนต์ — html2canvas วาดออกมาเป็นสี่เหลี่ยม จึงตัดทิ้ง */
.psheet-doc i,
.psheet-doc svg {
    display: none;
}

.psheet-doc ul {
    margin: 0;
    padding-left: 22px;
}

.psheet-doc li {
    margin-bottom: 4px;
}

.psheet-doc-foot {
    flex: 0 0 auto;
    padding-top: 12px;
    border-top: 1px solid #cbd5e1;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 13px;
    color: #475569;
}

.psheet-doc-foot-logo {
    width: 56px;
    height: 56px;
    object-fit: contain;
    flex: 0 0 auto;
}

.psheet-doc-foot-info {
    flex: 1 1 auto;
    min-width: 0;
}

.psheet-doc-foot-info strong {
    display: block;
    font-size: 15px;
    color: #0f172a;
}

.psheet-doc-foot-url {
    flex: 0 0 auto;
    text-align: right;
    font-weight: 700;
    color: #0369a1;
}
