:root {
  --bg: #eef3fb;
  --card-bg: #ffffff;
  --text: #0b1f3a;
  --muted: #6b7684;
  --border: #e1e8f5;
  --primary: #0068ff;
  --primary-dark: #0052cc;
  --primary-soft: #e8f1ff;
  --sidebar-bg: #ffffff;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); min-height: 1.2em; }
.success-text { color: var(--success); min-height: 1.2em; }
#login-signup-hint a { color: var(--primary); font-weight: 600; text-decoration: none; }
#login-signup-hint a:hover { text-decoration: underline; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eaf2ff 0%, #dce9ff 45%, #eef3fb 100%);
}
.login-box {
  background: var(--card-bg);
  padding: 36px 32px;
  border-radius: 20px;
  box-shadow: 0 12px 32px rgba(0, 104, 255, 0.12);
  width: 320px;
  text-align: center;
}
.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}
.login-logo.has-image { background: transparent; }
.login-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.login-box h1 { font-size: 19px; margin: 0 0 6px; }
.login-box input {
  width: 100%;
  padding: 11px 14px;
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  background: #f7f9fd;
}
.login-box input:focus { outline: none; border-color: var(--primary); background: #fff; }
.login-box button {
  width: 100%;
}

/* App shell */
.app { min-height: 100vh; }
.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
}
.sidebar-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.sidebar-logo.has-image { background: transparent; }
.sidebar-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.sidebar-brand-text { font-weight: 700; font-size: 15px; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.side-nav-btn:hover { background: var(--primary-soft); }
.side-nav-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.side-nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.btn-block { width: 100%; }

/* Main area */
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }

.pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}
.pill-ok { background: #dcfce7; color: #166534; }
.pill-bad { background: #fee2e2; color: #991b1b; }
.pill-unknown { background: #f1f5f9; color: #475569; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 14px 32px 0;
  background: transparent;
}
.tab-btn {
  border: none;
  background: none;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-radius: 999px;
  white-space: nowrap;
}
.tab-btn:hover { background: var(--primary-soft); }
.tab-btn.active {
  color: #fff;
  background: var(--primary);
  font-weight: 600;
}

.sub-tabs { padding-bottom: 6px; }

.content { padding: 20px 32px 40px; max-width: 1100px; margin: 0 auto; width: 100%; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Chatbox dùng hết chiều rộng/chiều cao cửa sổ thay vì bị bó trong khung 1100px căn giữa —
   trước đây trên màn hình rộng, khung chat bị "đóng khung cứng" nhỏ hẹp giữa 2 khoảng trắng lớn
   2 bên, khác hẳn cảm giác Zalo PC (luôn chiếm toàn bộ cửa sổ). */
.content.content-chat-mode {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 16px 20px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.content.content-chat-mode #tab-chatbox.active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.content.content-chat-mode .chat-layout {
  flex: 1;
  min-height: 0;
  height: auto;
}

.warning-text {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

.tags-chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, var(--tag-color) 15%, white);
  color: var(--tag-color);
  border: 1px solid color-mix(in srgb, var(--tag-color) 40%, white);
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.tag-chip-btn {
  background: none;
  border: none;
  color: inherit;
  padding: 0 4px;
  font-size: 12px;
  cursor: pointer;
}

.tag-pill {
  border: 1px solid color-mix(in srgb, var(--tag-color) 45%, white);
  background: white;
  color: var(--tag-color);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin: 3px 4px 3px 0;
}
.tag-pill-active {
  background: var(--tag-color);
  color: white;
}

.friend-tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.friend-tag-row:last-child { border-bottom: none; }
.friend-tag-name { font-size: 13px; font-weight: 600; min-width: 140px; }
.friend-tag-pills { display: flex; flex-wrap: wrap; }

h2 { font-size: 17px; margin: 22px 0 12px; }
.tab-panel > h2:first-child { margin-top: 0; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-header h2 { margin: 0; }

button {
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: none;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  transition: background-color 0.15s ease;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #f4f7fc; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-ghost.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-small { padding: 5px 12px; font-size: 12px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 3px rgba(11, 31, 58, 0.04);
}
.card-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.card-value { font-size: 21px; font-weight: 700; }
.card-value.small { font-size: 13px; font-weight: 500; word-break: break-all; }

/* Đăng nhập lại Zalo bằng QR */
.qr-login-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.qr-login-status {
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  line-height: 1.4;
}
.qr-login-image-wrap {
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.qr-login-image-wrap img {
  display: block;
  width: 220px;
  height: 220px;
  object-fit: contain;
}

.stats-container {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}
.stats-container > p.muted { padding: 14px; margin: 0; }
.stats-container table {
  width: 100%;
  border-collapse: collapse;
  border-radius: var(--radius);
  overflow: hidden;
}
.stats-container th, .stats-container td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.stats-container th { color: var(--muted); font-weight: 600; background: #f7f9fd; }
.stats-container tr:last-child td { border-bottom: none; }
.stats-container td .switch { vertical-align: middle; }

.branding-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.branding-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 3px rgba(11, 31, 58, 0.04);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.branding-item > label { font-size: 13px; font-weight: 600; color: var(--text); }
.branding-preview {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  overflow: hidden;
}
.branding-preview.has-image { background: #f2f4f8; border: 1px dashed var(--border); }
.branding-preview img { width: 100%; height: 100%; object-fit: contain; }
.branding-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.care-groups-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: #f9fafd;
}
/* Dùng ".form-grid .care-group-row" (2 class) thay vì chỉ ".care-group-row" (1 class) để
   thắng độ ưu tiên CSS so với ".form-grid label" (class + thẻ) — nếu không, hàng sẽ bị ép
   về flex-direction: column và căn giữa như style label mặc định. */
.form-grid .care-group-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 4px;
  font-size: 13px;
  font-weight: normal;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.care-group-name { flex: 1; min-width: 0; text-align: left; }

.model-option-list { display: flex; flex-direction: column; gap: 8px; }
.model-option-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f9fafd;
  cursor: pointer;
  font-weight: normal;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.model-option-card:hover { border-color: var(--primary); }
.model-option-card input[type="radio"] { margin-top: 3px; flex-shrink: 0; accent-color: var(--primary); }
.model-option-card.is-selected { border-color: var(--primary); background: #eef4ff; }
.model-option-body { flex: 1; min-width: 0; }
.model-option-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.model-option-name { font-size: 14px; font-weight: 600; color: var(--text); }
.model-option-price { font-size: 13px; font-weight: 600; color: var(--primary); white-space: nowrap; }
.model-option-desc { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.model-option-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #e2e8f0;
  color: var(--muted);
  vertical-align: middle;
}
.model-option-tag-recommend { background: #dcfce7; color: #15803d; }

.form-grid {
  display: grid;
  gap: 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(11, 31, 58, 0.04);
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.form-grid input, .form-grid textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  resize: vertical;
  background: #f9fafd;
}
.form-grid input:focus, .form-grid textarea:focus { outline: none; border-color: var(--primary); background: #fff; }
.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
}
.toggle {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  font-size: 13px;
}
.toggle input { width: auto; }

.faq-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 14px;
  padding: 10px 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.faq-toggle-label { font-size: 13px; color: var(--text); }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #cbd5e1;
  transition: background-color 0.2s ease;
  border-radius: 999px;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  transition: transform 0.2s ease;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Thông báo nổi kiểu "toast", dùng chung cho các hành động lưu/áp dụng tức thì (vd bật công tắc). */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}
.toast {
  background: #1f2937;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { background: #166534; }
.toast.toast-error { background: #991b1b; }

.faq-bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, white);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
}
.faq-row-check { margin-right: 10px; flex-shrink: 0; align-self: flex-start; margin-top: 4px; }

.req-list { display: flex; flex-direction: column; gap: 10px; }
.news-queue-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: 0 1px 3px rgba(11, 31, 58, 0.03);
}
.news-queue-item-header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.news-queue-image-thumb {
  display: block;
  max-width: 260px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 8px 0;
  object-fit: cover;
}

/* Hàng đợi tin — dạng lịch (calendar) + hẹn lịch đăng trước */
.nf-calendar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 4px 0 10px;
}
.nf-calendar-header b { font-size: 15px; min-width: 140px; text-align: center; }
.nf-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.nf-cal-weekday {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 4px;
}
.nf-cal-day {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 64px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.15s, border-color 0.15s;
}
.nf-cal-day:hover { background: var(--primary-soft); }
.nf-cal-day.is-other-month { opacity: 0.4; }
.nf-cal-day.is-today { border-color: var(--primary); border-width: 2px; }
.nf-cal-day.is-selected { background: var(--primary-soft); border-color: var(--primary); }
.nf-cal-day-num { font-size: 12px; font-weight: 600; }
.nf-cal-chips { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.nf-cal-chip { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.nf-cal-more { font-size: 10px; color: var(--muted); }
.nf-dot-scheduled { background: #2563eb; }
.nf-dot-pending { background: var(--warn); }
.nf-dot-posted { background: var(--success); }
.nf-dot-partial { background: var(--warn); }
.nf-dot-failed { background: var(--danger); }
.nf-dot-rejected { background: var(--muted); }

.nf-schedule-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nf-sched-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
}
.req-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  box-shadow: 0 1px 3px rgba(11, 31, 58, 0.03);
}
.req-item-main { flex: 1; }
.req-item-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.faq-badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.faq-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
}
.faq-badge-buyer { background: #e8f1ff; color: var(--primary-dark); }
.faq-badge-seller { background: #fff2e0; color: var(--warn); }
.faq-badge-platform { background: #f1e8ff; color: #7c3aed; }
.faq-badge-topic { background: #e6f7ee; color: #0f9d58; }

/* Bộ FAQ (nhóm nhiều mục FAQ theo ngành hàng/nền tảng, áp dụng riêng theo nhóm Zalo) — xem
   renderFaqSetTabs() trong app.js. Kiểu dáng đậm/nổi hơn faq-topic-tab (bên dưới) vì đây là lớp
   lọc CHA (chọn bộ) trong khi topic-tab là lớp lọc CON (lọc trong 1 bộ đã chọn). */
.faq-set-section { margin: 4px 0 16px; }
.faq-set-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 10px;
}
.faq-set-tab {
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.faq-set-tab:hover { border-color: var(--primary); color: var(--primary-dark); }
.faq-set-tab.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
}
.faq-set-tab-count { color: var(--muted); font-weight: 500; }
.faq-set-tab-add {
  border-style: dashed;
  color: var(--muted);
  background: transparent;
}
.faq-set-tab-add:hover { color: var(--primary-dark); border-color: var(--primary); }
.faq-set-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.faq-set-toolbar-scope { color: var(--muted); flex: 1; min-width: 200px; }
.faq-group-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-top: 6px;
}
/* Ghi đè ".modal-box label" (flex-direction: column; margin-bottom: 12px; ...) — mục này BẢN
   THÂN cũng là 1 thẻ <label> nằm trong modal nên bị luật đó thắng specificity, làm mỗi dòng nhóm
   bị xuống dòng (checkbox rồi tới tên) và căn giữa thay vì căn trái 1 dòng ngang như mong muốn.
   Dùng selector ghép ".faq-group-picker .faq-group-picker-item" để CHẮC CHẮN thắng specificity. */
.faq-group-picker .faq-group-picker-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  font-size: 13px;
  text-align: left;
  margin-bottom: 0;
}
.faq-group-picker-item input { width: auto; flex-shrink: 0; }
.faq-group-picker-empty { font-size: 13px; color: var(--muted); padding: 6px 0; }

/* Thanh tab lọc theo chủ đề (topic) phía trên danh sách FAQ — xem renderFaqTopicTabs() trong app.js */
.faq-topic-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 14px;
}
.faq-topic-tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.faq-topic-tab:hover { border-color: var(--primary); color: var(--primary-dark); }
.faq-topic-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.req-item-notes { font-size: 12px; color: var(--muted); }
.req-item-actions { display: flex; gap: 10px; flex-shrink: 0; align-items: center; }
.faq-row-switch { margin-right: 2px; }

.status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.status-done { background: #dcfce7; color: #166534; }
.status-in_progress { background: #fef3c7; color: #92400e; }
.status-planned { background: #f1f5f9; color: #475569; }

.sub-heading { font-size: 14px; margin: 20px 0 8px; }
.muted.small { font-size: 12px; margin-top: -8px; margin-bottom: 16px; }
.mono-small {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}

.log-viewer {
  background: #0b1f3a;
  color: #d1d5db;
  border-radius: var(--radius);
  padding: 16px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
  height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
}
.log-line { margin-bottom: 3px; }
.log-info { color: #93c5fd; }
.log-warn { color: #fcd34d; }
.log-error { color: #fca5a5; }
.log-debug { color: #9ca3af; }

/* Chatbox */
.chat-layout { display: flex; gap: 16px; height: 72vh; min-height: 420px; }
.chat-threads {
  width: 300px;
  flex-shrink: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-threads-header { padding: 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.chat-search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f0f2f5;
  border-radius: 999px;
  padding: 8px 12px;
}
.chat-search-icon { font-size: 13px; opacity: 0.6; }
#chat-search-input { flex: 1; min-width: 0; border: none; background: transparent; font-size: 13px; outline: none; color: var(--text); }
#chat-search-input::placeholder { color: var(--muted); }
.chat-thread-list { flex: 1; overflow-y: auto; }
.chat-thread-divider {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f7f9fd;
}
.chat-thread-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.chat-thread-item:hover { background: var(--primary-soft); }
.chat-thread-item.active { background: var(--primary-soft); }
.chat-thread-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-thread-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
/* Chấm nhỏ góc dưới-phải avatar để phân biệt hội thoại nhóm, kiểu Zalo. */
.chat-thread-avatar[data-badge]:not([data-badge=""])::after {
  content: "👥";
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-thread-meta { min-width: 0; flex: 1; }
.chat-thread-top-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.chat-thread-top-row .chat-thread-name { flex: 1; min-width: 0; }
.chat-thread-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.chat-thread-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-tag-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chat-tag-chip {
  display: inline-block;
  background: color-mix(in srgb, var(--tag-color) 15%, white);
  color: var(--tag-color);
  border: 1px solid color-mix(in srgb, var(--tag-color) 40%, white);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.6;
}

.chat-conversation {
  flex: 1;
  min-width: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Panel "Thông tin hội thoại" bên phải, giống Zalo PC — hiện lịch sử Ảnh/Video/File/Link đã
   trao đổi trong cuộc trò chuyện + gắn thẻ, ẩn/hiện bằng nút ⋮ trên thanh tiêu đề hội thoại. */
.chat-info-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-info-panel.hidden { display: none; }
.chat-info-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-info-body { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 18px; }
.chat-info-profile { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.chat-info-avatar { width: 64px; height: 64px; border-radius: 50%; overflow: hidden; }
.chat-info-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.chat-info-name { font-weight: 700; font-size: 15px; }
.chat-info-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}
.chat-info-tag-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-info-media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.chat-info-media-grid img, .chat-info-media-grid video {
  width: 100%;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  background: #eef1f6;
}
.chat-info-file-item, .chat-info-link-item {
  display: block;
  font-size: 12px;
  color: var(--primary-dark);
  text-decoration: none;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-info-file-item:last-child, .chat-info-link-item:last-child { border-bottom: none; }
.chat-info-empty { font-size: 12px; color: var(--muted); }
.chat-conv-header {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
}
.chat-conv-header-empty { color: var(--muted); font-weight: 500; }
.chat-conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-conv-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.chat-conv-header-meta { min-width: 0; }
.chat-conv-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conv-sub { font-weight: 400; font-size: 12px; color: var(--muted); }
.chat-conv-header-actions { margin-left: auto; display: flex; gap: 2px; flex-shrink: 0; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #f5f8fd;
}
.chat-bubble-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-bubble-row.out { justify-content: flex-end; }
.chat-bubble-row.start { margin-top: 10px; }
.chat-bubble-row.start:first-child { margin-top: 0; }
.chat-bubble-avatar,
.chat-bubble-avatar-spacer { width: 26px; height: 26px; flex-shrink: 0; }
.chat-bubble-avatar {
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  overflow: hidden;
}
.chat-bubble-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.chat-bubble-col { max-width: 68%; display: flex; flex-direction: column; min-width: 0; }
.chat-bubble-row.out .chat-bubble-col { align-items: flex-end; }
.chat-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  border: 1px solid var(--border);
}
.chat-bubble-row.in .chat-bubble { border-bottom-left-radius: 4px; }
.chat-bubble-row.out .chat-bubble { border-bottom-right-radius: 4px; }
.chat-bubble.has-image { padding: 4px; overflow: hidden; }
.chat-bubble-image { display: block; max-width: 220px; max-height: 220px; border-radius: 12px; object-fit: cover; }
.chat-bubble-video { display: block; max-width: 260px; max-height: 260px; border-radius: 12px; }
.chat-bubble-file {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 600;
}
.chat-bubble-file:hover { text-decoration: underline; }
.chat-bubble-card {
  display: flex;
  align-items: center;
  gap: 6px;
  font-style: italic;
  color: var(--muted);
}
.chat-bubble-sender { font-size: 11px; font-weight: 600; color: var(--primary-dark); margin: 0 0 2px 4px; }
.chat-bubble-time { font-size: 10px; color: var(--muted); margin-top: 3px; }
.chat-bubble-row.out .chat-bubble-time { text-align: right; }
.chat-send-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
}
.chat-send-icons { display: flex; align-items: center; gap: 2px; }
.chat-icon-btn {
  background: transparent;
  border: none;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  color: var(--muted);
}
.chat-icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
.chat-send-input-row { display: flex; align-items: center; gap: 8px; }
.chat-send-input-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 4px;
  border: none;
  font-size: 14px;
  background: transparent;
}
.chat-send-input-row input:focus { outline: none; }
.chat-send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.chat-send-btn:hover { background: var(--primary-dark); }
.chat-template-select {
  flex: 0 0 auto;
  max-width: 130px;
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  background: #f7f9fd;
  color: var(--text);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 58, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-box {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 22px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box h3 { margin-top: 0; }
.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.modal-box input, .modal-box textarea, .modal-box select {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* Modal "Thêm/Sửa nhắc nhở" — khối chọn tần suất (chỉ 1 khối hiện ra tuỳ tần suất đang chọn),
 * công cụ chọn nhóm, và bảng chọn thứ trong tuần. Xem openReminderModal() trong app.js. */
.reminder-freq-block { margin-bottom: 8px; }
.reminder-group-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -4px 0 12px;
  flex-wrap: wrap;
}
.reminder-group-tools .toggle { margin-bottom: 0; }
#m-schedule-preview {
  background: #f4f7fb;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin: -4px 0 14px;
}
.weekday-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.weekday-pill {
  flex-direction: row !important;
  align-items: center;
  gap: 4px !important;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 0 !important;
  user-select: none;
}
.weekday-pill input { width: auto; margin: 0; }
.weekday-pill:has(input:checked) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Danh sách biến thể câu trả lời FAQ (tối đa 4) — mỗi biến thể 1 ô nhập + nút xoá bên cạnh,
   bot sẽ chọn ngẫu nhiên 1 biến thể mỗi lần trả lời để đỡ lặp lại y hệt nhau. */
.faq-answer-variant-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.faq-answer-variant-row textarea { flex: 1; }
.faq-answer-remove { flex-shrink: 0; white-space: nowrap; }
#m-answer-add { margin-bottom: 12px; }
.faq-variant-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary-dark);
  font-size: 11px;
}

@media (max-width: 900px) {
  /* Màn hình hẹp (điện thoại): sidebar dọc bên trái không hợp lý (chiếm ngang màn hình vốn đã
     hẹp) — chuyển thành thanh điều hướng NẰM DƯỚI CÙNG, cố định, giống app Zalo/di động thật. */
  .app-shell { flex-direction: column; }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 40;
  }
  .sidebar-brand { display: none; } /* nhường chỗ cho thanh điều hướng, tên app đã có ở tiêu đề từng trang */

  .side-nav { flex-direction: row; flex: 1; gap: 0; justify-content: space-around; }
  .side-nav-btn {
    flex-direction: column;
    justify-content: center;
    width: auto;
    gap: 2px;
    padding: 6px 4px;
    font-size: 10px;
    text-align: center;
  }
  .side-nav-btn span:not(.side-nav-icon) { display: inline; }
  .side-nav-icon { font-size: 19px; width: auto; }

  .sidebar-footer {
    flex-direction: row;
    width: auto;
    padding-top: 0;
    border-top: none;
  }
  .sidebar-footer .pill { display: none; } /* trạng thái online/offline đã xem được ở tab Bảng điều khiển */
  .sidebar-footer .btn-block { width: auto; padding: 6px 10px; font-size: 10px; white-space: nowrap; }

  /* Chừa khoảng trống ở đáy trang để nội dung không bị thanh điều hướng cố định che mất. */
  .main-area { padding-bottom: 66px; }

  .chat-layout { flex-direction: column; height: auto; }
  .chat-threads { width: 100%; height: 200px; }
  .chat-conversation { height: 60vh; }
}

@media (max-width: 640px) {
  .content { padding: 14px; }
  .tabs { padding: 10px 14px 0; }
  .tab-btn { padding: 8px 12px; font-size: 13px; }
}
