/* แชทรวม (public/inbox.php) — โครงหน้าจอตาม .github/V5_UNIFIED_INBOX_PLAN.md §1 */
:root {
    --ib-font: "Inter", "IBM Plex Sans Thai Looped", "Noto Sans Thai", -apple-system, "Segoe UI", sans-serif;
    --ib-bg: #ffffff;
    --ib-bg-subtle: #f9fafb;
    --ib-bg-muted: #f2f4f7;
    --ib-border: #eaecf0;
    --ib-text: #101828;
    --ib-text-2: #344054;
    --ib-text-3: #667085;
    --ib-text-4: #98a2b3;
    --ib-dark: #1f2937;
    /* สีเน้น — เขียวมิ้นต์ (สวิตช์ เช็กบ็อกซ์ ลิงก์ จุดยังไม่อ่าน) */
    --ib-accent: #14b8a6;
    --ib-accent-dark: #0f8f81;
    --ib-accent-soft: #e6f7f5;
    --ib-red: #f04438;
    --ib-green: #12b76a;
    --ib-amber: #f79009;
    --ib-fb: #0866ff;
    --ib-line: #06c755;
    --ib-ig: #e1306c;
    --ib-bot-bubble: #f4f3ff;
    --ib-admin-bubble: #eff8ff;
    --ib-radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.ib {
    font-family: var(--ib-font);
    font-size: 14px;
    color: var(--ib-text);
    background: var(--ib-bg-subtle);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}
.ib button { font-family: inherit; }
.ib-hidden { display: none !important; }

.ib-app {
    display: grid;
    grid-template-columns: 56px 240px 344px minmax(0, 1fr) 280px;
    grid-template-rows: minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
}
.ib-app > * { min-height: 0; }
.ib-app.nav-collapsed { grid-template-columns: 56px 0 344px minmax(0, 1fr) 280px; }
.ib-app.nav-collapsed .ib-nav { visibility: hidden; }

/* ── Rail ───────────────────────────────────────── */
.ib-rail {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 12px 0; background: var(--ib-bg-subtle); border-right: 1px solid var(--ib-border);
}
.ib-rail a, .ib-rail button {
    width: 36px; height: 36px; display: grid; place-items: center;
    border-radius: 8px; color: var(--ib-text-3); text-decoration: none;
    border: 0; background: none; cursor: pointer; font-size: 15px;
}
.ib-rail a:hover, .ib-rail button:hover { background: var(--ib-bg-muted); color: var(--ib-text-2); }
.ib-rail a.active { background: var(--ib-bg-muted); color: var(--ib-dark); }
.ib-rail .spacer { flex: 1; }
.ib-rail .sep { width: 24px; height: 1px; background: var(--ib-border); margin: 6px 0; }

/* ── Inbox nav ──────────────────────────────────── */
.ib-nav {
    background: var(--ib-bg-subtle); border-right: 1px solid var(--ib-border);
    overflow-y: auto; padding: 16px 12px;
}
.ib-nav-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 12px; }
.ib-nav-head h1 { font-size: 14px; font-weight: 600; margin: 0; }
.ib-nav-section { font-size: 12px; color: var(--ib-text-4); margin: 14px 4px 6px; }
.ib-nav-item {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 7px 8px; border: 0; border-radius: 6px; background: none;
    color: var(--ib-text-2); font-size: 13px; text-align: left; cursor: pointer;
}
.ib-nav-item i { width: 16px; text-align: center; color: var(--ib-text-3); font-size: 13px; }
.ib-nav-item:hover { background: var(--ib-bg-muted); }
.ib-nav-item.active { background: var(--ib-border); color: var(--ib-text); font-weight: 500; }
.ib-nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-nav-item .count { color: var(--ib-text-3); font-size: 12px; }
.ib-badge {
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--ib-red); color: #fff; font-size: 11px; font-weight: 600;
    display: inline-grid; place-items: center;
}
.ib-nav-item.paused-ch { opacity: .55; }

/* ── Platform badge (มุมรูปโปรไฟล์) ───────────────── */
.ib-avatar { position: relative; flex: 0 0 auto; width: 40px; height: 40px; }
.ib-avatar img, .ib-avatar .ph {
    width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
    background: var(--ib-border); display: grid; place-items: center;
    color: var(--ib-text-3); font-weight: 600; font-size: 14px;
}
.ib-avatar .pf {
    position: absolute; right: -2px; bottom: -2px; width: 17px; height: 17px;
    border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center;
    color: #fff; font-size: 8px;
}
.pf.facebook { background: var(--ib-fb); }
.pf.line { background: var(--ib-line); }
.pf.instagram { background: var(--ib-ig); }
.ib-avatar.sm { width: 32px; height: 32px; }

/* ── List ───────────────────────────────────────── */
.ib-list { background: var(--ib-bg); border-right: 1px solid var(--ib-border); display: flex; flex-direction: column; min-width: 0; }
.ib-list-head { display: flex; align-items: center; gap: 6px; padding: 16px 16px 8px; }
.ib-list-head h2 { flex: 1; font-size: 14px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-icon-btn {
    width: 28px; height: 28px; border-radius: 6px; border: 0; background: none;
    color: var(--ib-text-3); cursor: pointer; display: grid; place-items: center;
}
.ib-icon-btn:hover { background: var(--ib-bg-muted); color: var(--ib-text-2); }
.ib-icon-btn:disabled { opacity: .4; cursor: default; background: none; }
.ib-search { padding: 0 16px 8px; }
.ib-search input {
    width: 100%; height: 34px; border: 1px solid var(--ib-border); border-radius: 8px;
    padding: 0 10px 0 32px; font: inherit; font-size: 13px; outline: none;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%2398a2b3' stroke-width='2'%3E%3Ccircle cx='6' cy='6' r='5'/%3E%3Cpath d='m13 13-3.5-3.5'/%3E%3C/svg%3E") no-repeat 11px center;
}
.ib-search input:focus { border-color: var(--ib-accent); box-shadow: 0 0 0 3px var(--ib-accent-soft); }
.ib-list-body { flex: 1; overflow-y: auto; padding: 0 6px 12px; }
.ib-row {
    display: flex; gap: 12px; padding: 12px 10px; border-radius: var(--ib-radius);
    cursor: pointer; position: relative;
}
.ib-row:hover { background: var(--ib-bg-subtle); }
.ib-row.active { background: var(--ib-bg-muted); }
.ib-row .meta { flex: 1; min-width: 0; }
.ib-row .top { display: flex; align-items: baseline; gap: 8px; }
.ib-row .name { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-row .time { font-size: 12px; color: var(--ib-text-4); flex: 0 0 auto; }
.ib-row .preview {
    font-size: 12px; color: #4b4a4b; margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ib-row.unanswered .name { font-weight: 600; }
.ib-row.unanswered .preview { color: var(--ib-text); font-weight: 500; }
.ib-row .chips { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.ib-chip {
    display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px;
    border-radius: 10px; font-size: 11px; font-weight: 500;
    background: var(--ib-bg-muted); color: var(--ib-text-3); white-space: nowrap;
}
.ib-chip.paused { background: #fffaeb; color: #b54708; }
.ib-chip.muted { background: #fef3f2; color: #b42318; }
.ib-chip.wait { background: #fef3f2; color: #b42318; }
.ib-chip.tier-vip { background: #f4f3ff; color: #5925dc; }
.ib-chip.tier-buyer { background: #ecfdf3; color: #027a48; }
.ib-chip.tier-hot { background: #fff4ed; color: #c4320a; }
.ib-empty { padding: 40px 16px; text-align: center; color: var(--ib-text-4); font-size: 13px; }
.ib-more { display: block; margin: 8px auto; border: 1px solid var(--ib-border); background: #fff; border-radius: 6px; padding: 6px 14px; font-size: 12px; cursor: pointer; color: var(--ib-text-2); }

/* ── Chat ───────────────────────────────────────── */
.ib-chat { background: var(--ib-bg); display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--ib-border); }
.ib-chat-empty { flex: 1; display: grid; place-items: center; color: var(--ib-text-4); text-align: center; }
.ib-chat-empty i { font-size: 40px; color: var(--ib-border); margin-bottom: 12px; }
.ib-chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.ib-chat-head .who { flex: 1; min-width: 0; }
.ib-chat-head .who .n { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-chat-head .who .c { font-size: 12px; color: var(--ib-text-3); }
.ib-back { display: none; }
.ib-bot-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
    border: 1px solid var(--ib-border); border-radius: 8px; background: #fff;
    font-size: 12px; font-weight: 500; color: var(--ib-text-2);
}
.ib-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ib-green); }
.ib-dot.paused { background: var(--ib-amber); }
.ib-dot.muted { background: var(--ib-red); }
.ib-strip {
    display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
    padding: 6px 16px; border-top: 1px solid var(--ib-border); border-bottom: 1px solid var(--ib-border);
    font-size: 12px; color: var(--ib-text-3);
}
.ib-strip b { font-weight: 500; color: var(--ib-text); margin-left: 8px; }
.ib-strip .code { color: var(--ib-dark); font-weight: 500; }
.ib-strip label { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }

.ib-timeline { flex: 1; overflow-y: auto; padding: 12px 20px 20px; }
.ib-day { text-align: center; font-size: 12px; color: var(--ib-text-4); margin: 16px 0 8px; }
.ib-msg { display: flex; flex-direction: column; align-items: flex-start; margin: 3px 0; }
.ib-msg.out { align-items: flex-end; }
.ib-msg .who { font-size: 11px; color: var(--ib-text-4); margin: 8px 4px 2px; }
.ib-msg .line { display: flex; align-items: flex-end; gap: 6px; max-width: min(72%, 560px); }
.ib-msg.out .line { flex-direction: row-reverse; }
.ib-bubble {
    padding: 8px 12px; border-radius: 12px; background: var(--ib-bg-muted);
    white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.45;
    min-width: 0;
}
.ib-msg.bot .ib-bubble { background: var(--ib-bot-bubble); }
.ib-msg.admin .ib-bubble { background: var(--ib-admin-bubble); }
.ib-bubble a { color: #175cd3; }
.ib-msg .t { font-size: 11px; color: var(--ib-text-4); flex: 0 0 auto; padding-bottom: 2px; }
.ib-img {
    display: block; max-width: 220px; max-height: 260px; border-radius: 12px;
    border: 1px solid var(--ib-border); background: var(--ib-bg-muted); object-fit: cover;
}
.ib-img-wrap { display: flex; flex-direction: column; gap: 4px; }
.ib-img-broken {
    width: 160px; height: 100px; border-radius: 12px; background: var(--ib-bg-muted);
    display: grid; place-items: center; color: var(--ib-text-4); font-size: 12px; text-align: center;
}
.ib-pill {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 16px;
    border: 1px dashed #d0d5dd; font-size: 12px; color: var(--ib-text-3); background: #fff;
}
.ib-codes { font-size: 11px; color: var(--ib-text-3); }
.ib-cards { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; padding-bottom: 4px; }
.ib-card {
    flex: 0 0 150px; border: 1px solid var(--ib-border); border-radius: 10px; overflow: hidden; background: #fff;
}
.ib-card img { width: 100%; height: 120px; object-fit: cover; display: block; background: var(--ib-bg-muted); }
.ib-card .b { padding: 6px 8px; font-size: 12px; }
.ib-card .code { color: var(--ib-text-3); font-size: 11px; }
.ib-card .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-card .pr { font-weight: 600; }
.ib-card .sold { color: var(--ib-red); font-size: 11px; }
.ib-card-text { font-size: 12px; color: var(--ib-text-3); max-width: 420px; white-space: pre-wrap; margin-top: 4px; }
.ib-sys {
    margin: 6px auto; max-width: 80%; font-size: 11px; color: var(--ib-text-4);
    background: var(--ib-bg-subtle); border: 1px solid var(--ib-border); border-radius: 6px;
    padding: 4px 8px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.ib-older { display: block; margin: 0 auto 8px; }

.ib-composer { border-top: 1px solid var(--ib-border); padding: 10px 16px 12px; }
.ib-composer .mode { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--ib-text-2); background: var(--ib-bg-muted); border-radius: 4px; padding: 2px 6px; }
.ib-composer textarea {
    width: 100%; border: 0; resize: none; outline: none; font: inherit; min-height: 64px;
    margin-top: 8px; background: transparent; color: var(--ib-text);
}
.ib-composer textarea:disabled { color: var(--ib-text-4); }
.ib-composer .bar { display: flex; align-items: center; gap: 4px; }
.ib-composer .bar .send { margin-left: auto; height: 32px; padding: 0 14px; border-radius: 8px; border: 0; background: var(--ib-dark); color: #fff; font-size: 13px; cursor: pointer; }
.ib-composer .bar .send:disabled { opacity: .35; cursor: default; }
.ib-composer .bar .hint { font-size: 11px; color: var(--ib-text-4); margin-left: 8px; }
.ib-window { font-size: 12px; color: #b54708; background: #fffaeb; border-radius: 6px; padding: 6px 10px; margin-bottom: 8px; }
.ib-composer.locked textarea, .ib-composer.locked .mode { opacity: .5; }
.ib-msg.pending .ib-bubble, .ib-msg.pending .ib-img { opacity: .6; }
.ib-msg.failed .ib-bubble { background: #fef3f2; }
.ib-msg .err { font-size: 11px; color: #b42318; margin-top: 3px; display: flex; gap: 8px; align-items: center; }
.ib-msg .err button { border: 0; background: none; color: #175cd3; cursor: pointer; font-size: 11px; padding: 0; }
button.ib-bot-btn { cursor: pointer; font-family: inherit; }
button.ib-bot-btn:hover { background: var(--ib-bg-subtle); }

/* ── Right panel ────────────────────────────────── */
.ib-side { background: var(--ib-bg); overflow-y: auto; min-width: 0; }
.ib-tabs { display: flex; gap: 4px; padding: 12px 12px 8px; position: sticky; top: 0; background: #fff; z-index: 1; border-bottom: 1px solid var(--ib-border); }
.ib-tab { width: 32px; height: 32px; border: 0; border-radius: 6px; background: none; color: var(--ib-text-3); cursor: pointer; }
.ib-tab.active { background: var(--ib-bg-muted); color: var(--ib-dark); }
.ib-sec { padding: 12px 14px; border-bottom: 1px solid var(--ib-border); }
.ib-sec h3 { font-size: 12px; font-weight: 500; margin: 0 0 10px; display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.ib-sec h3 i { font-size: 10px; color: var(--ib-text-3); transition: transform .15s; }
.ib-sec.closed h3 i { transform: rotate(-90deg); }
.ib-sec.closed .bd { display: none; }
.ib-kv { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px 8px; font-size: 12px; }
.ib-kv dt { color: var(--ib-text-3); }
.ib-kv dd { margin: 0; overflow-wrap: anywhere; }
.ib-kv dd.empty { color: var(--ib-text-4); }
.ib-linked { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.ib-linked:hover { background: var(--ib-bg-subtle); }
.ib-linked .cur { margin-left: auto; font-size: 10px; background: var(--ib-bg-muted); border-radius: 4px; padding: 1px 6px; color: var(--ib-text-3); }
.ib-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ib-order { font-size: 12px; padding: 6px 0; border-bottom: 1px dashed var(--ib-border); }
.ib-order:last-child { border-bottom: 0; }
.ib-muted-text { font-size: 12px; color: var(--ib-text-4); }

.ib-toast {
    position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
    background: var(--ib-dark); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 50;
}


/* ── P3 ทิกเก็ต ─────────────────────────────────── */
.ib-nav-section-row { display: flex; align-items: center; justify-content: space-between; }
.ib-icon-btn.sm { width: 22px; height: 22px; font-size: 11px; }
.ib-icon-btn.on { background: var(--ib-bg-muted); color: var(--ib-dark); }
.ib-tag-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; display: inline-block; }
/* สีแท็ก — ใช้ทั้ง chip และจุด */
.ib-chip.tg-gray { background: #f2f4f7; color: #344054; } .ib-tag-dot.tg-gray { background: #98a2b3; }
.ib-chip.tg-red { background: #fef3f2; color: #b42318; } .ib-tag-dot.tg-red { background: #f04438; }
.ib-chip.tg-orange { background: #fff4ed; color: #c4320a; } .ib-tag-dot.tg-orange { background: #fb6514; }
.ib-chip.tg-yellow { background: #fefbe8; color: #a15c07; } .ib-tag-dot.tg-yellow { background: #eaaa08; }
.ib-chip.tg-green { background: #ecfdf3; color: #027a48; } .ib-tag-dot.tg-green { background: #12b76a; }
.ib-chip.tg-blue { background: #eff8ff; color: #175cd3; } .ib-tag-dot.tg-blue { background: #2e90fa; }
.ib-chip.tg-purple { background: #f4f3ff; color: #5925dc; } .ib-tag-dot.tg-purple { background: #7a5af8; }
.ib-chip.tg-pink { background: #fdf2fa; color: #c11574; } .ib-tag-dot.tg-pink { background: #ee46bc; }
.ib-chip.closed { background: #ecfdf3; color: #027a48; }

.ib-row.unread .name { font-weight: 600; }
.ib-row.unread .preview { color: var(--ib-text); font-weight: 500; }
.ib-unread-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ib-accent); margin-right: 6px; vertical-align: 1px; }
.ib-follow-mark { color: var(--ib-amber); font-size: 11px; }
.ib-row-check { margin: 12px 0 0; flex: 0 0 auto; accent-color: var(--ib-dark); pointer-events: none; }
.ib-row.checked { background: #f5f8ff; }

.ib-bulk { display: flex; align-items: center; gap: 4px; padding: 0 12px 8px 16px; flex-wrap: wrap; }
.ib-bulk label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ib-text-2); margin-right: auto; cursor: pointer; }
.ib-bulk button { height: 28px; padding: 0 9px; border: 1px solid var(--ib-border); background: #fff; border-radius: 6px; font-size: 12px; color: var(--ib-text-2); cursor: pointer; }
.ib-bulk button:hover { background: var(--ib-bg-subtle); }
.ib-bulk button.x { border: 0; }

.ib-close-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 0; border-radius: 8px;
    background: var(--ib-dark); color: #fff; font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.ib-close-btn.reopen { background: #fff; color: var(--ib-text-2); border: 1px solid var(--ib-border); }
.ib-menu-wrap { position: relative; }
.ib-menu {
    position: absolute; right: 0; top: 34px; z-index: 30; min-width: 210px; background: #fff;
    border: 1px solid var(--ib-border); border-radius: 8px; box-shadow: 0 12px 24px rgba(16,24,40,.12); padding: 4px;
}
.ib-menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px; font: inherit; font-size: 13px; color: var(--ib-text-2); cursor: pointer; text-align: left; }
.ib-menu button:hover { background: var(--ib-bg-subtle); }
.ib-menu button i { width: 16px; color: var(--ib-text-3); }
kbd { margin-left: auto; font: 11px var(--ib-font); color: var(--ib-text-3); background: var(--ib-bg-muted); border-radius: 4px; padding: 1px 5px; white-space: nowrap; }

.ib-strip-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.ib-tag-add { height: 20px; padding: 0 7px; border: 1px dashed #d0d5dd; background: #fff; border-radius: 10px; font: inherit; font-size: 11px; color: var(--ib-text-3); cursor: pointer; }
.ib-tag-add:hover { color: var(--ib-text-2); border-color: var(--ib-text-4); }

.ib-pop {
    position: fixed; z-index: 40; width: 260px; background: #fff; border: 1px solid var(--ib-border);
    border-radius: 8px; box-shadow: 0 12px 24px rgba(16,24,40,.14); padding: 8px;
}
.ib-pop input[type=text] { width: 100%; height: 32px; border: 1px solid var(--ib-border); border-radius: 6px; padding: 0 8px; font: inherit; font-size: 13px; outline: none; }
.ib-pop-list { max-height: 240px; overflow-y: auto; margin-top: 6px; }
.ib-pop-row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px; border-radius: 6px; font-size: 13px; cursor: pointer; border: 0; background: none; text-align: left; font-family: inherit; color: var(--ib-text-2); }
.ib-pop-row:hover { background: var(--ib-bg-subtle); }
.ib-pop-row.create { color: var(--ib-accent-dark); }

/* composer modes */
.ib-composer .modes { display: flex; gap: 4px; }
.ib-composer .mode { border: 0; cursor: pointer; background: none; color: var(--ib-text-3); font-weight: 500; }
.ib-composer .mode.active { background: var(--ib-bg-muted); color: var(--ib-text-2); }
.ib-composer.note-mode { background: #fffcf0; }
.ib-composer.note-mode .mode.active { background: #fef0c7; color: #93370d; }
.ib-composer { position: relative; }
.ib-suggest {
    position: absolute; left: 12px; right: 12px; bottom: calc(100% - 4px); z-index: 25; background: #fff;
    border: 1px solid var(--ib-border); border-radius: 8px; box-shadow: 0 -8px 24px rgba(16,24,40,.1); padding: 4px; max-height: 280px; overflow-y: auto;
}
.ib-suggest-row { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ib-text-2); }
.ib-suggest-row small { display: block; color: var(--ib-text-4); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-suggest-row.sel, .ib-suggest-row:hover { background: var(--ib-bg-muted); }

/* timeline annotations */
.ib-note-item { margin: 8px 0 8px auto; max-width: min(72%, 560px); background: #fffaeb; border: 1px solid #fedf89; border-radius: 10px; padding: 6px 10px; }
.ib-note-item .h, .ib-note-card .h { font-size: 11px; color: #93370d; display: flex; align-items: center; gap: 6px; }
.ib-note-item .h button, .ib-note-card .h button { margin-left: auto; border: 0; background: none; color: #b54708; cursor: pointer; font-size: 11px; }
.ib-note-item .b, .ib-note-card .b { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; margin-top: 2px; }
.ib-note-card { background: #fffaeb; border: 1px solid #fedf89; border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; }
.ib-event { text-align: center; margin: 10px 0; }
.ib-event span { font-size: 11px; color: var(--ib-text-3); background: var(--ib-bg-subtle); border: 1px solid var(--ib-border); border-radius: 10px; padding: 2px 10px; }

/* side panel */
.ib-sec-act { margin-left: auto; border: 0; background: none; color: var(--ib-accent-dark); font: inherit; font-size: 12px; cursor: pointer; }
.ib-activity { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.ib-activity li { padding: 5px 0; border-bottom: 1px dashed var(--ib-border); color: var(--ib-text-2); }
.ib-activity li span { display: block; color: var(--ib-text-4); font-size: 11px; }

/* forms (modal + side) */
.ib-form { display: flex; flex-direction: column; gap: 10px; }
.ib-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ib-text-3); }
.ib-form input, .ib-form textarea, .ib-form select {
    font: inherit; font-size: 13px; color: var(--ib-text); border: 1px solid var(--ib-border); border-radius: 6px;
    padding: 7px 9px; outline: none; background: #fff; width: 100%;
}
.ib-form input:focus, .ib-form textarea:focus, .ib-form select:focus { border-color: var(--ib-accent); box-shadow: 0 0 0 3px var(--ib-accent-soft); }
.ib-form .row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.ib-form .actions { display: flex; justify-content: flex-end; gap: 8px; }
.ib-form button.primary { height: 32px; padding: 0 14px; border: 0; border-radius: 8px; background: var(--ib-dark); color: #fff; font: inherit; font-size: 13px; cursor: pointer; }
.ib-form button.ghost { height: 32px; padding: 0 12px; border: 1px solid var(--ib-border); border-radius: 8px; background: #fff; font: inherit; font-size: 13px; cursor: pointer; color: var(--ib-text-2); }
.ib-form.compact { gap: 8px; }

/* overlays */
.ib-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; }
.ib-palette, .ib-modal { width: 100%; max-width: 560px; background: #fff; border-radius: 12px; box-shadow: 0 24px 48px rgba(16,24,40,.2); overflow: hidden; display: flex; flex-direction: column; max-height: 76vh; }
.ib-palette input { border: 0; border-bottom: 1px solid var(--ib-border); padding: 14px 16px; font: inherit; font-size: 15px; outline: none; }
.ib-palette-list { overflow-y: auto; padding: 6px; }
.ib-pal-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 8px; font: inherit; font-size: 13px; color: var(--ib-text-2); cursor: pointer; text-align: left; }
.ib-pal-row i { width: 16px; color: var(--ib-text-3); }
.ib-pal-row .l { flex: 1; min-width: 0; }
.ib-pal-row small { display: block; color: var(--ib-text-4); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-pal-row.sel, .ib-pal-row:hover { background: var(--ib-bg-muted); }
.ib-palette-foot { font-size: 11px; color: var(--ib-text-4); padding: 8px 14px; border-top: 1px solid var(--ib-border); }
.ib-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--ib-border); }
.ib-modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.ib-modal-body { padding: 16px; overflow-y: auto; }
.ib-mlist { margin-top: 16px; border-top: 1px solid var(--ib-border); }
.ib-mrow { display: flex; align-items: center; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--ib-border); }
.ib-mrow .t { flex: 1; min-width: 0; font-size: 13px; }
.ib-mrow .t small { display: block; color: var(--ib-text-4); font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── สถานะเวลาทำการ (หัวเมนูซ้าย) ────────────────── */
.ib-open-state { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--ib-text-3); white-space: nowrap; }
.ib-open-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ib-text-4); }
.ib-open-state.on { color: var(--ib-accent-dark); }
.ib-open-state.on::before { background: var(--ib-accent); }
.ib-nav-head h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.ib-nav-item { text-decoration: none; }
input[type=checkbox], input[type=radio] { accent-color: var(--ib-accent); }

/* ── ข้อมูลเคส (แผงขวา) ──────────────────────────── */
.ib-form label.ib-case-check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--ib-text); cursor: pointer; }
.ib-form label.ib-case-check input { width: 16px; height: 16px; margin: 0; padding: 0; flex: 0 0 auto; }
.ib-kv dd.yes { color: var(--ib-accent-dark); font-weight: 500; }

/* ── หน้าตั้งค่า (public/inbox-settings.php) ─────── */
.st-app { display: grid; grid-template-columns: 56px 240px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100vh; height: 100dvh; }
.st-app > * { min-height: 0; }
.st-nav .ib-nav-item { padding: 8px 10px; }
.st-main { overflow-y: auto; background: var(--ib-bg-subtle); padding: 12px 12px 12px 0; }
.st-wrap { background: #fff; border: 1px solid var(--ib-border); border-radius: 12px; min-height: 100%; padding: 28px clamp(16px, 4vw, 64px) 48px; }
.st-crumb { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ib-text-4); margin-bottom: 28px; }
.st-crumb i { font-size: 10px; }
.st-crumb b { font-weight: 500; color: var(--ib-text); }
.st-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.st-head h1 { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.st-desc { font-size: 12px; color: var(--ib-text-3); margin: 0 0 14px; line-height: 1.6; }
.st-head .st-desc { margin: 0; }
.st-card { border: 1px solid var(--ib-border); border-radius: 10px; padding: 20px; margin-bottom: 20px; background: #fff; }
.st-card h2 { font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.st-form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.st-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ib-text-2); max-width: 420px; }
.st-form input:not([type=checkbox]):not([type=radio]), .st-form select, .st-form textarea {
    font: inherit; font-size: 13px; height: 38px; padding: 0 12px; border: 1px solid var(--ib-border); border-radius: 8px; background: #fff; color: var(--ib-text); outline: none;
}
.st-form input:focus, .st-form select:focus { border-color: var(--ib-accent); box-shadow: 0 0 0 3px var(--ib-accent-soft); }
.st-form select:disabled { background: var(--ib-bg-subtle); color: var(--ib-text-4); }
.st-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--ib-border); padding-top: 16px; margin-top: 4px; }
.st-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 16px; border-radius: 8px;
    border: 1px solid var(--ib-border); background: #fff; color: var(--ib-text-2); font: inherit; font-size: 13px; font-weight: 500;
    cursor: pointer; text-decoration: none; white-space: nowrap;
}
.st-btn:hover { background: var(--ib-bg-subtle); }
.st-btn.primary { background: var(--ib-dark); border-color: var(--ib-dark); color: #fff; min-width: 110px; justify-content: center; }
.st-btn.primary:hover { background: #111827; }
.st-link { border: 0; background: none; color: var(--ib-text-3); font: inherit; font-size: 12px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.st-link:hover { color: var(--ib-accent-dark); }

.st-hours { display: flex; flex-direction: column; gap: 10px; }
.st-hours-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.st-hours-row select { width: 120px; }
.st-check { display: inline-flex; align-items: center; gap: 12px; width: 150px; font-size: 13px; cursor: pointer; }
.st-check input, .st-radio input { width: 18px; height: 18px; margin: 0; flex: 0 0 auto; }
.st-to { font-size: 12px; color: var(--ib-text-3); }
.st-hours-row.off .st-check span { color: var(--ib-text-3); }
.st-now { margin-right: auto; font-size: 12px; color: var(--ib-text-3); }
.st-now.on { color: var(--ib-accent-dark); }

.st-alert { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 8px; border-left: 3px solid var(--ib-amber); background: #fffaeb; color: #93370d; font-size: 12px; flex-wrap: wrap; }
.st-alert > div { flex: 1; min-width: 200px; }
.st-alert.ok { border-color: var(--ib-accent); background: var(--ib-accent-soft); color: var(--ib-accent-dark); }
.st-alert.bad { border-color: var(--ib-red); background: #fef3f2; color: #b42318; }
.st-group-label { font-size: 13px; font-weight: 600; margin-top: 6px; }
.st-radio { display: flex; align-items: flex-start; gap: 12px; font-size: 13px; cursor: pointer; }
.st-radio small { display: block; color: var(--ib-text-3); font-size: 12px; margin-top: 2px; }

.st-table-wrap { border: 1px solid var(--ib-border); border-radius: 10px; overflow-x: auto; }
.st-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.st-table th { text-align: left; font-weight: 500; color: var(--ib-text-2); background: #fff; padding: 12px 14px; border-bottom: 1px solid var(--ib-border); white-space: nowrap; }
.st-table td { padding: 12px 14px; border-bottom: 1px solid var(--ib-border); vertical-align: middle; }
.st-table tr:last-child td { border-bottom: 0; }
.st-table tbody tr:hover { background: var(--ib-bg-subtle); }
.st-table .st-name small { display: block; color: var(--ib-text-4); font-size: 11px; margin-top: 2px; }
.st-table .st-type { color: var(--ib-text-2); white-space: nowrap; }
.st-table .st-type i { width: 16px; color: var(--ib-text-3); }
.st-table .st-ord { width: 64px; white-space: nowrap; }
.st-table .st-ord .ib-icon-btn { display: inline-grid; }
.st-row-act { text-align: right; white-space: nowrap; width: 90px; }
.st-row-act .ib-icon-btn { display: inline-grid; }
.st-sys { margin-left: 8px; font-size: 10px; color: var(--ib-text-3); background: var(--ib-bg-muted); border-radius: 4px; padding: 1px 6px; }
.st-clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ib-text-3); }
.st-empty { text-align: center; color: var(--ib-text-4); padding: 32px 14px !important; }
.st-table code { font-family: inherit; background: var(--ib-bg-muted); border-radius: 4px; padding: 2px 6px; font-size: 12px; }

.st-switch { position: relative; display: inline-block; width: 40px; height: 22px; cursor: pointer; }
.st-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.st-switch span { position: absolute; inset: 0; background: #e4e7ec; border-radius: 11px; transition: background .15s; }
.st-switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16,24,40,.2); transition: transform .15s; }
.st-switch input:checked + span { background: var(--ib-accent); }
.st-switch input:checked + span::after { transform: translateX(18px); }
.st-switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--ib-accent-soft); }

.st-inline { flex-direction: row; align-items: center; flex-wrap: wrap; }
.st-inline input[name=name] { flex: 1; min-width: 180px; }
.st-colors { display: flex; gap: 6px; }
.st-colors label { cursor: pointer; }
.st-colors input { position: absolute; opacity: 0; }
.st-colors .ib-tag-dot { width: 20px; height: 20px; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--ib-border); }
.st-colors input:checked + .ib-tag-dot { box-shadow: 0 0 0 2px var(--ib-dark); }

.st-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 16px; }
.st-ch { margin: 0; }
.st-ch-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.st-ch-top > div { flex: 1; min-width: 0; }
.st-ch-top b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-ch-top small { color: var(--ib-text-3); font-size: 12px; }
.st-ch-ico { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; flex: 0 0 auto; }
.st-ch-ico.fb { background: #eef4ff; color: var(--ib-fb); }
.st-ch-ico.line { background: #e9f9ef; color: var(--ib-line); }
.st-ch-ico.ig { background: #fdf2f8; color: var(--ib-ig); }
.st-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--ib-bg-muted); color: var(--ib-text-3); white-space: nowrap; }
.st-badge.on { background: var(--ib-accent-soft); color: var(--ib-accent-dark); }

@media (max-width: 860px) {
    .st-app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) 56px; }
    .st-app .ib-rail { grid-row: 3; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--ib-border); padding: 0 8px; }
    .st-app .ib-rail .spacer, .st-app .ib-rail .sep { display: none; }
    .st-nav { grid-row: 1; display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--ib-border); }
    .st-nav .ib-nav-head, .st-nav .ib-nav-section { display: none; }
    .st-nav .ib-nav-item { width: auto; flex: 0 0 auto; white-space: nowrap; }
    .st-main { grid-row: 2; padding: 0; }
    .st-wrap { border: 0; border-radius: 0; padding: 16px 16px 40px; }
    .st-crumb { display: none; }
    .st-check { width: 120px; }
    .st-hours-row { gap: 8px; }
    .st-hours-row select { width: 96px; }
    .st-card { padding: 16px; }
}

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 1280px) {
    .ib-app { grid-template-columns: 56px 0 320px minmax(0, 1fr) 260px; }
    .ib-nav { visibility: hidden; }
    .ib-app.nav-open { grid-template-columns: 56px 220px 320px minmax(0, 1fr) 260px; }
    .ib-app.nav-open .ib-nav { visibility: visible; }
}
@media (max-width: 1024px) {
    .ib-app, .ib-app.nav-open { grid-template-columns: 56px 0 300px minmax(0, 1fr) 0; }
    .ib-side { position: fixed; right: 0; top: 0; bottom: 0; width: 300px; box-shadow: -8px 0 24px rgba(16,24,40,.12); transform: translateX(105%); transition: transform .2s; z-index: 20; }
    .ib-app.side-open .ib-side { transform: none; }
    .ib-app.nav-open .ib-nav { position: fixed; left: 56px; top: 0; bottom: 0; width: 240px; z-index: 20; box-shadow: 8px 0 24px rgba(16,24,40,.12); }
}
@media (max-width: 760px) {
    .ib-app, .ib-app.nav-open { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 56px; }
    .ib-rail { grid-row: 2; grid-column: 1; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--ib-border); padding: 0 8px; }
    .ib-rail .spacer, .ib-rail .sep { display: none; }
    .ib-nav { position: fixed; left: 0; right: 0; top: 0; bottom: 56px; z-index: 20; display: none; }
    .ib-app.nav-open .ib-nav { display: block; visibility: visible; left: 0; width: auto; box-shadow: none; }
    .ib-list, .ib-chat { grid-row: 1; grid-column: 1; border-right: 0; }
    .ib-app.chat-open .ib-list { display: none; }
    .ib-app:not(.chat-open) .ib-chat { display: none; }
    .ib-back { display: grid; }
    .ib-msg .line { max-width: 88%; }
    .ib-side { width: 100%; bottom: 56px; }
    .ib-strip { gap: 4px 14px; }
    .ib-strip label { margin-left: 0; }
    .ib-close-btn span, .ib-bot-btn .lbl { display: none; }
    .ib-close-btn { padding: 0 10px; }
    .ib-chat-head { gap: 6px; padding: 10px; }
    .ib-overlay { padding-top: 8vh; }
    .ib-form .row2 { grid-template-columns: minmax(0, 1fr); }
}

/* ── แจ้งเตือน: แถบขอสิทธิ์ + การ์ดมุมจอ ───────────── */
.ib-notify-bar {
    display: flex; align-items: center; gap: 8px; margin: 8px 12px 0; padding: 8px 10px;
    background: var(--ib-accent-soft); color: var(--ib-accent-dark); border-radius: 8px; font-size: 12.5px; line-height: 1.4;
}
.ib-notify-bar span { flex: 1; min-width: 0; }
.ib-nbar-btn {
    border: 0; background: var(--ib-accent); color: #fff; border-radius: 6px; padding: 4px 12px;
    font: inherit; font-weight: 600; cursor: pointer; flex: 0 0 auto;
}
.ib-nbar-btn:hover { background: var(--ib-accent-dark); }
.ib-ntoasts {
    position: fixed; top: 14px; right: 14px; z-index: 60; display: flex; flex-direction: column; gap: 8px;
    width: min(320px, calc(100vw - 28px));
}
.ib-ntoast {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; text-align: left; width: 100%;
    background: #fff; border: 1px solid var(--ib-border, #e5e7eb); border-left: 4px solid var(--ib-accent);
    border-radius: 10px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(16, 24, 40, .14);
    font: inherit; font-size: 13px; color: var(--ib-dark); cursor: pointer; animation: ib-ntoast-in .18s ease-out;
}
.ib-ntoast.hot { border-left-color: #ef4444; }
.ib-ntoast b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-ntoast .tag { background: #fee2e2; color: #b91c1c; border-radius: 999px; padding: 0 8px; font-size: 11px; font-weight: 600; align-self: center; }
.ib-ntoast .pv { grid-column: 1 / -1; color: #667085; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes ib-ntoast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ══ ไทม์ไลน์แบบแอปแชท (Messenger / LINE) ══════════════════════════════
   สีตามแพลตฟอร์มของห้อง: .pf-facebook = Messenger, .pf-line = LINE
   บับเบิลต่อกันเป็นกลุ่ม (first/mid/last/single) มุมเล็กฝั่งผู้ส่งแบบ Messenger */
.ib-timeline {
    --b-in: #f0f2f5; --b-in-tx: #050505;
    --b-admin: #0866ff; --b-admin-tx: #fff;
    --b-bot: #4a8bff; --b-bot-tx: #fff;
    --tl-bg: #fff; --tl-meta: #8a8d91;
    background: var(--tl-bg); padding: 12px 16px 16px;
}
.ib-timeline.pf-line {
    --b-in: #fff; --b-in-tx: #111;
    --b-admin: #86d667; --b-admin-tx: #111;
    --b-bot: #c6eeb3; --b-bot-tx: #111;
    --tl-bg: #c9d7ea; --tl-meta: #5b6b82;
}
.ib-timeline .ib-day { color: var(--tl-meta); font-size: 11.5px; font-weight: 500; margin: 18px 0 10px; }
.ib-timeline.pf-line .ib-day { color: #fff; }
.ib-timeline.pf-line .ib-day::before { content: ''; }
.ib-timeline.pf-line .ib-day { display: table; margin: 18px auto 10px; background: rgba(0,0,0,.18); border-radius: 999px; padding: 2px 10px; }

.ib-timeline .ib-msg { margin: 1px 0; align-items: flex-start; }
.ib-timeline .ib-msg.first, .ib-timeline .ib-msg.single { margin-top: 8px; }
.ib-timeline .ib-msg.out { align-items: flex-end; }
.ib-timeline .ib-msg .who { font-size: 11px; color: var(--tl-meta); margin: 0 12px 3px; display: flex; gap: 4px; align-items: center; }
.ib-timeline .ib-msg .line { display: flex; align-items: flex-end; gap: 6px; max-width: min(78%, 600px); min-width: 0; }
.ib-timeline .ib-msg.out .line { flex-direction: row-reverse; }
.ib-timeline .ib-msg .av { flex: 0 0 28px; width: 28px; align-self: flex-end; }
.ib-avatar.xs { width: 28px; height: 28px; }
.ib-avatar.xs .pf { display: none; }
.ib-avatar.xs .ph { font-size: 12px; }
.ib-timeline .ib-msg .body { display: flex; flex-direction: column; gap: 3px; min-width: 0; max-width: 100%; }
.ib-timeline .ib-msg.out .body { align-items: flex-end; }
.ib-timeline .ib-msg .t { font-size: 10.5px; color: var(--tl-meta); padding-bottom: 3px; flex: 0 0 auto; }
.ib-timeline .ib-msg.flash .ib-bubble, .ib-timeline .ib-msg.flash .ib-grid { box-shadow: 0 0 0 3px #fbbf24; transition: box-shadow .2s; }

/* บับเบิล */
.ib-timeline .ib-bubble {
    background: var(--b-in); color: var(--b-in-tx); padding: 8px 12px; border-radius: 18px;
    font-size: 14.5px; line-height: 1.4; max-width: 100%;
}
.ib-timeline .ib-msg.admin .ib-bubble { background: var(--b-admin); color: var(--b-admin-tx); }
.ib-timeline .ib-msg.bot .ib-bubble { background: var(--b-bot); color: var(--b-bot-tx); }
.ib-timeline .ib-msg.out .ib-bubble a { color: inherit; text-decoration: underline; }
.ib-timeline.pf-line .ib-msg .ib-bubble a { color: #175cd3; }
/* มุมต่อกลุ่ม — ฝั่งลูกค้า (ซ้าย) */
.ib-timeline .ib-msg.in.first .ib-bubble { border-bottom-left-radius: 4px; }
.ib-timeline .ib-msg.in.mid .ib-bubble { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.ib-timeline .ib-msg.in.last .ib-bubble { border-top-left-radius: 4px; }
/* ฝั่งร้าน (ขวา) */
.ib-timeline .ib-msg.out.first .ib-bubble { border-bottom-right-radius: 4px; }
.ib-timeline .ib-msg.out.mid .ib-bubble { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.ib-timeline .ib-msg.out.last .ib-bubble { border-top-right-radius: 4px; }
/* LINE: มีหางที่บับเบิลแรก ไม่ใช่มุมตัด */
.ib-timeline.pf-line .ib-msg .ib-bubble { border-radius: 16px !important; }
.ib-timeline.pf-line .ib-msg.in.first .ib-bubble, .ib-timeline.pf-line .ib-msg.in.single .ib-bubble { border-top-left-radius: 4px !important; }
.ib-timeline.pf-line .ib-msg.out.first .ib-bubble, .ib-timeline.pf-line .ib-msg.out.single .ib-bubble { border-top-right-radius: 4px !important; }

.ib-timeline .ib-bubble.pb { font-weight: 500; }
.ib-timeline .ib-bubble.ph { background: transparent !important; color: var(--tl-meta) !important; border: 1px dashed currentColor; font-size: 13px; }

/* ตอบกลับ (quote) */
.ib-quote { display: flex; flex-direction: column; gap: 2px; max-width: min(70%, 480px); margin: 4px 12px -6px 46px; cursor: pointer; }
.ib-msg.out .ib-quote { margin: 4px 12px -6px 0; align-items: flex-end; }
.ib-quote .lb { font-size: 11px; color: var(--tl-meta); display: flex; gap: 4px; align-items: center; }
.ib-quote .qb {
    display: flex; gap: 6px; align-items: center; background: rgba(0,0,0,.05); color: #65676b; font-size: 13px;
    padding: 6px 12px 12px; border-radius: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.ib-timeline.pf-line .ib-quote .qb { background: rgba(255,255,255,.55); color: #333; }
.ib-quote .qb img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; flex: 0 0 auto; }
.ib-quote:hover .qb { filter: brightness(.96); }

/* รูป: ไม่มีบับเบิล + ตารางเมื่อหลายใบ */
.ib-grid { display: grid; gap: 2px; border-radius: 18px; overflow: hidden; width: min(260px, 100%); }
.ib-grid.n1 { grid-template-columns: 1fr; }
.ib-grid.n2 { grid-template-columns: 1fr 1fr; }
.ib-grid.n3 { grid-template-columns: 1fr 1fr; }
.ib-grid.n3 .cell:first-child { grid-column: 1 / -1; }
.ib-grid.n4 { grid-template-columns: 1fr 1fr; }
.ib-grid .cell { position: relative; border: 0; padding: 0; margin: 0; background: #e4e6eb; cursor: zoom-in; display: block; aspect-ratio: 1; }
.ib-grid.n1 .cell { aspect-ratio: auto; max-height: 340px; }
.ib-grid.n3 .cell:first-child { aspect-ratio: 2 / 1; }
.ib-grid .cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ib-grid.n1 .cell img { max-height: 340px; height: auto; }
.ib-grid .cell.broken { aspect-ratio: 4 / 3; cursor: default; }
.ib-grid .cell.broken::after { content: 'รูปหมดอายุ หรือเปิดไม่ได้'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: #65676b; }
.ib-grid .more { position: absolute; inset: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 22px; font-weight: 600; display: grid; place-items: center; }
.ib-timeline .ib-codes { font-size: 11px; color: var(--tl-meta); display: flex; gap: 4px; align-items: center; padding: 0 4px; }
.ib-file { display: inline-flex; gap: 6px; align-items: center; padding: 8px 12px; border-radius: 18px; background: var(--b-in); color: var(--b-in-tx); font-size: 13px; text-decoration: none; }

/* การ์ดสินค้าแบบ carousel (Messenger generic template) */
.ib-carousel { display: flex; gap: 8px; overflow-x: auto; max-width: min(100%, 560px); padding: 2px 2px 6px; scroll-snap-type: x mandatory; }
/* ฝั่งร้านชิดขวา — ใช้ auto margin (ไม่ใช้ justify-content:flex-end ที่ทำให้เลื่อนไปการ์ดแรกไม่ได้เมื่อล้น) */
.ib-msg.out .ib-carousel > :first-child { margin-left: auto; }
.ib-carousel { scrollbar-width: thin; scrollbar-color: #c4c7cc transparent; }
.ib-timeline .ib-msg .body:has(.ib-carousel) { width: 100%; }
.ib-pcard {
    flex: 0 0 210px; scroll-snap-align: start; background: #fff; border-radius: 16px; overflow: hidden;
    border: 1px solid #e4e6eb; display: flex; flex-direction: column; color: #050505;
}
.ib-pcard .ph { position: relative; aspect-ratio: 1; background: #f0f2f5; display: grid; place-items: center; color: #bcc0c4; font-size: 28px; }
.ib-pcard .ph img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.ib-pcard .badge { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.ib-pcard.sold .ph img { filter: grayscale(.6); opacity: .8; }
.ib-pcard .b { padding: 8px 12px 6px; }
.ib-pcard .tt { font-weight: 600; font-size: 13.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ib-pcard .sub { font-size: 12px; color: #65676b; margin-top: 2px; }
.ib-pcard .btn { border-top: 1px solid #e4e6eb; text-align: center; font-size: 13px; font-weight: 600; color: #0866ff; padding: 8px; }
.ib-timeline.pf-line .ib-pcard .btn { color: #06c755; }
.ib-pcard.missing .ph { aspect-ratio: 2 / 1; }

/* ดูรูปใหญ่ */
.ib-lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.88); display: grid; place-items: center; }
.ib-lightbox img { max-width: 92vw; max-height: 86vh; object-fit: contain; border-radius: 4px; }
.ib-lightbox button { position: absolute; border: 0; background: rgba(255,255,255,.12); color: #fff; width: 44px; height: 44px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.ib-lightbox button:hover { background: rgba(255,255,255,.24); }
.ib-lightbox .x { top: 16px; right: 16px; }
.ib-lightbox .prev { left: 16px; top: 50%; transform: translateY(-50%); }
.ib-lightbox .next { right: 16px; top: 50%; transform: translateY(-50%); }
.ib-lightbox .open { position: absolute; bottom: 16px; color: #fff; font-size: 13px; opacity: .8; }

/* ช่องพิมพ์แบบแคปซูล */
.ib-composer textarea { background: #f0f2f5; border-radius: 20px; padding: 10px 14px; min-height: 44px; }
.ib-composer .bar .send { border-radius: 999px; background: #0866ff; }
.ib-composer.pf-line .bar .send { background: #06c755; }

@media (max-width: 860px) {
    .ib-timeline .ib-msg .line { max-width: 90%; }
    .ib-quote { margin-left: 46px; max-width: 80%; }
    .ib-pcard { flex-basis: 180px; }
}
