/* Calida Chat (web app iPhone) — màu thương hiệu đo từ logo (brand/README.md), cùng bảng màu với app máy tính (client/ui/style.css).
   Đổi màu chủ đạo: sửa --brand, --brand-dark, --brand-light (và --brand-text cho chữ / viền trên nền tối). */
:root {
  --brand: #023da3;        /* xanh logo (đo từ điểm ảnh): nút chính, bong bóng của mình, huy hiệu, thanh tiêu đề, nút gọi */
  --brand-dark: #023182;   /* nhấn / đang bấm */
  --brand-light: #edf1f9;  /* nền nhạt */
  --brand-text: #023da3;   /* chữ / viền màu thương hiệu trên nền sáng (9,55 : 1 trên trắng) */
  --bg: var(--brand-light);
  --panel: #ffffff;
  --line: #d6deea;
  --text: #121722;
  --muted: #566074;
  --accent: var(--brand-text);
  --accent-soft: #dce5f2;
  --mine: var(--brand);
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --ok: #15803d;
  --err: #b91c1c;
  --heart: #e5304f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand-text: #6ea0f0;  /* 6,3 : 1 trên #171c26 */
    --bg: #0f131b;
    --panel: #171c26;
    --line: #283042;
    --text: #e8ecf4;
    --muted: #9aa5b8;
    --accent-soft: #1a2a47;
    --theirs: #222a38;
    --heart: #ff5a78;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); margin: 0; }
.note { font-size: 13px; color: var(--muted); margin: 0; }

button {
  font: inherit; cursor: pointer; border: 0; border-radius: 12px;
  background: var(--brand); color: #fff; padding: 12px 18px; font-weight: 600; min-height: 44px;
}
button:disabled { opacity: .5; }
button.primary:active:not(:disabled), .send:active:not(:disabled) { background: var(--brand-dark); }
button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--err); }
.link-btn { background: none; color: var(--accent); padding: 6px 0; min-height: 0; font-weight: 600; }
.icon-btn {
  background: transparent; color: var(--text); padding: 0; min-width: 44px; min-height: 44px;
  font-size: 22px; display: grid; place-items: center; border-radius: 12px;
}
.icon-btn.back { font-size: 34px; line-height: 1; padding-bottom: 4px; }
.icon-btn.spacer { visibility: hidden; }

/* Ô nhập >= 16px để iOS không tự phóng to khi chạm vào */
input, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; outline: none; width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); }
/* Viền focus (bàn phím) theo màu thương hiệu thay cho viền mặc định; trên thanh tiêu đề xanh thương hiệu thì viền trắng */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bar :focus-visible { outline-color: #fff; }

/* ----- Màn hình ----- */
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  padding-left: var(--safe-left); padding-right: var(--safe-right);
}
.screen.center {
  align-items: center; justify-content: center; overflow: auto;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.card {
  width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 24px 20px; display: grid; gap: 14px;
}
.card p { margin: 0; }
.app-icon { border-radius: 16px; justify-self: start; }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 15px; }
.code-input { font: 600 24px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .18em; text-align: center; text-transform: uppercase; }
.steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.step-n {
  flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.share-glyph {
  display: inline-block; width: 14px; height: 17px; vertical-align: -2px; margin: 0 2px;
  border: 2px solid var(--accent); border-top: 0; border-radius: 0 0 3px 3px; position: relative;
}
.share-glyph::before { content: ""; position: absolute; left: 4px; top: -8px; width: 2px; height: 12px; background: var(--accent); }
.share-glyph::after { content: ""; position: absolute; left: 1px; top: -9px; width: 6px; height: 6px; border-left: 2px solid var(--accent); border-top: 2px solid var(--accent); transform: rotate(45deg); }

.bar {
  flex: none; display: flex; align-items: center; gap: 4px;
  padding: calc(6px + var(--safe-top)) 8px 6px; background: var(--brand); color: #fff;
}
.bar .icon-btn { color: #fff; }
.bar .icon-btn:active { background: rgba(255, 255, 255, .16); }
.bar .conn, .bar .conn.offline, .bar .muted { color: rgba(255, 255, 255, .82); }
.bar .conn.online { color: #c6f3d4; }
.bar .conn.removed { color: #ffd6d6; }
.bar-mark { flex: none; width: 34px; height: 34px; margin-left: 4px; padding: 4px; border-radius: 10px; background: #fff; object-fit: contain; }
.brand-mark-lg { width: 72px; height: 72px; margin-bottom: 14px; }
.logo-box { display: flex; justify-content: center; padding: 12px 16px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.brand-logo { display: block; width: min(220px, 80%); height: auto; }
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 6px; }
.bar-title > span:first-child { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-name { font-size: 20px !important; }
.conn { font-size: 12px; }
.conn.online { color: var(--ok); }
.conn.offline { color: var(--muted); }
.conn.removed { color: var(--err); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(12px + var(--safe-bottom)); }

/* ----- Danh sách ----- */
.side-title {
  margin: 0; padding: 18px 18px 6px; font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.conv-list { list-style: none; margin: 0 10px; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.conv-list:empty { display: none; }
.conv {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px; cursor: pointer;
  border-top: 1px solid var(--line);
}
.conv:first-child { border-top: 0; }
.conv:active { background: var(--bg); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 17px; position: relative;
}
.avatar.group { border-radius: 13px; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--panel); background: var(--line); }
.avatar .dot.on { background: var(--ok); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; gap: 8px; align-items: baseline; }
.conv-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-last { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--brand); color: #fff; border-radius: 999px; font-size: 12px; padding: 2px 8px; font-weight: 700; flex: none; }
.warn-dot { color: var(--err); font-weight: 800; }
.e2e-note { padding: 18px; font-size: 13px; color: var(--muted); text-align: center; margin: 0; }
.empty { padding: 14px; color: var(--muted); font-size: 14px; }

.cta {
  margin: 12px 10px 0; padding: 14px; border-radius: 16px; background: var(--accent-soft);
  display: grid; gap: 10px;
}
.cta p { margin: 4px 0 0; font-size: 14px; }

.device-alerts { padding: 12px 10px 0; display: grid; gap: 8px; }
.device-alert {
  padding: 12px 14px; border-radius: 14px; font-size: 15px;
  background: color-mix(in srgb, var(--err) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--err) 45%, transparent);
}
.device-alert strong { color: var(--err); }
.device-alert p { margin: 6px 0 10px; }
.alert-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.alert-actions button { padding: 8px 14px; min-height: 40px; font-size: 15px; }

/* ----- Chat ----- */
.chat-title { align-items: flex-start; }
.key-banner {
  margin: 8px 10px 0; padding: 12px; border-radius: 14px; font-size: 14px;
  background: color-mix(in srgb, var(--err) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--err) 35%, transparent);
  display: grid; gap: 8px;
}
.key-banner p { margin: 0; }
.messages { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; color: var(--muted); font-size: 12px; margin: 12px 0 4px; }
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 2px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.bubble {
  background: var(--theirs); border: 1px solid var(--line); padding: 8px 12px;
  border-radius: 18px; white-space: pre-wrap; word-break: break-word; font-size: 16px;
}
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); border-color: transparent; }
.bubble.broken { font-style: italic; color: var(--muted); background: transparent; border-style: dashed; }
.meta { font-size: 11px; color: var(--muted); padding: 0 6px; }
.meta .failed, .meta .warn { color: var(--err); }
.sender { font-size: 12px; font-weight: 700; color: var(--accent); margin: 8px 0 0 10px; }
.system { align-self: center; font-size: 12px; color: var(--muted); background: var(--line); padding: 4px 12px; border-radius: 999px; text-align: center; max-width: 92%; margin: 4px 0; }
.system.device-note { background: var(--accent-soft); color: var(--text); cursor: pointer; }

.media { max-width: 100%; max-height: 320px; border-radius: 16px; display: block; background: var(--line); }
.media-wrap { display: grid; gap: 4px; justify-items: end; }
.msg:not(.mine) .media-wrap { justify-items: start; }
.filecard {
  display: flex; gap: 10px; align-items: center; padding: 10px 12px;
  background: var(--theirs); border: 1px solid var(--line); border-radius: 16px; min-width: 220px; max-width: 100%;
}
.filecard .name { font-weight: 600; word-break: break-all; font-size: 15px; }
.filecard .size { font-size: 12px; color: var(--muted); }
.filecard .grow { flex: 1; min-width: 0; }
.file-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.file-actions button { padding: 6px 12px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.offer { border-color: var(--accent); }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; width: 100%; margin-top: 6px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.composer {
  flex: none; display: flex; gap: 6px; align-items: flex-end;
  padding: 8px 8px calc(8px + var(--safe-bottom)); border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 20px; padding: 10px 14px; line-height: 1.35; }
.attach { font-size: 26px; color: var(--accent); cursor: pointer; }
.send { border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 18px; flex: none; }
.composer .icon-btn { flex: none; }
.composer .icon-btn.tool { min-width: 40px; font-size: 23px; }
.icon-btn.active { background: var(--accent-soft); }

/* ----- Emoji to (tin chỉ có 1–3 emoji) ----- */
.bubble.jumbo { background: transparent !important; border-color: transparent !important; padding: 0 2px; line-height: 1.15; }
.bubble.jumbo-1 { font-size: 52px; }
.bubble.jumbo-2 { font-size: 44px; }
.bubble.jumbo-3 { font-size: 38px; }

/* ----- Bảng emoji: nằm thay chỗ bàn phím, cuộn ngang theo nhóm, mục chọn nhóm ở dưới như bàn phím iOS ----- */
.screen.emoji-open .composer { padding-bottom: 8px; }
.emoji-host { flex: none; }
.emoji-panel {
  display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.emoji-scroll {
  position: relative; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 0 6px;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; scrollbar-width: none;
}
.emoji-scroll::-webkit-scrollbar { display: none; }
.emoji-group { flex: none; display: flex; flex-direction: column; min-width: 120px; }
.emoji-group-title {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  padding: 8px 6px 2px; white-space: nowrap; position: sticky; left: 0;
}
.emoji-grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(5, 44px); grid-auto-columns: 44px; }
.emoji {
  background: transparent; padding: 0; min-height: 44px; width: 44px; height: 44px; font-size: 30px; line-height: 1;
  border-radius: 10px; font-weight: 400; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.emoji:active { background: var(--accent-soft); }
.emoji-empty { color: var(--muted); font-size: 13px; padding: 10px 6px; max-width: 140px; }
.emoji-group.empty .emoji-grid { display: none; }
.emoji-tabs { order: 2; display: flex; border-top: 1px solid var(--line); padding: 2px 4px; }
.emoji-tab {
  flex: 1; background: transparent; padding: 0; min-height: 40px; font-size: 20px; font-weight: 400;
  border-radius: 10px; filter: grayscale(1); opacity: .65;
}
.emoji-tab.active { filter: none; opacity: 1; background: var(--accent-soft); }

/* ----- Khay ảnh dán chờ gửi ----- */
.attach-tray {
  flex: none; display: flex; gap: 8px; padding: 8px 10px; overflow-x: auto; background: var(--panel);
  border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.attach-tray::-webkit-scrollbar { display: none; }
.attach-item {
  position: relative; flex: none; display: flex; gap: 8px; align-items: center; max-width: 176px;
  padding: 6px 38px 6px 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg);
}
.attach-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 10px; background: var(--line); flex: none; }
.attach-thumb.file { display: grid; place-items: center; font-size: 28px; }
.attach-info { min-width: 0; }
.attach-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 64px; }
.attach-size { font-size: 12px; color: var(--muted); }
.attach-remove {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; min-height: 32px; padding: 0; border-radius: 50%;
  background: var(--text); color: var(--bg); font-size: 14px; line-height: 32px;
}

/* ----- Cài đặt ----- */
.group-box.name-box { padding: 12px 14px; display: grid; gap: 8px; } /* .group-box (khai báo sau) đặt padding: 0 */
.name-box .field { font-size: 15px; margin: 0; }
.name-box p { margin: 0; }
.name-row { display: flex; gap: 8px; align-items: center; }
.name-row input { flex: 1; min-width: 0; }
.group-box { margin: 0 10px; padding: 0; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; min-height: 52px;
  border-top: 1px solid var(--line); width: 100%; background: none; color: var(--text); border-radius: 0; font-weight: 400; text-align: left;
}
.row:first-child { border-top: 0; }
.small-btn { padding: 8px 14px; min-height: 38px; font-size: 15px; flex: none; }
.danger-row { color: var(--err); font-weight: 600; justify-content: center; }
.device-list li .grow { flex: 1; min-width: 0; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.tag.ok { background: color-mix(in srgb, var(--ok) 15%, var(--panel)); color: var(--ok); }
.tag.bad { background: color-mix(in srgb, var(--err) 15%, var(--panel)); color: var(--err); }
.about { text-align: center; padding: 18px; }
.switch {
  appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 999px; background: var(--line);
  position: relative; flex: none; padding: 0; border: 0; transition: background .2s; cursor: pointer;
}
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

/* ----- Hộp thoại, xem ảnh, toast ----- */
.dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 24px));
  background: var(--panel); color: var(--text); max-height: calc(100dvh - 40px);
}
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog form { padding: 20px; display: grid; gap: 14px; }
.dialog h2 { margin: 0; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.safety { display: grid; gap: 12px; max-height: 55dvh; overflow: auto; }
.safety p { margin: 0; }
.device-code { display: grid; gap: 6px; border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.device-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.code {
  font: 600 16px/1.6 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .04em; word-spacing: .3em;
  background: var(--bg); border-radius: 10px; padding: 8px 10px; text-align: center;
}
.device-code > button { justify-self: end; padding: 6px 12px; min-height: 36px; }

.viewer {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 10; display: flex; flex-direction: column;
  padding: calc(8px + var(--safe-top)) 8px calc(8px + var(--safe-bottom));
}
.viewer .viewer-bar { display: flex; justify-content: space-between; }
.viewer .viewer-bar button { background: rgba(255,255,255,.15); }
.viewer img, .viewer video { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: calc(100vw - 32px); font-size: 15px;
}

/* ----- Tìm tin nhắn ----- */
mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; font-weight: 700; border-radius: 3px; padding: 0 1px; }
.bar .icon-btn.bar-tool { min-width: 40px; font-size: 19px; }
.list-search { flex: none; display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.list-search input, .conv-search input {
  flex: 1; min-width: 0; padding: 8px 14px; border-radius: 999px; -webkit-appearance: none; appearance: none;
}
.list-search .link-btn, .conv-search .link-btn { flex: none; min-height: 40px; padding: 0 4px; }
.conv-search { flex: none; display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.conv-search .muted { flex: none; white-space: nowrap; }
.search-results { padding-top: 4px; }
.search-pop { background: var(--bg); padding: 6px 0 calc(12px + var(--safe-bottom)); }
.screen.searching .composer, .screen.searching #tray-host, .screen.searching .emoji-host, .screen.searching .key-banner { display: none; }
.search-empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.search-group { margin: 0 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.search-pop .search-group, .search-pop > .search-item { margin: 0 10px; }
.search-pop > .search-item { width: calc(100% - 20px); background: var(--panel); border: 1px solid var(--line); border-top: 0; border-radius: 0; }
.search-pop > .search-item:first-child { border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; }
.search-pop > .search-item:last-child { border-radius: 0 0 16px 16px; }
.search-pop > .search-item:only-child { border-radius: 16px; }
.search-conv { display: flex; align-items: center; gap: 10px; padding: 10px 14px 6px; }
.search-conv .conv-name { flex: 1; min-width: 0; }
.avatar.small { width: 30px; height: 30px; font-size: 13px; }
.avatar.small.group { border-radius: 9px; }
.search-item {
  display: block; width: 100%; text-align: left; background: transparent; color: var(--text); border-radius: 0;
  padding: 10px 14px; min-height: 56px; font-weight: 400; border-top: 1px solid var(--line);
}
.search-conv + .search-item { border-top: 0; }
.search-item:active { background: var(--bg); }
.search-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.search-from { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-time { color: var(--muted); flex: none; }
.search-snippet {
  font-size: 15px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word;
}
.search-snippet mark { color: var(--text); }
.search-more { display: block; width: 100%; text-align: center; border-top: 1px solid var(--line); border-radius: 0; padding: 10px; min-height: 44px; }
.older-btn { align-self: center; padding: 6px 14px; min-height: 36px; font-size: 14px; margin-bottom: 6px; }
.msg.flash, .system.flash { animation: msg-flash 1.6s ease-out; border-radius: 18px; }
@keyframes msg-flash {
  0%, 55% { background: color-mix(in srgb, var(--accent) 22%, transparent); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 22%, transparent); }
  100% { background: transparent; box-shadow: 0 0 0 6px transparent; }
}

/* ----- Kho ảnh, video, file (phủ lên màn chat) ----- */
.media-screen {
  position: fixed; inset: 0; z-index: 8; display: flex; flex-direction: column; background: var(--bg);
  padding-left: var(--safe-left); padding-right: var(--safe-right);
}
.media-tabs { flex: none; display: flex; gap: 6px; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.media-tab { flex: 1; background: var(--bg); color: var(--muted); border: 1px solid var(--line); min-height: 38px; padding: 6px 0; font-size: 15px; border-radius: 10px; }
.media-tab.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.media-body { padding: 0 2px calc(16px + var(--safe-bottom)); }
.media-empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.media-month { font-size: 13px; font-weight: 700; color: var(--muted); padding: 14px 10px 6px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
@media (min-width: 600px) { .media-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); } }
.media-tile {
  position: relative; aspect-ratio: 1; padding: 0; min-height: 0; border-radius: 0; overflow: hidden; background: var(--line);
  display: grid; place-items: center; color: var(--muted);
}
.media-tile .thumb { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.media-tile.unavailable > .thumb-ph, .media-tile.unavailable > .tile-label { opacity: .55; }
.thumb-ph { font-size: 28px; }
.tile-label { position: absolute; left: 0; right: 0; top: 8px; font-size: 12px; font-weight: 600; text-align: center; color: var(--text); }
.media-tile .small-btn { position: absolute; bottom: 6px; left: 6px; right: 6px; min-height: 32px; padding: 4px 6px; font-size: 13px; }
.media-tile .tag { position: absolute; bottom: 8px; }
.play-badge {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; display: grid; place-items: center; font-size: 14px; padding-left: 3px; pointer-events: none;
}
.file-list { list-style: none; margin: 10px; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.file-row { display: flex; align-items: center; gap: 6px; padding: 0 10px 0 0; border-top: 1px solid var(--line); }
.file-row:first-child { border-top: 0; }
.file-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 10px 4px 10px 12px; min-height: 60px;
  background: transparent; color: var(--text); border-radius: 0; font-weight: 400; text-align: left;
}
button.file-main:active { background: var(--bg); }
.file-row.unavailable .file-main { opacity: .55; }
.file-icon { font-size: 26px; flex: none; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-acts { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.file-acts .link-btn { font-size: 13px; padding: 4px 0; white-space: nowrap; }
.file-acts .small-btn { min-height: 34px; padding: 4px 12px; font-size: 14px; }

/* Xem lớn từ kho ảnh: thanh trên, ảnh giữa, nút ‹ › hai bên, vuốt ngang để qua ảnh */
.viewer .viewer-bar { align-items: center; gap: 8px; }
.viewer-title { flex: 1; min-width: 0; display: grid; text-align: center; color: #fff; font-size: 14px; line-height: 1.3; }
.viewer-title span { font-size: 12px; opacity: .7; }
.viewer-stage { flex: 1; min-height: 0; position: relative; display: flex; }
.viewer-stage img, .viewer-stage video { flex: 1; min-height: 0; min-width: 0; object-fit: contain; width: 100%; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; padding: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .16); color: #fff; font-size: 28px; line-height: 1;
}
.viewer-nav.prev { left: 4px; }
.viewer-nav.next { right: 4px; }
.viewer-nav:disabled { display: none; }
.viewer-foot { display: flex; justify-content: center; padding-top: 8px; }
.viewer-foot button { background: rgba(255, 255, 255, .15); color: #fff; border: 0; }

/* ---------- Gọi thoại 1-1 (màn gọi dùng chung, dựng bởi call-core mountCallUI) ---------- */
.call-screen {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(48px + env(safe-area-inset-top, 0px)) 24px calc(40px + env(safe-area-inset-bottom, 0px));
  color: #fbf7f2;
  background: radial-gradient(120% 70% at 50% 0%, #0b3b8c 0%, #062a66 55%, #041636 100%);
  font-variant-numeric: tabular-nums;
}
.call-top { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.call-avatar {
  width: 112px; height: 112px; border-radius: 50%;
  display: grid; place-items: center; margin-bottom: 14px;
  font-size: 46px; font-weight: 700; color: #fff;
  background: linear-gradient(145deg, #2f6fd6, #023da3);
  box-shadow: 0 0 0 0 rgba(110, 160, 240, .55);
}
.call-screen[data-phase="incoming"] .call-avatar,
.call-screen[data-phase="outgoing"] .call-avatar { animation: call-pulse 1.6s ease-out infinite; }
@keyframes call-pulse {
  0% { box-shadow: 0 0 0 0 rgba(110, 160, 240, .55); }
  100% { box-shadow: 0 0 0 26px rgba(110, 160, 240, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .call-screen .call-avatar { animation: none !important; }
}
.call-name { font-size: 26px; font-weight: 650; letter-spacing: .01em; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-status { font-size: 15px; color: rgba(251, 247, 242, .72); min-height: 1.4em; }
.call-timer { font-size: 20px; font-weight: 600; min-height: 1.3em; letter-spacing: .04em; }
.call-e2e { font-size: 12px; color: rgba(251, 247, 242, .5); margin-top: 6px; }
.call-tip {
  margin: 0 0 18px; max-width: 320px; text-align: center; font-size: 13px; line-height: 1.4;
  color: #dbe8fb; background: rgba(110, 160, 240, .16); border: 1px solid rgba(110, 160, 240, .35);
  border-radius: 12px; padding: 8px 12px;
}
.call-actions { display: flex; gap: 28px; justify-content: center; align-items: flex-start; flex-wrap: wrap; min-height: 96px; }
.call-screen .call-btn,
.call-screen .call-btn:hover,
.call-screen .call-btn:disabled {
  display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 72px;
  background: none; border: 0; border-radius: 0; box-shadow: none; padding: 0;
  color: #fbf7f2; cursor: pointer; font: inherit; font-size: 13px; font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
.call-btn .call-ico svg { width: 28px; height: 28px; display: block; }
.call-btn .call-ico {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 26px;
  background: rgba(255, 255, 255, .14); transition: background .15s, transform .1s;
}
.call-btn:hover .call-ico { background: rgba(255, 255, 255, .22); }
.call-btn:active .call-ico { transform: scale(.94); }
.call-btn.on .call-ico { background: #fbf7f2; color: #1f1d1a; }
.call-btn.call-red .call-ico { background: #dc2626; color: #fff; }
.call-btn.call-red:hover .call-ico { background: #ef4444; }
.call-btn.call-green .call-ico { background: #16a34a; color: #fff; }
.call-btn.call-green:hover .call-ico { background: #22c55e; }
.call-screen[data-phase="incoming"] .call-btn.call-green .call-ico { animation: call-shake 1.2s ease-in-out infinite; }
@keyframes call-shake {
  0%, 60%, 100% { transform: rotate(0); }
  70% { transform: rotate(-14deg); } 80% { transform: rotate(12deg); } 90% { transform: rotate(-8deg); }
}
.call-btn:focus-visible .call-ico { outline: 2px solid #9dc0f5; outline-offset: 3px; }
.system.call-note { background: var(--accent-soft); color: var(--text); }
.system.call-missed { background: rgba(220, 38, 38, .12); color: var(--err); }
.system .call-time { opacity: .7; }

/* ----- Cảm xúc (core/reactions-ui.mjs) ----- */
.msg { position: relative; }
/* Nhấn giữ để thả cảm xúc: tắt bảng "Sao chép / Chia sẻ" của iOS trên bong bóng (chữ vẫn chọn được; tin chữ có nút 📋 Chép) */
.msg .bubble, .msg .media, .msg .filecard { -webkit-touch-callout: none; }
/* Nút ❤️ luôn hiện cạnh bong bóng, phía ngoài (bên phải tin của người khác, bên trái tin của mình) */
.msg-row { display: flex; align-items: flex-end; gap: 2px; max-width: 100%; }
.msg.mine .msg-row { flex-direction: row-reverse; }
.msg-row > .bubble, .msg-row > .media-wrap, .msg-row > .filecard { min-width: 0; }
.heart-btn {
  position: relative; flex: none; width: 30px; height: 30px; min-height: 0; padding: 0; margin-bottom: 1px; border-radius: 50%;
  display: grid; place-items: center; background: transparent; color: var(--muted); border: 0; font-weight: 400;
}
.heart-btn::after { content: ""; position: absolute; inset: -7px -3px; } /* vùng chạm lớn hơn nút, không che chữ */
.heart-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; display: block; }
.heart-btn.mine { color: var(--heart); }
.heart-btn.mine svg { fill: currentColor; }
.heart-btn.other svg { display: none; }
.heart-emoji { font-size: 18px; line-height: 1; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.heart-btn:active { transform: scale(1.18); }
@media (hover: hover) { .heart-btn:hover { background: var(--accent-soft); } }
.react-picker {
  position: absolute; bottom: calc(100% - 2px); left: 0; z-index: 8;
  display: flex; align-items: center; gap: 0; padding: 4px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18); animation: react-pop .14s ease-out;
}
.msg.mine .react-picker { left: auto; right: 0; }
.react-picker.below { bottom: auto; top: calc(100% - 2px); }
@keyframes react-pop { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .react-picker { animation: none; } }
.react-opt, .react-extra {
  background: transparent; color: var(--text); min-height: 0; width: 42px; height: 42px; padding: 0;
  border-radius: 50%; font-weight: 400; font-size: 27px; line-height: 42px; transition: transform .1s;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.react-opt:active { transform: scale(1.3); }
.react-opt.current { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.react-extra { width: auto; font-size: 20px; padding: 0 8px; border-radius: 0 999px 999px 0; border-left: 1px solid var(--line); margin-left: 2px; }
.reactions {
  align-self: flex-start; display: flex; gap: 4px; margin: -6px 6px 0; z-index: 1; min-height: 0;
  padding: 2px 5px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}
.msg.mine .reactions { align-self: flex-end; }
.react-chip { padding: 0 4px; border-radius: 999px; white-space: nowrap; }
.react-chip.mine { background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.react-details { display: grid; gap: 12px; }
.react-detail-head { font-weight: 700; }
.react-detail-users { color: var(--muted); }

/* ----- Thành viên nhóm, nhóm trưởng ----- */
.members { display: grid; gap: 2px; max-height: 60vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.member { display: flex; align-items: flex-start; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); }
.member:first-of-type { border-top: 0; }
.avatar.small-av { width: 36px; height: 36px; font-size: 15px; }
.member .grow { flex: 1; min-width: 0; }
.member-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 36px; }
.member-name { font-weight: 600; }
.member-code { font-size: 12px; color: var(--muted); font-weight: 400; }
.member-acts { display: flex; gap: 16px; flex-wrap: wrap; }
.member-acts .link-btn { font-size: 14px; }
.link-btn.danger { color: var(--err); }
.tag.admin-tag { background: var(--accent-soft); color: var(--accent); }
.removed-note { color: var(--err) !important; }
.leave-btn { margin-top: 10px; width: 100%; }
.danger-text { color: var(--err) !important; }
.composer-locked {
  flex: none; padding: 14px 16px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--line);
  background: var(--panel); color: var(--muted); font-size: 14px; text-align: center;
}

/* ---------- ảnh đại diện (core/avatar-ui.mjs) ----------
   Mặc định: vòng tròn màu thương hiệu --brand + chữ cái đầu tên hiển thị; có ảnh thì <img> (blob: URL) phủ kín. */
.av {
  --av: 28px;
  width: var(--av); height: var(--av); flex: none; border-radius: 50%; overflow: hidden;
  display: inline-grid; place-items: center; background: var(--brand); color: #fff;
  font-weight: 700; font-size: calc(var(--av) * .44); line-height: 1; user-select: none; -webkit-user-select: none;
}
.av img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-touch-callout: none; }
.av.has-img { background: var(--accent-soft); }
.av-xs { --av: 20px; }
.av-sm { --av: 28px; }
.av-md { --av: 34px; }
.av-xl { --av: 88px; }
.av-fill { width: 100%; height: 100%; font-size: inherit; }
.av-group { border-radius: 10px; background: #fff; color: var(--brand); }
.avatar .av-fill + .dot { z-index: 1; }
/* Nút ôm khít ảnh (line-height 0, flex) để viền tròn không lệch; viền vẽ trên chính .av */
.me-avatar { display: inline-flex; padding: 0; margin: 0; border: 0; line-height: 0; background: none; border-radius: 50%; flex: none; min-width: 0; min-height: 0; }
.me-avatar .av { box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
.conv-avatar { display: inline-flex; flex: none; margin-left: 2px; }
/* Tên dài trong tiêu đề: cắt "…" thay vì tràn sang các nút (align-items: flex-start không co phần tử con) */
.chat-title > span { max-width: 100%; }
.conv-avatar .av { box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
.msg.grp { padding-left: 34px; }
.msg.grp .msg-av { position: absolute; left: 0; top: 24px; }
.react-detail-avs { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px; }
.search-top { align-items: center; }
.search-top .search-from { margin-right: auto; }
.avatar-box { display: flex; gap: 14px; align-items: center; padding: 14px; }
.settings-avatar-slot { display: inline-flex; flex: none; }
.avatar-acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1; min-width: 0; }
.avatar-acts p { flex-basis: 100%; margin: 0; }
/* <label> bọc <input type=file> (iPhone: Thư viện ảnh / Chụp ảnh / Chọn tệp) trông như nút phụ */
.file-btn {
  display: inline-flex; align-items: center; cursor: pointer; border-radius: 12px; font-weight: 600;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
}
.file-btn:active { background: var(--line); }
.call-avatar.has-img { background: #fff; overflow: hidden; }
.call-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
/* Khung cắt vuông */
.av-cropper { display: grid; gap: 12px; justify-items: center; }
.av-crop {
  position: relative; width: min(300px, 76vw); aspect-ratio: 1; border-radius: 14px; overflow: hidden;
  background: #111; touch-action: none; user-select: none; -webkit-user-select: none;
}
.av-crop-canvas { width: 100%; height: 100%; display: block; }
.av-crop-ring { position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 600px rgba(0, 0, 0, .45); border: 2px solid rgba(255, 255, 255, .9); pointer-events: none; }
.av-zoom-row { display: flex; align-items: center; gap: 12px; width: min(300px, 76vw); font-weight: 700; color: var(--muted); font-size: 20px; }
.av-zoom { flex: 1; accent-color: var(--brand); min-height: 32px; }
.av-crop-hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; max-width: 300px; }
