/* DBF UP — plan.css
   ส่วน "รายงานและแผน" — ชั้นวางเล่มจากตาราง law
   ------------------------------------------------------------
   ปกจริงในฐาน (admin/uploads/law/cover/) เป็นภาพ "จัตุรัส 600x600"
   ที่ออกแบบมาสวยอยู่แล้ว มีชื่อเรื่องอยู่ในรูป
   จึงเปลี่ยนกรอบปกจากทรง A4 แนวตั้ง (1:1.414) มาเป็นจัตุรัส 1:1
   และตัดลูกเล่นเลียนแบบสันหนังสือ/ขอบกระดาษที่ไม่เข้ากับปกจัตุรัสออก
   ============================================================ */

/* ขนาดปกในชั้นวาง — อยากใหญ่/เล็กกว่านี้ แก้ตัวเลขนี้ตัวเดียว */
:root {
    --book-w: 232px;
}

/* ---------- หัวข้อ + ตัวเลขสรุป ---------- */
.plan-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 48px;
    align-items: flex-end;
    margin-bottom: clamp(34px, 5vw, 54px);
}

.plan-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 20px
}

.plan-stats {
    display: flex;
    margin: 0;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    background: #fff;
}

.plan-stats>div {
    padding: 16px 24px;
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 3px;
    text-align: right;
}

.plan-stats>div:first-child {
    border-left: 0
}

.plan-stats dd {
    margin: 0;
    font-size: 26px;
    font-weight: 200;
    line-height: 1.1;
    color: var(--green-deep);
    font-variant-numeric: tabular-nums;
}

.plan-stats dd.sm {
    font-size: 15px;
    font-weight: 300;
    padding-top: 6px
}

.plan-stats dt {
    font-size: 11px;
    color: rgba(11, 20, 14, .5);
    letter-spacing: .02em
}

.plan-filters {
    margin-bottom: 0;
    justify-content: flex-end
}

/* ============================================================
   ชั้นวางเล่ม — เลื่อนแนวนอนอัตโนมัติแบบ carousel
   ============================================================ */
.shelf-wrap {
    position: relative;
    margin: 0 -6px
}

.plan-shelf {
    display: flex;
    align-items: flex-start;
    gap: clamp(16px, 2vw, 26px);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scroll-behavior: smooth;
    padding: 12px 6px 18px;
    /* เผื่อที่ให้เงาและการยกตัวตอน hover */
    perspective: 1600px;
    cursor: grab;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.plan-shelf::-webkit-scrollbar {
    display: none
}

.plan-shelf.grabbing {
    cursor: grabbing;
    scroll-behavior: auto;
    scroll-snap-type: none
}

.plan-shelf:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 6px;
    border-radius: 14px
}

.shelf-empty {
    padding: 60px 0;
    text-align: center;
    color: rgba(11, 20, 14, .45);
    font-size: 14px
}

.book {
    flex: 0 0 var(--book-w);
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ---------- ตัวปก ---------- */
.book-cover {
    position: relative;
    display: block;
    aspect-ratio: 1/1;
    /* ตรงกับไฟล์จริง 600x600 */
    border-radius: 20px;
    overflow: hidden;
    background: var(--mist, #EEF3EC);
    border: 1px solid var(--line);
    box-shadow:
        0 2px 6px rgba(11, 20, 14, .08),
        0 20px 38px -20px rgba(11, 20, 14, .4);
    transition: transform .5s var(--ease), box-shadow .5s var(--ease), border-color .5s var(--ease);
    will-change: transform;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .7s var(--ease);
    user-select: none;
    -webkit-user-drag: none;
}

/* เงาจาง ๆ ที่ขอบล่าง ให้ป้าย "เปิดอ่าน" กับตัวเลขอ่านง่ายบนปกสีสด */
.book-cover::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 42%;
    z-index: 1;
    background: linear-gradient(transparent, rgba(6, 18, 10, .34));
    opacity: 0;
    transition: .45s var(--ease);
    pointer-events: none;
}

.book:hover .book-cover::after {
    opacity: 1
}

/* แถบสีประจำเว็บที่ขอบซ้าย — เหลือไว้เป็นกลิ่นอายสันหนังสือ */
.book-spine {
    position: absolute;
    left: 0;
    top: 14px;
    bottom: 14px;
    width: 4px;
    z-index: 3;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(180deg, #9C3FCC, #45BF90, #2AD87F);
    opacity: 0;
    transform: translateX(-4px);
    transition: .45s var(--ease);
}

.book:hover .book-spine {
    opacity: 1;
    transform: none
}

/* ปกจัตุรัสไม่ต้องมีขอบกระดาษเลียนแบบเล่มจริง */
.book-edge {
    display: none
}

/* ป้ายครั้งที่ */
.book-no {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 4;
    font-size: 10.5px;
    letter-spacing: .04em;
    padding: 6px 12px;
    border-radius: 100px;
    background: rgba(6, 18, 10, .5);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .32);
    backdrop-filter: blur(8px);
    transition: .4s var(--ease);
}

.book:hover .book-no {
    background: rgba(6, 18, 10, .72)
}

/* ป้ายเปิดอ่าน โผล่ตอน hover */
.book-open {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 14px;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 10px;
    font-size: 12px;
    color: #fff;
    border-radius: 100px;
    background: rgba(6, 18, 10, .58);
    border: 1px solid rgba(255, 255, 255, .26);
    backdrop-filter: blur(10px);
    transform: translateY(14px);
    opacity: 0;
    transition: .45s var(--ease);
}

.book-open i {
    font-size: 12px;
    color: var(--green-leaf)
}

/* ปกสำรองเมื่อไม่มีภาพ */
.book-blank {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    padding: 20px;
    background:
        radial-gradient(120% 80% at 20% 0%, rgba(98, 229, 161, .22), transparent 60%),
        linear-gradient(155deg, #1c4d33, #0d2a1c 55%, #123722);
    color: #fff;
}

.book-blank b {
    font-weight: 300;
    font-size: 19px
}

.book-blank i {
    font-style: normal;
    font-size: 11.5px;
    color: var(--green-leaf);
    opacity: .85
}

/* ---------- ยกปกขึ้นตอนชี้ ---------- */
@media (hover:hover) {
    .book:hover .book-cover {
        transform: translateY(-8px) scale(1.025);
        border-color: rgba(20, 168, 98, .45);
        box-shadow:
            0 4px 10px rgba(11, 20, 14, .12),
            0 34px 58px -24px rgba(11, 20, 14, .5);
    }

    .book:hover .book-cover img {
        transform: scale(1.06)
    }

    .book:hover .book-open {
        transform: none;
        opacity: 1
    }
}

.book:focus-visible .book-cover {
    outline: 2px solid var(--green);
    outline-offset: 4px
}

/* ---------- ชื่อเล่มใต้ปก ---------- */
.book-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px
}

.book-meta b {
    font-weight: 300;
    font-size: 14px;
    line-height: 1.55;
    color: var(--ink);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-meta small {
    font-size: 11.5px;
    color: rgba(11, 20, 14, .45);
    font-variant-numeric: tabular-nums
}

.book:hover .book-meta b {
    color: var(--green-deep)
}

/* ---------- ปุ่มลูกศรซ้าย-ขวา ---------- */
.shelf-arrow {
    position: absolute;
    top: calc(50% - 34px);
    z-index: 5;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--green-deep);
    box-shadow: 0 12px 28px -12px rgba(11, 20, 14, .35);
    transition: .35s var(--ease);
    opacity: 0;
}

.shelf-arrow.prev {
    left: -10px;
    transform: translateX(6px)
}

.shelf-arrow.next {
    right: -10px;
    transform: translateX(-6px)
}

.shelf-wrap:hover .shelf-arrow {
    opacity: 1;
    transform: none
}

.shelf-arrow:hover {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
    scale: 1.08
}

.shelf-arrow:focus-visible {
    opacity: 1;
    transform: none;
    outline: 2px solid var(--green);
    outline-offset: 3px
}

.shelf-wrap.no-scroll .shelf-arrow {
    display: none
}

/* ---------- แถบบอกตำแหน่งการเลื่อน ---------- */
.shelf-rail {
    height: 3px;
    border-radius: 100px;
    background: rgba(11, 20, 14, .08);
    margin: 4px 6px 0;
    overflow: hidden;
}

.shelf-rail i {
    display: block;
    height: 100%;
    width: 20%;
    border-radius: 100px;
    background: linear-gradient(90deg, #9C3FCC, #2AD87F);
    transition: transform .35s var(--ease), width .35s var(--ease);
}

.shelf-wrap.no-scroll .shelf-rail {
    display: none
}

.shelf-note {
    margin: 10px 6px 0;
    font-size: 12px;
    color: rgba(11, 20, 14, .45);
    text-align: right;
    font-variant-numeric: tabular-nums
}

/* ---------- ปุ่มแยกประเภทรายงาน ---------- */
.plan-filters .fpill i {
    font-size: 12px;
    color: var(--green-deep);
    transition: .3s var(--ease)
}

.plan-filters .fpill.on i {
    color: var(--green-leaf)
}

.plan-filters .pl-short {
    display: none
}

/* ============================================================
   เอกสารเผยแพร่อื่น ๆ (ของเดิม)
   ============================================================ */
.plan-docs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 13px;
    margin-top: clamp(34px, 4vw, 52px);
    padding-top: clamp(26px, 3vw, 36px);
    border-top: 1px solid var(--line);
}

.doc {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    font-size: 13.5px;
    transition: .35s var(--ease)
}

.doc:hover {
    border-color: var(--green);
    transform: translateY(-3px);
    box-shadow: 0 14px 34px -14px rgba(10, 40, 22, .22)
}

.doc svg {
    width: 20px;
    height: 20px;
    color: var(--green-deep);
    flex: none
}

.doc i {
    font-size: 17px;
    color: var(--green-deep);
    flex: none
}

.doc span small {
    display: block;
    font-size: 11.5px;
    color: rgba(11, 20, 14, .5)
}

/* ============================================================
   แถบความคืบหน้า — ใช้เฉพาะตอน API ไม่ตอบ (ข้อมูลสำรอง)
   ============================================================ */
.plan-bars {
    display: flex;
    flex-direction: column;
    gap: 21px
}

.pbar b {
    font-weight: 300;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 9px
}

.pbar b em {
    font-style: normal;
    color: var(--green-deep);
    font-weight: 400
}

.pbar .track {
    height: 10px;
    border-radius: 100px;
    background: rgba(14, 107, 65, .1);
    overflow: hidden
}

.pbar .fill {
    height: 100%;
    width: 0;
    border-radius: 100px;
    background: linear-gradient(90deg, #9C3FCC, #45BF90, #2AD87F);
    transition: width 1.2s var(--ease)
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width:900px) {
    .plan-head {
        grid-template-columns: 1fr;
        gap: 28px;
        align-items: flex-start
    }

    .plan-side {
        align-items: flex-start;
        width: 100%
    }

    .plan-filters {
        justify-content: flex-start
    }

    .plan-stats {
        width: 100%
    }

    .plan-stats>div {
        flex: 1;
        text-align: left;
        padding: 14px 18px
    }

    .book {
        flex-basis: 190px
    }

    .shelf-arrow {
        display: none
    }

    .shelf-note {
        text-align: left
    }

    .plan-filters .pl-full {
        display: none
    }

    .plan-filters .pl-short {
        display: inline
    }
}

@media (max-width:560px) {
    .shelf-wrap {
        margin: 0 -20px
    }

    .plan-shelf {
        padding-inline: 20px;
        scroll-snap-type: x mandatory
    }

    .book {
        flex-basis: 56vw
    }

    .plan-stats dd {
        font-size: 21px
    }

    .plan-stats dd.sm {
        font-size: 13px
    }

    .plan-stats>div {
        padding: 12px 14px
    }

    .book-meta b {
        font-size: 12.5px
    }

    .book-no {
        font-size: 9.5px;
        padding: 4px 9px
    }
}

@media (prefers-reduced-motion:reduce) {

    .book-cover,
    .book-cover img,
    .book-open,
    .book-spine,
    .shelf-rail i {
        transition: none
    }

    .book:hover .book-cover {
        transform: none
    }

    .plan-shelf {
        scroll-behavior: auto
    }
}