/* Bố cục: thanh icon | danh sách hội thoại | khung chat | thông tin khách — kiểu ứng dụng nhắn tin */
:root {
  --brand: #1d6fb1;
  --brand-2: #0284c7;
  --orange: #f97316;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --hover: #f1f5f9;
  --selected: #e0f2fe;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --bubble-in: #ffffff;
  --bubble-in-text: #0f172a;
  --bubble-out-text: #ffffff;
  --danger: #ef4444;
  --warn-bg: #fffbeb;
  --warn-text: #b45309;
  --telegram: #229ed9;
  --messenger: #0084ff;
  --tiktok: #111111;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.05);
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 12px;
  font-family: var(--font);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090d16;
    --surface: #0f172a;
    --surface-2: #1e293b;
    --surface-3: #334155;
    --hover: #1e293b;
    --selected: #1e3a5f;
    --line: #1e293b;
    --text: #f8fafc;
    --muted: #94a3b8;
    --bubble-in: #1e293b;
    --bubble-in-text: #f8fafc;
    --warn-bg: #451a03;
    --warn-text: #fde68a;
    --brand-2: #38bdf8;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #090d16;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --surface-3: #334155;
  --hover: #1e293b;
  --selected: #1e3a5f;
  --line: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --bubble-in: #1e293b;
  --bubble-in-text: #f8fafc;
  --warn-bg: #451a03;
  --warn-text: #fde68a;
  --brand-2: #38bdf8;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
}

svg.ic {
  width: 20px;
  height: 20px;
  flex: none;
}

.brand-o {
  color: var(--orange);
}

.brand-b {
  color: var(--brand-2);
}

.spacer {
  flex: 1;
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  margin: 0;
  font-size: 13px;
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
  margin: 8px 0 0;
}

button.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  padding: 10px 16px;
}

button.primary:hover {
  background: var(--brand-2);
}

button.soft {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 500;
}

button.soft:hover {
  background: var(--surface-3);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: var(--brand-2);
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn.active {
  background: var(--selected);
}

/* Logo */
.logo-mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  flex: none;
  background: linear-gradient(135deg, var(--orange) 0%, var(--orange) 45%, var(--brand) 55%, var(--brand) 100%);
  background: var(--surface-2);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.logo-mark.small {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 8px;
}

.logo-mark.small {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  margin-bottom: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.rail-logo-img {
  width: 32px;
  height: auto;
  max-height: 32px;
  object-fit: contain;
}

/* Đăng nhập */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--orange) 14%, transparent), transparent),
    radial-gradient(900px 600px at 110% 110%, color-mix(in srgb, var(--brand) 18%, transparent), transparent), var(--bg);
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 20px;
  padding: clamp(20px, 6vw, 32px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
}

.login-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  margin-bottom: 18px;
}

.login-logo-img {
  max-width: 250px;
  height: auto;
  object-fit: contain;
}

.login-brand-desc {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

:root:not([data-theme="light"]) .login-logo-img,
:root[data-theme="dark"] .login-logo-img {
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.5)) brightness(1.1);
}

.login-card label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  margin-top: 6px;
}

.login-card input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.login-card input:focus {
  background: var(--surface);
}

.login-card .primary {
  margin-top: 14px;
  padding: 12px;
}

.demo-accounts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 4px;
}

.demo-accounts p {
  margin: 0;
  width: 100%;
  font-size: 12.5px;
  color: var(--muted);
}

/* Khung ứng dụng */
:root {
  --sidebar-w: 360px;
}

.app {
  display: grid;
  grid-template-columns: 68px var(--sidebar-w) minmax(0, 1fr) auto;
  height: 100%;
  background: var(--surface);
  transition: grid-template-columns 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 861px) {
  .rail {
    grid-column: 1;
  }

  .sidebar {
    grid-column: 2;
  }

  .chat {
    grid-column: 3;
    min-width: 0;
  }

  .info {
    grid-column: 4;
  }
}

/* Chế độ phóng to chiều rộng sidebar */
.app.sidebar-wide {
  --sidebar-w: 460px;
}

/* Chế độ thu nhỏ (ẩn sidebar) */
.app.sidebar-collapsed {
  --sidebar-w: 0px !important;
  grid-template-columns: 68px 0 minmax(0, 1fr) auto !important;
}

.app.sidebar-collapsed .sidebar {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border-right: none !important;
  overflow: hidden !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

.list-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-actions .icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
}

.sidebar-actions .icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-actions .icon-btn.active {
  background: var(--selected);
  color: var(--brand-2);
}

.btn-chat-toggle-sidebar {
  display: inline-grid;
  margin-right: 4px;
}

.empty-head {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.rail-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail-btn {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.rail-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateY(-1px);
}

.rail-btn.active {
  background: var(--selected);
  color: var(--brand-2);
}

.rail-btn.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 10px;
  bottom: 10px;
  width: 3.5px;
  border-radius: 0 4px 4px 0;
  background: var(--brand);
}

.rail-btn svg.ic {
  width: 22px;
  height: 22px;
}

.rail-count {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.rail-count:empty {
  display: none;
}

.rail .avatar {
  margin-top: 8px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border-right: 1px solid var(--line);
}

.list-head {
  padding: 16px 16px 6px;
}

.list-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.me {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.search {
  margin: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--muted);
  transition: all 0.2s ease;
}

.search:focus-within {
  border-color: var(--brand-2);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 15%, transparent);
  color: var(--text);
}

.search svg.ic {
  width: 18px;
  height: 18px;
}

.search input {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 0;
  outline: none;
}

.chips {
  display: flex;
  gap: 6px;
  padding: 4px 16px 10px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: all 0.15s ease;
}

.chip svg.ic {
  width: 15px;
  height: 15px;
}

.chip:hover {
  background: var(--surface-3);
  border-color: var(--line);
}

.chip.active {
  background: var(--selected);
  color: var(--brand-2);
  border-color: color-mix(in srgb, var(--brand-2) 30%, transparent);
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  overflow-y: auto;
  flex: 1;
}

.conv {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  margin-bottom: 3px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.16s ease;
}

.conv:hover {
  background: var(--hover);
  border-color: var(--line);
}

.conv.active {
  background: var(--selected);
  border-color: color-mix(in srgb, var(--brand-2) 30%, transparent);
  box-shadow: var(--shadow-sm);
}

.conv-body {
  flex: 1;
  min-width: 0;
}

.conv-name {
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-line {
  display: flex;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
}

.conv-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.conv-time {
  flex: none;
}

.conv-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  min-width: 0;
}

.conv-meta>span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta .pill {
  flex: none;
}

.conv.unread .conv-name {
  font-weight: 700;
}

.conv.unread .conv-preview {
  color: var(--text);
  font-weight: 600;
}

.unread-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--brand-2);
  flex: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.pill.mine {
  background: var(--selected);
  color: var(--brand-2);
}

.pill.free {
  background: color-mix(in srgb, var(--orange) 15%, transparent);
  color: var(--orange);
}

.list-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

/* Avatar */
.avatar {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  background: var(--av, var(--brand));
}

.avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.avatar.md {
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.avatar.sm {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.avatar.xs {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.avatar.xl {
  width: 84px;
  height: 84px;
  font-size: 30px;
}

.ch-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid var(--surface);
  color: #fff;
}

.ch-badge svg.ic {
  width: 11px;
  height: 11px;
}

.ch-badge.telegram {
  background: var(--telegram);
}

.ch-badge.messenger {
  background: var(--messenger);
}

.avatar.md .ch-badge {
  width: 16px;
  height: 16px;
}

.avatar.md .ch-badge svg.ic {
  width: 9px;
  height: 9px;
}

/* Khung chat */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 24px;
}

.empty .empty-ic {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--brand-2);
}

.empty .empty-ic svg.ic {
  width: 32px;
  height: 32px;
}

.empty h3 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
}

.empty p {
  margin: 0;
  max-width: 32ch;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .03);
}

.chat-head .title {
  flex: 1;
  min-width: 0;
}

.chat-head .title strong {
  display: block;
  font-size: 15.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-head .title small {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
}

.chat-head .actions {
  display: flex;
  gap: 2px;
  align-items: center;
  flex: none;
}

#btn-back {
  display: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 8px;
  display: flex;
  flex-direction: column;
}

.day-sep {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin: 16px 0 10px;
}

.row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.row.out {
  justify-content: flex-end;
}

.row.first {
  margin-top: 10px;
}

.row .av-slot {
  width: 28px;
  flex: none;
}

.who {
  font-size: 11.5px;
  color: var(--muted);
  margin: 10px 12px 2px;
  align-self: flex-end;
}

.who.in {
  align-self: flex-start;
  margin-left: 48px;
}

.bubble {
  max-width: min(68%, 560px);
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 14.5px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--line);
}

.bubble .text {
  white-space: pre-wrap;
}

.row.out .bubble {
  background: linear-gradient(135deg, var(--brand-2) 0%, var(--brand) 100%);
  color: var(--bubble-out-text);
  border-color: transparent;
  box-shadow: 0 3px 12px color-mix(in srgb, var(--brand) 25%, transparent);
}

.row.in:not(.last) .bubble {
  border-bottom-left-radius: 6px;
}

.row.in:not(.first) .bubble {
  border-top-left-radius: 6px;
}

.row.out:not(.last) .bubble {
  border-bottom-right-radius: 6px;
}

.row.out:not(.first) .bubble {
  border-top-right-radius: 6px;
}

.bubble.media-only {
  background: transparent !important;
  padding: 0;
}

.bubble img {
  max-width: 240px;
  max-height: 320px;
  border-radius: 14px;
  display: block;
}

.bubble video {
  max-width: 260px;
  border-radius: 14px;
  display: block;
}

.bubble a {
  color: inherit;
  text-decoration: underline;
}

.bubble .file {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.bubble[title] {
  cursor: default;
}

.row.failed .bubble {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--text);
  border: 1px solid var(--danger);
}

.status {
  align-self: flex-end;
  font-size: 11.5px;
  color: var(--muted);
  margin: 3px 4px 0;
  display: flex;
  gap: 4px;
  align-items: center;
}

.status svg.ic {
  width: 14px;
  height: 14px;
}

.status.failed {
  color: var(--danger);
}

.warn {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 16px 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 13px;
}

.warn svg.ic {
  width: 18px;
  height: 18px;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 18px 14px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.composer .attach {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex: none;
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: all 0.16s ease;
}

.composer .attach:hover {
  background: var(--surface-2);
  color: var(--brand-2);
}

.composer .attach svg.ic {
  width: 21px;
  height: 21px;
}

.attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 16px 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 14px;
}

.attach-preview img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 10px;
  flex: none;
}

.attach-preview .att-ic {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--brand-2);
  flex: none;
}

.attach-preview .att-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
}

.attach-preview .att-remove {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  flex: none;
}

.attach-preview .att-remove:hover {
  background: var(--surface);
  color: var(--text);
}

.attach-preview .att-remove svg.ic {
  width: 17px;
  height: 17px;
}

.composer .field {
  flex: 1;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2px 6px 2px 14px;
  transition: all 0.2s ease;
}

.composer .field:focus-within {
  border-color: var(--brand-2);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 15%, transparent);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  padding: 10px 0;
  height: 42px;
  max-height: 140px;
  outline: none;
  line-height: 1.45;
}

.composer .send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--brand-2);
}

.composer .send:hover {
  background: var(--surface-2);
}

.composer .send:disabled {
  color: var(--muted);
  opacity: .5;
  cursor: default;
}

.composer .send svg.ic {
  width: 22px;
  height: 22px;
}

.quick {
  display: flex;
  gap: 6px;
  padding: 0 16px 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick::-webkit-scrollbar {
  display: none;
}

.quick button {
  flex: none;
  white-space: nowrap;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  color: var(--brand-2);
  font-weight: 500;
}

.quick button:hover {
  background: var(--selected);
}


/* Thông tin khách */
.info {
  width: 300px;
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: relative;
}

.info-close {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
}

.info-top {
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
}

.info-top h3 {
  margin: 6px 0 0;
  font-size: 17px;
}

.info-top p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.info-sec h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.kv {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px 4px;
  font-size: 13.5px;
}

.kv svg.ic {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.kv small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.info select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.info .soft {
  width: 100%;
  justify-content: center;
  margin-top: 6px;
}

/* Cài đặt */
dialog {
  border: 0;
  border-radius: 18px;
  width: min(760px, calc(100vw - 32px));
  padding: 22px 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(10, 16, 24, 0.45);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}

.settings-sec {
  margin-top: 18px;
}

.settings-sec h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.rows {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.rows li {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.rows li:last-child {
  border-bottom: 0;
}

.rows .grow {
  flex: 1;
  min-width: 0;
}

.rows .grow small {
  display: block;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2fb36a;
  flex: none;
}

.dot.off {
  background: var(--muted);
}

.inline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.inline input,
.inline select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.inline input {
  flex: 1;
  min-width: 150px;
}

@media (max-width: 1180px) {
  .app {
    grid-template-columns: 68px var(--sidebar-w, minmax(280px, 340px)) minmax(0, 1fr) auto;
  }

  .app.sidebar-collapsed {
    grid-template-columns: 68px 0 minmax(0, 1fr) auto !important;
  }

  .info {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(340px, 100%);
    padding-top: 56px;
    background: var(--surface);
    box-shadow: var(--shadow);
    z-index: 20;
  }

  .info-close {
    display: inline-grid;
  }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    height: 100dvh;
  }

  .rail {
    flex-direction: row;
    grid-row: 2;
    justify-content: space-around;
    padding: 6px max(16px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    border-right: 0;
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 95%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 15;
  }

  .rail-btn {
    width: 46px;
    height: 46px;
  }

  .rail-btn.active::before {
    top: 0;
    left: 12px;
    right: 12px;
    bottom: auto;
    width: auto;
    height: 3px;
    border-radius: 0 0 3px 3px;
  }

  .rail-group {
    flex-direction: row;
    gap: 6px;
  }

  .rail .logo-mark,
  .rail .avatar,
  .rail .spacer {
    display: none;
  }

  .app.has-chat .sidebar,
  .app.has-chat .rail {
    display: none;
  }

  .app:not(.has-chat) .chat {
    display: none;
  }

  .app.has-chat {
    grid-template-rows: 1fr;
    height: 100dvh;
  }

  #btn-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--brand-2);
    margin-right: 4px;
    flex: none;
  }

  #btn-back:hover {
    background: var(--surface-3);
  }

  .bubble {
    max-width: 86%;
  }

  .info {
    width: 100%;
  }

  .messages {
    padding: 12px 14px 8px;
  }

  .composer {
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .list-head {
    padding: 14px 16px 4px;
  }

  .list-head h2 {
    font-size: 21px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .row.new {
    animation: pop .18s ease-out;
  }

  @keyframes pop {
    from {
      transform: translateY(6px);
      opacity: .4;
    }

    to {
      transform: none;
      opacity: 1;
    }
  }
}
/* ---------- Emoji ---------- */
.composer { position: relative; }
.composer .field { align-items: flex-end; }
.composer .emoji-btn {
  width: 36px;
  height: 36px;
  margin: 3px 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  color: var(--muted);
}
.composer .emoji-btn:hover,
.composer .emoji-btn.active { color: var(--brand-2); background: var(--surface); }
.composer .emoji-btn svg.ic { width: 22px; height: 22px; }

.emoji-pop {
  position: absolute;
  right: 16px;
  bottom: calc(100% - 6px);
  z-index: 30;
  width: min(360px, calc(100vw - 24px));
  height: 380px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: emoji-in .14s ease-out;
}
.emoji-pop.hidden { display: none; }
@keyframes emoji-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 4px;
  border-bottom: 1px solid var(--line);
}
.emoji-tab {
  flex: 1;
  height: 34px;
  border-radius: 10px;
  font-size: 19px;
  line-height: 1;
  opacity: .55;
  filter: grayscale(.4);
}
.emoji-tab:hover { background: var(--surface-2); opacity: .9; }
.emoji-tab.active { background: var(--surface-2); opacity: 1; filter: none; }
.emoji-search { padding: 8px 10px 4px; }
.emoji-search input {
  width: 100%;
  border: 0;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13.5px;
}
.emoji-body { flex: 1; overflow-y: auto; padding: 0 8px 8px; scrollbar-width: thin; }
.emoji-body h5 {
  position: sticky;
  top: 0;
  margin: 0;
  padding: 8px 4px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  z-index: 1;
}
.emo-grid { display: grid; grid-template-columns: repeat(8, 1fr); }
.emo {
  aspect-ratio: 1;
  font-size: 24px;
  line-height: 1;
  border-radius: 10px;
  display: grid;
  place-items: center;
  transition: transform .08s;
}
.emo:hover { background: var(--surface-2); transform: scale(1.15); }
.emoji-empty { text-align: center; color: var(--muted); padding: 32px 8px; font-size: 13.5px; }
@media (max-width: 600px) {
  .emoji-pop { right: 8px; left: 8px; width: auto; height: 320px; }
  .emo { font-size: 22px; }
}

/* ---------- Loading ---------- */
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  display: inline-block;
  animation: spin .7s linear infinite;
  flex: none;
}
.spinner.lg { width: 34px; height: 34px; border-width: 3px; color: var(--brand-2); }
@keyframes spin { to { transform: rotate(360deg); } }

.chat-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13.5px;
}

/* Nút đang xử lý: ẩn nội dung, hiện vòng quay */
button.loading { position: relative; pointer-events: none; }
button.loading > * { visibility: hidden; }
button.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  animation: spin .7s linear infinite;
}
button.primary.loading { color: transparent; }
button.primary.loading::after { border-color: #fff; border-right-color: transparent; }
.composer .send.loading { opacity: 1; color: var(--brand-2); }

.composer.sending textarea { opacity: .6; }
.attach-preview.sending { opacity: .65; }
.attach-preview.sending .att-name::after { content: ' · Đang gửi…'; color: var(--muted); }

/* Khung xương khi tải danh sách */
.conv.skeleton { pointer-events: none; }
.sk {
  display: block;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 55%, var(--line)) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
.sk-av { width: 52px; height: 52px; border-radius: 50%; flex: none; }
.sk-line { height: 11px; margin: 5px 0; }
.sk-line.w40 { width: 40%; }
.sk-line.w60 { width: 60%; }
.sk-line.w90 { width: 90%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .spinner, button.loading::after, .sk { animation-duration: 2s; }
  .emoji-pop { animation: none; }
}

/* ---------- Trang Cài đặt ---------- */
body:not(.is-admin) .admin-only { display: none !important; }
#me-avatar { cursor: pointer; }
.app.settings-mode .sidebar,
.app.settings-mode .chat,
.app.settings-mode .info { display: none !important; }
.settings-page {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  background: var(--surface-2);
}
.settings-page.hidden { display: none; }

.set-nav {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.set-back {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 10px 6px 4px;
  border-radius: 10px;
}
.set-back:hover { color: var(--text); background: var(--surface-2); }
.set-back svg.ic { width: 18px; height: 18px; }
.set-nav h1 { font-size: 26px; margin: 8px 10px 14px; letter-spacing: -0.02em; }
#set-tabs { display: flex; flex-direction: column; gap: 4px; }
#set-tabs button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  text-align: left;
  color: var(--text);
}
#set-tabs button svg.ic {
  width: 38px;
  height: 38px;
  padding: 9px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  flex: none;
}
#set-tabs button span { display: flex; flex-direction: column; font-weight: 600; font-size: 14.5px; }
#set-tabs button small { font-weight: 400; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
#set-tabs button:hover { background: var(--surface-2); }
#set-tabs button.active { background: var(--selected); }
#set-tabs button.active svg.ic { background: var(--brand-2); color: #fff; }

.set-body { overflow-y: auto; padding: 28px clamp(16px, 4vw, 48px) 48px; }
.set-sec { display: none; max-width: 860px; margin: 0 auto; flex-direction: column; gap: 16px; }
.set-sec.show { display: flex; animation: set-in .18s ease-out; }
@keyframes set-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.set-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }
.set-head h2 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.set-head p { margin: 0; color: var(--muted); max-width: 520px; font-size: 14px; line-height: 1.5; }
.stat-row { display: flex; gap: 8px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  min-width: 84px;
}
.stat strong { font-size: 20px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.good strong { color: #1f9d55; }
.stat.muted strong { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px;
}
.card h3 { font-size: 15px; margin: 0 0 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.card input:not([type=radio]):not([type=checkbox]),
.card select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.card input:focus,
.card select:focus { border-color: var(--brand-2); background: var(--surface); }

.type-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.type-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.type-opt input { position: absolute; opacity: 0; pointer-events: none; }
.type-opt span { display: flex; flex-direction: column; }
.type-opt strong { font-size: 14px; }
.type-opt small { font-size: 12.5px; color: var(--muted); }
.type-opt:has(input:checked) { border-color: var(--brand-2); background: var(--selected); }
.type-opt:has(input:focus-visible) { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.type-ic {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid !important;
  place-items: center;
  color: #fff;
  flex: none;
}
.type-ic svg.ic { width: 22px; height: 22px; }
.type-ic.tg { background: var(--telegram); }
.type-ic.fb { background: var(--messenger); }
.token-row { display: flex; gap: 8px; }
.token-row input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px !important; }
.token-row .primary { flex: none; }
.steps { margin: 14px 0 0; padding: 12px 14px 12px 34px; background: var(--surface-2); border-radius: 12px; font-size: 13px; color: var(--muted); line-height: 1.65; }
.steps code { background: var(--surface); padding: 1px 5px; border-radius: 6px; font-size: 12px; color: var(--text); }
.steps b { color: var(--text); }

.set-list { list-style: none; margin: 0; padding: 0; }
.set-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-top: 1px solid var(--line);
}
.set-list li:first-child { border-top: 0; }
.set-list li.off .grow,
.set-list li.off .type-ic,
.set-list li.off .avatar { opacity: .55; }
.set-list .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.set-list .grow strong { font-size: 14.5px; display: flex; align-items: center; gap: 6px; }
.set-list .grow small { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-loading { justify-content: center; color: var(--muted); font-size: 13.5px; padding: 24px !important; }
.set-empty { flex-direction: column; text-align: center; padding: 28px 8px !important; gap: 4px !important; color: var(--muted); font-size: 13.5px; }
.set-empty svg.ic { width: 34px; height: 34px; color: var(--brand-2); margin-bottom: 4px; }
.set-empty strong { color: var(--text); font-size: 14.5px; }
.status-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.status-pill.on { background: color-mix(in srgb, #1f9d55 14%, transparent); color: #1f9d55; }
.role-sel { width: auto !important; padding: 7px 10px !important; font-size: 13px !important; }
.lock-slot { width: 76px; flex: none; }
.set-list .soft { min-width: 76px; justify-content: center; }
button.soft.danger { color: var(--danger); }
button.soft.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.switch { position: relative; width: 44px; height: 26px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .18s; pointer-events: none; }
.switch span::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .18s;
}
.switch input:checked + span { background: #1f9d55; }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.switch input:disabled + span { opacity: .6; }

.user-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.user-grid > .primary { grid-column: 1 / -1; justify-self: start; }
.user-grid.pw { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.user-grid.pw > .primary { grid-column: auto; justify-self: stretch; }
.mini-search { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border-radius: 10px; padding: 0 10px; width: 240px; max-width: 50%; }
.mini-search svg.ic { width: 16px; height: 16px; color: var(--muted); flex: none; }
.mini-search input { background: transparent !important; padding: 8px 0 !important; border: 0 !important; }

.profile-card { display: flex; align-items: center; gap: 16px; }
.profile-card h3 { margin: 0 0 2px; font-size: 18px; }
.profile-card p { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }
.theme-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-pick button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.theme-pick button.active { border-color: var(--brand-2); background: var(--selected); }
.th-prev { width: 100%; height: 54px; border-radius: 10px; border: 1px solid var(--line); }
.th-prev.light { background: linear-gradient(90deg, #f0f3f7 30%, #fff 30%); }
.th-prev.dark { background: linear-gradient(90deg, #1e2631 30%, #121820 30%); }
.th-prev.system { background: linear-gradient(135deg, #fff 50%, #121820 50%); }
.danger-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.danger-card h3 { margin: 0 0 2px; }
.danger-card p { margin: 0; color: var(--muted); font-size: 13.5px; }

.toast-box { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--text);
  color: var(--surface);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  max-width: 380px;
  animation: toast-in .2s ease-out;
  transition: opacity .3s, transform .3s;
}
.toast svg.ic { width: 18px; height: 18px; flex: none; color: #4ade80; }
.toast.err svg.ic { color: #f87171; }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 860px) {
  .app.settings-mode { grid-template-rows: minmax(0, 1fr) auto; }
  .app.settings-mode .rail { display: flex !important; }
  .settings-page { grid-column: 1; grid-row: 1; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .set-nav { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 12px 8px; }
  .set-nav h1 { font-size: 20px; margin: 4px 4px 8px; }
  .set-back { display: none; }
  #set-tabs { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  #set-tabs button { padding: 6px 12px 6px 6px; flex: none; }
  #set-tabs button svg.ic { width: 30px; height: 30px; padding: 6px; border-radius: 10px; }
  #set-tabs button small { display: none; }
  .set-body { padding: 16px 12px 32px; }
  .type-pick, .user-grid, .user-grid.pw { grid-template-columns: minmax(0, 1fr); }
  .token-row { flex-direction: column; }
  .set-list li { flex-wrap: wrap; }
  .set-list .grow { flex-basis: calc(100% - 60px); }
  .mini-search { max-width: none; width: 100%; }
  .card-head { flex-direction: column; align-items: stretch; }
  .toast-box { left: 12px; right: 12px; bottom: 80px; }
}
.card input:not([type=radio]):not([type=checkbox]):not(.mini-search input),
.card select:not(.role-sel) { height: 42px; }

/* ---------- Xoá hội thoại ---------- */
.conv { position: relative; }
.conv-del {
  position: absolute;
  right: 10px;
  top: 50%;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(18, 26, 38, .12), 0 0 0 1px var(--line);
  opacity: 0;
  transform: translateY(-50%) scale(.85);
  transition: opacity .15s, transform .15s, color .15s, background .15s;
  pointer-events: none;
}
.conv-del svg.ic { width: 18px; height: 18px; }
.conv:hover .conv-del,
.conv:focus-within .conv-del,
.conv-del:focus-visible { opacity: 1; transform: translateY(-50%) scale(1); pointer-events: auto; }
.conv:hover .unread-dot { visibility: hidden; }
.conv-del:hover { color: #fff; background: var(--danger); box-shadow: 0 4px 12px color-mix(in srgb, var(--danger) 35%, transparent); }
.conv-del:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }
@media (hover: none) {
  .conv-del { opacity: .9; transform: translateY(-50%) scale(.9); pointer-events: auto; width: 32px; height: 32px; box-shadow: none; background: transparent; }
  .conv .unread-dot { margin-right: 34px; }
}
.conv.removing { animation: conv-out .22s ease-in forwards; pointer-events: none; }
@keyframes conv-out { to { opacity: 0; transform: translateX(-16px); } }

#info-delete { margin-bottom: 8px; }

.cfm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 14, 20, .45);
  backdrop-filter: blur(3px);
  animation: cfm-fade .15s ease-out;
}
.cfm-backdrop.out { opacity: 0; transition: opacity .15s; }
.cfm {
  width: min(400px, 100%);
  background: var(--surface);
  color: var(--text);
  border-radius: 20px;
  padding: 24px 24px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
  text-align: center;
  animation: cfm-pop .18s cubic-bezier(.2, .9, .3, 1.2);
}
.cfm-ic {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--selected);
  color: var(--brand-2);
}
.cfm-ic.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.cfm-ic svg.ic { width: 26px; height: 26px; }
.cfm h3 { margin: 0 0 8px; font-size: 18px; }
.cfm p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.cfm p strong { color: var(--text); }
.cfm p small { display: block; margin-top: 8px; font-size: 12.5px; }
.cfm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cfm-actions button { justify-content: center; padding: 11px 14px; border-radius: 12px; font-weight: 600; }
button.primary.danger { background: var(--danger); }
button.primary.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
@keyframes cfm-fade { from { opacity: 0; } }
@keyframes cfm-pop { from { opacity: 0; transform: scale(.94) translateY(6px); } }
@media (hover: hover) {
  body.is-admin .conv:hover .conv-body,
  body.is-admin .conv:focus-within .conv-body { padding-right: 40px; }
}

/* TikTok */
.ch-badge.tiktok { background: var(--tiktok); }
.type-ic.tt { background: linear-gradient(135deg, #25f4ee, #111 45%, #111 55%, #fe2c55); }
.type-pick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.type-opt .soon { font-style: normal; font-size: 10.5px; font-weight: 700; background: #fe2c55; color: #fff; padding: 1px 6px; border-radius: 6px; margin-left: 4px; vertical-align: 2px; }
#channel-form button.primary:disabled { opacity: .5; cursor: not-allowed; }
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) { --tiktok: #2a2a2a; } }
:root[data-theme=dark] { --tiktok: #2a2a2a; }

/* ================= Làm đẹp trang Cài đặt + nút xoá (v2) ================= */
/* Đầu mục: tiêu đề + nhóm số liệu gọn */
.set-head { align-items: center; padding-bottom: 4px; }
.set-head h2 { font-size: 24px; }
.stat-row {
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 4px;
}
.stat {
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 6px 16px;
  min-width: 0;
  align-items: flex-start;
  position: relative;
}
.stat + .stat::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 1px;
  background: var(--line);
}
.stat strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { white-space: nowrap; }

/* Thẻ: bóng nhẹ, tiêu đề có icon + mô tả */
.card {
  border-radius: 20px;
  padding: 20px 22px;
  box-shadow: 0 1px 2px rgba(18, 26, 38, .04);
}
.card-title { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; min-width: 0; }
.card-title h3 { margin: 0 0 2px !important; font-size: 15.5px; }
.card-title p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.ct-ic {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--selected);
  color: var(--brand-2);
}
.ct-ic svg.ic { width: 18px; height: 18px; }
.card-head { align-items: flex-start; margin-bottom: 8px; }
.card-head .card-title { margin-bottom: 0; }

/* Ô chọn loại kênh */
.type-opt { padding: 14px; border-radius: 16px; background: var(--surface); position: relative; }
.type-opt:hover { border-color: color-mix(in srgb, var(--brand-2) 45%, var(--line)); }
.type-opt:has(input:checked)::after {
  content: '';
  position: absolute;
  top: 10px;
  right: 10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 11px no-repeat;
}
.type-opt span { min-width: 0; }
.type-opt strong { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.type-opt .soon { margin-left: 0; vertical-align: 0; }
.token-row input, .token-row .primary { height: 44px; }
.token-row .primary { padding: 0 18px; border-radius: 12px; }

/* Danh sách kênh / nhân viên: mỗi dòng là một ô bo góc */
.set-list { display: flex; flex-direction: column; gap: 6px; }
.set-list li {
  border-top: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-2);
  transition: background .15s;
}
.set-list li:hover { background: color-mix(in srgb, var(--surface-2) 70%, var(--line)); }
.set-list li.set-loading, .set-list li.set-empty { background: transparent; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; }
.status-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.role-sel { background: var(--surface) !important; border: 1px solid var(--line) !important; }
.set-list .soft { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; }

/* Đổi mật khẩu: nút nằm hàng riêng bên phải */
.user-grid.pw > .form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.form-actions .primary { padding: 10px 18px; border-radius: 12px; }

/* Ô xem trước giao diện: mô phỏng app thu nhỏ */
.theme-pick button { padding: 8px 8px 12px; border-radius: 16px; transition: border-color .15s, background .15s; position: relative; }
.theme-pick button:hover { border-color: color-mix(in srgb, var(--brand-2) 45%, var(--line)); }
.theme-pick button.active::after {
  content: '';
  position: absolute;
  top: 14px;
  right: 14px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 11px no-repeat;
}
.th-prev {
  --a: #f0f3f7; --b: #ffffff; --c: #dfe5ee; --d: #2d8cff;
  height: 76px;
  position: relative;
  overflow: hidden;
  background: var(--b);
  border-radius: 11px;
}
.th-prev.dark { --a: #1b222c; --b: #11161d; --c: #2a3340; --d: #3d9bff; }
.th-prev.system { background: linear-gradient(120deg, #fff 50%, #11161d 50%); }
.th-prev i { position: absolute; left: 0; top: 0; bottom: 0; width: 26%; background: var(--a); }
.th-prev.system i { background: #f0f3f7; }
.th-prev b { position: absolute; height: 9px; border-radius: 6px; }
.th-prev b:nth-of-type(1) { left: 34%; top: 18px; width: 40%; background: var(--c); }
.th-prev b:nth-of-type(2) { right: 10%; top: 40px; width: 34%; background: var(--d); }
.th-prev.system b:nth-of-type(1) { background: #dfe5ee; }
.th-prev.system b:nth-of-type(2) { background: #3d9bff; }

/* Thẻ đăng xuất */
.danger-card { border-color: color-mix(in srgb, var(--danger) 22%, var(--line)); }
.danger-card .soft.danger { border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); padding: 9px 14px; border-radius: 12px; }

/* Thanh mục bên trái */
#set-tabs button { transition: background .15s; }
#set-tabs button.active span { color: var(--brand-2); }
#set-tabs button.active small { color: var(--muted); }

@media (max-width: 860px) {
  .type-pick { grid-template-columns: minmax(0, 1fr); }
  .type-opt:has(input:checked)::after { top: 50%; transform: translateY(-50%); right: 14px; }
  .set-head { align-items: stretch; }
  .stat-row { align-self: flex-start; }
  .user-grid.pw > .form-actions .primary { width: 100%; justify-content: center; }
  .set-list li { gap: 8px 12px; }
}

/* ---------- Nút xoá hội thoại v2: không đè chữ, nền mờ dần ---------- */
body.is-admin .conv:hover .conv-body,
body.is-admin .conv:focus-within .conv-body { padding-right: 0; }
.conv-del {
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--danger) 18%, transparent);
  transform: translateY(-50%) translateX(6px);
}
.conv-del svg.ic { width: 17px; height: 17px; }
/* lớp mờ ở mép phải dòng để chữ dài tan dần thay vì bị nút đè cắt ngang */
body.is-admin .conv::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 96px;
  border-radius: 0 12px 12px 0;
  background: linear-gradient(90deg, transparent, var(--hover) 50%);
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
  z-index: 1;
}
body.is-admin .conv.active::after { background: linear-gradient(90deg, transparent, var(--selected) 50%); }
body.is-admin .conv:hover::after,
body.is-admin .conv:focus-within::after { opacity: 1; }
.conv-del { z-index: 2; }
.conv:hover .conv-del,
.conv:focus-within .conv-del,
.conv-del:focus-visible { transform: translateY(-50%) translateX(0); }
.conv-del:hover {
  color: #fff;
  background: var(--danger);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--danger) 35%, transparent);
}
.conv-del:active { transform: translateY(-50%) scale(.94); }
@media (hover: none) {
  .conv-del { background: transparent; box-shadow: none; transform: translateY(-50%); }
  body.is-admin .conv::after { display: none; }
}

/* Hộp xác nhận: gọn hơn, nút cao bằng nhau */
.cfm { border-radius: 22px; padding: 26px 24px 20px; border: 1px solid var(--line); }
.cfm-ic { box-shadow: 0 0 0 8px color-mix(in srgb, var(--danger) 6%, transparent); }
.cfm-actions button { height: 44px; }
.cfm-actions .soft { background: var(--surface-2); }
.cfm-actions .soft:hover { background: color-mix(in srgb, var(--surface-2) 70%, var(--line)); }

/* Liên kết pháp lý dưới ô đăng nhập */
.login-legal { display: flex; justify-content: center; gap: 8px; margin-top: 16px; font-size: 12.5px; color: var(--muted); }
.login-legal a { color: var(--muted); text-decoration: none; }
.login-legal a:hover { color: var(--text); text-decoration: underline; }
.login { align-content: center; }

/* ================= Câu trả lời mẫu + ghi chú nội bộ ================= */
:root { --note: #e0a100; --note-bg: color-mix(in srgb, #ffc533 16%, var(--surface)); }
.quick.hidden { display: none; }
.quick button { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

kbd {
  font: 600 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
}

/* Thanh chọn: Trả lời khách | Ghi chú nội bộ */
.compose-tabs { display: flex; align-items: center; gap: 4px; padding: 2px 16px 0; }
.compose-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--muted);
}
.compose-tabs button svg.ic { width: 15px; height: 15px; }
.compose-tabs button:hover { color: var(--text); background: var(--hover); }
.compose-tabs button.active { color: var(--brand-2); background: var(--selected); }
.compose-tabs button[data-mode='note'].active { color: color-mix(in srgb, var(--note) 75%, var(--text)); background: var(--note-bg); }
.compose-hint { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-hint kbd { font-size: 11px; padding: 1px 5px; }

/* Ô nhập ở chế độ ghi chú: nền vàng để không nhầm với tin gửi khách */
.composer.note-mode .field { background: var(--note-bg); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--note) 55%, transparent); }
.composer.note-mode .send:not(:disabled) { background: var(--note); }
.composer.note-mode .attach { opacity: .35; pointer-events: none; }

/* Gợi ý khi gõ / */
.slash-pop {
  position: absolute;
  left: 66px;
  right: 66px;
  bottom: calc(100% - 4px);
  z-index: 30;
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(10, 16, 26, .16);
  animation: set-in .12s ease-out;
}
.slash-pop.hidden { display: none; }
.slash-pop button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 13.5px;
}
.slash-pop button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.slash-pop button kbd { flex: none; color: var(--brand-2); background: var(--selected); border-color: transparent; }
.slash-pop button.on, .slash-pop button:hover { background: var(--hover); }
.slash-pop button.on { box-shadow: inset 3px 0 0 var(--brand-2); }
.slash-empty { padding: 10px; font-size: 13px; color: var(--muted); }

/* Thẻ ghi chú trong dòng tin nhắn */
.note-card {
  align-self: center;
  width: min(520px, 92%);
  margin: 10px auto;
  padding: 10px 14px 12px;
  border-radius: 14px;
  background: var(--note-bg);
  border: 1px dashed color-mix(in srgb, var(--note) 60%, transparent);
}
.note-card.new { animation: set-in .2s ease-out; }
.note-head { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.note-head svg.ic { width: 15px; height: 15px; color: var(--note); flex: none; }
.note-head strong { color: var(--text); font-size: 12.5px; }
.note-del { margin-left: auto; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); opacity: 0; transition: opacity .15s; }
.note-del svg.ic { width: 14px; height: 14px; color: inherit; }
.note-card:hover .note-del, .note-del:focus-visible { opacity: 1; }
.note-del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.note-text { margin-top: 4px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (hover: none) { .note-del { opacity: 1; } }

/* Trang Cài đặt: câu trả lời mẫu */
.canned-form { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 12px; align-items: start; }
.canned-form .form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.canned-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 84px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.canned-form textarea:focus { border-color: var(--brand-2); background: var(--surface); }
.sc-input { display: flex; align-items: center; background: var(--surface-2); border-radius: 12px; padding-left: 12px; border: 1px solid transparent; }
.sc-input:focus-within { border-color: var(--brand-2); background: var(--surface); }
.sc-input > span { color: var(--brand-2); font: 600 15px ui-monospace, SFMono-Regular, Menlo, monospace; }
.card .sc-input input { background: transparent !important; border: 0 !important; padding-left: 4px !important; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.set-head p kbd, .set-head p code, .card-title p code { font-size: 12px; }
.set-head p code, .card-title p code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }
.canned-list li { align-items: flex-start; }
.canned-list li.editing { box-shadow: inset 0 0 0 1.5px var(--brand-2); }
.canned-list kbd.sc { flex: none; margin-top: 2px; color: var(--brand-2); background: var(--surface); }
.canned-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.set-list .soft.icon-only { min-width: 0; width: 34px; height: 34px; padding: 0; display: grid; place-items: center; }
.set-list .soft.icon-only svg.ic { width: 16px; height: 16px; }
.hidden.soft { display: none; }
@media (max-width: 860px) {
  .canned-form { grid-template-columns: minmax(0, 1fr); }
  .compose-hint { display: none; }
  .slash-pop { left: 12px; right: 12px; }
}

/* ================= Nhãn hội thoại ================= */
.lc-blue { --lc: #2b7de9; } .lc-green { --lc: #1f9d55; } .lc-amber { --lc: #d48806; } .lc-red { --lc: #e0383e; }
.lc-purple { --lc: #7c4ddb; } .lc-pink { --lc: #d63384; } .lc-teal { --lc: #0f9d9a; } .lc-gray { --lc: #6b7684; }
.lbl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  padding: 5px 10px;
  border-radius: 999px;
  color: color-mix(in srgb, var(--lc, var(--muted)) 82%, var(--text));
  background: color-mix(in srgb, var(--lc, var(--muted)) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--lc, var(--muted)) 22%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lbl svg.ic { width: 13px; height: 13px; flex: none; }
button.lbl { cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
button.lbl:hover { background: color-mix(in srgb, var(--lc) 20%, transparent); }
.lbl.on { color: #fff; background: var(--lc); border-color: var(--lc); }
button.lbl.on:hover { background: color-mix(in srgb, var(--lc) 88%, #000); }
.lbl.sm { font-size: 11px; padding: 2px 7px; flex: none; max-width: 92px; }
.lbl.more { --lc: var(--muted); }
.conv-meta .lbl.sm + span:last-child { min-width: 0; }
.label-chips { padding-top: 0; gap: 6px; }
.label-chips.hidden { display: none; }
.label-chips .lbl { font-size: 12px; padding: 4px 10px; }

.lbl-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.lbl-pick .lbl:disabled { opacity: .6; cursor: progress; }
.h4-link { float: right; font-size: 12px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--brand-2); text-decoration: none; }
.h4-link:hover { text-decoration: underline; }

.label-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 20px; align-items: end; }
.label-foot { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.label-foot .form-actions { display: flex; gap: 8px; }
.label-preview { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; height: 42px; align-items: center; }
.swatch { position: relative; width: 28px; height: 28px; cursor: pointer; }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch span { position: absolute; inset: 0; border-radius: 50%; background: var(--lc); box-shadow: 0 0 0 2px var(--surface), 0 0 0 2px transparent; transition: box-shadow .15s, transform .15s; pointer-events: none; }
.swatch:hover span { transform: scale(1.08); }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--lc); }
.swatch input:focus-visible + span { outline: 2px solid var(--brand-2); outline-offset: 4px; }
#label-list li .grow small { white-space: normal; }
#label-list li.editing { box-shadow: inset 0 0 0 1.5px var(--brand-2); }
@media (max-width: 860px) {
  .label-form { grid-template-columns: minmax(0, 1fr); }
  .swatches { height: auto; }
}

/* ================= Hồ sơ khách ================= */
.kv-val { min-width: 0; overflow-wrap: anywhere; }
.kv-val a { color: var(--text); text-decoration: none; }
.kv-val a:hover { color: var(--brand-2); text-decoration: underline; }
.info .hint.small { font-size: 11.5px; margin: 6px 0 0; }
.info .soft.suggest { justify-content: flex-start; text-align: left; color: var(--brand-2); background: var(--selected); }
.profile-form { display: flex; flex-direction: column; gap: 8px; }
.profile-form label { display: flex; flex-direction: column; gap: 4px; }
.profile-form label > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.profile-form input, .profile-form textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  outline: none;
  resize: vertical;
}
.profile-form input:focus, .profile-form textarea:focus { border-color: var(--brand-2); background: var(--surface); }
.profile-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }
.info .profile-actions .soft, .info .profile-actions .primary { margin: 0; width: 100%; justify-content: center; padding: 9px 12px; border-radius: 10px; }
button.h4-link { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--brand-2); float: right; }
button.h4-link:hover { text-decoration: underline; }

/* ---------- Tìm trong tin nhắn + tải tin cũ ---------- */
.list-sec {
  padding: 14px 12px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
}
.list-sec span {
  font-weight: 600;
  letter-spacing: 0;
  background: var(--surface-2);
  border-radius: 99px;
  padding: 1px 7px;
}
.hit {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
}
.hit:hover, .hit:focus-visible { background: var(--hover); outline: none; }
.hit .avatar.sm { width: 34px; height: 34px; font-size: 14px; }
.hit-body { min-width: 0; flex: 1; }
.hit-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.hit-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hit-top span { color: var(--muted); font-size: 12px; flex: none; }
.hit-text {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.hit-text em { font-style: normal; color: var(--text); }
.hit-text mark {
  background: color-mix(in srgb, var(--orange) 28%, transparent);
  color: var(--text);
  border-radius: 3px;
  padding: 0 1px;
}
.hit-empty {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px 16px;
  font-size: 13.5px;
  color: var(--muted);
}
.hit-empty .spinner { width: 14px; height: 14px; border-width: 2px; }

.load-older {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 6px 0 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.load-older .spinner { display: none; width: 14px; height: 14px; border-width: 2px; }
.load-older.busy .spinner { display: inline-block; }
.load-older.done { opacity: .7; }
.row.flash .bubble {
  animation: msg-flash 2.4s ease;
}
@keyframes msg-flash {
  0%, 60% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 60%, transparent); }
  100% { box-shadow: 0 0 0 3px transparent; }
}

/* ---------- Thông báo & ứng dụng ---------- */
.pref-list { display: grid; gap: 4px; }
.pref {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.pref:first-child { border-top: 0; padding-top: 4px; }
.pref > div { flex: 1; min-width: 0; display: grid; gap: 2px; }
.pref strong { font-size: 14.5px; font-weight: 600; }
.pref small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.pref-ic {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--surface-2);
  color: var(--brand-2);
}
.pref .soft { flex: none; }
.pref .pill { font-size: 12.5px; padding: 3px 10px; }
.pill.ok { background: color-mix(in srgb, #1f9d55 14%, transparent); color: #1f9d55; }
.pill.warn { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.link-btn {
  background: none;
  border: 0;
  padding: 4px 6px;
  color: var(--brand-2);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  flex: none;
}
.link-btn:hover { text-decoration: underline; }
@media (max-width: 560px) {
  .pref { flex-wrap: wrap; }
  .pref > div { flex-basis: calc(100% - 48px); }
  .pref .soft, .pref .pill, .pref .link-btn { margin-left: 48px; }
}

/* ================= Hộp thư: lọc nhanh, giai đoạn, đội, bộ lọc đã lưu ================= */
.views {
  display: flex;
  gap: 2px;
  margin: 2px 16px 6px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
}
.views button {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 6px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.views button:hover { color: var(--text); }
.views button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(18, 26, 38, .12); }
.vc { font-size: 11.5px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.vc:empty { display: none; }
.views button.active .vc { color: var(--brand-2); }

.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 16px 8px; }
.mini-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; cursor: pointer; }
.mini-toggle .switch { width: 34px; height: 20px; }
.mini-toggle .switch span::after { width: 14px; height: 14px; }
.mini-toggle .switch input:checked + span { background: var(--brand-2); }
.mini-toggle .switch input:checked + span::after { transform: translateX(14px); }
.mini-toggle .vc { padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--orange) 15%, transparent); color: var(--orange); }
.filter-btn { position: relative; }
.filter-btn.active { background: var(--selected); color: var(--brand-2); }
.fb-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--brand-2); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.fb-count.hidden { display: none; }

.filter-panel {
  margin: 0 12px 8px;
  padding: 10px 4px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  max-height: 46vh;
  overflow-y: auto;
}
.filter-panel.hidden { display: none; }
.fp-sec.hidden { display: none; }
.fp-title { display: block; padding: 0 12px 2px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.filter-panel .chips { padding: 4px 12px 10px; }
.filter-panel .lbl { font-size: 12px; padding: 4px 10px; }
.filter-panel .lbl .vc { color: inherit; opacity: .75; margin-left: 2px; }
.fp-foot { position: sticky; bottom: 0; display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); background: var(--surface); }
.fp-foot input { flex: 1; min-width: 0; padding: 7px 10px; font-size: 13px; }
.fp-foot .soft { padding: 7px 10px; font-size: 13px; }

.saved-views { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.saved-views.hidden { display: none; }
.sv { display: inline-flex; align-items: center; border-radius: 999px; background: var(--surface-2); max-width: 100%; }
.sv button { display: inline-flex; align-items: center; gap: 5px; padding: 5px 4px 5px 10px; font-size: 12.5px; font-weight: 500; color: var(--text); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sv button svg.ic { width: 13px; height: 13px; flex: none; color: var(--muted); }
.sv .sv-del { padding: 5px 8px 5px 2px; color: var(--muted); }
.sv .sv-del:hover { color: var(--danger); }
.sv.on { background: var(--selected); }
.sv.on button:first-child, .sv.on button:first-child svg.ic { color: var(--brand-2); }

/* Dòng hội thoại: tên · chữ tắt người phụ trách · giờ */
.conv-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-top .conv-name { flex: 1; min-width: 0; }
.conv-top .conv-time { font-size: 12px; color: var(--muted); }
.conv.unread .conv-top .conv-time { color: var(--brand-2); font-weight: 600; }
.who {
  flex: none;
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
  background: var(--av, var(--muted));
}
.who.me { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--brand-2); }
.who.free { background: color-mix(in srgb, var(--orange) 15%, transparent); color: var(--orange); }
.who.free svg.ic { width: 13px; height: 13px; }
.conv-line .you { font-style: normal; flex: none; color: var(--muted); }
.lbl.sm.team svg.ic { width: 11px; height: 11px; }

/* Giai đoạn trong khung thông tin khách */
.stage-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.stage-pick button {
  padding: 8px 6px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
}
.stage-pick button:hover { border-color: var(--lc); }
.stage-pick button.on { background: var(--lc); border-color: var(--lc); color: #fff; }
.stage-pick button:disabled { opacity: .6; cursor: progress; }
#team-sel { width: 100%; }

/* Cài đặt → Đội */
.team-list li { flex-direction: column; align-items: stretch; gap: 10px; }
.team-row { display: flex; align-items: center; gap: 12px; }
.team-row .lbl svg.ic { width: 14px; height: 14px; }
.member-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.member {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
}
.member .avatar.xs { width: 24px; height: 24px; font-size: 10px; }
.member svg.ic { width: 13px; height: 13px; }
.member:hover { border-color: var(--brand-2); }
.member.on { color: var(--text); background: var(--selected); border-color: color-mix(in srgb, var(--brand-2) 40%, transparent); font-weight: 500; }
.member.on svg.ic { color: var(--brand-2); }
.member:disabled { opacity: .6; cursor: progress; }
.set-list li .role-sel[data-ch-team] { max-width: 160px; }
@media (max-width: 720px) {
  .set-list li .role-sel[data-ch-team] { max-width: 120px; }
}

/* ================= Danh bạ ================= */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.app.contacts-mode .sidebar,
.app.contacts-mode .chat,
.app.contacts-mode .info { display: none !important; }
.contacts-page {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  background: var(--surface);
}
.contacts-page.hidden { display: none; }
.ct-nav .spacer { flex: 1; }
.ct-nav-title { margin: 14px 10px 4px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.ct-views { display: flex; flex-direction: column; gap: 2px; }
.ct-views button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  text-align: left;
}
.ct-views button svg.ic { width: 18px; height: 18px; color: var(--muted); flex: none; }
.ct-views button span:not(.dot) { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-views button b { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.ct-views button:hover { background: var(--surface-2); }
.ct-views button.active { background: var(--selected); font-weight: 600; }
.ct-views button.active svg.ic, .ct-views button.active b { color: var(--brand-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--lc, var(--muted)); flex: none; display: inline-block; }
.ct-views .dot { margin: 0 4px 0 5px; }

.ct-body { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ct-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 10px; flex-wrap: wrap; }
.ct-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ct-title h2 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.ct-total { font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.ct-total:empty { display: none; }
.ct-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ct-search { width: 280px; max-width: 100%; }
.ct-filters, .ct-bulk { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 0 20px 10px; }
.ct-filters select, .ct-bulk select { width: auto; max-width: 200px; padding: 7px 28px 7px 10px; font-size: 13px; }
.ct-filters select.hidden, .ct-bulk select.hidden { display: none; }
.ct-bulk {
  margin: 0 20px 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--selected);
  border: 1px solid color-mix(in srgb, var(--brand-2) 30%, transparent);
}
.ct-bulk.hidden { display: none; }
.ct-bulk strong { font-size: 13.5px; color: var(--brand-2); margin-right: 4px; }
.ct-bulk select { background-color: var(--surface); }

.ct-table-wrap { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--line); }
.ct-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; min-width: 980px; }
.ct-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.ct-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.ct-table tbody tr { cursor: pointer; }
.ct-table tbody tr:hover td { background: var(--hover); }
.ct-table tbody tr.sel td { background: var(--selected); }
.ct-table tbody tr:focus-visible { outline: 2px solid var(--brand-2); outline-offset: -2px; }
.ct-check { width: 36px; padding-right: 0 !important; }
.ct-check input { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--brand-2); }
.ct-name { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.ct-name > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.ct-name strong { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.ct-name small { color: var(--muted); font-size: 12px; }
.ct-ch { display: inline-flex; align-items: center; gap: 6px; }
.ct-ch svg.ic { width: 16px; height: 16px; }
.ct-ch.ch-telegram svg.ic { color: var(--telegram); }
.ct-ch.ch-messenger svg.ic { color: var(--messenger); }
.ct-mono { font-variant-numeric: tabular-nums; }
.ct-email { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.ct-dash { color: var(--muted); }
.ct-stage { display: inline-flex; align-items: center; gap: 7px; }
.ct-labels { display: flex; gap: 4px; align-items: center; }
.ct-who { display: inline-flex; align-items: center; gap: 7px; }
.ct-time { color: var(--muted); }
.ct-act { width: 1%; text-align: right; }
.ct-act .icon-btn { opacity: 0; color: var(--muted); }
.ct-table tbody tr:hover .ct-act .icon-btn, .ct-act .icon-btn:focus-visible { opacity: 1; }
.ct-act .icon-btn:hover { color: var(--danger); }
.ct-act .soft { padding: 6px 12px; font-size: 13px; }
.ct-empty { text-align: center; color: var(--muted); padding: 48px 12px !important; cursor: default; }
.ct-empty svg.ic { width: 34px; height: 34px; color: var(--brand-2); display: block; margin: 0 auto 8px; }
.ct-empty strong { color: var(--text); font-size: 14.5px; }
.ct-empty .spinner { margin-right: 8px; vertical-align: middle; }
.ct-pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 10px 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.ct-pager:empty { display: none; }
.ct-pager > span:first-child { margin-right: auto; }
.ct-pager .soft { padding: 6px 12px; font-size: 13px; }
.ct-pager .flip svg.ic { transform: scaleX(-1); }
.ct-pno { font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .app.contacts-mode { grid-template-rows: minmax(0, 1fr) auto; }
  .app.contacts-mode .rail { display: flex !important; }
  .contacts-page { grid-column: 1; grid-row: 1; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .ct-nav { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 12px 8px; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; align-items: center; scrollbar-width: none; gap: 4px; }
  .ct-nav h1, .ct-nav .set-back, .ct-nav .spacer, .ct-nav-title { display: none; }
  .ct-views { flex-direction: row; flex: none; }
  .ct-views button { flex: none; padding: 6px 10px; font-size: 13px; }
  .ct-head { padding: 12px 12px 8px; }
  .ct-title h2 { font-size: 18px; }
  .ct-tools, .ct-search { width: 100%; }
  .ct-search { flex: 1; }
  .ct-filters { padding: 0 12px 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ct-filters select { flex: none; }
  .ct-bulk { margin: 0 12px 8px; }
  .ct-pager { padding: 8px 12px; }
}
.ct-table td { padding: 8px 10px; }
.ct-table th { padding: 10px; }
.ct-who > span:last-child { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.ct-name strong { max-width: 170px; }
.ct-labels { max-width: 230px; overflow: hidden; }
.ct-filters select, .ct-bulk select { padding-top: 6px; padding-bottom: 6px; max-width: 170px; }
@media (max-width: 1500px) {
  .ct-ch > span { display: none; }
  .ct-email { max-width: 150px; }
}
.ct-table { min-width: 900px; }
.ct-contact { display: flex; flex-direction: column; line-height: 1.3; }
.ct-contact .ct-email { color: var(--muted); font-size: 12px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }

/* Danh bạ v2: thanh thao tác hàng loạt, menu nhỏ, chọn cột */
.ct-bulk { gap: 6px; padding: 6px 8px 6px 14px; }
.ct-bulk .link-btn { font-size: 13px; }
.ct-bulk .link-btn.hidden { display: none; }
.ct-bulk-sep { width: 1px; height: 22px; background: color-mix(in srgb, var(--brand-2) 30%, transparent); margin: 0 4px; }
.bb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.bb svg.ic { width: 15px; height: 15px; color: var(--muted); }
.bb:hover, .bb[aria-expanded="true"] { background: var(--surface); }
.bb.hidden { display: none; }
.bb.danger, .bb.danger svg.ic { color: var(--danger); }
.ct-bulk-x { margin-left: auto; }
.ct-pop {
  position: fixed;
  z-index: 60;
  min-width: 200px;
  max-width: 280px;
  max-height: 340px;
  overflow-y: auto;
  padding: 6px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.ct-pop.hidden { display: none; }
.pop-title { margin: 4px 8px 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.ct-pop button, .pop-check {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.ct-pop button:hover, .ct-pop button:focus-visible, .pop-check:hover { background: var(--surface-2); outline: none; }
.ct-pop button.muted { color: var(--muted); }
.ct-pop .who { min-width: 22px; }
.pop-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand-2); }
.pop-empty { margin: 8px 10px; font-size: 13px; color: var(--muted); }
.ct-more { display: inline-flex; align-items: center; gap: 8px; }
.ct-pager { justify-content: space-between; }
.ct-pager > span:first-child { margin-right: 0; }
.ct-table.no-crm .c-crm, .ct-table.no-channel .c-channel, .ct-table.no-phone .c-phone, .ct-table.no-email .c-email,
.ct-table.no-stage .c-stage, .ct-table.no-labels .c-labels, .ct-table.no-team .c-team,
.ct-table.no-assignee .c-assignee, .ct-table.no-last .c-last, .ct-table.no-created .c-created { display: none; }
.ct-table td.c-email .ct-email { max-width: 190px; overflow: hidden; text-overflow: ellipsis; color: var(--text); font-size: 13.5px; }
/* Đang chọn khách: hiện ô tích ở mọi dòng */
@media (max-width: 860px) {
  .ct-bulk { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ct-bulk > * { flex: none; }
  .ct-bulk-x { margin-left: 0; }
}
@media (max-width: 860px) {
  .ct-tools { flex-wrap: nowrap; }
  .ct-search { width: auto; min-width: 0; }
  .ct-export-txt { display: none; }
}

/* ---------- Thêm liên hệ thủ công + gợi ý gộp ---------- */
.cfm.ct-form { width: min(460px, 100%); text-align: left; display: flex; flex-direction: column; gap: 12px; }
.cfm.ct-form h3 { margin: 0; }
.cfm.ct-form .ct-form-hint { margin: 0 0 4px; font-size: 13px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.ct-form label { display: flex; flex-direction: column; gap: 5px; }
.ct-form label > span { font-size: 12.5px; font-weight: 600; color: var(--text); }
.ct-form .req { color: var(--danger); font-weight: 600; }
.ct-form input {
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}
.ct-form input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 18%, transparent); }
.cfm.ct-form .ct-form-err { margin: 0; color: var(--danger); font-size: 13px; }
.ct-form .cfm-actions { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); margin-top: 4px; }
.ct-form .cfm-actions .spacer { flex: 1; }
.ct-form .cfm-actions button { min-width: 88px; }
.ct-form .cfm-actions button[data-save]:disabled { opacity: .5; cursor: not-allowed; }
button.danger-text { color: var(--danger); }
.ct-ch.ch-manual { color: var(--muted); }
.ct-ch.ch-manual svg.ic { color: var(--muted); }
.info .merge-hint {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--orange) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--orange) 35%, transparent);
}
.info .merge-hint > svg.ic { width: 18px; height: 18px; margin-top: 1px; color: var(--orange); }
.info .merge-hint > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.info .merge-hint > div span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.info .merge-hint > button { grid-column: 1 / -1; width: 100%; justify-content: center; }

/* ---------- Kết nối Facebook bằng đăng nhập ---------- */
.fb-connect { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 12px; }
.fb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 18px;
  border: 0;
  border-radius: 12px;
  background: #1877f2;
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.fb-btn:hover { background: #166fe5; }
.fb-btn svg.ic { width: 20px; height: 20px; color: #fff; }
.fb-btn.loading { opacity: .7; cursor: progress; }
.fb-connect .hint { margin: 0; }
.fb-connect .hint .spinner { margin-right: 8px; vertical-align: -2px; }
.fb-missing {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 13.5px;
}
.fb-missing > svg.ic { flex: none; width: 18px; height: 18px; margin-top: 2px; }
.fb-missing div { display: flex; flex-direction: column; gap: 4px; }
.fb-missing code { font-size: 12.5px; }
.fb-setup summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 4px 0; }
.fb-steps { margin-top: 6px; }
.fb-steps li { line-height: 1.55; }
.copy-row { display: flex; align-items: center; gap: 6px; margin: 4px 0 6px; }
.copy-row code {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.copy-row .icon-btn { flex: none; }
.fb-pick .fb-pages { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.fb-page {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.fb-page:has(input:checked) { border-color: var(--brand-2); background: var(--selected); }
.fb-page.done { opacity: .6; cursor: default; }
.fb-page .grow { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.fb-page .grow small { color: var(--muted); font-size: 12px; }

/* ---------- Hướng dẫn lần đầu ---------- */
.onboard {
  width: min(460px, 100%);
  margin: 22px auto 0;
  padding: 18px 18px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  box-shadow: var(--shadow);
}
.onboard header { display: flex; align-items: center; justify-content: space-between; }
.onboard h4 { margin: 0; font-size: 15px; }
.ob-count { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.ob-bar { height: 6px; margin: 10px 0 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.ob-bar span { display: block; height: 100%; border-radius: inherit; background: var(--brand-2); }
.onboard ol { list-style: none; margin: 0; padding: 0; }
.onboard li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.onboard li:last-child { border-bottom: 0; }
.onboard li > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.onboard li strong { font-size: 14px; }
.onboard li small { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.onboard li.ok strong { color: var(--muted); text-decoration: line-through; }
.ob-n {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.onboard li.ok .ob-n { background: color-mix(in srgb, #18a37a 15%, transparent); color: #18a37a; }
.ob-n svg.ic { width: 14px; height: 14px; }
.ob-go { flex: none; text-decoration: none; background: var(--surface-2); color: var(--brand-2); padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.onboard #ob-hide { margin-top: 6px; font-size: 12.5px; color: var(--muted); }

/* ---------- Logo trên thanh bên: bấm để về hộp thư ---------- */
.rail .logo-mark.rail-home {
  width: 44px;
  height: 44px;
  padding: 0;
  margin-bottom: 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .06);
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.rail .logo-mark.rail-home .rail-logo-img {
  width: 30px;
  max-height: 30px;
  transition: transform .2s ease;
}
.rail .logo-mark.rail-home:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--brand-2) 35%, var(--line));
  box-shadow: 0 2px 4px rgba(15, 23, 42, .08), 0 8px 20px color-mix(in srgb, var(--brand-2) 18%, transparent);
}
.rail .logo-mark.rail-home:hover .rail-logo-img { transform: scale(1.06); }
.rail .logo-mark.rail-home:active { transform: scale(.96); }
.rail .logo-mark.rail-home:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
:root[data-theme="dark"] .rail .logo-mark.rail-home { background: #fff; border-color: transparent; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .rail .logo-mark.rail-home { background: #fff; border-color: transparent; }
}

/* ---------- Trang Báo cáo bán hàng (chỉ quản trị) ---------- */
.app.reports-mode .sidebar,
.app.reports-mode .chat,
.app.reports-mode .info { display: none !important; }
.reports-page {
  grid-column: 2 / -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--surface-2);
}
.reports-page.hidden { display: none; }
.rp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.rp-title { display: flex; align-items: center; gap: 14px; }
.rp-title h1 { font-size: 20px; margin: 0; }
.rp-back { background: none; }
.rp-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.rp-live {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; color: #1f9d55;
  padding: 4px 10px; border-radius: 999px;
  background: color-mix(in srgb, #1f9d55 12%, transparent);
}
.rp-live .ic { width: 14px; height: 14px; }
.rp-periods { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.rp-periods button {
  padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 500;
  color: var(--muted); background: none; white-space: nowrap;
}
.rp-periods button:hover { color: var(--text); }
.rp-periods button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(15,23,42,.08); }

.rp-body { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 24px 40px; transition: opacity .15s ease; }
.rp-body.rp-loading { opacity: .45; pointer-events: none; }

.rp-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.rp-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.rp-card-ic {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 11px;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--brand-2) 12%, var(--surface-2));
  color: var(--brand-2);
}
.rp-card-ic .ic { width: 20px; height: 20px; }
.rp-card.good .rp-card-ic { background: color-mix(in srgb, #1f9d55 14%, var(--surface-2)); color: #1f9d55; }
.rp-card.brand .rp-card-ic { background: color-mix(in srgb, var(--brand) 16%, var(--surface-2)); color: var(--brand); }
.rp-card-body { display: flex; flex-direction: column; min-width: 0; }
.rp-card-body strong { font-size: 24px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.rp-card-body span { font-size: 13px; color: var(--muted); }
.rp-card-body em { font-size: 11.5px; color: var(--muted); font-style: normal; margin-top: 2px; opacity: .85; }

.rp-staff { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.rp-h2 { display: flex; align-items: center; gap: 8px; font-size: 15px; margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.rp-h2 .ic { width: 17px; height: 17px; color: var(--brand); }
.rp-table-wrap { overflow-x: auto; }
.rp-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rp-table th, .rp-table td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rp-table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.rp-table th.num, .rp-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rp-table tbody tr:last-child td { border-bottom: none; }
.rp-table tbody tr:hover { background: var(--surface-2); }
.rp-table td.good { color: #1f9d55; font-weight: 600; }
.rp-table td.rp-muted { color: var(--muted); }
.rp-rank {
  display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 10px;
  border-radius: 7px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
}
.rp-table tbody tr:nth-child(1) .rp-rank { background: color-mix(in srgb, #f5b301 22%, var(--surface-2)); color: #a9790a; }
.rp-table tbody tr:nth-child(2) .rp-rank { background: color-mix(in srgb, #9aa6b2 26%, var(--surface-2)); color: #5b6775; }
.rp-table tbody tr:nth-child(3) .rp-rank { background: color-mix(in srgb, #cd7f32 24%, var(--surface-2)); color: #8a5a22; }
.rp-name { font-weight: 500; }
.rp-rate {
  display: inline-block; min-width: 42px; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 13px;
  background: color-mix(in srgb, var(--brand-2) calc(var(--v) * 0.45%), var(--surface-2));
  color: var(--text);
}
.rp-empty { text-align: center; color: var(--muted); padding: 28px; }

@media (max-width: 760px) {
  .app.reports-mode { grid-template-rows: minmax(0, 1fr) auto; }
  .app.reports-mode .rail { display: flex !important; }
  .reports-page { grid-column: 1; grid-row: 1; }
  .rp-head { padding: 12px 16px; }
  .rp-body { padding: 16px 14px 32px; }
  .rp-periods button { padding: 6px 9px; }
}

/* ---------- Nút chọn ngôn ngữ (cờ) ---------- */
.lang-box { position: relative; }
.lang-rail { display: flex; justify-content: center; }
.lang-flag {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; cursor: pointer;
  background: none; border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.lang-flag:hover { background: var(--surface-2); }
/* Cờ SVG: khối chữ nhật bo góc, có viền nhẹ để cờ trắng (Nhật) nổi trên nền trắng */
.lang-emoji { display: inline-flex; line-height: 0; }
.lang-emoji svg {
  display: block; width: 26px; height: 17px; border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(15,23,42,.12); object-fit: cover;
}
.lang-flag .lang-emoji svg { width: 28px; height: 19px; }
.lang-menu {
  position: absolute; z-index: 40; min-width: 168px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(15,23,42,.16); padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.lang-rail .lang-menu { left: calc(100% + 8px); bottom: 0; }
.lang-login .lang-menu { right: 0; top: calc(100% + 6px); }
.lang-menu.hidden { display: none; }
.lang-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 8px; font-size: 14px; color: var(--text);
  background: none; text-align: left; cursor: pointer;
}
.lang-item:hover { background: var(--surface-2); }
.lang-item.on { background: color-mix(in srgb, var(--brand-2) 14%, transparent); font-weight: 600; }
.lang-item .lang-emoji svg { width: 24px; height: 16px; }
/* Nút cờ trên trang đăng nhập: góc trên phải thẻ đăng nhập */
.lang-login { position: absolute; top: 14px; right: 14px; }
.login-card { position: relative; }
