:root { --blue: #0068ff; --bg: #eef0f1; --line: #e1e4ea; --muted: #7589a3; --me: #e5efff; --tr: #f0f6ff; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Noto Sans KR", "Malgun Gothic", sans-serif; color: #081c36; background: #fff; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
.err { color: #d93025; font-size: 13px; min-height: 18px; margin-top: 6px; white-space: pre-wrap; }
.hint { color: var(--muted); font-size: 12.5px; }

.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #e8f1ff, #fff); padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 16px; padding: 28px 24px; box-shadow: 0 6px 30px rgba(0, 60, 150, .12); text-align: center; }
.login-card h1 { margin: 10px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.login-card input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; }
.login-card button { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 10px; background: var(--blue); color: #fff; font-weight: 600; }

.app { display: flex; height: 100vh; height: 100dvh; }
.side { width: 340px; min-width: 280px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: #fff; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--blue); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; flex: 1; }
.brand img { border-radius: 7px; background: #fff; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #bbb; box-shadow: 0 0 0 2px rgba(255, 255, 255, .6); }
.conn.ok { background: #35d07f; } .conn.warn { background: #ffb020; } .conn.bad { background: #ff4d4f; }
.icon-btn { background: transparent; border: 0; color: inherit; font-size: 18px; padding: 4px 8px; border-radius: 8px; }
.side-head .icon-btn:hover { background: rgba(255, 255, 255, .15); }
#installBtn { font-size: 13px; border: 1px solid rgba(255, 255, 255, .6); }
.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 8px 12px; border-radius: 8px; border: 0; background: var(--bg); font-size: 14px; }
.bridge-warn { background: #fff4e5; color: #8a5300; font-size: 12.5px; padding: 8px 12px; border-bottom: 1px solid #ffe1b3; }
.rooms { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.room { display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f3f4f6; }
.room:hover { background: #f3f5f8; } .room.active { background: #e5efff; }
.av { width: 46px; height: 46px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 18px; }
.room-main { flex: 1; min-width: 0; }
.room-top { display: flex; gap: 6px; align-items: baseline; }
.room-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-time { color: var(--muted); font-size: 12px; flex: none; }
.room-bottom { display: flex; gap: 6px; align-items: center; }
.room-prev { flex: 1; color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room.unread .room-prev { color: #081c36; font-weight: 600; }
.badge { background: #fa383e; color: #fff; border-radius: 10px; font-size: 11.5px; font-weight: 700; padding: 1px 6px; flex: none; }
.empty, .no-room { color: var(--muted); text-align: center; padding: 40px 20px; font-size: 14px; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.no-room { margin: auto; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: #fff; border-bottom: 1px solid var(--line); }
.chat-head .back { display: none; font-size: 28px; line-height: 1; color: var(--blue); }
.chat-title { flex: 1; min-width: 0; }
#roomTitle { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--muted); font-size: 12px; }
.zalo-btn { background: var(--blue); color: #fff; text-decoration: none; font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 8px; white-space: nowrap; }
#roomInfoBtn { color: var(--muted); font-size: 20px; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 18px 22px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: rgba(0, 0, 0, .18); color: #fff; font-size: 12px; border-radius: 10px; padding: 2px 10px; margin: 10px 0 6px; }
.more { align-self: center; font-size: 13px; color: var(--blue); background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 4px 12px; margin-bottom: 6px; }
.row { display: flex; flex-direction: column; max-width: min(78%, 560px); }
.row.in { align-self: flex-start; } .row.me { align-self: flex-end; align-items: flex-end; }
.sender { font-size: 12px; color: var(--muted); margin: 6px 0 2px 10px; }
.bubble { background: #fff; border-radius: 12px; padding: 8px 12px; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.row.me .bubble { background: var(--me); }
.orig { color: #081c36; }
.tr { margin: 6px -12px -8px; padding: 6px 12px 8px; background: var(--tr); border-radius: 0 0 12px 12px; color: #0b4db8; border-top: 1px solid #dbe8ff; }
.tr::before { content: "KO  "; font-size: 10.5px; font-weight: 700; color: #5b8def; letter-spacing: .5px; }
.row.me .vi { color: #081c36; }
.row.me .ko { color: #0b4db8; margin-top: 2px; }
.row.me .src { color: var(--muted); font-size: 12px; margin-top: 4px; border-top: 1px dashed #c9d8f5; padding-top: 3px; }
.label { color: var(--muted); font-size: 13px; }
.meta { font-size: 11.5px; color: var(--muted); margin: 2px 6px 4px; display: flex; gap: 6px; align-items: center; }
.st-failed, .st-unknown { color: #d93025; }
.st-sent { color: #1a9e55; }
.retry { white-space: nowrap; flex: none; font-size: 12px; border: 1px solid #d93025; color: #d93025; background: #fff; border-radius: 10px; padding: 0 8px; }
.imgs { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.imgs img { min-width: 60px; min-height: 60px; max-width: 240px; max-height: 260px; border-radius: 10px; cursor: zoom-in; background: #dde3ea; object-fit: cover; }
.imgs.sticker img { max-width: 130px; max-height: 130px; background: transparent; cursor: default; }
.composer { display: flex; gap: 8px; padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 9px 14px; font: inherit; font-size: 16px; max-height: 140px; outline: none; }
.composer textarea:focus { border-color: var(--blue); }
.composer button { border: 0; background: var(--blue); color: #fff; border-radius: 18px; padding: 9px 16px; font-weight: 600; }
.composer button:disabled { opacity: .5; }
.composer .attach-btn { background: #eef2f6; color: #344054; padding: 9px 12px; font-size: 20px; line-height: 1; }
.imgs video { min-width: 120px; max-width: 240px; max-height: 260px; border-radius: 10px; display: block; background: #111; }

.dlg { border: 0; border-radius: 14px; padding: 20px; width: min(420px, 92vw); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.dlg h2 { margin: 0 0 4px; font-size: 18px; }
.dlg-sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.dlg label { display: block; margin: 10px 0; font-size: 14px; }
.dlg label input[type=tel], .dlg label input[type=url] { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; }
.dlg .chk { display: flex; gap: 8px; align-items: flex-start; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dlg-btns button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 14px; }
.dlg-btns button[value=save], .dlg-btns button[value=close] { background: var(--blue); color: #fff; border-color: var(--blue); }
.dlg-btns .danger { color: #d93025; margin-right: auto; }
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); display: flex; align-items: center; justify-content: center; z-index: 50; cursor: zoom-out; }
.viewer img, .viewer video { max-width: 96vw; max-height: 96vh; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: #263238; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13.5px; z-index: 60; max-width: 90vw; }

@media (max-width: 760px) {
  .side { width: 100%; min-width: 0; border-right: 0; }
  .chat { display: none; }
  .app.in-room .side { display: none; }
  .app.in-room .chat { display: flex; }
  .chat-head .back { display: block; }
  .row { max-width: 86%; }
  .zalo-btn { padding: 4px 8px; font-size: 12px; }
  .side-head { gap: 4px; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top)); }
  .brand { font-size: 14px; gap: 6px; }
  .brand img { width: 22px; height: 22px; }
  .logout-top { font-size: 11px; padding: 2px 4px; }
  .search { padding: 4px 8px; }
  .search input { padding: 5px 10px; font-size: 13px; }
  .room { gap: 8px; padding: 6px 10px; }
  .av { width: 38px; height: 38px; font-size: 15px; }
  .room-prev { font-size: 12.5px; }
  .chat-head {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "back av title info" "tools tools tools tools";
    gap: 2px 6px;
    padding: 4px 8px 5px;
    padding-top: max(4px, env(safe-area-inset-top));
    align-items: center;
  }
  .chat-head .back { grid-area: back; font-size: 22px; padding: 0 2px; }
  .head-av { grid-area: av; width: 26px; height: 26px; font-size: 11px; margin-right: 0; }
  .chat-title { grid-area: title; }
  #roomTitle { font-size: 14px; }
  #roomSub { display: none; }
  #roomInfoBtn { grid-area: info; font-size: 16px; padding: 0 2px; }
  .chat-tools { grid-area: tools; display: flex; gap: 6px; align-items: center; min-width: 0; }
  .tr-toggle button { font-size: 11px; padding: 3px 6px; }
  html, body { font-size: 14px; }
  .bubble { padding: 6px 10px; }
  .msgs { padding: 8px 12px 16px; gap: 2px; }
}

/* v1.9.1 avatars + 번역 안 함 */
.av { position: relative; overflow: hidden; }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.head-av { width: 36px; height: 36px; font-size: 14px; margin-right: 8px; }
.row.in.with-av { position: relative; padding-left: 40px; }
.row.in .mav { position: absolute; left: 0; width: 32px; height: 32px; font-size: 12px; }
.row.in .mav.at-sender { top: 22px; } .row.in .mav.top { top: 0; }
.nt-tag { flex: none; font-size: 11px; color: var(--muted); border: 1px solid currentColor; border-radius: 8px; padding: 0 5px; margin-left: 6px; white-space: nowrap; }
.hint-inline { font-weight: normal; font-size: 12px; color: var(--muted); }
.bubble .raw { white-space: pre-wrap; }

/* v1.9.2 message actions (회수 / 나에게서 삭제) */
.msg-more { border: 0; background: transparent; color: inherit; opacity: .55; font-size: 15px; line-height: 1; padding: 0 6px; margin-left: 4px; cursor: pointer; border-radius: 6px; }
.msg-more:hover, .msg-more:focus-visible { opacity: 1; background: rgba(127,127,127,.18); }
@media (hover: hover) and (pointer: fine) { .row .msg-more { visibility: hidden; } .row:hover .msg-more, .row .msg-more:focus-visible { visibility: visible; } }
@media (pointer: coarse) { .row .msg-more { opacity: .4; } .row .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }
.msg-menu { position: fixed; z-index: 1000; min-width: 150px; background: var(--card, #fff); color: inherit; border: 1px solid rgba(127,127,127,.3); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 4px; display: flex; flex-direction: column; }
.msg-menu .mi { border: 0; background: transparent; color: inherit; text-align: left; font-size: 15px; padding: 10px 12px; border-radius: 7px; cursor: pointer; }
.msg-menu .mi:hover { background: rgba(127,127,127,.15); }
.msg-menu .mi.danger { color: #d33; }
.meta .act.st-failed { white-space: normal; }

/* v1.9.2 unread badges (Zalo style red circle) */
.badge { min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; border-radius: 9px; text-align: center; box-sizing: border-box; font-size: 11px; }
.icon-btn.back { position: relative; }
.icon-btn.back[data-n]::after { content: attr(data-n); position: absolute; top: 0; right: -6px; min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px; border-radius: 8px; background: #fa383e; color: #fff; font-size: 10px; font-weight: 700; box-sizing: border-box; text-align: center; }

/* v1.9.7 recalled / deleted: text stays, orange strip on the bubble only */
.row.removed .bubble { box-shadow: inset 0 0 0 3px #f97316; }
.row.removed .imgs { box-shadow: 0 0 0 3px #f97316; border-radius: 12px; }

.logout-top { font-size: 12px; padding: 4px 8px; white-space: nowrap; }

/* v1.9.2 pinned rooms */
.room { position: relative; }
.pin-ic { font-size: 11px; margin-left: 4px; flex: none; }
.room.pinned { background: rgba(0,104,255,.04); }
.room-more { position: absolute; right: 6px; top: 6px; border: 0; background: rgba(255,255,255,.9); border-radius: 6px; padding: 0 6px; font-size: 15px; cursor: pointer; color: #555; visibility: hidden; }
@media (hover: hover) and (pointer: fine) { .room:hover .room-more, .room-more:focus-visible { visibility: visible; } }
@media (pointer: coarse) { .room { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }
/* v1.9.3 답장 */
.reply-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #f3f6fb; border-top: 1px solid var(--line); border-left: 3px solid var(--blue); }
.reply-bar .rb-main { flex: 1; min-width: 0; }
.reply-bar .rb-who { font-size: 12px; color: var(--blue); font-weight: 600; }
.reply-bar .rb-text { font-size: 13px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .rb-x { border: 0; background: none; font-size: 18px; color: #888; cursor: pointer; padding: 4px 8px; }
.bubble .quote { border-left: 3px solid rgba(0,0,0,.25); background: rgba(0,0,0,.05); border-radius: 6px; padding: 4px 8px; margin-bottom: 6px; font-size: 13px; cursor: pointer; }
.bubble .quote .q-who { font-weight: 600; font-size: 12px; opacity: .8; }
.bubble .quote .q-text, .bubble .quote .q-tr { white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.bubble .quote .q-tr { opacity: .7; }
.bubble .quote img { max-width: 80px; max-height: 60px; border-radius: 4px; display: block; }
.row.flash .bubble { outline: 2px solid var(--blue); }
/* v1.9.4 media label bubbles */
.bubble.media-bubble .media-label { font-weight: 600; color: #444; margin-bottom: 4px; }
.row.me .bubble.media-bubble .media-label { color: inherit; }
.bubble .zalo-view { display: inline-block; margin-top: 4px; border: 1px solid var(--blue); color: var(--blue); background: #fff; border-radius: 14px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer; }

/* v18: per-room 번역함 / 번역안함 in the chat header */
.chat-tools { display: flex; align-items: center; gap: 8px; flex: none; }
.tr-toggle { display: flex; flex: none; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.tr-toggle button { border: 0; background: transparent; color: #667085; font-size: 12.5px; font-weight: 700; padding: 6px 9px; line-height: 1.2; }
.tr-toggle button.on { background: var(--blue); color: #fff; }
.tr-toggle button#trOff.on { background: #667085; }
@media (max-width: 760px) {
  .tr-toggle button { font-size: 11px; padding: 3px 6px; }
}

.rx { position: relative; display: flex; flex-wrap: wrap; gap: 4px; margin: -2px 8px 2px; align-items: center; }
.row.me .rx { justify-content: flex-end; }
.rx-pill { background: #fff; border: 1px solid var(--line); border-radius: 12px; font-size: 13px; line-height: 1.3; padding: 1px 7px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.bubble, .imgs { position: relative; }
.rx-add { position: absolute; right: 0; bottom: 0; transform: translate(25%, 25%); width: 16px; height: 16px; padding: 0; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(9,30,66,.22); display: flex; align-items: center; justify-content: center; z-index: 3; cursor: pointer; overflow: hidden; }
.rx-add svg { width: 15px; height: 15px; fill: #5f6f86; display: block; }
.rx-pop { position: fixed; display: flex; gap: 2px; background: #fff; border-radius: 22px; padding: 4px 6px; z-index: 40; box-shadow: 0 2px 12px rgba(9,30,66,.2); }
.rx-choice { border: 0; background: transparent; box-shadow: none; font-size: 22px; line-height: 1; padding: 2px 4px; cursor: pointer; border-radius: 50%; }
.rx-choice:hover { background: #f2f4f7; }
.rx-off { font-size: 12px; font-weight: 700; color: #667085; padding: 4px 8px; }

/* v1.9.23 group collage (Zalo .zavatar-multi) + read receipt */
.av.av-stack { background: #d0d5dd; }
.av.av-stack .av-cell { position: absolute; border-radius: 50%; overflow: hidden; background: #98a2b3; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.av.av-stack .av-cell img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.av-stack.n2 .av-cell { width: 66%; height: 66%; font-size: .42em; }
.av-stack.n2 .av-cell:nth-child(1) { left: 0; top: 33%; }
.av-stack.n2 .av-cell:nth-child(2) { left: 33%; top: 0; }
.av-stack.n3 .av-cell { width: 58%; height: 58%; font-size: .38em; }
.av-stack.n3 .av-cell:nth-child(1) { left: 21%; top: 0; }
.av-stack.n3 .av-cell:nth-child(2) { left: 0; top: 42%; }
.av-stack.n3 .av-cell:nth-child(3) { left: 42%; top: 42%; }
.av-stack.n4 .av-cell { width: 50%; height: 50%; font-size: .34em; }
.av-stack.n4 .av-cell:nth-child(1) { left: 0; top: 0; }
.av-stack.n4 .av-cell:nth-child(2) { right: 0; top: 0; }
.av-stack.n4 .av-cell:nth-child(3) { left: 0; bottom: 0; }
.av-stack.n4 .av-cell:nth-child(4) { right: 0; bottom: 0; }
.receipt { display: flex; justify-content: flex-end; align-items: center; margin: 1px 2px 4px; min-height: 16px; }
.receipt .sav { width: 16px; height: 16px; border-radius: 50%; overflow: hidden; margin-left: -4px; border: 1px solid #fff; background: #d0d5dd; position: relative; }
.receipt .sav:first-child { margin-left: 0; }
.receipt .sav img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.receipt .tick { color: var(--muted); font-size: 12px; letter-spacing: -2px; line-height: 1; }
.receipt .tick.one { letter-spacing: 0; }
