: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);
}

* {
  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 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  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: 10px 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%;
  margin: 0;
  padding: 10px 14px 10px 36px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
}

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

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

.thread-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  min-height: 66px;
  padding: 9px 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-title,
.thread-preview,
.chat-header h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-title {
  margin-bottom: 3px;
  font-weight: 700;
  font-size: 14px;
}

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

.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 {
  height: 100%;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto;
}

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

.chat-header h2 {
  margin: 0;
  font-size: 17px;
}

.messages {
  overflow-y: auto;
  padding: 20px 22px;
}

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

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

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

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

/* 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);
  border-color: var(--bubble-self-line);
  color: var(--text);
}

.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: 4px;
  color: var(--muted);
  font-size: 11px;
}

/* 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: var(--muted);
  opacity: 1;
}

.date-divider {
  margin: 18px auto 12px;
  width: fit-content;
  max-width: 100%;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.send-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

#message-input {
  min-width: 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
}

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

.send-button {
  min-width: 84px;
  border-radius: 999px;
}

.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: 32px;
  height: 32px;
}

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

  .profile > div,
  .thread-preview,
  .thread-title {
    display: none;
  }

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

  /* Khong con cho cho icon kinh lup ben trong o tim kiem hep nay. */
  .thread-search-wrap svg {
    display: none;
  }

  .thread-search {
    padding: 9px 10px;
  }

  .thread-item {
    grid-template-columns: 46px;
    justify-content: center;
  }

  .messages {
    padding: 14px 12px;
  }

  .send-form {
    padding: 10px 12px;
  }

  .bubble-wrap {
    max-width: 82%;
  }
}

/* --- 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-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-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: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.training-header h2 {
  margin: 0;
  font-size: 18px;
}

.training-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

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

.training-actions .secondary-button {
  padding: 6px 12px;
  font-size: 12px;
}

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

.training-msg {
  max-width: min(720px, 88%);
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.5;
  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;
  background: var(--other);
  border: 1px solid var(--line);
}

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

.training-msg-files {
  margin-bottom: 6px;
  font-size: 12px;
  opacity: 0.85;
}

.training-copy {
  display: block;
  margin-top: 10px;
  padding: 4px 10px;
  font-size: 12px;
}

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

.training-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

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

.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: 10px;
  align-items: end;
}

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

.training-buttons {
  display: flex;
  gap: 8px;
}

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

.training-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(420px, 1.08fr) minmax(360px, 0.92fr);
  background: var(--bg);
}

.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: 18px;
  background: color-mix(in srgb, var(--surface) 90%, var(--accent) 10%);
}

.training-config-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

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

.training-config-header h3 {
  margin: 3px 0 0;
  font-size: 18px;
}

.onboarding-progress {
  flex: none;
  padding: 5px 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: 999px;
  color: var(--accent);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
}

.onboarding-key-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 12px;
}

.onboarding-key-links span {
  color: var(--muted);
  font-weight: 600;
}

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

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

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

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

.canonical-config-section h4 {
  margin: 0 0 9px;
  font-size: 13px;
  color: var(--text);
}

.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 {
  line-height: 1.45;
}

.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 {
  display: none;
}

.onboarding-first-run {
  z-index: 1200;
}

.onboarding-first-run-card {
  width: min(440px, calc(100vw - 32px));
  padding: 28px;
  text-align: center;
  border-radius: 16px;
}

.onboarding-first-run-icon {
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--on-accent);
  background: var(--accent);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.onboarding-first-run-card h2 {
  margin: 0;
  font-size: 22px;
}

.onboarding-first-run-card p {
  margin: 11px 0 20px;
  color: var(--muted);
  line-height: 1.55;
}

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

.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;
}

@media (max-width: 980px) {
  .training-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(420px, 1fr) minmax(320px, 0.85fr);
    overflow-y: auto;
  }

  .training-command-panel {
    min-height: 420px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .training-config-panel {
    overflow: visible;
  }
}

@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-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;
}

/* --- 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) {
  .app-shell {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .module-label,
  .account-name,
  .account-caret {
    display: none;
  }

  .module-item {
    height: 42px;
  }

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

  .rail-item {
    height: 40px;
  }

  /* Hai menu tha van bung sang phai rail, chi thu hep lai cho vua man hinh. */
  .account-menu,
  .rail-menu {
    left: calc(100% + 6px);
    right: auto;
    width: min(200px, calc(100vw - 70px));
  }

  .modal {
    padding: 12px;
  }

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

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