/* ==========================================================================
   Zalo Agent — giao diện web
   ========================================================================== */

:root {
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;

  --brand: #0b5cff;
  --brand-2: #2f7bff;
  --brand-3: #6a5cff;
  --brand-grad: linear-gradient(135deg, #1a73ff 0%, #0b5cff 45%, #6a5cff 100%);
  --brand-soft: rgba(11, 92, 255, .10);
  --brand-ring: rgba(11, 92, 255, .28);

  --bg: #eef2f9;
  --bg-glow-1: rgba(47, 123, 255, .18);
  --bg-glow-2: rgba(122, 92, 255, .14);
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #edf1f8;
  --surface-glass: rgba(255, 255, 255, .78);
  --rail: #0d1b33;
  --rail-2: #14274a;
  --border: #e3e8f2;
  --border-strong: #d3dbea;
  --text: #0f1b2e;
  --text-2: #4a5872;
  --text-3: #8592a8;
  --on-brand: #ffffff;

  --bubble-in: #ffffff;
  --bubble-in-text: #0f1b2e;
  --bubble-out: linear-gradient(135deg, #2f7bff 0%, #0b5cff 100%);
  --bubble-out-text: #ffffff;
  --stream-bg: #f3f6fb;
  --stream-dots: rgba(11, 92, 255, .07);

  --success: #12b76a;
  --success-soft: rgba(18, 183, 106, .12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, .14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, .12);

  --shadow-sm: 0 1px 2px rgba(16, 32, 64, .06), 0 1px 3px rgba(16, 32, 64, .06);
  --shadow-md: 0 6px 18px rgba(16, 32, 64, .08), 0 2px 6px rgba(16, 32, 64, .05);
  --shadow-lg: 0 24px 60px rgba(16, 32, 64, .18), 0 8px 20px rgba(16, 32, 64, .08);
  --shadow-brand: 0 10px 24px rgba(11, 92, 255, .32);

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #4c8dff;
    --brand-ring: rgba(76, 141, 255, .4);
    --brand-soft: rgba(77, 140, 255, .16);
    --bg: #070d1a;
    --bg-glow-1: rgba(47, 123, 255, .16);
    --bg-glow-2: rgba(122, 92, 255, .14);
    --surface: #0f1829;
    --surface-2: #131f35;
    --surface-3: #1a2842;
    --surface-glass: rgba(15, 24, 41, .82);
    --rail: #050a14;
    --rail-2: #0f1a2e;
    --border: #1e2c47;
    --border-strong: #2a3b5c;
    --text: #e8eefb;
    --text-2: #a5b3cc;
    --text-3: #6f7f9c;
    --bubble-in: #17243c;
    --bubble-in-text: #e8eefb;
    --stream-bg: #0b1324;
    --stream-dots: rgba(120, 160, 255, .06);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --brand: #4c8dff;
  --brand-ring: rgba(76, 141, 255, .4);
  --brand-soft: rgba(77, 140, 255, .16);
  --bg: #070d1a;
  --bg-glow-1: rgba(47, 123, 255, .16);
  --bg-glow-2: rgba(122, 92, 255, .14);
  --surface: #0f1829;
  --surface-2: #131f35;
  --surface-3: #1a2842;
  --surface-glass: rgba(15, 24, 41, .82);
  --rail: #050a14;
  --rail-2: #0f1a2e;
  --border: #1e2c47;
  --border-strong: #2a3b5c;
  --text: #e8eefb;
  --text-2: #a5b3cc;
  --text-3: #6f7f9c;
  --bubble-in: #17243c;
  --bubble-in-text: #e8eefb;
  --stream-bg: #0b1324;
  --stream-dots: rgba(120, 160, 255, .06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at -10% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }
img { display: block; max-width: 100%; }
kbd {
  font: 600 11px/1 var(--font);
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
}
code { font-size: 12px; padding: 1px 5px; border-radius: 5px; background: var(--surface-3); }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }

.i {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.only-dark { display: none; }
:root[data-theme="dark"] .only-dark { display: block; }
:root[data-theme="dark"] .only-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .only-dark { display: block; }
  :root:not([data-theme="light"]) .only-light { display: none; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-3); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .15s var(--ease), box-shadow .2s var(--ease), background .2s, color .2s;
}
.btn .i { width: 18px; height: 18px; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn-primary { color: var(--on-brand); background: var(--brand-grad); box-shadow: var(--shadow-brand); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 14px 30px rgba(11, 92, 255, .42); transform: translateY(-1px); }
.btn-soft { background: var(--surface-3); color: var(--text); }
.btn-soft:hover:not(:disabled) { background: var(--brand-soft); color: var(--brand); }
.btn-ghost-danger { color: var(--danger); background: var(--danger-soft); }
.btn-ghost-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border-radius: 12px;
  color: var(--text-2);
  transition: background .2s, color .2s, transform .15s var(--ease);
}
.icon-btn:hover:not(:disabled) { background: var(--brand-soft); color: var(--brand); }
.icon-btn:active:not(:disabled) { transform: scale(.94); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 9px; }
.icon-btn.small .i { width: 16px; height: 16px; }
.icon-btn.spinning .i { animation: spin .9s linear infinite; }

/* ---------- Avatars ---------- */
.avatar, .me-avatar, .conv-avatar, .msg-avatar, .rail-account-face, .contact-avatar, .qr-person, .card-avatar {
  position: relative; display: grid; place-items: center; flex: none;
  border-radius: 50%; overflow: hidden;
  background: var(--brand-grad);
  color: #fff; font-weight: 700;
}
.avatar img, .me-avatar img, .conv-avatar img, .msg-avatar img, .rail-account-face img, .contact-avatar img, .qr-person img, .card-avatar img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.avatar-fallback { display: grid; place-items: center; width: 100%; height: 100%; letter-spacing: .02em; }
.avatar-fallback .i { width: 56%; height: auto; aspect-ratio: 1; stroke-width: 1.8; fill: rgba(255, 255, 255, .22); }
.avatar-md { width: 42px; height: 42px; font-size: 15px; }
.avatar[data-hue], .conv-avatar[data-hue], .msg-avatar[data-hue], .contact-avatar[data-hue], .card-avatar[data-hue] {
  background: linear-gradient(135deg, hsl(var(--hue) 85% 62%), hsl(calc(var(--hue) + 40) 80% 52%));
}

/* ==========================================================================
   Layout
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: 72px 360px minmax(0, 1fr);
  height: 100dvh;
  padding: 12px 12px 12px 0;
  gap: 12px;
}

/* ---------- Rail ---------- */
.rail {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 14px 0 12px;
  background: linear-gradient(180deg, var(--rail-2), var(--rail));
  border-radius: 0 22px 22px 0;
  box-shadow: var(--shadow-md);
  min-height: 0;
}
.rail-logo { width: 44px; height: 44px; margin-bottom: 6px; filter: drop-shadow(0 6px 14px rgba(11, 92, 255, .45)); }
.rail-logo img { width: 100%; height: 100%; border-radius: 14px; }
/* overflow-y cũng cắt chiều ngang: giãn hết bề rộng rail để viền chọn và vạch chỉ báo không bị cắt. */
.rail-accounts {
  display: flex; flex-direction: column; align-items: center; gap: 10px; align-self: stretch;
  overflow-y: auto; scrollbar-width: none; padding: 6px 0; min-height: 0;
}
.rail-accounts::-webkit-scrollbar { display: none; }
.rail-account { position: relative; width: 46px; height: 46px; display: grid; place-items: center; }
.rail-account-face {
  width: 44px; height: 44px; font-size: 14px;
  border-radius: 50%;
  transition: border-radius .25s var(--ease), transform .2s var(--ease), box-shadow .2s;
  box-shadow: 0 0 0 2px transparent;
}
.rail-account:hover .rail-account-face { border-radius: 14px; transform: translateY(-1px); }
.rail-account.active .rail-account-face { border-radius: 14px; box-shadow: 0 0 0 2px var(--rail), 0 0 0 4px #4d8dff; }
.rail-account::before {
  content: ""; position: absolute; left: -13px; top: 50%;
  width: 4px; height: 0; border-radius: 0 4px 4px 0; background: #fff;
  transform: translateY(-50%); transition: height .25s var(--ease);
}
.rail-account:hover::before { height: 18px; }
.rail-account.active::before { height: 34px; }
.rail-account .presence {
  position: absolute; right: 0; bottom: 0;
  width: 13px; height: 13px; border-radius: 50%;
  border: 2.5px solid var(--rail); background: var(--text-3);
}
.rail-account .presence.on { background: var(--success); }
.rail-account .presence.warn { background: var(--warning); }
.rail-badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; border: 2px solid var(--rail); background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 14px; text-align: center;
}
.rail-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 14px;
  color: #8ea3c7;
  transition: background .2s, color .2s, transform .15s var(--ease);
}
.rail-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.rail-btn.active { background: rgba(77, 141, 255, .2); color: #fff; }
.rail-add { border: 1.5px dashed rgba(142, 163, 199, .45); }
.rail-add:hover { border-color: #4d8dff; color: #4d8dff; background: rgba(77, 141, 255, .1); }
.rail-spacer { flex: 1; }
.rail-me { position: relative; margin-top: 4px; }
.rail-me-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #f97316);
  color: #fff; font-weight: 700; font-size: 13px;
  box-shadow: 0 0 0 2px var(--rail), 0 0 0 3px rgba(255, 255, 255, .15);
}

/* ---------- Popovers & menus ---------- */
.popover {
  position: absolute; z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: pop .18s var(--ease);
}
.agent-menu { left: 54px; bottom: 0; width: 250px; padding: 8px; }
.agent-menu-head { display: grid; gap: 2px; padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.agent-menu-head span { color: var(--text-3); font-size: 12px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px; border-radius: 10px; font-weight: 600; text-align: left;
}
.menu-item:hover { background: var(--surface-3); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-item .i { width: 18px; height: 18px; }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.sidebar-head { display: grid; gap: 12px; padding: 14px 14px 10px; }
.me-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border-radius: 16px;
  background: linear-gradient(135deg, var(--brand-soft), transparent 70%), var(--surface-2);
  border: 1px solid var(--border);
}
.me-avatar { width: 44px; height: 44px; font-size: 15px; box-shadow: 0 0 0 3px var(--surface); transition: transform .2s var(--ease); }
.me-avatar:hover { transform: scale(1.05); }
.me-copy { display: grid; min-width: 0; flex: 1; }
.me-copy strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); min-width: 0; }
.me-status span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-actions { display: flex; gap: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot.warn { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.search {
  display: flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 12px;
  border-radius: 12px;
  background: var(--surface-3);
  border: 1px solid transparent;
  color: var(--text-3);
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.search:focus-within { background: var(--surface); border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); color: var(--brand); }
.search .i { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search.small { height: 36px; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 999px;
  font-weight: 600; font-size: 13px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: all .2s var(--ease);
}
.chip:hover { color: var(--brand); border-color: var(--brand-ring); }
.chip.active { color: #fff; background: var(--brand-grad); border-color: transparent; box-shadow: 0 6px 14px rgba(11, 92, 255, .28); }
.chip-count:empty, .chip-num:empty { display: none; }
.chip-num { font-size: 11.5px; font-weight: 700; opacity: .6; }
#filter-tabs, #status-tabs { display: grid; gap: 4px; overflow: visible; }
#filter-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#status-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#filter-tabs .chip, #status-tabs .chip { justify-content: center; padding: 0 6px; gap: 4px; min-width: 0; }
#filter-tabs .chip { height: 30px; font-size: 12.5px; }
.chip.active .chip-num { opacity: .85; }
.chips-sm { margin-top: -4px; }
.chips-sm .chip { height: 28px; padding: 0 10px; font-size: 12.5px; }
.chips-sm .chip.active { background: var(--brand-soft); color: var(--brand); box-shadow: none; border-color: var(--brand-ring); }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px; border-radius: 6px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  color: var(--text-2); background: var(--surface-3);
}
.tag:empty { display: none; }
.tag .i { width: 11px; height: 11px; }
.tag.brand { color: var(--brand); background: var(--brand-soft); }
.tag.warn { color: #b45309; background: var(--warning-soft); }
.tag.ok { color: var(--success); background: var(--success-soft); }
.tag.muted { color: var(--text-3); background: var(--surface-3); }
.tag.custom { color: #7c3aed; background: rgba(124, 58, 237, .12); }
:root[data-theme="dark"] .tag.warn { color: #fbbf24; }
:root[data-theme="dark"] .tag.custom { color: #c4b5fd; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag.warn { color: #fbbf24; }
  :root:not([data-theme="light"]) .tag.custom { color: #c4b5fd; }
}
.chip-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; display: grid; place-items: center; background: var(--danger); color: #fff; }

.sync-banner {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 12px; border-radius: 14px;
  background: var(--brand-soft); color: var(--text);
  animation: fade-up .25s var(--ease);
}
.sync-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--surface); color: var(--brand); flex: none; }
.sync-icon .i { width: 17px; height: 17px; animation: spin 1.2s linear infinite; }
.sync-copy { display: grid; min-width: 0; font-size: 12.5px; }
.sync-copy strong { font-size: 13px; }
.sync-copy span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; overflow: hidden; }
.sync-bar i { position: absolute; top: 0; bottom: 0; width: 40%; border-radius: 3px; background: var(--brand-grad); animation: indeterminate 1.4s var(--ease) infinite; }
.sync-banner.done { background: var(--success-soft); }
.sync-banner.done .sync-icon { color: var(--success); }
.sync-banner.done .sync-icon .i { animation: none; }
.sync-banner.done .sync-bar { display: none; }
.sync-banner.paused .sync-icon .i { animation: none; }
.sync-banner.paused .sync-bar { display: none; }

.history-sync-action { display: grid; gap: 5px; }
.history-sync-action .btn { width: 100%; justify-content: center; min-height: 40px; }
.history-sync-action > span { font-size: 11.5px; line-height: 1.4; color: var(--text-3); text-align: center; }

.conversation-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; min-height: 0; }
.conv {
  position: relative; display: flex; align-items: center; gap: 12px;
  /* Dòng ngoài khung nhìn không cần layout/paint; auto nhớ chiều cao thật sau lần vẽ đầu. */
  content-visibility: auto; contain-intrinsic-size: auto 96px;
  width: 100%; padding: 10px; margin-bottom: 2px;
  border-radius: 14px; text-align: left;
  transition: background .18s, transform .18s var(--ease);
}
.conv.enter { animation: fade-up .3s var(--ease) both; }
.conv:hover { background: var(--surface-3); }
.conv.active { background: var(--brand-soft); }
.conv.active::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px;
  width: 3px; border-radius: 3px; background: var(--brand-grad);
}
.conv-avatar { width: 50px; height: 50px; font-size: 16px; }
.stranger { background: linear-gradient(135deg, #94a3b8, #64748b); }
.conv-avatar.stranger .i { width: 26px; height: 26px; }
.preview-i { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; color: var(--text-3); }
.conv-group-badge {
  position: absolute; left: 44px; top: 42px;
  display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); color: var(--brand);
  box-shadow: var(--shadow-sm);
}
.conv-group-badge .i { width: 12px; height: 12px; stroke-width: 2.5; }
.conv-body { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }
.conv-name { flex: 1; min-width: 0; font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11.5px; color: var(--text-3); flex: none; }
.conv-bottom { display: flex; align-items: center; gap: 8px; }
.conv-preview { flex: 1; min-width: 0; color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview b { color: var(--text); font-weight: 600; }
.conv.unread .conv-name, .conv.unread .conv-preview { color: var(--text); font-weight: 700; }
.conv-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.conv.closed .conv-avatar, .conv.closed .conv-body { opacity: .65; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 10px;
  font-size: 11px; font-weight: 700;
  color: #fff; background: linear-gradient(135deg, #ff5a5f, #ef4444);
  box-shadow: 0 4px 10px rgba(239, 68, 68, .35);
  flex: none;
}

.list-empty { display: grid; justify-items: center; gap: 8px; padding: 48px 20px; text-align: center; color: var(--text-2); }
.list-empty .orb { width: 64px; height: 64px; border-radius: 22px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.list-empty .orb .i { width: 30px; height: 30px; }
.list-empty strong { color: var(--text); font-size: 15px; }
.list-empty p { margin: 0; font-size: 13px; }

.skeleton-list { display: grid; gap: 6px; padding: 4px; }
.skeleton-row {
  height: 64px; border-radius: 14px;
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}

.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; border-top: 1px solid var(--border);
  font-size: 12px;
}
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 600; min-width: 0; }
.live span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-dot { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.live.on .live-dot, .log-head .live-dot { background: var(--success); }
.live.on .live-dot::after, .log-head .live-dot::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--success); opacity: 0; animation: ping 1.8s infinite;
}
.live.warn .live-dot { background: var(--warning); }
.live.off .live-dot { background: var(--danger); }
.live.pulse .live-dot { animation: beat .35s var(--ease); }

/* ---------- Chat ---------- */
.chat {
  position: relative; min-width: 0; min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.welcome {
  height: 100%; display: grid; place-items: center; padding: 32px;
  background:
    radial-gradient(600px 300px at 50% 0%, var(--brand-soft), transparent 70%),
    radial-gradient(var(--stream-dots) 1.2px, transparent 1.2px) 0 0 / 22px 22px,
    var(--stream-bg);
}
.welcome-card { max-width: 460px; text-align: center; display: grid; justify-items: center; gap: 12px; animation: fade-up .5s var(--ease) both; }
.welcome-orb {
  width: 96px; height: 96px; border-radius: 32px;
  display: grid; place-items: center;
  background: var(--brand-grad); color: #fff;
  box-shadow: var(--shadow-brand), inset 0 1px 0 rgba(255, 255, 255, .35);
  animation: float 5s ease-in-out infinite;
}
.welcome-orb .i { width: 46px; height: 46px; stroke-width: 1.6; }
.welcome h1 { margin: 10px 0 0; font-size: 26px; letter-spacing: -.02em; }
.welcome p { margin: 0; color: var(--text-2); font-size: 15px; }
.welcome-actions { margin-top: 8px; }
.welcome-features { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 10px; text-align: left; }
.welcome-features li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); font-weight: 500; box-shadow: var(--shadow-sm);
}
.welcome-features .i { color: var(--brand); width: 18px; height: 18px; }

.workspace { position: relative; display: flex; height: 100%; min-height: 0; }
.chat-col { position: relative; display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.chat-top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; z-index: 2;
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.back-btn { display: none; }
.chat-title { flex: 1; min-width: 0; display: grid; }
.chat-title-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-title h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chat-title span { color: var(--text-3); font-size: 12.5px; }
.chat-title span.typing { color: var(--brand); font-weight: 600; }
.chat-top-actions { display: flex; align-items: center; gap: 4px; }
.btn-sm { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn-sm .i { width: 16px; height: 16px; }
.btn.is-on { background: var(--brand-soft); color: var(--brand); }

.stream {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 18px 22px 12px;
  background:
    radial-gradient(var(--stream-dots) 1.2px, transparent 1.2px) 0 0 / 22px 22px,
    var(--stream-bg);
  outline: 0;
  scroll-behavior: auto;
}
.load-older { display: flex; justify-content: center; margin: 2px 0 10px; }
.load-older button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; color: var(--brand);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.load-older button:hover { border-color: var(--brand-ring); background: var(--brand-soft); }
.load-older button .i { width: 15px; height: 15px; }
.load-older.busy .i { animation: spin .9s linear infinite; }
.load-older.done button { color: var(--text-3); cursor: default; background: transparent; box-shadow: none; border-style: dashed; }
.stream-state { display: grid; place-items: center; gap: 10px; height: 100%; color: var(--text-3); text-align: center; }
.stream-state .spinner { width: 34px; height: 34px; }

.day-divider { display: flex; justify-content: center; margin: 18px 0 12px; }
.day-divider span {
  padding: 5px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  background: var(--surface-glass); backdrop-filter: blur(10px);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}

.notice-row { display: flex; justify-content: center; margin: 10px 0; }
.notice-pill {
  display: inline-flex; align-items: center; gap: 8px; max-width: min(520px, 90%);
  padding: 5px 14px 5px 5px; border-radius: 999px;
  font-size: 13px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border);
}
.notice-pill b { color: var(--text); font-weight: 600; }
.notice-avatar, .notice-icon { width: 26px; height: 26px; flex: none; border-radius: 50%; object-fit: cover; }
.notice-icon { border-radius: 6px; object-fit: contain; }
.notice-pill:not(:has(img)) { padding-left: 14px; }
.msg { display: flex; align-items: flex-end; gap: 8px; margin-top: 2px; }
.msg.enter { animation: msg-in .28s var(--ease) both; }
.msg.start { margin-top: 12px; }
.msg.out { flex-direction: row-reverse; }
.msg-avatar { width: 34px; height: 34px; font-size: 12px; }
.msg-avatar-gap { width: 34px; flex: none; }
.msg-col { position: relative; display: flex; flex-direction: column; align-items: flex-start; max-width: min(72%, 620px); min-width: 0; }
.msg.out .msg-col { align-items: flex-end; }
.msg-sender { font-size: 12px; font-weight: 600; color: var(--brand); margin: 0 0 3px 12px; }

.bubble {
  position: relative;
  padding: 9px 13px 7px;
  border-radius: 18px;
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
  min-width: 64px;
}
.msg.in.start .bubble { border-top-left-radius: 6px; }
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); box-shadow: 0 6px 16px rgba(11, 92, 255, .22); }
.msg.out.start .bubble { border-top-right-radius: 6px; }
.bubble p { margin: 0; white-space: pre-wrap; }
.bubble a { color: inherit; }
/* Sticker/ảnh không chú thích nằm thẳng trên nền chat, kể cả tin mình gửi (thắng .msg.out .bubble). */
.msg .bubble.media { padding: 0; background: transparent; box-shadow: none; min-width: 0; }
.bubble.recalled { background: transparent; border: 1px dashed var(--border-strong); color: var(--text-3); box-shadow: none; font-style: italic; }
.msg.out .bubble.recalled { color: var(--text-3); }
.bubble.recalled p { display: flex; align-items: center; gap: 6px; }
.bubble.recalled .i { width: 15px; height: 15px; }

.meta { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 3px; font-size: 11px; opacity: .7; }
.meta .i { width: 14px; height: 14px; }
.meta.seen { opacity: 1; }
.msg.out .meta.seen .i { color: #b8f7d4; }
.bubble.media .meta {
  position: absolute; right: 8px; bottom: 8px; margin: 0;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, .45); color: #fff; opacity: 1;
}

.quote {
  display: flex; gap: 8px; margin: 2px 0 6px;
  padding: 6px 10px; border-radius: 10px;
  background: rgba(11, 92, 255, .08);
  border-left: 3px solid var(--brand);
  font-size: 12.5px;
}
.msg.out .quote { background: rgba(255, 255, 255, .16); border-left-color: rgba(255, 255, 255, .8); }
.quote strong { display: block; }
.quote span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; opacity: .85; }

.album { display: grid; gap: 3px; border-radius: 16px; overflow: hidden; max-width: 380px; }
.album[data-count="1"] { grid-template-columns: 1fr; }
/* Như Zalo: tối đa 3 ảnh một hàng. */
/* Độ rộng cố định + max-width (không dùng min(…, 100%)): % trong bong bóng co theo nội dung
   khiến bong bóng rộng hơn album và nhãn giờ lệch ra ngoài ảnh. */
.album[data-count="2"] { grid-template-columns: repeat(2, 1fr); width: 300px; max-width: 100%; }
.album:not([data-count="1"]):not([data-count="2"]) { grid-template-columns: repeat(3, 1fr); width: 372px; max-width: 100%; }
.album-item { position: relative; display: block; cursor: zoom-in; background: var(--surface-3); aspect-ratio: 1; overflow: hidden; }
.album[data-count="1"] .album-item { aspect-ratio: auto; max-height: 420px; }
.album-item img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s var(--ease), filter .2s; }
.album[data-count="1"] .album-item img { max-height: 420px; object-fit: contain; }
.album-item:hover img { transform: scale(1.03); filter: brightness(1.05); }
/* Ảnh từ bản sao lưu: giữ đúng khung trước khi tải, ảnh mờ làm nền chờ. */
.album[data-count="1"] .album-item.sized { max-width: 100%; max-height: none; }
.album[data-count="1"] .album-item.sized img { position: relative; max-height: none; object-fit: cover; }
.album-item.has-thumb::before {
  content: ''; position: absolute; inset: 0;
  background: var(--thumb) center / cover no-repeat;
  filter: blur(10px); transform: scale(1.12);
}
.album-item.has-thumb img { position: relative; }
.album-item.expired { cursor: default; }
.album-item.expired::before { display: none; }
.album[data-count="1"] .album-item.expired:not(.sized) { width: 220px; aspect-ratio: 4 / 3; }
.media-expired {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-3); background: var(--surface-3);
}
.media-expired .i { width: 34px; height: 34px; opacity: .55; }
.bubble:not(.media) .album { margin: 2px -7px 6px; }

.sticker { display: block; cursor: pointer; background-repeat: no-repeat; }
/* Sticker gửi liên tiếp: lưới 3 ô một hàng, thu nhỏ để gọn như Zalo. */
.sticker-row { display: grid; grid-template-columns: repeat(3, auto); gap: 2px; }
.sticker-row[data-count="2"] { grid-template-columns: repeat(2, auto); }
.msg.out .sticker-row { justify-content: end; }
.sticker-row .sticker { zoom: .72; }

.file-card, .rich-card, .call-card, .contact-card-msg {
  display: flex; align-items: center; gap: 12px;
  min-width: 240px; max-width: 340px;
  padding: 10px; border-radius: 14px;
  background: var(--surface-2); color: var(--text);
  text-decoration: none;
}
.msg.out .file-card, .msg.out .rich-card, .msg.out .call-card, .msg.out .contact-card-msg { background: rgba(255, 255, 255, .16); color: #fff; }
.bubble .file-card, .bubble .rich-card, .bubble .call-card, .bubble .contact-card-msg { margin: 0 -5px 2px; }
.file-icon {
  width: 42px; height: 48px; flex: none;
  display: grid; place-items: end center; padding-bottom: 6px;
  border-radius: 8px 14px 8px 8px;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  color: #fff; font-size: 10px; font-weight: 800; letter-spacing: .04em;
}
.file-icon[data-kind="pdf"] { background: linear-gradient(135deg, #f87171, #dc2626); }
.file-icon[data-kind="doc"] { background: linear-gradient(135deg, #60a5fa, #1d4ed8); }
.file-icon[data-kind="xls"] { background: linear-gradient(135deg, #4ade80, #15803d); }
.file-icon[data-kind="zip"] { background: linear-gradient(135deg, #fbbf24, #d97706); }
.file-icon[data-kind="media"] { background: linear-gradient(135deg, #c084fc, #7c3aed); }
.card-copy { flex: 1; min-width: 0; display: grid; gap: 2px; }
.card-copy strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-copy small { opacity: .7; font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-action {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}
.msg.out .card-action { background: rgba(255, 255, 255, .22); color: #fff; }
.card-action .i { width: 18px; height: 18px; }
.rich-icon {
  width: 42px; height: 42px; flex: none; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}
.msg.out .rich-icon { background: rgba(255, 255, 255, .22); color: #fff; }
.rich-thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; }
.rich-card audio { width: 100%; height: 34px; margin-top: 4px; }
.video-card video { display: block; max-width: 360px; width: 100%; border-radius: 14px; background: #000; }
.call-card .rich-icon.missed { background: var(--danger-soft); color: var(--danger); }
.call-card .rich-icon.ok { background: var(--success-soft); color: var(--success); }
.contact-card-msg .card-avatar { width: 46px; height: 46px; }
.bank-card .bank-logo { width: 46px; height: 46px; object-fit: contain; background: #fff; padding: 4px; }
.bank-card .bank-number { font-size: 16px; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.bank-card .bank-qr { width: 52px; height: 52px; flex: none; border-radius: 6px; background: #fff; padding: 3px; cursor: zoom-in; }

.reactions {
  position: absolute; bottom: -12px; right: 10px;
  display: flex; align-items: center; gap: 1px;
  padding: 2px 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); font-size: 13px;
}
.msg.out .reactions { right: auto; left: 10px; }
.msg.has-reactions { margin-bottom: 12px; }

.msg-actions {
  position: absolute; top: 50%; z-index: 3;
  display: flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  opacity: 0; transform: translateY(-50%) scale(.94); pointer-events: none;
  transition: opacity .15s, transform .15s var(--ease);
}
.msg.in .msg-actions { left: calc(100% + 6px); }
.msg.out .msg-actions { right: calc(100% + 6px); flex-direction: row-reverse; }
.msg:hover .msg-actions, .msg-actions:focus-within, .msg-actions.picking { opacity: 1; transform: translateY(-50%); pointer-events: auto; }
.act {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 17px;
  color: var(--text-3);
  transition: transform .15s var(--ease), background .15s, color .15s;
}
.act:hover { background: var(--surface-3); color: var(--brand); }
.act .i { width: 16px; height: 16px; }
.act.danger:hover { background: var(--danger-soft); color: var(--danger); }
.react-picker {
  position: absolute; bottom: calc(100% + 8px);
  display: none; gap: 2px; padding: 4px;
  border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: pop .18s var(--ease);
}
.msg.in .react-picker { left: 0; }
.msg.out .react-picker { right: 0; }
.msg-actions.picking .react-picker { display: flex; }
.react-picker .act { width: 34px; height: 34px; font-size: 21px; }
.react-picker .act:hover { background: transparent; transform: scale(1.3) translateY(-2px); }

.stranger-list { display: grid; gap: 6px; max-width: 560px; margin: 0 auto; }
.stranger-list h3 { margin: 4px 4px 6px; font-size: 15px; }
.stranger-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); text-align: left; }
.stranger-item:hover { border-color: var(--brand-ring); box-shadow: var(--shadow-sm); }

.jump-btn {
  position: absolute; right: 22px; bottom: 120px; z-index: 4;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); color: var(--brand);
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
  animation: pop .2s var(--ease);
}

.dropzone {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(11, 92, 255, .12);
  backdrop-filter: blur(6px);
}
.dropzone-box {
  display: grid; justify-items: center; gap: 8px;
  padding: 36px 48px; border-radius: 24px;
  border: 2px dashed var(--brand);
  background: var(--surface); color: var(--text-2);
  box-shadow: var(--shadow-lg);
}
.dropzone-box .i { width: 44px; height: 44px; color: var(--brand); }
.dropzone-box strong { color: var(--text); font-size: 16px; }

/* ---------- Composer ---------- */
.composer { position: relative; padding: 10px 16px 12px; background: var(--stream-bg); }
.quick-replies { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; overflow-x: auto; scrollbar-width: none; }
.quick-replies::-webkit-scrollbar { display: none; }
.quick-label { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); flex: none; margin-right: 2px; }
.quick-btn {
  height: 30px; padding: 0 12px; flex: none; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border);
  transition: all .18s var(--ease);
}
.quick-btn:hover { color: var(--brand); border-color: var(--brand-ring); background: var(--brand-soft); transform: translateY(-1px); }

.composer-card {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: border-color .2s, box-shadow .2s;
}
.composer-card:focus-within { border-color: var(--brand-ring); box-shadow: var(--shadow-md), 0 0 0 4px var(--brand-soft); }
.composer-tools { display: flex; gap: 2px; padding-bottom: 1px; }
.tool {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; color: var(--text-3);
  transition: background .2s, color .2s, transform .15s var(--ease);
}
.tool:hover, .tool.active { color: var(--brand); background: var(--brand-soft); }
.tool:active { transform: scale(.92); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0;
  background: transparent;
  padding: 9px 4px; max-height: 160px;
  line-height: 1.45;
}
.composer textarea::placeholder { color: var(--text-3); }
.send-btn {
  width: 42px; height: 42px; flex: none; border-radius: 14px;
  display: grid; place-items: center;
  color: #fff; background: var(--brand-grad);
  box-shadow: var(--shadow-brand);
  transition: transform .2s var(--ease), opacity .2s, box-shadow .2s;
}
.send-btn .i { width: 19px; height: 19px; transform: translateX(-1px) rotate(0); transition: transform .25s var(--ease); }
.send-btn:hover:not(:disabled) .i { transform: translate(1px, -1px) rotate(-8deg); }
.send-btn:disabled { opacity: .35; box-shadow: none; cursor: default; }
.send-btn.busy .i { animation: spin .9s linear infinite; }
.composer-hint { margin: 6px 6px 0; font-size: 11.5px; color: var(--text-3); }

.reply-banner {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px; padding: 8px 8px 8px 14px;
  border-radius: 14px; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--brand);
  animation: fade-up .2s var(--ease);
}
.reply-banner > .i { color: var(--brand); }
.reply-copy { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-2); }
.reply-copy p { margin: 1px 0 0; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Hồ sơ khách hàng ---------- */
.profile-panel {
  width: 340px; flex: none; display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--border); background: var(--surface);
  animation: slide-in .25s var(--ease);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 18px; border-bottom: 1px solid var(--border); }
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 14px; background: var(--stream-bg); }
.panel-body > * { flex-shrink: 0; }
.panel-hero { display: grid; justify-items: center; gap: 6px; padding: 8px 0 4px; text-align: center; }
.panel-hero .avatar { width: 72px; height: 72px; font-size: 22px; box-shadow: 0 0 0 4px var(--surface), var(--shadow-md); }
.panel-hero strong { font-size: 16px; }
.panel-card { display: grid; gap: 10px; padding: 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.panel-card h4 { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); }
.field.sm { gap: 5px; font-size: 12px; }
.field.sm input, .field.sm select { height: 38px; padding: 0 12px; border-radius: 10px; }
.field select { height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); outline: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel-card textarea {
  width: 100%; resize: vertical; min-height: 90px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); outline: 0;
}
.panel-card textarea:focus, .field select:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 4px var(--brand-soft); }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list .empty { color: var(--text-3); font-size: 13px; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: #7c3aed; background: rgba(124, 58, 237, .12); }
.tag-chip button { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; color: inherit; opacity: .7; }
.tag-chip button:hover { opacity: 1; background: rgba(124, 58, 237, .16); }
.tag-chip .i { width: 13px; height: 13px; }
.tag-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-preset { height: 26px; padding: 0 10px; border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--text-2); border: 1px dashed var(--border-strong); }
.tag-preset:hover { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
.tag-add { display: flex; gap: 6px; }
.tag-add input { flex: 1; min-width: 0; height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); outline: 0; }
.tag-add input:focus { border-color: var(--brand); background: var(--surface); }
.tag-add .icon-btn { width: 34px; height: 34px; background: var(--surface-3); }
#pf-save { width: 100%; }
.pf-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pf-log li { position: relative; padding-left: 16px; font-size: 12.5px; color: var(--text-2); }
.pf-log li::before { content: ""; position: absolute; left: 2px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.pf-log li strong { color: var(--text); font-weight: 600; }
.pf-log li time { display: block; color: var(--text-3); font-size: 11.5px; }
.pf-log .empty::before { display: none; }

/* ---------- Sticker popover ---------- */
.sticker-popover {
  left: 16px; bottom: calc(100% - 4px);
  width: min(420px, calc(100vw - 32px));
  height: 440px;
  display: flex; flex-direction: column; overflow: hidden;
}
.sticker-head { display: flex; align-items: center; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border); }
.sticker-head .search { flex: 1; }
.seg { display: flex; padding: 3px; border-radius: 11px; background: var(--surface-3); }
.seg-btn { height: 30px; padding: 0 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--text-2); }
.seg-btn.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
.sticker-panel { flex: 1; overflow-y: auto; padding: 8px 10px; min-height: 0; }
.sticker-section { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 2px 8px; font-size: 13px; }
.sticker-section span { color: var(--text-3); font-size: 12px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 4px; }
.sticker-btn { aspect-ratio: 1; border-radius: 12px; padding: 6px; transition: background .15s, transform .15s var(--ease); }
.sticker-btn:hover { background: var(--brand-soft); transform: scale(1.06); }
.sticker-btn img { width: 100%; height: 100%; object-fit: contain; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; }
.emoji-btn { height: 38px; border-radius: 10px; font-size: 22px; transition: transform .12s var(--ease), background .12s; }
.emoji-btn:hover { background: var(--surface-3); transform: scale(1.2); }
.sticker-rail { display: flex; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; flex: none; }
.rail-cat { width: 40px; height: 40px; flex: none; border-radius: 10px; padding: 4px; display: grid; place-items: center; color: var(--text-2); }
.rail-cat:hover { background: var(--surface-3); }
.rail-cat.active { background: var(--brand-soft); color: var(--brand); box-shadow: inset 0 0 0 1.5px var(--brand-ring); }
.rail-cat img { width: 100%; height: 100%; object-fit: contain; }
.rail-cat .i { width: 18px; height: 18px; }
.picker-state { grid-column: 1 / -1; padding: 40px 10px; text-align: center; color: var(--text-3); }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(5, 12, 26, .38); backdrop-filter: blur(3px); animation: fade .2s; }
.drawer {
  position: fixed; top: 12px; right: 12px; bottom: 12px; z-index: 51;
  width: min(400px, calc(100vw - 24px));
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: slide-in .28s var(--ease);
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 18px 12px; }
.drawer-head h3 { margin: 0; font-size: 17px; }
.drawer-head p { margin: 2px 0 0; color: var(--text-3); font-size: 12.5px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 0 18px 18px; display: flex; flex-direction: column; gap: 14px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); display: grid; gap: 2px; }
.stat span { color: var(--text-3); font-size: 12px; font-weight: 600; }
.stat strong { font-size: 17px; }
.stat strong.on { color: var(--success); }
.stat strong.off { color: var(--danger); }
.stat strong.warn { color: var(--warning); }
.drawer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.log-head { display: flex; align-items: center; gap: 8px; }
.event-log { display: grid; gap: 6px; }
.event {
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  background: var(--surface-2); font-size: 12.5px;
  animation: fade-up .2s var(--ease);
}
.event time { color: var(--text-3); font-variant-numeric: tabular-nums; }
.event p { margin: 0; overflow-wrap: anywhere; }
.privacy { display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 12px; border-radius: 12px; background: var(--success-soft); color: var(--text-2); font-size: 12.5px; }
.privacy .i { color: var(--success); width: 18px; height: 18px; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(5, 12, 26, .5); backdrop-filter: blur(6px); animation: fade .2s; }
.modal-card {
  position: relative; width: min(440px, 100%); max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column; gap: 14px;
  padding: 22px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  animation: modal-in .3s var(--ease);
  overflow: hidden;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-head p { margin: 3px 0 0; color: var(--text-3); font-size: 13px; }
.modal-close { position: absolute; top: 14px; right: 14px; z-index: 2; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }

/* Mất kết nối Zalo */
.lost-card { max-width: 420px; gap: 18px; }
.lost-hero { display: grid; justify-items: center; gap: 14px; text-align: center; padding-top: 6px; }
.lost-hero h3 { margin: 0; font-size: 21px; }
.lost-pair { display: flex; align-items: center; gap: 12px; }
.lost-app, .lost-zalo {
  position: relative; display: grid; place-items: center;
  width: 52px; height: 52px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow-md);
}
.lost-app { color: var(--brand); }
.lost-app .i { width: 26px; height: 26px; }
.lost-zalo { color: #0068ff; font-weight: 800; font-size: 14px; }
.lost-zalo i {
  position: absolute; top: -5px; right: -5px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font-style: normal; font-size: 11px;
  background: var(--warning, #f59e0b); color: #fff; box-shadow: 0 0 0 2px var(--surface);
}
.lost-link { color: var(--text-3); }
.lost-link .i { width: 20px; height: 20px; }
.lost-points { margin: 0; padding-left: 20px; display: grid; gap: 10px; color: var(--text-2); font-size: 13.5px; line-height: 1.55; }
.lost-points b { color: var(--text); }
.lost-actions { display: grid; gap: 8px; }
.lost-actions .btn { width: 100%; justify-content: center; }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; color: var(--text-2); }
.field input, .admin-form input, .admin-form select, .auth-form input {
  height: 44px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  outline: 0; transition: border-color .2s, box-shadow .2s, background .2s;
}
.field input:focus, .admin-form input:focus, .admin-form select:focus, .auth-form input:focus {
  border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 4px var(--brand-soft);
}

.qr-card { width: min(420px, 100%); text-align: center; padding-top: 28px; }
.qr-hero { display: grid; justify-items: center; gap: 4px; }
.qr-badge { width: 52px; height: 52px; border-radius: 18px; display: grid; place-items: center; background: var(--brand-grad); color: #fff; box-shadow: var(--shadow-brand); margin-bottom: 6px; }
.qr-badge .i { width: 26px; height: 26px; }
.qr-hero h3 { margin: 0; font-size: 20px; }
.qr-hero p { margin: 0; color: var(--text-3); font-size: 13px; }
.qr-stage {
  position: relative; margin: 4px auto 0;
  width: 264px; height: 264px;
  display: grid; place-items: center;
  border-radius: 24px;
  background: var(--surface-2);
}
.qr-stage::before {
  content: ""; position: absolute; inset: -2px; z-index: -1; border-radius: 26px;
  background: conic-gradient(from var(--angle, 0deg), #1a73ff, #6a5cff, #12b76a, #1a73ff);
  animation: rotate 4s linear infinite;
  opacity: .9;
}
.qr-view { display: grid; justify-items: center; align-content: center; gap: 8px; width: 100%; height: 100%; padding: 16px; animation: fade .25s; }
.qr-view strong { font-size: 16px; }
.qr-view span { color: var(--text-2); font-size: 13px; }
.qr-frame { position: relative; width: 224px; height: 224px; padding: 10px; border-radius: 18px; background: #fff; overflow: hidden; }
.qr-frame img { width: 100%; height: 100%; image-rendering: pixelated; }
.qr-scanline {
  position: absolute; left: 10px; right: 10px; height: 3px; top: 10px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, #1a73ff, transparent);
  box-shadow: 0 0 14px #1a73ff;
  animation: scan 2.6s ease-in-out infinite;
}
.qr-person { width: 84px; height: 84px; font-size: 26px; box-shadow: 0 0 0 6px var(--brand-soft); }
.qr-person .i { width: 38px; height: 38px; }
.qr-person.success { background: linear-gradient(135deg, #34d399, #12b76a); box-shadow: 0 0 0 6px var(--success-soft); animation: pop .4s var(--ease); }
.qr-person.warn { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 0 0 6px var(--warning-soft); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.success { background: var(--success-soft); color: var(--success); }
.qr-status { margin: 0; color: var(--text-2); font-size: 13.5px; min-height: 20px; }
.qr-status.error { color: var(--danger); }
.qr-steps { margin: 0; padding: 12px 14px 12px 34px; border-radius: 14px; background: var(--surface-2); text-align: left; color: var(--text-2); font-size: 13px; display: grid; gap: 4px; }
.qr-steps b { color: var(--text); }
.qr-card .modal-foot { justify-content: center; }

.list-card { width: min(480px, 100%); height: min(620px, calc(100dvh - 32px)); }
.contact-list { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 4px; margin: 0 -8px; padding: 0 8px; }
.contact-row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 14px; }
.contact-row:hover { background: var(--surface-2); }
.contact-avatar { width: 44px; height: 44px; font-size: 14px; }
.contact-row .btn { height: 34px; padding: 0 12px; font-size: 13px; }

.admin-card { width: min(720px, 100%); height: min(640px, calc(100dvh - 32px)); }
.admin-form { display: grid; grid-template-columns: 1.1fr 1fr 1.2fr .8fr auto; gap: 8px; }
.admin-form .btn { height: 44px; }
.admin-list { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 6px; }
.admin-row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.admin-row .avatar { width: 40px; height: 40px; font-size: 14px; }
.admin-row .card-copy small { opacity: 1; color: var(--text-3); }
.admin-row select { height: 34px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.status-toggle { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 12.5px; font-weight: 700; }
.status-toggle.on { background: var(--success-soft); color: var(--success); }
.status-toggle.off { background: var(--danger-soft); color: var(--danger); }

/* ---------- Lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(3, 7, 15, .92); animation: fade .2s; }
.lightbox-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; color: #fff; }
.lightbox-counter, .lightbox-zoom { font-weight: 600; font-variant-numeric: tabular-nums; }
.lightbox-zoom { min-width: 48px; text-align: center; font-size: 13px; }
.lightbox-tools { display: flex; align-items: center; gap: 4px; }
.icon-btn.glass { color: #fff; background: rgba(255, 255, 255, .08); }
.icon-btn.glass:hover { background: rgba(255, 255, 255, .18); color: #fff; }
/* Ảnh mở ra luôn cao bằng vùng xem (kể cả ảnh nhỏ), bề ngang không vượt quá 100%. */
.lightbox-stage { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; padding: 70px 80px; overflow: hidden; }
.lightbox-stage img { height: calc(100dvh - 140px); width: auto; max-width: 100%; object-fit: contain; border-radius: 8px; filter: drop-shadow(0 30px 60px rgba(0, 0, 0, .5)); transition: transform .2s var(--ease); animation: modal-in .3s var(--ease); cursor: zoom-in; }
.lightbox-stage.zoomed img { cursor: zoom-out; }
.lightbox-nav { position: absolute; top: 50%; z-index: 2; width: 48px; height: 48px; margin-top: -24px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: rgba(255, 255, 255, .1); }
.lightbox-nav:hover { background: rgba(255, 255, 255, .22); }
.lightbox-nav.prev { left: 18px; }
.lightbox-nav.next { right: 18px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: grid; gap: 8px; justify-items: end; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px;
  max-width: min(380px, calc(100vw - 40px));
  padding: 12px 16px; border-radius: 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-weight: 500;
  animation: toast-in .3s var(--ease);
  pointer-events: auto;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; box-shadow: 0 0 0 4px var(--brand-soft); }
.toast.success::before { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.toast.error::before { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.toast.clickable { cursor: pointer; }
.toast.clickable:hover { border-color: var(--brand); }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: all .25s var(--ease); }

.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--brand-soft); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}

/* ---------- Auth page ---------- */
.auth-page { overflow: auto; }
.auth-shell { min-height: 100dvh; display: grid; grid-template-columns: 1.1fr .9fr; align-items: center; gap: 48px; max-width: 1080px; margin: 0 auto; padding: 32px 24px; }
.auth-brand { display: inline-flex; align-items: center; gap: 12px; font-weight: 800; font-size: 18px; }
.auth-brand img { width: 44px; height: 44px; border-radius: 14px; filter: drop-shadow(0 8px 18px rgba(11, 92, 255, .4)); }
.auth-intro h1 { margin: 28px 0 14px; font-size: clamp(30px, 4vw, 46px); line-height: 1.1; letter-spacing: -.03em; }
.auth-intro h1 em { font-style: normal; background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-intro p { margin: 0; color: var(--text-2); font-size: 16px; max-width: 480px; }
.auth-features { display: grid; gap: 10px; margin-top: 28px; }
.auth-features span { display: inline-flex; align-items: center; gap: 12px; width: fit-content; padding: 10px 16px; border-radius: 14px; background: var(--surface-glass); border: 1px solid var(--border); font-weight: 600; color: var(--text-2); box-shadow: var(--shadow-sm); }
.auth-features .i { color: var(--brand); width: 18px; height: 18px; }
.auth-card { padding: 28px; border-radius: var(--radius-xl); background: var(--surface-glass); backdrop-filter: blur(18px); border: 1px solid var(--border); box-shadow: var(--shadow-lg); display: grid; gap: 18px; animation: fade-up .5s var(--ease) both; }
.auth-tabs { display: flex; align-items: center; gap: 6px; padding: 4px; border-radius: 14px; background: var(--surface-3); }
.auth-tab { flex: 1; height: 38px; border-radius: 10px; font-weight: 700; color: var(--text-2); }
.auth-tab.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
.auth-error { padding: 10px 14px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-weight: 600; font-size: 13px; }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; color: var(--text-2); }
.auth-submit { height: 48px; margin-top: 4px; font-size: 15px; }
.auth-note { margin: 0; text-align: center; color: var(--text-3); font-size: 12.5px; }

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(30px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes indeterminate { from { left: -40%; } to { left: 100%; } }
@keyframes ping { 0% { transform: scale(.6); opacity: .8; } 100% { transform: scale(1.8); opacity: 0; } }
@keyframes beat { 50% { transform: scale(1.6); } }
@keyframes float { 50% { transform: translateY(-8px); } }
@keyframes scan { 0%, 100% { top: 12px; } 50% { top: calc(100% - 14px); } }
@property --angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
@keyframes rotate { to { --angle: 360deg; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  /* Vòng xoay đang tải là thông tin, không phải trang trí: vẫn quay (chậm hơn),
     nếu không người dùng tưởng màn hình bị treo. */
  .spinner, .icon-btn.spinning .i, .sync-icon .i, .load-older.busy .i, .send-btn.busy .i {
    animation-duration: 1.4s !important; animation-iteration-count: infinite !important;
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1280px) {
  .profile-panel {
    position: absolute; top: 0; right: 0; bottom: 0; z-index: 25;
    box-shadow: var(--shadow-lg);
  }
  .chat-top-actions .btn-sm .btn-text { display: none; }
  .chat-top-actions .btn-sm { width: 34px; padding: 0; }
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 72px 310px minmax(0, 1fr); }
  .admin-form { grid-template-columns: 1fr 1fr; }
  .admin-form .btn { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 64px minmax(0, 1fr); padding: 0; gap: 0; }
  .rail { border-radius: 0; }
  .rail-logo { width: 40px; height: 40px; }
  .sidebar, .chat { border-radius: 0; border: 0; box-shadow: none; }
  .chat { position: fixed; inset: 0; z-index: 30; transform: translateX(100%); transition: transform .3s var(--ease); }
  .app.chat-open .chat { transform: none; }
  .back-btn { display: inline-grid; }
  .profile-panel { width: 100%; border-left: 0; }
  .chat-title-row .tag { display: none; }
  .msg-col { max-width: 84%; }
  .msg-actions { top: auto; bottom: calc(100% + 4px); transform: none; }
  .msg.in .msg-actions { left: 0; }
  .msg.out .msg-actions { right: 0; }
  .msg:hover .msg-actions, .msg-actions:focus-within, .msg-actions.picking { transform: none; }
  .stream { padding: 14px 12px 10px; }
  .composer { padding: 8px 10px 10px; }
  .composer-hint { display: none; }
  .search kbd { display: none; }
  .composer-tools .tool { width: 34px; height: 34px; }
  .lightbox-stage { padding: 64px 12px; }
  .lightbox-stage img { height: calc(100dvh - 128px); }
  .lightbox-nav { display: none; }
  .auth-shell { grid-template-columns: 1fr; gap: 24px; }
  .auth-intro h1 { margin-top: 18px; }
  .auth-features { display: none; }
}

@media (max-width: 480px) {
  .app { grid-template-columns: 56px minmax(0, 1fr); }
  .rail { gap: 8px; padding-top: 10px; }
  .rail-logo { width: 36px; height: 36px; }
  .rail-account { width: 40px; height: 40px; }
  .rail-account-face { width: 38px; height: 38px; font-size: 12px; }
  .rail-account::before { left: -8px; }
  .rail-btn { width: 38px; height: 38px; }
  .rail-me-btn { width: 36px; height: 36px; }
  .sidebar-head { padding: 12px 10px 8px; }
  .me-card { padding: 8px; gap: 10px; }
  .composer-tools #btn-quick-card { display: none; }
  .welcome { padding: 20px 16px; }
  .modal-card { padding: 18px; }
}
