/* ===========================================================================
 * assets/css/cafe.css — ☕ สภากาแฟ (ชุด B)
 * ---------------------------------------------------------------------------
 * โครงบับเบิลอ้างอิงแนวทางจากโมดูลเดิม mes-aon-song (csb-side-left/right)
 * แต่เขียนใหม่ให้เข้ากับธีมทองของ v5 และใช้ token สีจาก :root เดิมทั้งหมด
 *
 * กติกาจัดฝั่ง: เราอยู่ขวา (cafe-side-right) คนอื่นอยู่ซ้าย (cafe-side-left)
 * =========================================================================== */

.cafe-page { display: flex; flex-direction: column; gap: 16px; padding-bottom: 40px; }

/* ---- รายชื่อห้อง ---- */
.cafe-room-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}
.cafe-room-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface);
    text-decoration: none;
    color: inherit;
    transition: border-color .15s ease;
}
.cafe-room-card:hover { border-color: var(--gold-dim); }
.cafe-room-vip { border-color: var(--gold-dim); background: linear-gradient(150deg, rgba(212,175,55,.07), var(--surface)); }
.cafe-room-pvp { border-color: rgba(179,32,42,.4); }
.cafe-room-secret { border-style: dashed; }

.cafe-room-type { font-size: .68rem; color: var(--gold-soft); font-weight: 800; }
.cafe-room-title { font-weight: 700; font-size: .95rem; color: var(--text); }
.cafe-room-topic { font-size: .76rem; color: var(--text-dim); }
.cafe-room-meta { font-size: .7rem; color: var(--text-mute); }

/* ---- หัวห้อง ---- */
.cafe-room-head { display: flex; align-items: center; gap: 12px; }
.cafe-room-head h1 { margin: 0; font-size: 1.2rem; }
.cafe-room-head p { margin: 2px 0 0; font-size: .8rem; }

/* ---- กฎห้องลับ (ToS) ---- */
.cafe-tos { padding: 20px; max-width: 640px; margin: 0 auto; }
.cafe-tos-text {
    white-space: pre-wrap;
    font-size: .82rem;
    line-height: 1.7;
    color: var(--text-dim);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 16px;
    border: 1px solid var(--line);
    font-family: inherit;
}
.cafe-tos-check { display: flex; align-items: center; gap: 8px; margin: 16px 0; font-size: .86rem; }

/* ---- แผงดวล PVP ---- */
.cafe-duel-panel {
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid rgba(179,32,42,.35);
    background: linear-gradient(160deg, rgba(179,32,42,.08), var(--surface));
}
.cafe-duel-vs { display: flex; align-items: center; justify-content: space-around; gap: 12px; }
.cafe-duel-vs-label { font-weight: 900; color: var(--red-soft); font-size: 1.1rem; }
.cafe-duel-side { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.cafe-duel-name { font-weight: 700; font-size: .9rem; }
.cafe-duel-score { font-size: 1.1rem; color: var(--gold-soft); font-weight: 800; }
.cafe-cheer-btn { font-size: .76rem; padding: 4px 12px; }

/* ---- ห้องสนทนา ---- */
.cafe-thread {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface);
    min-height: 320px;
    max-height: 60vh;
    overflow-y: auto;
}

.cafe-bubble-wrap { display: flex; gap: 8px; max-width: 78%; }
/* คนอื่น = ซ้าย (รูปโปรไฟล์อยู่ซ้ายของข้อความ) */
.cafe-side-left { align-self: flex-start; flex-direction: row; }
/* เรา = ขวา (สลับให้รูปโปรไฟล์อยู่ขวา ข้อความชิดขวา) */
.cafe-side-right { align-self: flex-end; flex-direction: row-reverse; }
.cafe-side-right .cafe-bubble-col { align-items: flex-end; }
.cafe-side-right .cafe-bubble-name { flex-direction: row-reverse; }

.cafe-bubble-avatar {
    width: 36px; height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    /* [แก้ 6 ก.ย. 2569] overflow เดิม hidden ตัดป้ายอิโมจิที่ล้นออกมุม — ย้าย
       การตัดวงกลมไปที่ <img> แทน แล้วให้วงนี้เป็นจุดอ้างอิงตำแหน่งของป้าย */
    overflow: visible;
    position: relative;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
}
.cafe-bubble-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
/* (เดิม) สติกเกอร์แทนรูป — ยังคงไว้เผื่อที่อื่นใช้ */
.cafe-avatar-sticker { font-size: 1.5rem; line-height: 1; }
/* [แก้ 6 ก.ย. 2569] ป้ายอิโมจิเล็กทับมุมล่างขวาของรูปโปรไฟล์ — เล็กกว่ารูปเสมอ */
.cafe-avatar-sticker--badge {
    position: absolute; right: -4px; bottom: -4px;
    font-size: .95rem; line-height: 1;
    width: 18px; height: 18px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface); border: 1px solid var(--line);
    box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.cafe-avatar-fallback { font-size: .9rem; font-weight: 700; color: var(--text-dim); }

.cafe-bubble-col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cafe-bubble-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .7rem;
    color: var(--text-mute);
}
.cafe-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: .86rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--line);
    white-space: pre-wrap;
    word-break: break-word;
}
/* บับเบิลของเราสีทองอ่อน แยกจากคนอื่นชัดเจนโดยไม่ต้องอ่านชื่อ */
.cafe-side-right .cafe-bubble {
    background: linear-gradient(150deg, rgba(212,175,55,.16), rgba(212,175,55,.08));
    border-color: var(--gold-dim);
}

/* ---- แท็กติดตาม 3 สถานะ (เห็นเฉพาะเจ้าของแท็ก) ---- */
.cafe-watch-dot { font-size: .64rem; padding: 1px 6px; border-radius: 999px; }
.cafe-watch-following .cafe-watch-dot { background: rgba(60,160,90,.22); color: #7fd9a0; }
.cafe-watch-observing .cafe-watch-dot { background: rgba(70,130,200,.22); color: #8cc0f0; }
.cafe-watch-suspicious .cafe-watch-dot { background: rgba(200,80,60,.22); color: #f0a08c; }

.cafe-tag-form { margin-top: 2px; }
.cafe-tag-form select {
    font-size: .64rem;
    padding: 2px 6px;
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text-mute);
    border-radius: 6px;
}

/* ---- กล่องพิมพ์ ---- */
.cafe-composer { display: flex; flex-direction: column; gap: 8px; }
.cafe-sticker-row { display: flex; gap: 6px; flex-wrap: wrap; }
.cafe-sticker-btn {
    font-size: 1.2rem;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 4px 8px;
    cursor: pointer;
    line-height: 1;
}
.cafe-sticker-btn.is-active { border-color: var(--gold); background: rgba(212,175,55,.18); }
.cafe-composer-row { display: flex; gap: 8px; }
.cafe-composer-row input[type="text"] { flex: 1 1 auto; }

@media (max-width: 640px) {
    .cafe-bubble-wrap { max-width: 88%; }
    .cafe-thread { max-height: 55vh; }
}

/* ---- [เพิ่มใหม่] ลิงก์คลังเก่า + หน้าคลังข้อความ ---- */
.cafe-archive-link { flex-shrink: 0; font-size: .76rem; }
.cafe-archive-list { display: flex; flex-direction: column; gap: 10px; }
.cafe-archive-item {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: .82rem;
}
.cafe-archive-who { font-weight: 700; color: var(--gold-soft); }
.cafe-archive-when { color: var(--text-mute); font-size: .72rem; }
.cafe-archive-body { flex-basis: 100%; color: var(--text); }
