:root {
  color-scheme: light;

  /* Bang mau moi: xanh duong kieu ung dung nhan tin. Thanh dieu huong la khoi
     mau dam duy nhat; toan bo phan con lai la trang / xam rat nhat de tin nhan
     noi len. */
  --nav-blue: #0068ff;
  --nav-blue-hover: #2a85ff;
  --selected-bg: #e6f0ff;
  --chat-bg: #eef1f6;
  --bubble-self: #dbe9ff;
  --bubble-self-line: #c3dbff;

  /* Bon ten mau cu duoc giu lai va tro sang tong xanh. Khong xoa vi con vai
     cho tham chieu toi chung; doi gia tri la du. */
  --cream: #ffffff;
  --amber: var(--nav-blue);
  --sage: #127a52;
  --forest: #0f1c2e;

  /* --bg hoi lech trang mot chut de nhung o nhap / khoi log long ra khoi nen
     trang thuan cua --surface. */
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #eaeff5;
  --line: #e2e7ee;

  --text: #0f1c2e;
  /* Tren nen trang dat tuong phan ~5.0, du cho chu 12-13px. */
  --muted: #63707f;

  --accent: var(--nav-blue);
  /* Nen xanh dam thi chu phai trang. */
  --on-accent: #ffffff;
  --other: #ffffff;

  /* Ba mau trang thai deu duoc lam dam cho du tuong phan khi dung lam MAU CHU
     tren nen trang (email.js va config.js co dung chung lam mau chu). */
  --ok: #127a52;
  --warn: #9a6a00;
  --danger: #d13438;

  --shadow: rgba(15, 28, 46, 0.14);

  --training-title-size: 20px;
  --training-title-line: 28px;
  --training-section-size: 15px;
  --training-section-line: 22px;
  --training-subsection-size: 13px;
  --training-subsection-line: 18px;
  --training-field-size: 12px;
  --training-field-line: 17px;
  --training-body-size: 13px;
  --training-body-line: 19px;
  --training-helper-size: 11px;
  --training-helper-line: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(380px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}

.login-card h1 {
  margin: 0 0 22px;
  font-size: 32px;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  color: var(--text);
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.secondary-button {
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.qr-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
}

#qr-image {
  width: 240px;
  height: 240px;
  object-fit: contain;
  background: white;
  border-radius: 8px;
}

#qr-status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
}

.chat-app {
  /* 100% cua module-panel, khong phai 100vh: khung ngoai da chan chieu cao roi */
  height: 100%;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  /* Chan chieu cao hang grid, neu khong hang ngam dinh la auto: cot chat se cao
     theo noi dung tin nhan, #messages khong bao gio can cuon va o nhap tin bi day
     xuong duoi 100vh roi bi overflow:hidden cat mat. */
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.thread-list {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.profile {
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

.profile-name {
  font-weight: 700;
  font-size: 14px;
}

.profile-status,
.empty-hint {
  color: var(--muted);
  font-size: 13px;
}

/* Den bao duong day Zalo. Thay cho dong chu cung "Dang ket noi realtime" cu -
   dong do hien y het nhau ke ca khi da mat ket noi ca tieng dong ho. */
.zalo-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.zalo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--muted);
}

.zalo-dot-ok { background: var(--ok); }
.zalo-dot-cho { background: var(--warn); }
.zalo-dot-loi {
  background: var(--danger);
  animation: zalo-nhap-nhay 1.2s ease-in-out infinite;
}

@keyframes zalo-nhap-nhay {
  50% { opacity: 0.25; }
}

/* --- Phan he Email --- */

.email-panel {
  height: 100%;
  overflow-y: auto;
  padding: 20px 24px 40px;
}

.email-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.email-header h2 {
  margin: 0 0 2px;
}

.email-header > div {
  flex: 1;
  min-width: 0;
}

.email-khoi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.email-khoi h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.email-hang {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.email-hang label {
  width: 130px;
  flex: none;
  font-size: 13px;
  color: var(--muted);
}

.email-hang input,
.email-hang select {
  flex: 1;
  min-width: 0;
}

.email-nut {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 4px;
}

.email-gat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 10px;
}

.email-vach {
  border: none;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.email-khoi code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.thread-search-wrap {
  position: relative;
  margin: 8px 12px;
}

.thread-search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.thread-search {
  width: 100%;
  height: 34px;
  margin: 0;
  padding: 0 14px 0 36px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
}

.thread-search:focus {
  outline: none;
  border-color: var(--nav-blue);
  background: var(--surface);
}

.threads {
  list-style: none;
  margin: 0 8px 8px;
  padding: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #bcc6d2 transparent;
}

.threads::-webkit-scrollbar,
.messages::-webkit-scrollbar { width: 7px; }

.threads::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #bcc6d2;
}

.thread-item {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  height: 64px;
  min-height: 64px;
  margin: 1px 0;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
}

.thread-item:hover {
  background: var(--surface-2);
}

/* Cuoc tro chuyen dang mo: xanh rat nhat, khac han mau di chuot. */
.thread-item.active {
  background: var(--selected-bg);
}

.thread-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  width: 3px;
  height: 46px;
  border-radius: 0 3px 3px 0;
  background: var(--nav-blue);
}

.thread-body,
.thread-title { min-width: 0; }

.thread-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
}

.thread-time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.thread-item.active .thread-time { color: var(--nav-blue); }

.thread-title,
.thread-preview,
.chat-header h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-title {
  margin-bottom: 3px;
  font-weight: 600;
  font-size: 16px;
}

.thread-preview {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.empty-hint {
  margin: 18px;
}

.chat-main {
  min-width: 0;
  position: relative;
  /* Nen xam-xanh rat nhat de bong bong tin nhan trang noi han len. */
  background: var(--chat-bg);
}

.chat-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.chat-panel {
  --bot-typing-composer-height: 94px;
  position: relative;
  height: 100%;
  display: grid;
  grid-template-rows: 60px minmax(0, 1fr) auto;
}

.chat-header {
  min-width: 0;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.chat-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.chat-header #chat-avatar {
  width: 38px;
  height: 38px;
}

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

.mobile-menu-button,
.mobile-chat-back,
.chat-more-button,
.mobile-drawer-backdrop { display: none; }

.messages {
  overflow-y: auto;
  padding: 14px 26px 10px;
  background: var(--chat-bg);
  scrollbar-width: thin;
  scrollbar-color: #bcc6d2 transparent;
}

.chat-panel.bot-is-typing .messages { padding-bottom: 38px; }

.bot-typing-indicator {
  position: absolute;
  z-index: 6;
  left: 26px;
  bottom: calc(var(--bot-typing-composer-height) + 8px);
  max-width: calc(100% - 52px);
  padding: 4px 10px;
  border: 1px solid #d7e2ef;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
  pointer-events: none;
}

.bubble-row {
  display: flex;
  gap: 9px;
  align-items: flex-end;
  margin: 0 0 2px;
}

.bubble-row.cluster-end { margin-bottom: 9px; }

.bubble-row.self {
  justify-content: flex-end;
}

.bubble-wrap {
  max-width: min(680px, 60%);
}

.bubble {
  padding: 8px 12px;
  border-radius: 14px;
  border: 0;
  background: var(--other);
  box-shadow: 0 1px 1px rgba(15, 28, 46, 0.04);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.bubble-media {
  max-width: 100%;
  padding: 4px;
  white-space: normal;
}

.chat-image-wrap,
.chat-image-link {
  display: block;
  max-width: 100%;
}

.chat-image {
  display: block;
  width: auto;
  max-width: min(250px, 100%);
  max-height: 420px;
  border-radius: 11px;
  object-fit: contain;
}

.chat-media-caption {
  padding: 7px 7px 3px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-media-fallback {
  display: inline-flex;
  padding: 10px 12px;
  color: var(--nav-blue);
  font-weight: 700;
}

.chat-file-card,
.chat-selected-file {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.chat-file-card {
  max-width: 340px;
  padding: 10px;
  text-decoration: none;
}

.chat-file-card:hover {
  border-color: var(--nav-blue);
}

.chat-file-icon {
  flex: none;
  font-size: 22px;
}

.chat-file-info {
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  line-height: 1.3;
}

.chat-file-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-file-info small,
.chat-file-action {
  color: var(--muted);
  font-size: 11px;
}

.chat-file-action {
  flex: none;
  font-weight: 700;
}

/* Tin cua minh: xanh RAT NHAT chu khong phu xanh dam ca bong bong, de chu van
   la chu den doc thoai mai. */
.self .bubble {
  background: var(--bubble-self);
  color: var(--text);
}

.bubble-row.other.cluster-end .bubble { border-bottom-left-radius: 5px; }
.bubble-row.self.cluster-end .bubble { border-bottom-right-radius: 5px; }

.bubble.bubble-sticker,
.self .bubble.bubble-sticker {
  padding: 4px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.sticker {
  display: block;
  width: 130px;
  max-width: 100%;
}

.sender {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.bubble-time {
  display: block;
  margin-top: 3px;
  color: #8a95a3;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  text-align: right;
  white-space: nowrap;
}

/* Bong bong cua minh gio la nen sang, nen gio khong con dung mau chu tren nen
   dam nua - dung chung mau phu voi phia ben kia. */
.self .bubble-time {
  text-align: right;
  color: #7d8ba0;
  opacity: 1;
}

.date-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 11px 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.date-divider::before,
.date-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: #dfe4ec;
}

.send-form {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  grid-template-rows: auto 42px minmax(52px, auto);
  column-gap: 4px;
  padding: 0;
  border-top: 0;
  background: var(--surface);
}

.composer-toolbar {
  grid-column: 1 / -1;
  grid-row: 2;
  height: 42px;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.thread-bot-status {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: #29476f;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.thread-bot-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--nav-blue);
}

.thread-bot-copy {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-bot-global-hint {
  margin-left: 6px;
  color: #9a5a00;
  font-weight: 600;
}

.thread-bot-toggle {
  height: 30px;
  padding: 0 12px;
  border: 1px solid #b8cff2;
  border-radius: 8px;
  background: #ffffff;
  color: #48627f;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  opacity: 1;
}

.thread-bot-toggle:hover:not(:disabled) { background: #eff5ff; }

.thread-bot-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.thread-bot-status.is-off .thread-bot-dot { background: #8b97a8; }
.thread-bot-status.global-off .thread-bot-dot { background: #d98200; }

.thread-bot-mobile-label { display: none; }

.send-input-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.chat-attachment-preview {
  grid-column: 1 / -1;
  grid-row: 1;
  padding: 8px 14px 0;
}

.chat-selected-file {
  width: fit-content;
  max-width: 100%;
  padding: 7px 9px;
}

.chat-selected-file img {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 8px;
  object-fit: cover;
}

.chat-file-remove {
  width: 26px;
  height: 26px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.chat-attach-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #344054;
}

.chat-tool-icon {
  display: block;
  width: 22px;
  height: 22px;
  flex: none;
  color: currentColor;
}

.chat-attach-button:hover:not(:disabled) {
  background: #eef2f7;
}

.chat-attach-button:active:not(:disabled) {
  background: #e3e8ef;
}

.chat-attach-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

#message-input {
  width: auto;
  min-width: 0;
  height: 46px;
  min-height: 46px;
  max-height: 156px;
  padding-block: 11px;
  padding-left: 13px;
  border: 1px solid #e5e9f0;
  border-radius: 20px;
  background: #f5f7fa;
  color: var(--text);
  font-size: 16px;
  line-height: 22px;
  overflow-y: hidden;
  resize: none;
}

#message-input:focus {
  outline: none;
  border-color: var(--nav-blue);
  background: var(--surface);
}

.send-button {
  min-width: 68px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--nav-blue);
  font-size: 13px;
  font-weight: 600;
}

#message-input::placeholder { color: #8b95a5; }

.send-button:hover:not(:disabled) { background: var(--nav-blue-hover); }

.chat-panel .send-input-row {
  display: contents;
  grid-template-columns: minmax(0, 1fr) auto;
}

.chat-panel #btn-chat-image {
  z-index: 1;
  grid-column: 1;
  grid-row: 2;
  margin-left: 12px;
}

.chat-panel #btn-chat-attach {
  z-index: 1;
  grid-column: 2;
  grid-row: 2;
}

.chat-panel #message-input {
  grid-column: 1 / 4;
  grid-row: 3;
  margin: 8px 0 8px 12px;
}

.chat-panel .send-button {
  grid-column: 4;
  grid-row: 3;
  align-self: end;
  margin: 9px 12px 9px 0;
}

.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--nav-blue);
  color: #ffffff;
  font-weight: 700;
  overflow: hidden;
}

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

.avatar-small {
  width: 36px;
  height: 36px;
}

.avatar-medium {
  width: 44px;
  height: 44px;
}

.bubble-avatar {
  width: 30px;
  height: 30px;
}

.bubble-avatar-spacer {
  width: 30px;
  flex: 0 0 30px;
}

@media (max-width: 760px) {
  .chat-app {
    position: relative;
    display: block;
  }

  .thread-list {
    width: 100%;
    height: 100%;
    border-right: 0;
  }

  .profile {
    height: 56px;
    min-height: 56px;
    gap: 8px;
    padding: 0 6px;
  }

  .profile #my-avatar {
    display: none;
  }

  .profile-info {
    min-width: 0;
    flex: 1;
    text-align: center;
  }

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

  .profile .zalo-status { justify-content: center; font-size: 12px; }

  .mobile-menu-button,
  .profile .icon-button,
  .mobile-chat-back,
  .chat-more-button {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
  }

  .mobile-menu-button svg,
  .mobile-chat-back svg { width: 24px; height: 24px; }

  .thread-search-wrap { margin: 8px 12px; }

  .thread-search { height: 40px; padding: 0 14px 0 38px; font-size: 15px; }

  .threads { margin: 0; padding: 0; }

  .thread-item {
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 12px;
    height: 76px;
    min-height: 76px;
    margin: 0;
    padding: 12px;
    border-radius: 0;
  }

  .thread-item::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 0;
    left: 80px;
    height: 1px;
    background: var(--line);
  }

  .thread-item.active::before { display: none; }
  .thread-item .avatar { width: 52px; height: 52px; }
  .thread-title { font-size: 16px; font-weight: 600; }
  .thread-preview { font-size: 14px; font-weight: 400; }
  .thread-time { font-size: 12px; font-weight: 400; }

  .chat-main {
    position: absolute;
    z-index: 2;
    inset: 0;
    min-width: 0;
    background: var(--chat-bg);
    transform: translateX(100%);
    transition: transform 180ms ease;
    pointer-events: none;
  }

  .chat-app.mobile-chat-open .chat-main {
    transform: translateX(0);
    pointer-events: auto;
  }

  .chat-empty { display: none; }
  .chat-panel {
    --bot-typing-composer-height: 112px;
    grid-template-rows: 56px minmax(0, 1fr) auto;
  }

  .chat-header {
    height: 56px;
    gap: 8px;
    padding: 0 4px;
  }

  .chat-header #chat-avatar { width: 36px; height: 36px; }
  .chat-header h2 { font-size: 16px; font-weight: 600; }

  .chat-more-button {
    margin-left: auto;
    cursor: not-allowed;
    font-size: 18px;
    letter-spacing: 1px;
    opacity: 1;
  }

  .messages {
    min-height: 0;
    padding: 12px 12px 8px;
  }
  .chat-panel.bot-is-typing .messages { padding-bottom: 36px; }
  .bot-typing-indicator {
    left: 12px;
    max-width: calc(100% - 24px);
  }
  .bubble-row { gap: 8px; }
  .bubble-row.cluster-end { margin-bottom: 10px; }
  .bubble-wrap { max-width: 78%; }
  .bubble { border-radius: 16px; font-size: 15px; line-height: 20px; }
  .bubble-row.other.cluster-end .bubble { border-bottom-left-radius: 6px; }
  .bubble-row.self.cluster-end .bubble { border-bottom-right-radius: 6px; }
  .bubble-avatar { width: 28px; height: 28px; }
  .bubble-avatar-spacer { width: 28px; flex-basis: 28px; }
  .sticker { width: 104px; max-height: 104px; object-fit: contain; }

  .send-form {
    display: grid;
    grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
    grid-template-rows: auto auto auto;
    align-items: center;
    gap: 4px;
    min-height: 60px;
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .composer-toolbar,
  .chat-panel .send-input-row { display: contents; }

  .thread-bot-status {
    grid-column: 1 / -1;
    grid-row: 2;
    width: calc(100% + 16px);
    min-height: 40px;
    margin: -6px -8px 0;
    padding: 5px 8px;
    border-bottom: 1px solid #cfe0fb;
    background: #eff5ff;
    font-size: 12px;
  }

  .thread-bot-status .thread-bot-toggle {
    height: 30px;
    margin-left: auto;
    padding: 0 12px;
    font-size: 12px;
  }

  .thread-bot-desktop-label { display: none; }
  .thread-bot-mobile-label { display: inline; }

  .chat-attach-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    justify-content: center;
    padding: 0;
  }

  .chat-tool-icon { width: 24px; height: 24px; }

  .chat-attachment-preview {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: 0;
  }

  .chat-panel .send-input-row {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
  }

  .chat-panel #btn-chat-image {
    grid-column: 1;
    grid-row: 3;
    align-self: end;
    margin: 0;
  }

  .chat-panel #btn-chat-attach {
    grid-column: 2;
    grid-row: 3;
    align-self: end;
    margin: 0;
  }

  .chat-panel #message-input {
    grid-column: 3;
    grid-row: 3;
    border-radius: 20px;
    margin: 0;
  }

  .send-button {
    min-width: 64px;
    padding-inline: 12px;
  }

  .chat-panel .send-input-row .send-button {
    grid-column: 4;
    grid-row: 3;
    align-self: end;
    min-width: 44px;
    width: 44px;
    height: 44px;
    padding-inline: 0;
    border-radius: 50%;
    font-size: 0;
    margin: 0;
  }

  .chat-panel .send-input-row .send-button::before {
    content: "➤";
    font-size: 18px;
  }

  .chat-image {
    max-width: min(212px, 100%);
    max-height: 150px;
  }

  .chat-file-card { width: 100%; }
}

/* --- KHUNG APP 2 COT --- */

.app-shell {
  --sidebar-width: 240px;
  height: 100vh;
  display: grid;
  /* Rail dieu huong rong CO DINH 64px. Co tinh dung so that thay vi
     var(--sidebar-width): app.js van ghi bien do vao inline style tu localStorage
     cu, neu de bien o day thi mo lai trang rail se phinh ra 180-480px. */
  /* CHI CON 2 COT. Thanh keo o giua da bi an bang display:none, ma phan tu
     display:none thi KHONG duoc xep vao luoi nua - de nguyen 3 cot thi .app-main
     tut xuong o thu hai va bi bop con 0px, mat sach vung noi dung. */
  /* Hang phai bi chan chieu cao, neu khong cot noi dung se cao theo noi dung
     va day o nhap tin nhan xuong duoi man hinh. */
  grid-template-columns: 64px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.app-shell.is-resizing {
  cursor: col-resize;
  user-select: none;
}

.app-sidebar {
  min-width: 0;
  display: grid;
  /* avatar · danh sach phan he · nhom duoi (bot, cau hinh, dang xuat) */
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--nav-blue);
  /* Khong duoc cat: hai menu tha (tai khoan / dang xuat) bung ra ben phai rail. */
  overflow: visible;
}

.account-bar {
  position: relative;
  display: grid;
  place-items: center;
  padding: 12px 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.account-toggle {
  display: grid;
  place-items: center;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
}

.account-toggle:hover,
.account-toggle[aria-expanded="true"] {
  border-color: rgba(255, 255, 255, 0.75);
  background: transparent;
}

/* Avatar tren nen xanh phai dao mau lai, neu khong no tang vao nen rail. */
.account-toggle .avatar {
  background: #ffffff;
  color: var(--nav-blue);
}

/* Rail chi rong 64px: ten va mui ten khong con cho. app.js van ghi chu vao
   #account-name nhu cu, chi la khong hien ra. */
.account-name,
.account-caret {
  display: none;
}

.account-menu {
  position: absolute;
  z-index: 900;
  top: 8px;
  left: calc(100% + 8px);
  right: auto;
  width: 210px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 28px var(--shadow);
}

.account-menu-item {
  padding: 9px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.account-menu-item:hover {
  background: var(--surface-2);
}

.account-menu-danger {
  margin-top: 4px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 6px 6px;
  color: var(--danger);
}

/* Cong tac tong cua bot. De ngay duoi ten tai khoan, luon nhin thay - thu nay
   phai voi toi duoc trong mot giay, khong duoc chon trong menu Cau hinh. */
.bot-switch {
  width: 100%;
  padding: 8px 2px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.bot-scope-label,
.rail-item-label { display: none; }

.bot-toggle {
  width: 100%;
  display: flex;
  /* Trong rail hep thi xep doc: dong chu trang thai o tren, nut gat o duoi. */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 2px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #ffffff;
  text-align: center;
  cursor: pointer;
}

.bot-toggle:hover {
  border-color: transparent;
  background: var(--nav-blue-hover);
}

.bot-toggle[aria-checked="true"] {
  border-color: transparent;
  background: transparent;
}

/* Nut gat */
.bot-track {
  flex: none;
  position: relative;
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  transition: background 0.15s ease;
}

.bot-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--other);
  box-shadow: 0 1px 3px rgba(15, 28, 46, 0.35);
  transition: transform 0.15s ease;
}

.bot-toggle[aria-checked="true"] .bot-track {
  background: #3ddc97;
}

.bot-toggle[aria-checked="true"] .bot-knob {
  transform: translateX(15px);
}

.bot-toggle:disabled {
  cursor: wait;
  opacity: 0.6;
}

.bot-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

/* Chu nho nhung VAN GIU: day la cong tac quan trong nhat, nguoi dung phai doc
   duoc bot dang BAT hay TAT ma khong can di chuot len. */
.bot-label strong {
  font-size: 9px;
  font-weight: 700;
  line-height: 1.25;
}

/* Cau giai thich dai khong con cho trong rail; van con o thuoc tinh title. */
.bot-label small {
  display: none;
}

.module-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  overflow-y: auto;
}

.module-item {
  width: 100%;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  cursor: pointer;
}

.module-item:hover {
  background: var(--nav-blue-hover);
  color: #ffffff;
}

/* Muc dang mo: mang trang mo hon han luc di chuot, khong chi dam hon mot chut. */
.module-item.active {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  font-weight: 700;
}

.module-icon {
  flex: none;
  display: grid;
  place-items: center;
}

.module-icon svg {
  display: block;
  width: 23px;
  height: 23px;
}

/* Rail chi con icon; ten phan he nam o title/aria-label de van doc duoc bang
   chuot va bang trinh doc man hinh. */
.module-label {
  display: none;
}

/* --- Nhom duoi cua rail: cong tac bot, cau hinh, dang xuat --- */

.rail-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 8px 10px;
}

.rail-item {
  width: 100%;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

.rail-item:hover {
  background: var(--nav-blue-hover);
  color: #ffffff;
}

.rail-item[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.rail-item svg {
  display: block;
  width: 22px;
  height: 22px;
}

.rail-logout {
  position: relative;
  width: 100%;
}

.rail-menu {
  position: absolute;
  z-index: 950;
  bottom: 0;
  left: calc(100% + 8px);
  width: 216px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 28px var(--shadow);
}

.rail-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.rail-menu-item svg {
  flex: none;
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.rail-menu-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-menu-copy small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.rail-menu-item:hover {
  background: var(--surface-2);
}

/* Dang xuat Zalo la viec khac han dang xuat app - to do de khong bam nham. */
.rail-menu-danger,
.rail-menu-danger svg {
  color: var(--danger);
}

.rail-menu-danger:hover {
  background: #fdeceb;
}

/* Rail rong co dinh nen khong con gi de keo. Giu the trong DOM (xem index.html)
   de cac listener cu khong bao loi. */
.app-resizer {
  display: none;
}

.app-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.module-panel {
  /* Ghim moi panel vao cung mot o. Neu de auto-placement, panel thu hai se
     tao them mot hang ngam dinh kieu auto va lam vo chieu cao cua khung. */
  grid-area: 1 / 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Man hinh QR cua Zalo nam trong panel nen phai bam theo panel, khong phai 100vh */
.module-panel .login-screen {
  min-height: 0;
  height: 100%;
}

/* --- XUONG HUAN LUYEN --- */

.training-panel {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.training-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.training-heading {
  min-width: 0;
}

.training-header h1 {
  margin: 0;
  font-size: var(--training-title-size);
  line-height: var(--training-title-line);
  font-weight: 700;
}

.training-meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: var(--training-helper-size);
  line-height: var(--training-helper-line);
}

.training-meta.training-warn {
  color: var(--danger);
}

.training-actions {
  display: flex;
  gap: 7px;
  flex: none;
  align-items: center;
}

.training-actions .secondary-button {
  min-height: 34px;
  padding: 5px 9px;
  border-color: color-mix(in srgb, var(--line) 82%, transparent);
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
}

.training-actions .secondary-button:hover,
.training-actions .secondary-button:focus-visible {
  color: var(--text);
  background: var(--bg);
}

.training-config-toggle {
  position: relative;
  width: 36px;
  min-width: 36px;
  padding: 0 !important;
}

.training-config-toggle svg {
  width: 17px;
  height: 17px;
}

.training-log {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.training-msg {
  max-width: min(720px, 88%);
  padding: 9px 11px;
  border-radius: 7px;
  font-size: var(--training-body-size);
  line-height: var(--training-body-line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.training-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--on-accent);
}

.training-assistant {
  align-self: flex-start;
  max-width: min(750px, 92%);
  padding: 7px 0;
  border-radius: 0;
  background: transparent;
  border: 0;
}

.training-assistant:not(.training-waiting)::before {
  content: "TRỢ LÝ";
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.training-waiting {
  color: var(--muted);
  font-style: italic;
}

.training-msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 5px;
  font-size: var(--training-helper-size);
}

.training-media-card {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 6px;
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--text);
  white-space: normal;
}

.training-media-image-card {
  flex-direction: column;
  align-items: flex-start;
}

.training-message-image {
  display: block;
  width: auto;
  max-width: min(320px, 100%);
  max-height: 360px;
  border-radius: 8px;
  object-fit: contain;
}

.training-file-icon {
  flex: none;
  font-size: 18px;
}

.training-file-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.training-file-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.training-file-info small {
  opacity: 0.72;
}

.training-copy {
  display: block;
  margin-top: 9px;
  padding: 4px 9px;
  font-size: var(--training-helper-size);
}

.onboarding-starters {
  display: flex;
  padding: 0 16px 9px;
  background: var(--surface);
}

.onboarding-starters.hidden {
  display: none;
}

.onboarding-starter-chip {
  min-height: 36px;
  padding: 6px 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.onboarding-starter-chip:hover,
.onboarding-starter-chip:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--surface) 84%, var(--accent) 16%);
}

.onboarding-starter-chip:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.training-form {
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.training-tool-row {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 7px;
}

.training-tool-action {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.training-tool-action:hover,
.training-tool-action:focus-visible {
  color: var(--accent);
  background: color-mix(in srgb, var(--surface) 82%, var(--accent) 18%);
}

.training-tool-action svg {
  width: 17px;
  height: 17px;
  flex: none;
}

.training-tool-action:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.training-files {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}

.training-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
}

.training-chip-selected {
  max-width: min(100%, 360px);
  border-radius: 10px;
}

.training-chip-image {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 7px;
  object-fit: cover;
}

.training-chip button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.training-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
}

#training-text {
  width: 100%;
  min-height: 38px;
  max-height: 108px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: var(--training-body-size);
  line-height: var(--training-body-line);
  resize: none;
  overflow-y: auto;
}

.training-send-button {
  min-width: 54px;
  min-height: 38px;
  padding-inline: 14px;
}

#module-training .training-tool-action,
#module-training .training-send-button,
#module-training .training-actions button {
  min-height: 36px;
  font-size: 13px;
  font-weight: 600;
}

/* --- FIRST-RUN AI ONBOARDING --- */

#module-training {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.training-mobile-topbar,
.training-mobile-segments {
  display: none;
}

.training-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(480px, 36vw, 520px);
  background: var(--bg);
  transition: grid-template-columns 180ms ease;
}

.training-layout.training-config-collapsed {
  grid-template-columns: minmax(0, 1fr) 0;
}

.training-layout.training-config-collapsed .training-config-panel {
  visibility: hidden;
  padding-right: 0;
  padding-left: 0;
  border: 0;
}

.training-command-panel {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.training-config-panel {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: color-mix(in srgb, var(--surface) 90%, var(--accent) 10%);
}

.training-config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 20px;
  margin-bottom: 10px;
}

.training-config-kicker {
  display: block;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.training-setup-progress {
  width: min(300px, 34vw);
  display: grid;
  grid-template-columns: auto minmax(96px, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  color: var(--accent);
  font-size: var(--training-helper-size);
  font-weight: 700;
}

.training-setup-progress.hidden {
  display: none;
}

.training-setup-progress-track {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--line));
}

.training-setup-progress-bar {
  display: block;
  width: 11.111%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.onboarding-key-links {
  display: grid;
  gap: 6px;
  font-size: var(--training-body-size);
  line-height: var(--training-body-line);
}

.provider-resource-heading {
  margin: 0;
}

.onboarding-key-links a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 400;
}

.onboarding-key-links a:hover {
  text-decoration: underline;
}

.provider-resource-group {
  min-width: 0;
  border-bottom: 1px solid var(--line);
}

.provider-resource-links {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 0;
}

.provider-resource-row {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.provider-resource-row:last-child {
  border-bottom: 0;
}

.provider-other-toggle {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 4px;
  border: 0;
  color: var(--text);
  background: transparent;
  font-size: var(--training-subsection-size);
  line-height: var(--training-subsection-line);
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.provider-other-toggle svg,
.canonical-section-toggle svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 160ms ease;
}

.provider-other-toggle[aria-expanded="true"] svg,
.canonical-section-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.provider-other-content {
  margin: 0;
}

.provider-resource-name {
  color: var(--muted);
  cursor: default;
}

.training-key-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr);
  gap: 7px;
}

.training-key-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.training-key-disabled :disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.training-connected-providers {
  margin-top: 9px;
  padding: 9px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--bg);
}

.training-connected-providers span {
  display: block;
  color: var(--text);
  font-size: var(--training-helper-size);
  font-weight: 650;
}

.training-connected-providers p {
  margin: 4px 0 0;
  font-size: var(--training-helper-size);
}

.training-open-config {
  justify-self: start;
  padding: 6px 2px;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 650;
  cursor: pointer;
}

#module-training[data-training-mode="explicit"] .training-header {
  box-shadow: inset 4px 0 0 var(--accent);
}

#module-training[data-training-mode="explicit"] .training-heading {
  display: grid;
  gap: 1px;
}

#module-training[data-training-mode="explicit"] #btn-training-exit-setup {
  border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
  color: var(--accent);
  background: var(--surface);
}

.canonical-config-stack {
  display: grid;
  gap: 10px;
}

.canonical-config-section {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(15, 38, 70, 0.035);
}

.canonical-config-section-header {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.training-config-section-title {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: var(--training-section-size);
  line-height: var(--training-section-line);
  font-weight: 700;
}

.canonical-section-toggle {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.canonical-section-toggle:hover {
  color: var(--accent);
  background: var(--bg);
}

.canonical-config-section-content {
  min-width: 0;
  margin-top: 11px;
}

.canonical-config-section-content[hidden],
.provider-other-content[hidden] {
  display: none !important;
}

.canonical-admin-section {
  background: color-mix(in srgb, var(--surface) 96%, var(--bg) 4%);
  box-shadow: none;
}

.canonical-config-section .form-group,
.canonical-config-section .key-block,
.canonical-config-section .form-actions,
.canonical-config-section .smtp-grid {
  margin: 0;
}

.canonical-config-section .field-hint {
  color: var(--muted);
  font-size: var(--training-helper-size) !important;
  line-height: var(--training-helper-line);
  font-weight: 400;
}

.canonical-actions-section:has(> div:empty) {
  display: none;
}

#onboarding-slot-admin-actions #btn-smtp-test,
#onboarding-slot-ai-actions #btn-oc-test,
#onboarding-slot-ai-actions #btn-oc-reset,
#module-training #ai-status {
  display: none;
}

#module-training .portal-shared-label {
  display: none;
}

#module-training .canonical-config-section,
#module-training .canonical-config-section input,
#module-training .canonical-config-section select,
#module-training .canonical-config-section textarea {
  font-size: var(--training-body-size);
  line-height: var(--training-body-line);
  font-weight: 400;
}

#module-training .canonical-config-section label:not(.portal-shared-label),
#module-training .canonical-config-section .ai-model-field > span {
  font-size: var(--training-field-size);
  line-height: var(--training-field-line);
  font-weight: 600;
}

#module-training .canonical-config-section h3,
#module-training .canonical-config-section .ai-model-kind {
  font-size: var(--training-subsection-size);
  line-height: var(--training-subsection-line);
  font-weight: 700;
}

#module-training .canonical-config-section button {
  min-height: 36px;
  font-size: 13px;
  font-weight: 600;
}

#module-training .canonical-config-section .canonical-section-toggle,
#module-training .canonical-config-section .provider-other-toggle,
#module-training .canonical-config-section .provider-resource-row {
  min-height: 36px;
}

#module-training .canonical-config-section input,
#module-training .canonical-config-section select {
  min-height: 36px;
  padding: 8px 10px;
}

#module-training .canonical-config-section textarea {
  padding: 9px;
}

#module-training .canonical-config-section .smtp-grid {
  gap: 10px;
}

#module-training .canonical-config-section .ai-model-row + .ai-model-row {
  margin-top: 10px;
}

.training-assistant-save-copy {
  margin: 9px 0 7px;
  color: var(--muted);
  font-size: var(--training-helper-size);
  line-height: var(--training-helper-line);
}

.onboarding-first-run {
  z-index: 1200;
  background: rgba(15, 28, 46, 0.52);
}

.modal-content.onboarding-first-run-card {
  width: min(400px, calc(100vw - 32px));
  max-width: 400px;
  padding: 22px;
  text-align: left;
  border: 1px solid color-mix(in srgb, var(--line) 86%, transparent);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 22px 54px rgba(15, 28, 46, 0.28);
}

.onboarding-first-run-icon {
  width: 38px;
  height: 38px;
  margin: 0 0 13px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--accent);
  background: color-mix(in srgb, var(--surface) 82%, var(--accent) 18%);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.onboarding-first-run-card h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
}

.onboarding-first-run-copy {
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.onboarding-first-run-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.onboarding-first-run-actions button {
  min-height: 38px;
  min-width: 74px;
}

.onboarding-first-run-note {
  margin: 17px 0 0;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.onboarding-coach {
  position: fixed;
  inset: 0;
  z-index: auto;
  pointer-events: none;
}

.onboarding-highlight {
  position: fixed;
  z-index: 1150;
  border: 2px solid color-mix(in srgb, var(--accent) 88%, white);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(13, 29, 55, 0.28), 0 0 0 4px rgba(56, 132, 255, 0.13);
  transition: left 160ms ease, top 160ms ease, width 160ms ease, height 160ms ease;
}

.onboarding-bubble {
  position: fixed;
  z-index: 1154;
  width: min(340px, calc(100vw - 24px));
  padding: 16px 17px 15px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(15, 38, 70, 0.13);
  pointer-events: auto;
}

.onboarding-bubble-step {
  display: block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.onboarding-bubble h3 {
  margin: 0 24px 7px 0;
  font-size: 17px;
}

.onboarding-bubble p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}

.onboarding-bubble-actions {
  display: flex;
  gap: 8px;
  margin-top: 13px;
}

.onboarding-bubble-actions:empty {
  display: none;
}

.onboarding-dismiss {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.onboarding-dismiss:hover {
  background: var(--other);
}

.onboarding-bubble-tail {
  position: absolute;
  width: 14px;
  height: 14px;
  border-left: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  background: var(--surface);
  transform: rotate(45deg);
}

.onboarding-bubble[data-side="right"] .onboarding-bubble-tail {
  left: -8px;
  top: calc(50% - 7px);
}

.onboarding-bubble[data-side="left"] .onboarding-bubble-tail {
  right: -8px;
  top: calc(50% - 7px);
  transform: rotate(225deg);
}

.onboarding-bubble[data-side="bottom"] .onboarding-bubble-tail {
  top: -8px;
  left: 24px;
  transform: rotate(135deg);
}

.onboarding-bubble[data-side="top"] .onboarding-bubble-tail {
  bottom: -8px;
  left: 24px;
  transform: rotate(-45deg);
}

.training-form-composer-spotlight {
  position: relative;
  z-index: 1152;
  pointer-events: auto;
  outline: 2px solid color-mix(in srgb, var(--accent) 82%, white);
  outline-offset: -2px;
  box-shadow: 0 -8px 24px rgba(15, 38, 70, 0.12);
}

.training-form-onboarding #btn-training-attach {
  display: inline-flex;
}

.training-form-onboarding #btn-training-attach-file {
  display: inline-flex;
}

@media (max-width: 980px) {
  body:has(#module-training:not(.hidden)) {
    overflow: hidden;
  }

  #module-training:not(.hidden) {
    height: 100dvh;
  }

  #module-training {
    grid-template-rows: auto auto minmax(0, 1fr);
    background: var(--surface);
  }

  .training-mobile-topbar {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .training-mobile-topbar > div { min-width: 0; }

  .training-mobile-topbar h1 {
    margin: 0;
    font-size: var(--training-title-size);
    line-height: var(--training-title-line);
    font-weight: 700;
  }

  .training-mobile-topbar .training-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .training-mobile-segments {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    margin: 8px 12px;
    padding: 4px;
    border-radius: 11px;
    background: var(--surface-2);
  }

  .training-mobile-segments button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font-weight: 650;
    cursor: pointer;
  }

  .training-mobile-segments button.active {
    color: var(--accent);
    background: var(--surface);
    box-shadow: 0 1px 5px rgba(15, 28, 46, 0.1);
  }

  .training-layout,
  .training-layout.training-config-collapsed {
    display: block;
    min-height: 0;
    overflow: hidden;
  }

  .training-command-panel,
  .training-config-panel {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    visibility: visible !important;
  }

  .training-command-panel {
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }

  .training-command-panel > #training-log {
    min-height: 0;
  }

  #module-training[data-mobile-segment="chat"] .training-config-panel,
  #module-training[data-mobile-segment="config"] .training-command-panel {
    display: none;
  }

  .training-config-panel {
    overflow-y: auto;
  }

  .training-header {
    min-height: 48px;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 12px;
  }

  .training-heading { display: none; }

  .training-actions {
    width: 100%;
    overflow-x: auto;
  }

  .training-config-toggle { display: none; }

  #module-training .mobile-menu-button,
  #module-training .training-actions button,
  #module-training .training-tool-action,
  #module-training .training-send-button,
  #module-training .canonical-config-section button,
  #module-training .canonical-config-section input,
  #module-training .canonical-config-section select,
  #module-training .provider-resource-row {
    min-height: 44px;
  }
}

@media (max-width: 600px) {
  .training-header {
    flex-direction: column;
    padding: 12px;
  }

  .training-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .training-config-panel {
    padding: 12px;
  }

  .training-form {
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  }

  .training-input-row {
    gap: 6px;
  }

  .training-tool-row {
    min-height: 44px;
    margin-bottom: 6px;
  }

  .training-tool-action,
  .training-send-button {
    min-height: 44px !important;
  }

  .training-tool-action {
    padding-inline: 10px;
  }

  .training-message-image {
    max-width: 100%;
    max-height: 52vh;
  }

  .training-config-header,
  .onboarding-first-run-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .onboarding-bubble {
    left: 12px !important;
    right: 12px;
    width: auto;
  }
}

.module-placeholder {
  height: 100%;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
}

.module-placeholder-icon {
  font-size: 42px;
}

.module-placeholder h2 {
  margin: 0;
  font-size: 20px;
}

.module-placeholder p {
  margin: 0;
  color: var(--muted);
}

/* --- PHAN HE CONG CU --- */

/* .module-panel dat overflow:hidden nen phan cuon phai nam o day, giong
   .email-panel. */
.tools-panel {
  --tools-text-page-title: 24px;
  --tools-text-section-title: 18px;
  --tools-text-subsection-title: 15px;
  --tools-text-card-title: 16px;
  --tools-text-body: 14px;
  --tools-text-label: 13px;
  --tools-text-meta: 12px;
  --tools-text-button: 14px;
  --tools-text-input: 14px;
  height: 100%;
  overflow-y: auto;
  padding: 20px 24px 40px;
  font-size: var(--tools-text-body);
  font-weight: 400;
  line-height: 1.5;
}

.tools-header {
  margin-bottom: 18px;
}

.tools-header h2 {
  margin: 0 0 4px;
  font-size: var(--tools-text-page-title);
  font-weight: 700;
  line-height: 1.3;
}

.tools-header p {
  margin: 0;
  color: var(--muted);
  font-size: var(--tools-text-body);
  font-weight: 400;
  line-height: 1.5;
}

.tools-panel button {
  font-size: var(--tools-text-button);
  font-weight: 600;
  line-height: 1.4;
}

.tools-panel input,
.tools-panel select {
  font-size: var(--tools-text-input);
  font-weight: 400;
  line-height: normal;
}

.tools-panel label {
  font-size: var(--tools-text-label);
  font-weight: 500;
  line-height: 1.4;
}

.tools-panel .field-hint,
.tools-panel .training-meta {
  font-size: var(--tools-text-meta);
  font-weight: 400;
  line-height: 1.5;
}

/* auto-fit lo 3 the tren man rong, tu xuong 2 roi 1 khi hep - khong can
   media query va khong bao gio tran ngang. */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.tool-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.tool-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: var(--surface-2);
}

.tool-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tool-card.active {
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.tool-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-bottom: 2px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
}

.tool-icon svg {
  width: 20px;
  height: 20px;
}

.tool-name {
  margin: 0;
  font-size: var(--tools-text-card-title);
  font-weight: 600;
  line-height: 1.4;
}

.tool-desc {
  margin: 0;
  color: var(--muted);
  font-size: var(--tools-text-body);
  font-weight: 400;
  line-height: 1.5;
}

/* Trung tinh, KHONG dung mau canh bao: chua ket noi khong phai la loi. */
.tool-status {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: var(--tools-text-meta);
  font-weight: 400;
  line-height: 1.5;
}

/* Tai moi thoi diem chi mot tools-detail duoc hien. */
.tools-detail {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.tools-detail-header {
  margin-bottom: 14px;
}

.tools-detail-title {
  margin: 0 0 4px;
  font-size: var(--tools-text-section-title);
  font-weight: 700;
  line-height: 1.4;
}

.tools-detail-status {
  margin: 0;
  color: var(--muted);
  font-size: var(--tools-text-meta);
  font-weight: 400;
  line-height: 1.5;
}

/* .email-panel duoc viet cho thoi no la mot phan he rieng: tu cuon va tu chua
   het chieu cao. Gio no nam BEN TRONG .tools-panel (chinh .tools-panel moi la
   cai cuon), nen phai go hai thu do - de nguyen se sinh thanh cuon long nhau.
   Ghi de CO PHAM VI, khong dung den quy tac .email-panel goc. */
.tools-panel #email-panel {
  height: auto;
  overflow: visible;
  padding: 0;
}

/* email.js tu dung mot <h2>Email</h2> trong khoi header cua no. Ten do la di
   san tu thoi Email con la phan he rieng; nay no nam duoi tieu de "Zoho Mail"
   nen thanh thua va sai nghia. Chi an DUNG dong tieu de - dong trang thai va
   den bao ngay ben canh van hien nguyen. Khong sua email.js. */
.tools-detail .email-header h2 {
  display: none;
}

.tools-panel .email-khoi h3 {
  font-size: var(--tools-text-subsection-title);
  font-weight: 600;
  line-height: 1.4;
}

/* --- WEBSITE API CONNECTOR --- */
.website-connector,
.website-customers {
  max-width: 1000px;
}

.website-form {
  display: grid;
  gap: 14px;
  max-width: 720px;
}

.website-field {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.website-field > span {
  color: var(--muted);
  font-size: var(--tools-text-body);
  font-weight: 600;
}

.website-actions,
.website-customers-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.website-actions {
  margin-top: 2px;
}

.website-message {
  min-height: 20px;
  margin: 0;
}

.website-customers {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.website-customers-header {
  justify-content: space-between;
  margin-bottom: 10px;
}

.website-customers-header h4 {
  margin: 0;
  font-size: var(--tools-text-subsection-title);
}

.website-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.website-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

.website-table th,
.website-table td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.website-table th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--tools-text-meta);
  font-weight: 600;
}

.website-table tr:last-child td {
  border-bottom: 0;
}

.website-empty {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  .website-field {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }
}

/* --- KHOI CAU HINH ZOOM --- */

#zoom-panel {
  width: 100%;
  max-width: 1000px;
}

.zoom-ket-noi-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.zoom-ket-noi-actions[hidden],
.zoom-cau-hinh[hidden] {
  display: none;
}

.zoom-ket-noi-actions .primary-button,
.zoom-ket-noi-actions .secondary-button {
  padding: 8px 14px;
}

.zoom-cau-hinh {
  width: 100%;
  max-width: 900px;
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.zoom-muc-tieu-de {
  margin: 0 0 10px;
  font-size: var(--tools-text-subsection-title);
  font-weight: 600;
  line-height: 1.4;
}

.zoom-huong-dan {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: var(--tools-text-body);
  font-weight: 400;
  line-height: 1.5;
}

.zoom-huong-dan p {
  margin: 0 0 4px;
}

.zoom-huong-dan code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
}

.zoom-hang {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.zoom-hang label {
  color: var(--muted);
  font-size: var(--tools-text-label);
  font-weight: 500;
  line-height: 1.4;
}

.zoom-hang input,
.zoom-hang select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.zoom-nut {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 6px;
}

.zoom-nut .primary-button,
.zoom-nut .secondary-button {
  padding: 8px 14px;
}

/* Man hep: nhan xuong dong tren o nhap thay vi ep o nhap co lai. */
@media (max-width: 720px) {
  .zoom-hang {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
}

/* Khoi tao cuoc hop - desktop dat tieu de va nut tren cung mot hang. */
.zoom-tao-hop {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "title action"
    "form form"
    "message message"
    "results results";
  align-items: end;
  gap: 10px 14px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.zoom-tao-tieu-de {
  grid-area: title;
  margin: 0;
  font-size: var(--tools-text-subsection-title);
  font-weight: 600;
  line-height: 1.4;
}

.zoom-tao-submit {
  grid-area: action;
  justify-self: end;
  padding: 8px 14px;
}

.zoom-tao-luoi {
  grid-area: form;
  display: grid;
  grid-template-columns:
    minmax(220px, 2fr)
    minmax(130px, 1fr)
    minmax(105px, 0.8fr)
    minmax(125px, 0.9fr)
    minmax(175px, 1.4fr);
  gap: 10px;
  min-width: 0;
}

.zoom-truong {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: var(--tools-text-label);
  font-weight: 500;
  line-height: 1.4;
}

.zoom-truong input,
.zoom-truong select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

#zm-hop-bao {
  grid-area: message;
}

.zoom-ket-qua-danh-sach {
  grid-area: results;
  display: grid;
  gap: 10px;
}

.zoom-ket-qua {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: var(--tools-text-body);
  font-weight: 400;
  line-height: 1.5;
  /* Link tham gia co the dai hon khung - be dong, khong tran ngang. */
  overflow-wrap: anywhere;
}

.zoom-ket-qua-so {
  grid-column: 1;
  grid-row: 1 / span 3;
  font-weight: 700;
  color: var(--ok);
}

.zoom-ket-qua-dong {
  grid-column: 2;
  min-width: 0;
}

.zoom-ket-qua-hanh-dong {
  grid-column: 3;
  grid-row: 1 / span 3;
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-ket-qua-hanh-dong .secondary-button {
  padding: 7px 12px;
}

.zoom-sao-chep-phan-hoi {
  min-width: 92px;
  color: var(--muted);
  font-size: var(--tools-text-meta);
  font-weight: 400;
  line-height: 1.5;
}

/* Vua: form tao hop xuong hai hang co can, moi o van co du rong de doc. */
@media (max-width: 900px) {
  .zoom-tao-luoi {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .zoom-truong-ten {
    grid-column: span 6;
  }

  .zoom-truong:not(.zoom-truong-ten) {
    grid-column: span 3;
  }
}

/* Hep/mobile: ngay-gio va thoi luong-mui gio thanh hai cap; nut nam sau form. */
@media (max-width: 640px) {
  .tools-panel {
    padding-inline: 16px;
  }

  .zoom-tao-hop {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "title"
      "form"
      "action"
      "message"
      "results";
  }

  .zoom-tao-submit {
    justify-self: start;
  }

  .zoom-ket-qua {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .zoom-ket-qua-hanh-dong {
    grid-column: 2;
    grid-row: auto;
    justify-self: start;
    flex-wrap: wrap;
  }
}

/* --- P2D: PROVIDER-SOURCE-OF-TRUTH ZOOM DASHBOARD --- */

.zoom-scope-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 5px 10px;
  margin: 8px 0;
}

.zoom-scope-list code {
  min-width: 0;
  overflow-wrap: anywhere;
}

.zoom-lich {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.zoom-lich-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.zoom-lich-header .zoom-tao-tieu-de {
  margin: 0;
}

.zoom-tao-hop {
  display: block;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.zoom-tao-hop[hidden],
.zoom-row-menu[hidden] {
  display: none;
}

.zoom-tao-hop h5 {
  margin: 0 0 10px;
  font-size: var(--tools-text-subsection-title);
  line-height: 1.4;
}

.zoom-form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.zoom-form-actions .zoom-tao-submit {
  grid-area: auto;
  justify-self: auto;
}

#zm-hop-bao {
  grid-area: auto;
  margin-top: 6px;
}

.zoom-lich-bao {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 48px;
}

.zoom-lich-bao p {
  margin: 0;
}

.zoom-lich-loi,
.zoom-inline-bao {
  color: var(--danger);
  font-size: var(--tools-text-meta);
}

.zoom-lich-danh-sach {
  min-width: 0;
}

.zoom-lich-dau,
.zoom-lich-dong {
  display: grid;
  grid-template-columns:
    minmax(170px, 2fr)
    minmax(92px, 0.9fr)
    minmax(62px, 0.65fr)
    minmax(92px, 0.8fr)
    minmax(120px, 1fr)
    minmax(220px, auto);
  gap: 10px;
  align-items: center;
}

.zoom-lich-dau {
  padding: 8px 12px;
  color: var(--muted);
  font-size: var(--tools-text-meta);
  font-weight: 600;
}

.zoom-lich-dong {
  position: relative;
  min-width: 0;
  margin-bottom: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: var(--tools-text-body);
  line-height: 1.45;
}

.zoom-lich-cot {
  min-width: 0;
  overflow-wrap: anywhere;
}

.zoom-lich-ten {
  font-weight: 600;
}

.zoom-loai-badge {
  display: block;
  width: fit-content;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--tools-text-meta);
  font-weight: 500;
}

.zoom-lich-hanh-dong {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.zoom-mo-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  text-decoration: none;
  white-space: nowrap;
}

.zoom-lich-hanh-dong .secondary-button,
.zoom-row-menu-button {
  padding: 7px 10px;
}

.zoom-sao-chep-phan-hoi {
  min-width: 0;
  max-width: 150px;
  overflow-wrap: anywhere;
}

.zoom-row-menu-wrap {
  position: relative;
}

.zoom-row-menu-button {
  min-width: 36px;
  letter-spacing: 1px;
}

.zoom-row-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 5px);
  right: 0;
  width: 150px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.zoom-row-menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.zoom-row-menu-item:hover,
.zoom-row-menu-item:focus-visible {
  background: var(--surface-2);
}

.zoom-row-menu-item-danger {
  color: var(--danger);
}

.zoom-lich-dong-dang-sua {
  display: block;
}

.zoom-sua-form {
  display: grid;
  grid-template-columns:
    minmax(220px, 2fr)
    minmax(130px, 1fr)
    minmax(110px, 0.8fr)
    minmax(120px, 0.8fr)
    minmax(175px, 1.4fr);
  gap: 10px;
  min-width: 0;
}

.zoom-sua-form input,
.zoom-sua-form select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.zoom-xoa-xac-nhan {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--danger) 6%, transparent);
}

.zoom-xoa-xac-nhan p {
  margin: 0;
  font-weight: 600;
}

.danger-button {
  padding: 8px 12px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
}

.danger-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

@media (max-width: 900px) {
  .zoom-lich-dau {
    display: none;
  }

  .zoom-lich-dong {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .zoom-lich-ten,
  .zoom-lich-hanh-dong,
  .zoom-xoa-xac-nhan {
    grid-column: 1 / -1;
  }

  .zoom-lich-hanh-dong {
    justify-content: flex-start;
  }

  .zoom-lich-cot:not(.zoom-lich-ten)::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-size: var(--tools-text-meta);
    font-weight: 500;
  }

  .zoom-sua-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .zoom-sua-form .zoom-truong-ten {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .zoom-lich-header {
    align-items: flex-start;
  }

  .zoom-lich-dong,
  .zoom-sua-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .zoom-lich-ten,
  .zoom-lich-hanh-dong,
  .zoom-xoa-xac-nhan,
  .zoom-sua-form .zoom-truong-ten {
    grid-column: 1;
  }

  .zoom-lich-hanh-dong {
    align-items: flex-start;
  }

  .zoom-row-menu {
    right: auto;
    left: 0;
  }
}

/* --- DANG NHAP / TAI KHOAN --- */

.profile-info {
  flex: 1;
  min-width: 0;
}

.auth-card {
  width: min(360px, 92vw);
  text-align: left;
}

.auth-card h1 {
  text-align: center;
}

.auth-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.auth-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

.auth-card .primary-button {
  width: 100%;
}

.otp-channels {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.otp-channel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.otp-channel:hover {
  border-color: var(--accent);
}

.otp-channel.active {
  border-color: var(--accent);
  background: var(--surface-2);
}

.otp-channel span {
  color: var(--muted);
  font-size: 12px;
}

.otp-actions {
  display: flex;
  gap: 8px;
}

.otp-actions .primary-button,
.otp-actions .secondary-button {
  flex: 1;
  width: auto;
}

#otp-code {
  letter-spacing: 6px;
  text-align: center;
  font-size: 20px;
}

.section-divider {
  margin: 22px 0;
  border: none;
  border-top: 1px solid var(--line);
}

.key-block {
  padding: 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--bg);
}

.smtp-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 12px;
}

.ai-key-manager > summary,
.ai-opencode-advanced > summary {
  color: var(--accent);
  font-weight: 650;
  cursor: pointer;
}

.ai-key-manager-body,
.ai-opencode-advanced-body {
  margin-top: 12px;
}

.ai-model-grid {
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  align-items: end;
}

.ai-model-config {
  min-width: 0;
}

.ai-model-row + .ai-model-row {
  margin-top: 12px;
}

.ai-model-kind {
  display: block;
  margin: 0 0 6px;
  font-size: var(--training-helper-size);
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ai-model-kind-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.ai-model-kind-row .ai-model-kind {
  margin: 0;
}

.ai-model-kind-row .field-hint {
  margin: 0;
}

.ai-model-save-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 10px;
}

.ai-model-save-row .field-hint {
  flex: 1;
  margin: 0;
}

.ai-model-field {
  min-width: 0;
  margin: 0 !important;
}

.ai-model-field > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.ai-model-field > select {
  width: 100%;
}

.ai-model-save {
  min-height: 38px;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .ai-model-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .ai-model-save {
    justify-self: start;
  }

  .ai-model-save-row {
    align-items: stretch;
    flex-direction: column;
  }
}

/* --- KHO TRI THUC + LOG --- */

.knowledge-subtitle {
  display: block;
  margin: 8px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.knowledge-picker {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--bg);
}

.knowledge-pick-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}

.kp-meta {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.kp-content {
  margin: 0;
  max-height: 60vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.5;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-item {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: var(--bg);
}

.log-item.log-ok {
  border-left-color: var(--ok);
}

.log-item.log-warn {
  border-left-color: var(--warn);
}

.log-item.log-error {
  border-left-color: var(--danger);
}

.log-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}

.log-time {
  color: var(--muted);
  font-size: 12px;
}

.log-badge {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
}

.log-summary {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.log-detail-btn {
  margin-top: 6px;
  padding: 2px 8px;
  font-size: 12px;
}

.log-detail {
  margin: 6px 0 0;
  max-height: 320px;
  overflow: auto;
  padding: 10px;
  border-radius: 6px;
  background: var(--surface);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 12px;
}

/* --- SETTINGS MODAL --- */
.icon-button {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  color: var(--muted);
}

.dang-quay {
  animation: quay 0.9s linear infinite;
}

@keyframes quay {
  to { transform: rotate(360deg); }
}

.icon-button:hover {
  color: var(--text);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 28, 46, 0.45);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 24px;
}

.modal-content {
  background: var(--bg);
  /* Rong hon han ban cu 600px - bay 7 tab cau hinh deu la form dai. Van chua
     90vw nen luon con vien ho tho hai ben. */
  width: min(90vw, 1080px);
  max-width: 100%;
  max-height: 88vh;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 44px var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.close-button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}

.close-button:hover {
  color: var(--text);
}

.modal-tabs {
  display: flex;
  flex-wrap: wrap;
  background: var(--surface);
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-weight: bold;
}

.tab-button.active {
  color: var(--nav-blue);
  border-bottom-color: var(--nav-blue);
}

.modal-body {
  padding: 26px 28px;
  overflow-y: auto;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* --- AUTO REPLY STYLES --- */
.rule-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.rule-list-header h3 {
  margin: 0;
}

.rule-list {
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
}

.rule-item {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 12px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.rule-info {
  flex: 1;
}

.rule-cmd {
  font-weight: bold;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 4px;
}

.rule-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.rule-reply-preview {
  font-size: 13px;
  white-space: pre-wrap;
  background: var(--surface-2);
  padding: 8px;
  border-radius: 4px;
}

.rule-actions {
  display: flex;
  gap: 8px;
}

.rule-form {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 16px;
  border-radius: 8px;
}

.rule-form h4 {
  margin-top: 0;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
}

.input-prefix {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.input-prefix span {
  color: var(--muted);
  font-weight: bold;
}

.input-prefix input {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 10px 4px;
  flex: 1;
  outline: none;
}

.checkbox-label, .radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: normal !important;
  cursor: pointer;
}

.radio-group {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 24px;
}

textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  resize: vertical;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Responsive cua khung app: PHAI dat cuoi file. Media query cung specificity
   voi rule goc, nen neu dat truoc .app-shell thi rule goc se de len va khong
   bao gio co tac dung. */
@media (max-width: 760px) {
  body {
    min-height: 100dvh;
  }

  body:has(.chat-app.mobile-chat-open) {
    overflow: hidden;
  }

  .app-shell {
    height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
  }

  .app-sidebar {
    position: fixed;
    z-index: 1000;
    inset: 0 auto 0 0;
    width: 306px;
    max-width: calc(100vw - 42px);
    height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: var(--surface);
    color: var(--text);
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 12px 0 30px rgba(15, 28, 46, 0.2);
  }

  .app-shell.mobile-drawer-open .app-sidebar { transform: translateX(0); }

  .mobile-drawer-backdrop {
    position: fixed;
    z-index: 999;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    padding: 0;
    border: 0;
    background: rgba(15, 28, 46, 0.45);
  }

  .account-bar {
    min-height: 92px;
    display: block;
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  .account-toggle {
    width: 100%;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 10px;
    justify-items: start;
    padding: 6px;
    border: 0;
    border-radius: 12px;
    color: var(--text);
    text-align: left;
  }

  .account-toggle:hover,
  .account-toggle[aria-expanded="true"] {
    border-color: transparent;
    background: var(--surface-2);
  }

  .account-toggle .avatar { width: 44px; height: 44px; }

  .account-name {
    min-width: 0;
    display: block;
    align-self: center;
    overflow: hidden;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .account-caret { display: block; align-self: center; color: var(--muted); }

  .app-shell.mobile-drawer-open #zalo-status {
    position: fixed;
    z-index: 1002;
    top: 66px;
    left: 74px;
    color: var(--muted);
    pointer-events: none;
  }

  .account-menu {
    top: 74px;
    left: 12px;
    width: calc(100% - 24px);
  }

  .module-nav {
    align-items: stretch;
    gap: 4px;
    padding: 10px 12px;
  }

  .module-item {
    height: 48px;
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 14px;
    border-radius: 12px;
    color: var(--text);
  }

  .module-item:hover { background: var(--surface-2); color: var(--text); }

  .module-item.active {
    background: var(--selected-bg);
    color: var(--nav-blue);
    font-weight: 600;
  }

  .module-label { display: inline; font-size: 15px; }

  .module-icon svg {
    width: 22px;
    height: 22px;
  }

  .rail-bottom {
    align-items: stretch;
    gap: 8px;
    padding: 8px 12px 16px;
    border-top: 1px solid var(--line);
  }

  .bot-switch {
    padding: 0;
    border: 0;
    border-radius: 14px;
    background: #eff5ff;
  }

  .bot-toggle {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    justify-items: start;
    padding: 12px;
    border: 1px solid #cfe0fb;
    border-radius: 14px;
    color: var(--text);
    text-align: left;
  }

  .bot-toggle:hover { border-color: #b8cff2; background: #eff5ff; }
  .bot-toggle[aria-checked="true"] { border-color: #cfe0fb; background: #eff5ff; }

  .bot-scope-label {
    grid-column: 1 / -1;
    display: block;
    color: var(--nav-blue);
    font-size: 13px;
    font-weight: 600;
  }

  .bot-label { align-items: flex-start; }
  .bot-label strong { font-size: 13px; }
  .bot-label small { display: block; margin-top: 2px; font-size: 12px; }
  .bot-track { align-self: center; }

  .rail-item {
    height: 48px;
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 14px;
    border-radius: 12px;
    color: var(--text);
  }

  .rail-item:hover { background: var(--surface-2); color: var(--text); }
  .rail-item-label { display: inline; font-size: 15px; }

  #rail-logout-toggle { display: none; }

  .rail-menu.hidden {
    position: static;
    width: 100%;
    display: flex !important;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .rail-menu-item {
    min-height: 44px;
    border-radius: 10px;
    padding: 9px 12px;
  }

  .rail-menu-danger {
    order: -1;
    border: 1px solid #efb9b7;
    background: #fffafa;
  }

  .rail-menu-copy strong { font-size: 14px; }

  .app-main {
    width: 100%;
    min-width: 0;
  }

  .modal {
    padding: 12px;
  }

  .modal-content {
    width: 100%;
    max-height: 92vh;
  }

  .modal-header,
  .modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* =====================================================================
   MESSAGING POWER PACK V1

   Chi THEM. Khong dong nao o day sua hinh hoc da duyet cua Inbox UI-A:
   luoi .send-form giu nguyen bon cot, .send-input-row giu nguyen khai bao
   goc, va bo doi Anh/Tep giu nguyen o cu. Nut sticker nam DE LEN dau phai
   cua o soan tin nen khong can them mot cot thu nam - them cot la o nhap
   bi bop lai tren may dien thoai hep.
   ===================================================================== */

.send-form { position: relative; }

.chat-sticker-button {
  z-index: 2;
  width: 30px;
  height: 30px;
  min-width: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.chat-sticker-button:hover:not(:disabled) { background: #eef2f7; color: var(--text); }
.chat-sticker-button:disabled { cursor: wait; opacity: 0.6; }
.chat-sticker-button .chat-tool-icon { width: 20px; height: 20px; flex: none; }

.chat-panel #btn-chat-sticker {
  grid-column: 3;
  grid-row: 3;
  justify-self: end;
  align-self: end;
  margin-right: 8px;
  margin-bottom: 16px;
}

/* --- DATA KHACH HANG --- */

.data-panel {
  position: relative;
  height: 100%;
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--bg);
}

.data-panel > .data-header { grid-row: 1; }
.data-panel > .data-sync-status { grid-row: 2; }
.data-panel > #data-toolbar { grid-row: 3; }
.data-panel > #data-date-note { grid-row: 4; }
.data-panel > #data-message { grid-row: 5; }
.data-panel > .data-results { grid-row: 6; }
.data-panel > .data-pagination { grid-row: 7; }

.data-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.data-header .mobile-menu-button { display: none; }
.data-heading { flex: 1; min-width: 0; }
.data-heading h2 { margin: 0; font-size: 20px; }
.data-heading p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.data-sync-status {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.data-sync-status > span {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 14px;
  background: var(--surface);
}

.data-sync-status small { color: var(--muted); font-size: 11px; }
.data-sync-status strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }

.data-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(130px, 1fr) auto minmax(130px, 1fr) minmax(145px, 1fr);
  gap: 8px;
  padding: 12px 18px 8px;
}

.data-toolbar input,
.data-toolbar select,
.data-pagination select {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.data-date-filter { display: flex; gap: 6px; }
.data-date-filter input { width: 132px; }
.data-toolbar :disabled { color: var(--muted); cursor: not-allowed; opacity: 0.65; }
.data-date-note, .data-message { margin: 0; padding: 0 18px 8px; color: var(--muted); font-size: 12px; }
.data-message { min-height: 20px; color: var(--danger); }

.data-results { min-height: 0; overflow: auto; padding: 0 18px; }
.data-table-wrap { min-width: 940px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 13px; }
.data-table th, .data-table td { padding: 10px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--muted); font-size: 11px; text-transform: uppercase; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover, .data-table tbody tr:focus { outline: none; background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-cards { display: none; }
.data-empty { margin: 28px 0; color: var(--muted); text-align: center; }

.data-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: 12px;
}
.data-pagination label { display: flex; align-items: center; gap: 6px; margin-right: auto; }
.data-pagination button { padding: 7px 11px; }

.data-detail-backdrop { position: absolute; inset: 0; z-index: 40; border: 0; background: rgba(15, 28, 46, 0.28); }
.data-detail {
  position: absolute;
  z-index: 41;
  top: 0;
  right: 0;
  width: min(440px, 92%);
  height: 100%;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -12px 0 30px var(--shadow);
}
.data-detail > header { position: sticky; top: 0; display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.data-detail > header h3 { flex: 1; margin: 0; }
.data-detail > header button { border: 0; background: transparent; color: var(--muted); font-size: 28px; cursor: pointer; }
#data-detail-body { padding: 16px 18px; }
.data-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.data-card-line { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.data-card-line small { color: var(--muted); font-size: 11px; }
.data-card-line span { overflow-wrap: anywhere; }
.data-detail section { margin-top: 20px; }
.data-detail section h4 { margin: 0 0 8px; }
.data-detail section p { margin: 6px 0; font-size: 13px; }
.data-detail-empty { color: var(--muted); }

@media (max-width: 760px) {
  .data-panel { grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto; }
  .data-header { padding: 10px 12px; }
  .data-header .mobile-menu-button { display: grid; }
  .data-heading h2 { font-size: 17px; }
  .data-heading p { display: none; }
  .data-header .primary-button { padding: 8px 10px; font-size: 12px; }
  .data-sync-status { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .data-sync-status > span { padding: 8px 10px; }
  .data-toolbar { grid-template-columns: 1fr 1fr; padding: 10px 12px 7px; }
  #data-search { grid-column: 1 / -1; }
  .data-date-filter { grid-column: 1 / -1; }
  .data-date-filter input { width: auto; flex: 1; }
  .data-toolbar input, .data-toolbar select, .data-pagination select { font-size: 16px; }
  .data-date-note, .data-message { padding: 0 12px 7px; }
  .data-results { padding: 0 12px; }
  .data-table-wrap { display: none; }
  .data-cards { display: grid; gap: 9px; }
  .data-card { display: grid; gap: 7px; width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; }
  .data-card > strong { font-size: 15px; }
  .data-card-line { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: baseline; }
  .data-pagination { padding: 8px 12px; flex-wrap: wrap; }
  .data-pagination label { width: 100%; }
  .data-detail { width: 100%; }
}

/* Cho nut sticker cho trong, khong de chu chay ra sau no. */
.chat-panel #message-input { padding-right: 42px; }

.sticker-picker {
  position: absolute;
  right: 12px;
  bottom: calc(100% - 4px);
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: min(320px, calc(100% - 24px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(15, 28, 46, 0.16);
}

.sticker-option {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}

.sticker-option:hover { border-color: var(--nav-blue); background: var(--selected-bg); }

/* --- Thao tac cua tung tin --- */

.msg-action-trigger {
  position: absolute;
  top: 0;
  left: calc(100% + 4px);
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  /* An cho den khi tro chuot toi hoac ban phim focus vao - de khung chat
     yen tinh dung nhu ban da duyet. */
  opacity: 0;
  transition: opacity 0.12s ease;
}

.bubble-row:hover .msg-action-trigger,
.msg-action-trigger:focus-visible { opacity: 1; }
.msg-action-trigger:hover { background: var(--surface-2); color: var(--text); }

.bubble-wrap { position: relative; }
.bubble-row.self .msg-action-trigger {
  right: calc(100% + 4px);
  left: auto;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: -4px;
  padding: 0 4px;
}

.msg-reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  line-height: 18px;
}

.msg-reaction-chip.mine { border-color: var(--nav-blue); background: var(--selected-bg); }

.msg-action-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: transparent;
}

.msg-action-sheet {
  position: absolute;
  z-index: 41;
  min-width: 208px;
  max-width: min(320px, calc(100% - 16px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 14px 34px rgba(15, 28, 46, 0.18);
}

.msg-action-sheet.dang-cho { pointer-events: none; opacity: 0.6; }

.msg-action-reactions {
  display: flex;
  gap: 2px;
  padding-bottom: 6px;
}

.msg-action-reactions:empty { display: none; }

.msg-reaction-option {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.msg-reaction-option:hover { background: var(--surface-2); }

.msg-action-list { display: grid; }
.msg-action-list:empty { display: none; }

.msg-action-item {
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.msg-action-item:hover { background: var(--surface-2); }
.msg-action-item.nguy-hiem { color: var(--danger, #b42318); }

.bubble.bubble-recalled { background: var(--surface-2); }

.recalled-note {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
}

/* --- Chuyen tiep: mot tin chu, MOT cuoc dich --- */

.forward-dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 28, 46, 0.42);
}

.forward-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(420px, 100%);
  max-height: min(560px, 84vh);
  padding: 16px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 22px 48px rgba(15, 28, 46, 0.28);
}

.forward-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.forward-header h3 { margin: 0; font-size: 16px; }

.forward-close {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.forward-close:hover { background: var(--surface-2); color: var(--text); }

.forward-search {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.forward-list {
  display: grid;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
}

.forward-item {
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.forward-item:hover { background: var(--selected-bg); }

/* --- Dien thoai: cung mot the DOM, trinh bay thanh sheet duoi day --- */
@media (max-width: 760px) {
  .chat-panel #btn-chat-sticker {
    grid-column: 3;
    grid-row: 3;
    justify-self: end;
    width: 36px;
    height: 36px;
    min-width: 36px;
    margin-right: 4px;
    margin-bottom: 4px;
  }

  .chat-sticker-button .chat-tool-icon { width: 22px; height: 22px; }
  .chat-panel #message-input { padding-right: 44px; }

  .sticker-picker {
    right: 8px;
    left: 8px;
    width: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Tren dien thoai khong co tro chuot de "hover" ra, nen nut phai hien san. */
  .msg-action-trigger {
    top: 2px;
    width: 28px;
    height: 28px;
    opacity: 1;
    font-size: 17px;
  }

  .bubble-row.other .msg-action-trigger {
    right: -18px;
    left: auto;
  }

  .bubble-row.self .msg-action-trigger {
    right: auto;
    left: -18px;
  }

  .msg-action-trigger::before {
    content: "";
    position: absolute;
    inset: -8px;
  }

  .msg-action-backdrop { background: rgba(15, 28, 46, 0.34); }

  .msg-action-sheet {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    max-width: none;
    padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
  }

  .msg-action-reactions {
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
  }

  .msg-reaction-option { width: 44px; height: 44px; font-size: 23px; }
  .msg-action-item { padding: 13px 10px; font-size: 15px; }
  .forward-panel { max-height: 80vh; }
}

@media (max-width: 760px) {
  .thread-search,
  #training-text,
  #module-training .canonical-config-section input,
  #module-training .canonical-config-section select,
  #module-training .canonical-config-section textarea,
  .tools-panel input,
  .tools-panel select,
  .auth-input,
  .forward-search {
    font-size: 16px;
  }
}
