/* ===========================================================================
   กล่องคอมเมนต์เด้งทับ (ระยะ 15)
   ===========================================================================
   มือถือ    = กางจากล่างขึ้น เต็มความสูงเกือบทั้งจอ
   แท็บเล็ต+ = กล่องลอยกลางจอ มีขอบมน 4 มุม (แยกด้วย media query ด้านล่าง)
   =========================================================================== */
.cmt-overlay {
    position: fixed;
    inset: 0;
    z-index: 200020;
    background: rgba(0, 0, 0, .55);
    display: flex;
    align-items: flex-end;      /* มือถือ: ชิดล่าง */
    justify-content: center;
}
.cmt-overlay[hidden] { display: none; }

.cmt-sheet {
    width: 100%;
    max-width: 620px;
    /* [แก้ 12 ก.ย. 2569 — แม่บท 4/2] vh ไม่หดตามแป้นพิมพ์ → เพิ่ม dvh (ความสูงจอที่เหลือจริง)
       คู่กับ interactive-widget=resizes-content ใน layout-head.php แผ่นจะหดเองเมื่อแป้นพิมพ์ขึ้น
       บรรทัด vh คือ fallback ให้เบราว์เซอร์เก่าที่ยังไม่รู้จัก dvh */
    height: 88vh;
    height: 88dvh;
    display: flex;
    flex-direction: column;
    background: var(--mes-bg-card, #141416);
    border: 1px solid var(--mes-line, #2a2a2e);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    transition: transform .22s ease;
    will-change: transform;
}

/* ขีดจับด้านบน — จุดที่ลากลงเพื่อปิด (เหมือนเฟซบุ๊ก) */
.cmt-grip {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
    cursor: grab;
    touch-action: none;   /* กันเบราว์เซอร์แย่งท่าลากไปเลื่อนหน้าแทน */
}
.cmt-grip span {
    width: 44px;
    height: 4px;
    border-radius: 2px;
    background: #55555c;
}

.cmt-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 14px 10px;
    border-bottom: 1px solid var(--mes-line, #2a2a2e);
    font-weight: 700;
    color: var(--mes-gold, #d4af37);
    font-size: .92rem;
}
.cmt-close {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, .08);
    color: var(--mes-text, #ece5e0);
    cursor: pointer;
    font-size: .95rem;
}

.cmt-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}
.cmt-loading {
    text-align: center;
    color: var(--mes-text-mute, #6f6360);
    font-size: .85rem;
    padding: 30px 10px;
}

.cmt-item { display: flex; gap: 8px; }
.cmt-item.is-reply { padding-left: 34px; }   /* ตอบกลับย่อหน้าเข้าไป */

.cmt-avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    background: #1c1c20;
    color: var(--mes-gold, #d4af37);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
}
.cmt-avatar img { width: 100%; height: 100%; object-fit: cover; }

.cmt-bubble {
    background: #1c1c20;
    border-radius: 14px;
    padding: 8px 12px;
    max-width: 100%;
    min-width: 0;
}
.cmt-name { font-size: .78rem; color: var(--mes-gold-soft, #f0d98a); font-weight: 600; }
.cmt-text {
    font-size: .88rem;
    color: var(--mes-text, #ece5e0);
    line-height: 1.5;
    word-break: break-word;
}
.cmt-text img { max-width: 100%; border-radius: 8px; }
.cmt-media { max-width: 100%; border-radius: 8px; margin-top: 6px; display: block; }

.cmt-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 4px;
    font-size: .72rem;
    color: var(--mes-text-mute, #6f6360);
}
.cmt-reply-btn {
    background: none;
    border: none;
    color: var(--mes-text-dim, #a1938c);
    cursor: pointer;
    font-size: .72rem;
    padding: 0;
    font-family: inherit;
}
.cmt-reply-btn:hover { color: var(--mes-gold, #d4af37); }

/* แถบบอกว่ากำลังตอบกลับใคร */
.cmt-replying {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 14px;
    background: rgba(212, 175, 55, .08);
    border-top: 1px solid var(--mes-line, #2a2a2e);
    font-size: .76rem;
    color: var(--mes-gold-soft, #f0d98a);
}
.cmt-replying[hidden] { display: none; }
.cmt-replying button {
    background: none;
    border: none;
    color: var(--mes-text-dim, #a1938c);
    cursor: pointer;
    font-size: .76rem;
    font-family: inherit;
}

/* ช่องพิมพ์ล่างสุด — ติดขอบล่างเสมอ ไม่เลื่อนหนีตอนแป้นพิมพ์เด้ง */
.cmt-compose {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--mes-line, #2a2a2e);
    background: var(--mes-bg-card, #141416);
}
.cmt-compose textarea {
    flex: 1;
    min-height: 38px;
    max-height: 110px;
    padding: 9px 12px;
    border-radius: 18px;
    border: 1px solid var(--mes-line, #2a2a2e);
    background: #1c1c20;
    color: var(--mes-text, #ece5e0);
    font-family: inherit;
    font-size: .88rem;
    resize: none;
}
.cmt-send {
    flex-shrink: 0;
    padding: 9px 18px;
    border-radius: 18px;
    border: none;
    background: var(--mes-gold, #d4af37);
    color: #0c0c0e;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}
.cmt-send:disabled { opacity: .5; cursor: default; }

/* ---------------------------------------------------------------------------
   แท็บเล็ตขึ้นไป — กล่องลอยกลางจอแทนการกางจากล่าง (ตามที่เจ้าของสั่งให้แยก)
   --------------------------------------------------------------------------- */
/* [เพิ่ม 12 ก.ย. 2569 — แม่บท 4/2 · เจ้าของสั่ง "แท็บเล็ตเป็นตัวกำหนดขนาดใหญ่สุด"]
   จอกว้างแค่ไหนแผ่นก็ไม่เกิน 560px — มือถือเต็มขอบจอ แท็บเล็ต/คอมอยู่กึ่งกลาง ขนาดเท่ากันทุกเครื่อง */
@media (min-width: 768px) {
    .cmt-overlay { align-items: center; }
    .cmt-sheet { max-width: 560px; }
    .cmt-sheet {
        height: 78vh;
        height: 78dvh;
        border-radius: 16px;
        border-bottom: 1px solid var(--mes-line, #2a2a2e);
    }
    /* จอใหญ่ไม่ต้องมีขีดลาก — ใช้เมาส์กดปุ่ม ✕ สะดวกกว่าอยู่แล้ว */
    .cmt-grip { display: none; }
}

/* ---------------------------------------------------------------------------
   [ระยะ 16] เครื่องมือสื่อในคอมเมนต์ — วางลิงก์สกัดรูป / GIF
   --------------------------------------------------------------------------- */
.cmt-tool {
    flex-shrink: 0;
    height: 38px;
    min-width: 38px;
    padding: 0 8px;
    border-radius: 50%;
    border: 1px solid var(--mes-line, #2a2a2e);
    background: #1c1c20;
    color: var(--mes-gold, #d4af37);
    cursor: pointer;
    font-size: .78rem;
    font-family: inherit;
}
.cmt-tool:hover { border-color: var(--mes-gold, #d4af37); }

.cmt-media-bar {
    border-top: 1px solid var(--mes-line, #2a2a2e);
    padding: 10px 12px;
    background: #121214;
}
.cmt-media-bar[hidden] { display: none; }

.cmt-media-row { display: flex; gap: 8px; }
.cmt-media-row input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--mes-line, #2a2a2e);
    background: #1c1c20;
    color: var(--mes-text, #ece5e0);
    font-family: inherit;
    font-size: .82rem;
}
.cmt-media-row button {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    background: var(--mes-gold, #d4af37);
    color: #0c0c0e;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    font-size: .8rem;
}

.cmt-media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 6px;
    max-height: 190px;
    overflow-y: auto;
    margin-top: 8px;
}
.cmt-pick-cell {
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 1px solid var(--mes-line, #2a2a2e);
    border-radius: 8px;
    overflow: hidden;
    background: #101013;
    cursor: pointer;
}
.cmt-pick-cell:hover { border-color: var(--mes-gold, #d4af37); }
.cmt-pick-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* รูปที่เลือกแล้ว รอส่งไปกับคอมเมนต์ */
.cmt-attached {
    position: relative;
    padding: 8px 12px;
    border-top: 1px solid var(--mes-line, #2a2a2e);
}
.cmt-attached[hidden] { display: none; }
.cmt-attached img {
    max-height: 110px;
    border-radius: 8px;
    display: block;
}
.cmt-attached button {
    position: absolute;
    top: 12px;
    left: 96px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .7);
    color: #fff;
    cursor: pointer;
    font-size: .78rem;
}

/* [ข้อ 2,3] แถบเกริ่นว่ากำลังคอมเมนต์โพสต์ไหน */
.cmt-context {
    padding: 8px 14px;
    border-bottom: 1px solid var(--mes-line, #2a2a2e);
    color: var(--mes-text-dim, #a1938c);
    font-size: .8rem;
    line-height: 1.5;
    background: rgba(255, 255, 255, .02);
}
.cmt-context[hidden] { display: none; }

/* [ข้อ 4,5,6] ช่องพิมพ์ต้องอยู่เหนือแป้นพิมพ์เสมอ
   sticky ทำให้ติดขอบล่างของกล่องแม้รายการจะเลื่อน
   ส่วน padding-bottom ที่ JS ใส่ให้ตอนแป้นพิมพ์ขึ้น เป็นตัวดันขึ้นอีกชั้น */
.cmt-compose {
    position: sticky;
    bottom: 0;
    z-index: 3;
}
.cmt-sheet { transition: transform .22s ease, padding-bottom .18s ease; }

/* ==========================================================================
   [เพิ่มใหม่] ปุ่มของเจ้าของคอมเมนต์ (แก้ไข / ลบ)
   --------------------------------------------------------------------------
   🐞 แก้บั๊ก "คอมเมนต์ของตัวเอง แต่ระบบทำเหมือนไม่รู้จักกัน" — เซิร์ฟเวอร์รู้ว่า
   ใครเป็นเจ้าของมาตลอด แต่หน้าเว็บไม่เคยวาดปุ่มพวกนี้ออกมาเลยสักครั้ง
   ========================================================================== */
.cmt-own-btn {
    background: none;
    border: 0;
    padding: 0 2px;
    font: inherit;
    font-size: .74rem;
    color: var(--mes-text-mute, #9a938d);
    cursor: pointer;
}
.cmt-own-btn:hover { text-decoration: underline; }
.cmt-del-btn:hover { color: #ef4444; }
.cmt-edit-btn:hover { color: var(--mes-gold, #d4af37); }

/* คอมเมนต์ของตัวเอง — ขอบทองบาง ๆ ให้เห็นชัดว่า "อันนี้ของเรา" */
.cmt-item.is-mine .cmt-bubble {
    border: 1px solid rgba(212, 175, 55, .28);
}

/* กล่องแก้ไขในที่ — ไม่ต้องเปิดหน้าใหม่ */
.cmt-edit-box { margin-top: 6px; }
.cmt-edit-input {
    width: 100%;
    background: #1c1c20;
    border: 1px solid var(--mes-gold, #d4af37);
    border-radius: 8px;
    color: var(--mes-text, #ece5e0);
    font: inherit;
    font-size: .84rem;
    padding: 8px;
    resize: vertical;
}
.cmt-edit-actions { display: flex; gap: 8px; margin-top: 6px; }
.cmt-edit-actions button {
    font: inherit;
    font-size: .76rem;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--mes-line, #2a2a2e);
    background: #1c1c20;
    color: var(--mes-text, #ece5e0);
}
.cmt-edit-save { border-color: var(--mes-gold, #d4af37) !important; color: var(--mes-gold, #d4af37) !important; }

/* ==========================================================================
   [เพิ่มใหม่] แผงคอมเมนต์ต้องขยับตามแป้นพิมพ์
   --------------------------------------------------------------------------
   comment-sheet.js เป็นคนคำนวณ padding-bottom ให้เท่าความสูงแป้นพิมพ์จริง
   (ดู bindKeyboardDock) ตรงนี้แค่ทำให้การขยับดูนุ่มนวลไม่กระตุก
   ========================================================================== */
#cmt-sheet {
    transition: padding-bottom .18s ease-out;
}

/* ==========================================================================
   [เพิ่มใหม่] แถวตัวเลือกโพลในกล่องพิมพ์ — มีปุ่มลบของตัวเอง
   ========================================================================== */
.poll-opt-row { display: flex; align-items: center; gap: 6px; }
.poll-opt-row .mes-poll-opt { flex: 1; }
.poll-opt-remove {
    background: none;
    border: 1px solid var(--mes-line, #2a2a2e);
    border-radius: 6px;
    color: var(--mes-text-mute, #9a938d);
    font: inherit;
    font-size: .8rem;
    padding: 6px 10px;
    cursor: pointer;
    flex-shrink: 0;
}
.poll-opt-remove:hover { color: #ef4444; border-color: #ef4444; }

/* [8 ก.ย. 2569 — เลนฟีด] 💬 กำลังพิมพ์… + ปุ่มเพดาน (ดูอีก N / ดูทั้งหมด) */
.cmt-typing { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--text-mute); padding: .25rem .9rem; min-height: 1.6rem; }
.cmt-typing-dots { display: inline-flex; gap: 3px; align-items: center; }
.cmt-typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--gold-dim); animation: cmt-bounce 1.2s infinite ease-in-out; }
.cmt-typing-dots i:nth-child(2) { animation-delay: .2s; } .cmt-typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes cmt-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-4px); opacity: 1; } }
.cmt-more { display: block; margin: .3rem 0 .5rem; padding: .3rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--gold-soft); font-size: .8rem; cursor: pointer; font-family: inherit; }
.cmt-more:hover { border-color: var(--gold-dim); }
.cmt-more-reply { margin-left: 34px; }
.cmt-more-top { margin: .6rem auto .2rem; }

/* [9 ก.ย. 2569 — เลนฟีด · ม็อคอัพผ่าน] ↩ ตอบกลับใคร + ช่องตอบในที่ (แผ่นเม้นเร็ว) */
.cmt-reply-to { display: inline-block; font-size: .72rem; color: var(--text-mute); text-decoration: none; margin: .05rem 0 .2rem;
  border-left: 2px solid var(--gold-dim); padding-left: .4rem; line-height: 1.4; }
.cmt-reply-to b { color: var(--gold-soft); font-weight: 600; }
.cmt-item.is-target .cmt-bubble { outline: 2px solid var(--gold); outline-offset: 2px; }
.cmt-inline-reply { display: flex; gap: .4rem; align-items: flex-end; margin: .3rem 0 .4rem 34px; animation: cmt-pop .18s ease; }
.cmt-inline-field { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--gold-dim); border-radius: 14px; padding: .35rem .65rem; }
.cmt-inline-to { font-size: .7rem; color: var(--text-mute); margin-bottom: .1rem; }
.cmt-inline-to b { color: var(--gold-soft); }
.cmt-inline-field textarea { width: 100%; border: 0; background: transparent; color: var(--text); font-family: inherit; font-size: .9rem; resize: none; outline: 0; min-height: 1.5rem; }
.cmt-inline-send { border: 0; background: var(--gold-dim); color: #1a1414; font-weight: 700; padding: .45rem .75rem; border-radius: 9px; font-family: inherit; cursor: pointer; }
.cmt-inline-send[disabled] { opacity: .6; }
.cmt-inline-cancel { border: 0; background: transparent; color: var(--text-mute); font-size: .78rem; padding: .45rem .1rem; font-family: inherit; cursor: pointer; }
@keyframes cmt-pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* [เพิ่ม 12 ก.ย. 2569 — แม่บท 4/2] แถวปุ่มเครื่องมือบนกล่องคอมเมนต์หน้าโพสต์เต็ม
   (แผ่นคอมเมนต์ลอยวางปุ่มพวกนี้แนบกับช่องพิมพ์เลย ฟอร์มหน้าโพสต์เต็มเป็นแนวตั้ง จึงแยกแถว) */
.cmt-tools-row { display: flex; gap: 8px; margin-bottom: 8px; }

/* [เพิ่ม 12 ก.ย. 2569] แถบ "กำลังตอบกลับ + ยกเลิก" ในฟอร์มหน้าโพสต์เต็ม (#replying-to) */
#replying-to:not(:empty) { display: inline-flex; align-items: center; gap: 8px; color: var(--mes-gold, #d4af37); }
.replying-cancel { border: none; background: none; color: var(--mes-text-mute, #8a7c78); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

/* [เพิ่ม 12 ก.ย. 2569 — แม่บท 4/2] เลื่อนสุดขอบรายการแล้วไม่ทะลุไปเลื่อนหน้าหลัง */
.cmt-list, .cmt-media-grid { overscroll-behavior: contain; }
.cmt-overlay { touch-action: none; }
.cmt-sheet { touch-action: pan-y; }

/* ===========================================================================
   [12 ก.ย. 2569 — แม่บท 4/2 · สเปกใหม่จากเจ้าของ (เริ่มนับ 1 ใหม่)]
   ① ใช้เครื่องมือตัวล่างเท่านั้น — กล่องพิมพ์อยู่ล่างสุดตายตัว แถบสูงขึ้นกว่าเดิม
   ② กดตอบใครก็ตาม → เลื่อนรายการให้คอมเมนต์คนนั้นวิ่งขึ้นไปอยู่บนสุด (.is-reply-target)
   ③ แป้นพิมพ์ — ไม่วัดพิกเซลเอง ปล่อยให้ interactive-widget=resizes-content + dvh จัดการ
   =========================================================================== */

/* ① แถบเครื่องมือ + กล่องพิมพ์ สูงขึ้น กดง่ายขึ้น */
.cmt-compose {
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
}
.cmt-compose textarea {
    min-height: 48px;
    padding: 13px 16px;
    font-size: .95rem;
    border-radius: 24px;
}
.cmt-send { padding: 13px 22px; border-radius: 24px; font-size: .95rem; }
.cmt-tool { height: 48px; min-width: 48px; font-size: .92rem; }

/* แถบ "กำลังตอบกลับ" ในกล่องพิมพ์ — เด่นขึ้น อ่านง่ายขึ้น */
.cmt-replying {
    padding: 12px 16px;
    font-size: .92rem;
    font-weight: 600;
    background: rgba(212, 175, 55, .14);
    border-top: 1px solid var(--mes-gold-dim, #8a7128);
}
.cmt-replying button { font-size: .84rem; }

/* ② [ม็อคอัพ v5 ผ่าน] แถบ "กำลังตอบกลับ" บรรทัดเดียว — ข้อความเท่านั้น ไม่เอารูปมาโปะ */
.cmt-replying {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
}
.cmt-replying #cmt-replying-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cmt-replying #cmt-replying-name b { color: var(--mes-gold-soft, #f0d98a); }
.cmt-replying-snip {
    color: var(--mes-text-dim, #a1938c);
    font-weight: 400;
    margin-left: 6px;
}
.cmt-replying button { flex: none; }

/* คอมเมนต์ที่กำลังตอบ — ตัวจริงในรายการ ติดกรอบทองให้รู้ว่าอันไหน (ไม่ได้ก๊อปมาโปะ) */
.cmt-item.is-reply-target > .cmt-body,
.cmt-item.is-reply-target .cmt-bubble {
    border-color: var(--mes-gold, #d4af37);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, .22);
}

/* ที่ว่างท้ายรายการ — ให้คอมเมนต์อันล่าง ๆ เลื่อนขึ้นไปอยู่ "บนสุด" ได้จริงตอนกดตอบกลับ */
.cmt-tailpad { height: 60vh; flex: none; pointer-events: none; }

/* [ม็อคอัพ v5 ข้อ 3] ข้อความที่เราเพิ่งส่ง — ไฮไลต์ให้เห็นชัดหลังเลื่อนมาหา */
.cmt-item.cmt-just-sent {
    animation: cmtJustSent 2.2s ease;
    border-radius: 12px;
}
@keyframes cmtJustSent {
    0%, 45% { background: rgba(212, 175, 55, .18); }
    100% { background: transparent; }
}

/* ===========================================================================
   [12 ก.ย. 2569 — แม่บท 4/2 · ม็อคอัพ postpage-bottom-dock ผ่าน]
   หน้าโพสต์เต็ม/บทความ — แถบเครื่องมือล่างสุด ชุดเดียวกับแผ่นคอมเมนต์ลอย
   (ยกเลิกกล่องพิมพ์เดิมที่ฝังกลางหน้าแล้ว ดู app/partials/comment-box.php)
   =========================================================================== */
.cmt-page-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    background: var(--mes-bg-card, #141416);
    border-top: 1px solid var(--mes-line, #2a2a2e);
    margin: 0;
    box-shadow: 0 -8px 18px rgba(0, 0, 0, .45);
}
/* จอกว้าง — กว้างเท่ากรอบเนื้อหากลาง ไม่ยืดเต็มจอ */
@media (min-width: 768px) {
    .cmt-page-dock { left: 50%; transform: translateX(-50%); max-width: 720px; border-radius: 14px 14px 0 0; }
}
.cmt-page-dock .cmt-compose { border-top: 0; }
.cmt-page-dock .cmt-media-bar { max-height: 46vh; overflow-y: auto; }

/* ที่ว่างท้ายหน้า: กันแถบล่างบังคอมเมนต์อันสุดท้าย + ให้เลื่อนคอมเมนต์ขึ้นบนสุดได้ */
.cmt-page-tailpad { height: 62vh; pointer-events: none; }

/* คอมเมนต์ที่กำลังตอบในหน้าโพสต์เต็ม — กรอบทองเหมือนแผ่นลอย */
.comment.is-reply-target,
.comment.is-reply-target > .card {
    outline: 1px solid var(--mes-gold, #d4af37);
    outline-offset: 2px;
    border-radius: 12px;
}
