/* ============ Khung chat ============ */
.chat { position: relative; display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--chat-bg); }
.chat-head {
  flex: none; height: var(--top-h); display: flex; align-items: center; gap: 2px; padding: 0 6px;
  background: var(--surface); border-bottom: 1px solid var(--border); z-index: 4;
}
@media (min-width: 900px) { .chat-head .back { display: none; } .chat-head { padding-left: 14px; } }
.chat-peer { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; padding: 6px 4px; border-radius: 10px; }
.chat-peer:hover { background: var(--hover); }
.chat-peer-text { display: flex; flex-direction: column; min-width: 0; }
.chat-peer-text b { font-size: 16px; }
.chat-peer-text small { color: var(--text-2); font-size: 12.5px; }
.chat-peer .dot-online { width: 14px; height: 14px; max-width: none; max-height: none; right: -1px; bottom: -1px; }
.chat-tools { display: flex; flex: none; }
.chat-tools .icon-btn:disabled { opacity: .35; }

.call-bar {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--accent-soft); color: var(--accent-text); font-weight: 600; font-size: 14px;
}
.call-bar span { flex: 1; }
.search-bar { flex: none; display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(var(--top-h) + 54px); max-height: 55%; overflow-y: auto;
  background: var(--surface); box-shadow: var(--shadow); z-index: 6; border-bottom: 1px solid var(--border);
}
.search-results mark { background: #fde68a; color: #111; border-radius: 3px; padding: 0 1px; }

/* Danh sách tin */
.msgs { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px 4px; outline: none; }
@media (min-width: 900px) { .msgs { padding: 12px 24px 4px; } }
.chat-begin { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 16px 12px; color: var(--text-2); text-align: center; }
.chat-begin b { color: var(--text); font-size: 17px; }
.day-sep { display: flex; justify-content: center; margin: 14px 0 6px; }
.day-sep span, .sys-msg span {
  font-size: 12px; color: var(--text-2); background: var(--surface); padding: 3px 10px; border-radius: 99px; box-shadow: var(--shadow-sm);
}
.sys-msg { display: flex; justify-content: center; margin: 8px 24px; text-align: center; }
.sys-msg span { background: color-mix(in srgb, var(--surface) 75%, transparent); line-height: 1.5; }

.mwrap { scroll-margin: 80px; }
.mwrap.flash .bubble, .mwrap.flash .jumbo, .mwrap.flash .sticker { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px #fbbf24; } }
.mrow { display: flex; align-items: flex-start; gap: 8px; margin-top: 2px; }
.mrow.first { margin-top: 10px; }
.mrow.mine { flex-direction: row-reverse; }
.m-ava { width: 32px; flex: none; }
.m-col { display: flex; flex-direction: column; align-items: flex-start; max-width: min(76%, 560px); min-width: 0; }
.mine .m-col { align-items: flex-end; }
.m-name { font-size: 12.5px; color: var(--text-2); margin: 0 0 2px 10px; }
.m-body { position: relative; display: flex; align-items: center; gap: 4px; max-width: 100%; }
.mine .m-body { flex-direction: row-reverse; }

.bubble {
  position: relative; padding: 7px 12px 6px; border-radius: 18px; background: var(--bubble-other); color: var(--bubble-other-text);
  box-shadow: var(--shadow-sm); min-width: 0; max-width: 100%; overflow-wrap: anywhere;
}
.other .bubble { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.other.last .bubble { border-bottom-left-radius: 18px; }
.mine .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
.mine.first .bubble { border-top-right-radius: 18px; }
.mine.last .bubble { border-bottom-right-radius: 18px; }
.bubble .text { white-space: pre-wrap; line-height: 1.42; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.other .bubble a { color: var(--accent-text); }
.bubble .time { display: block; font-size: 11.5px; color: var(--text-2); text-align: right; margin-top: 2px; line-height: 1.2; }
.mine .bubble .time { color: var(--bubble-me-sub); }
.bubble-time { font-size: 11.5px; color: var(--text-2); padding: 0 6px; }
.bubble.recalled { background: transparent; border: 1px solid var(--border); box-shadow: none; color: var(--text-2); }
.mine .bubble.recalled { background: transparent; color: var(--text-2); }
.mine .bubble.recalled .time { color: var(--text-2); }
.retry { color: #fff; font-weight: 700; text-decoration: underline; font-size: 11.5px; }

.jumbo { font-size: 44px; line-height: 1.15; padding: 2px 4px; }
.sticker { font-size: 88px; line-height: 1; padding: 4px; animation: pop .5s cubic-bezier(.3, 1.6, .5, 1); user-select: none; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.jumbo + .bubble-time, .sticker + .bubble-time { align-self: flex-end; }
.mrow.jumbo .m-body { flex-direction: column; align-items: flex-start; }
.mrow.mine.jumbo .m-body { align-items: flex-end; }

/* Trích dẫn khi trả lời */
.quote {
  display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; margin: 2px 0 6px; padding: 5px 8px;
  border-left: 3px solid var(--accent); border-radius: 6px; background: var(--surface-2); font-size: 13px; color: var(--text);
}
.quote > span { display: flex; flex-direction: column; min-width: 0; }
.quote b { font-size: 12.5px; }
.quote .ellipsis { color: var(--text-2); }
.quote img { width: 36px; height: 36px; border-radius: 4px; object-fit: cover; flex: none; }
.mine .quote { background: rgba(255, 255, 255, .16); border-left-color: #fff; color: #fff; }
.mine .quote .ellipsis { color: var(--bubble-me-sub); }

/* Ảnh */
.bubble.media { padding: 3px; background: var(--bubble-other); }
.mine .bubble.media { background: var(--bubble-me); }
.bubble.media .quote { margin: 4px 4px 6px; width: auto; }
.img-box {
  position: relative; display: block; width: min(280px, 62vw); max-height: 380px; border-radius: 15px; overflow: hidden;
  background: var(--skeleton);
}
.img-box.tall { width: min(200px, 48vw); }
.img-box img { width: 100%; height: 100%; object-fit: cover; }
.media .time { padding: 2px 8px 2px; }
.progress-ring {
  position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%;
  background: conic-gradient(#fff calc(var(--p) * 1%), rgba(255, 255, 255, .25) 0); display: grid; place-items: center;
}
.progress-ring b {
  width: 46px; height: 46px; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; display: grid; place-items: center;
}

/* File */
.bubble.file { min-width: 240px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
.file-ic {
  width: 44px; height: 44px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center;
  font-size: 11px; font-weight: 800; flex: none; letter-spacing: .02em;
}
.mine .file-ic { background: rgba(255, 255, 255, .22); }
.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-meta small { color: var(--text-2); font-size: 12.5px; }
.mine .file-meta small { color: var(--bubble-me-sub); }
.file-row .icon-btn { color: inherit; }
.bar { display: block; height: 4px; border-radius: 2px; background: rgba(127, 127, 127, .3); margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: currentColor; transition: width .15s; }

/* Tin cuộc gọi */
.call-card { min-width: 220px; padding: 10px 12px 6px; }
.call-row { display: flex; align-items: center; gap: 10px; }
.call-row > span:last-child { display: flex; flex-direction: column; }
.call-row small { font-size: 12.5px; color: var(--text-2); }
.mine .call-row small { color: var(--bubble-me-sub); }
.call-ic { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--call-green); flex: none; }
.mine .call-ic { background: rgba(255, 255, 255, .2); color: #fff; }
.call-card.missed .call-ic { color: var(--danger); }
.mine .call-card.missed .call-ic { color: #fecaca; }
.call-back {
  display: block; width: 100%; margin-top: 8px; padding: 7px 0 3px; border-top: 1px solid rgba(127, 127, 127, .25);
  font-weight: 600; font-size: 14px; color: var(--accent-text);
}
.mine .call-back { color: #fff; }

/* Cảm xúc */
.reacts {
  display: inline-flex; align-items: center; gap: 2px; margin: -6px 6px 0; padding: 1px 6px; position: relative; z-index: 1;
  border-radius: 99px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; box-shadow: var(--shadow-sm);
}
.reacts span { font-size: 12px; color: var(--text-2); margin-left: 2px; }
.reacts.mine { border-color: var(--accent); }
.react-emo { font-size: 22px; }
.m-actions { display: flex; gap: 0; opacity: 0; transition: opacity .12s; flex: none; }
.m-actions button { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); }
.m-actions button:hover { background: var(--surface); color: var(--text); }
@media (hover: hover) { .mrow:hover .m-actions, .m-actions:focus-within { opacity: 1; } }
@media (hover: none) { .m-actions { display: none; } }
.react-pop, .react-bar { display: flex; gap: 2px; }
.react-pop { position: fixed; z-index: 120; padding: 4px 6px; border-radius: 99px; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border); }
.react-pop button, .react-bar button { width: 40px; height: 40px; border-radius: 50%; font-size: 24px; transition: transform .12s; }
.react-pop button:hover, .react-bar button:hover { transform: scale(1.2); }
.react-pop button.on, .react-bar button.on { background: var(--accent-soft); }
.react-bar { justify-content: space-around; padding: 6px 4px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }

/* Trạng thái gửi */
.msg-status { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 12px; color: var(--text-2); padding: 3px 4px 6px; min-height: 22px; }
.msg-status.seen { color: var(--accent-text); }
.seen-avatars { display: inline-flex; }
.seen-avatars .avatar { margin-left: -4px; box-shadow: 0 0 0 1.5px var(--chat-bg); border-radius: 50%; }

.typing { flex: none; display: flex; align-items: center; gap: 8px; padding: 2px 16px 4px; font-size: 12.5px; color: var(--text-2); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: dot 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.jump-new {
  position: absolute; right: 16px; bottom: 92px; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 99px; background: var(--surface); color: var(--accent-text); font-weight: 600; font-size: 13.5px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}

/* Ô soạn tin */
.composer { flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 8px calc(6px + var(--safe-b)); }
.composer-row { display: flex; align-items: flex-end; gap: 2px; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: var(--surface-2); border-radius: 20px;
  padding: 10px 14px; min-height: 40px; max-height: 140px; line-height: 1.4; margin: 0 4px;
}
.composer textarea:focus { box-shadow: 0 0 0 2px var(--accent-soft); }
.send-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--on-accent); transition: background .15s;
}
.send-btn:disabled { background: var(--surface-2); color: var(--text-3); opacity: 1; }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 4px 4px 8px 8px; color: var(--accent-text); }
.reply-text { flex: 1; min-width: 0; display: flex; flex-direction: column; border-left: 3px solid var(--accent); padding-left: 8px; }
.reply-text b { font-size: 13px; }
.reply-text span { color: var(--text-2); font-size: 13px; }
.blocked-note { text-align: center; padding: 10px; color: var(--text-2); font-size: 14px; }
.emoji-panel { height: 250px; display: flex; flex-direction: column; border-top: 1px solid var(--border); margin-top: 6px; }
.emoji-tabs { display: flex; gap: 6px; padding: 6px 4px; flex: none; }
.emoji-tabs button { padding: 4px 12px; border-radius: 99px; font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.emoji-tabs button.on { background: var(--accent-soft); color: var(--accent-text); }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); align-content: start; }
.emoji-grid button { height: 42px; font-size: 26px; border-radius: 8px; }
.emoji-grid button:hover { background: var(--hover); }
.emoji-grid.sticker { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
.emoji-grid.sticker button { height: 78px; font-size: 54px; }

.drop-zone {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; text-align: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent); border: 3px dashed var(--accent); color: var(--accent-text);
  font-weight: 700; pointer-events: none; backdrop-filter: blur(2px);
}
.drop-zone .ic { margin: 0 auto 8px; }
.fwd-preview { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 14px; white-space: pre-wrap; max-height: 90px; overflow: hidden; }

/* ============ Xem ảnh toàn màn hình ============ */
.viewer { position: fixed; inset: 0; z-index: 150; background: #000; color: #fff; display: flex; flex-direction: column; }
.viewer .icon-btn { color: #fff; }
.viewer .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.viewer-bar { display: flex; align-items: center; gap: 4px; padding: calc(8px + var(--safe-t)) 8px 8px 16px; position: relative; z-index: 2; background: linear-gradient(rgba(0, 0, 0, .6), transparent); }
.viewer-info { flex: 1; display: flex; flex-direction: column; font-size: 13px; min-width: 0; }
.viewer-info span { color: #c7c7c7; }
.viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
.viewer-track { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.viewer-track img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255, 255, 255, .14); color: #fff; display: grid; place-items: center;
}
.viewer-nav.prev { left: 12px; }
.viewer-nav.next { right: 12px; }
.viewer-nav[hidden] { display: none; }
@media (hover: none) { .viewer-nav { display: none; } }
.viewer-count { text-align: center; padding: 10px 0 calc(12px + var(--safe-b)); font-size: 13px; color: #c7c7c7; }
