/* ── Variables ── */
:root {
  --sidebar-w: 170px;
  --sidebar-bg: #7b1fa2;
  --sidebar-text: #f3e5f5;
  --sidebar-hover: #9c27b0;
  --sidebar-active: #ab47bc;
  --primary: #4361ee;
  --primary-dark: #3a4fd4;
  --success: #06c270;
  --danger: #e84040;
  --warning: #f4a100;
  --info: #17a2b8;
  --bg: #f0f2f8;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6c757d;
  --border: #e0e4ef;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(160deg, #9c27b0 0%, #6a0080 40%, #7b1fa2 70%, #b039c8 100%);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
}
.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid #1e2130;
}
.sidebar-brand .logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.sidebar-brand .logo-sub {
  font-size: .72rem;
  color: var(--sidebar-text);
  margin-top: 2px;
}
.nav-menu {
  list-style: none;
  padding: 10px 0;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 18px;
  color: var(--sidebar-text);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .18s;
  font-size: .88rem;
  font-weight: 500;
  user-select: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: rgba(67,97,238,.15); color: #fff; border-left-color: var(--primary); }
.nav-item .nav-icon { width: 18px; text-align: center; font-size: .95rem; opacity: .85; }
.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid #1e2130;
  color: var(--sidebar-text);
  font-size: .75rem;
}

/* ── Main area ── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  background: var(--card);
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.topbar-title { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.topbar-sub   { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.tab-section  { flex: 1; overflow-y: auto; padding: 20px 24px; }

/* ── Stat Cards ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(67,97,238,.12); color: var(--primary); }
.stat-icon.green  { background: rgba(6,194,112,.12);  color: var(--success); }
.stat-icon.orange { background: rgba(244,161,0,.12);  color: var(--warning); }
.stat-icon.purple { background: rgba(130,0,183,.12);  color: #8200b7; }
.stat-icon.cyan   { background: rgba(23,162,184,.12); color: var(--info); }
.stat-icon.red    { background: rgba(232,64,64,.12);  color: var(--danger); }
.stat-val  { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.stat-lbl  { font-size: .73rem; color: var(--muted); margin-top: 3px; }

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.card-title { font-weight: 700; font-size: .95rem; }
.card-body  { padding: 18px; }

/* ── Toolbar / Filters ── */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0 12px;
  font-size: .84rem;
  outline: none;
  transition: border-color .15s;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--primary); }
.toolbar input[type=search] { width: 220px; }

/* ── Buttons ── */
.btn {
  height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 7px;
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { filter: brightness(.92); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { filter: brightness(.9); }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-warning:hover  { filter: brightness(.9); }
.btn-warning.active-filter { background: #e65c00; box-shadow: 0 0 0 3px rgba(230,92,0,.3); }
.btn-info     { background: var(--info); color: #fff; }
.btn-secondary{ background: #6c757d; color: #fff; }
.btn-light    { background: #f0f2f8; color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: .78rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .83rem; }
thead th {
  background: #f6f8fd;
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  color: var(--muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
tbody tr:hover { background: #f8f9ff; }
tbody tr:last-child td { border-bottom: none; }

/* ── Badges ── */
.badge {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  display: inline-block;
}
.badge-success   { background: rgba(6,194,112,.12);  color: #029a59; }
.badge-danger    { background: rgba(232,64,64,.12);  color: #c0392b; }
.badge-primary   { background: rgba(67,97,238,.12);  color: var(--primary); }
.badge-secondary { background: rgba(108,117,125,.12); color: #6c757d; }
.badge-warning   { background: rgba(244,161,0,.12);  color: #b37a00; }
.badge-info      { background: rgba(23,162,184,.12); color: #0f7a8d; }
.source-pancake  { background: #fff3cd; color: #856404; }
.source-poscake  { background: #d1ecf1; color: #0c5460; }
.source-manual   { background: #f0f2f8; color: #495057; }
.tag-pill {
  display: inline-block;
  background: rgba(67,97,238,.1);
  color: var(--primary);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: .7rem;
  margin: 1px 2px;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 0 4px;
  justify-content: center;
  flex-wrap: wrap;
}
.page-btn {
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  font-size: .8rem;
  cursor: pointer;
  transition: all .15s;
}
.page-btn:hover   { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn.active  { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .45; cursor: default; }
.page-info { font-size: .8rem; color: var(--muted); }

/* ── Connection cards ── */
.conn-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
}
.conn-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.conn-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  font-weight: 800;
}
.conn-logo.pancake { background: #fff3cd; color: #856404; }
.conn-logo.poscake { background: #d1ecf1; color: #0c5460; }
.conn-logo.facebook{ background: #dbeafe; color: #1d4ed8; }
.conn-status { font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.conn-status.ok  { background: rgba(6,194,112,.12); color: #029a59; }
.conn-status.err { background: rgba(232,64,64,.12); color: #c0392b; }
.conn-status.off { background: #f0f2f8; color: #6c757d; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.form-group input, .form-group select, .form-group textarea {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: .85rem;
  outline: none;
  transition: border-color .15s;
  background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; font-family: inherit; }

/* ── Chatbot ── */
.rule-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.rule-body { flex: 1; min-width: 0; }
.rule-name { font-weight: 700; font-size: .9rem; margin-bottom: 4px; }
.rule-keywords { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.rule-response {
  font-size: .83rem;
  color: var(--muted);
  background: #f6f8fd;
  padding: 8px 12px;
  border-radius: 7px;
  max-height: 60px;
  overflow: hidden;
}
.rule-actions { display: flex; gap: 6px; flex-shrink: 0; }
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px; height: 22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #ccc;
  border-radius: 22px;
  transition: .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
input:checked + .toggle-slider { background: var(--success); }
input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Test chatbot ── */
.chat-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 80px;
  background: #f6f8fd;
  font-size: .85rem;
}
.chat-bubble {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 18px;
  max-width: 80%;
  margin: 4px 0;
}
.chat-bubble.user  { background: var(--primary); color: #fff; margin-left: auto; display: block; width: fit-content; }
.chat-bubble.bot   { background: #fff; border: 1px solid var(--border); display: block; width: fit-content; }

/* ── Campaign cards ── */
.campaign-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.campaign-meta { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.camp-status { font-size: .75rem; font-weight: 700; padding: 2px 9px; border-radius: 20px; }
.camp-status.draft    { background: #f0f2f8; color: #6c757d; }
.camp-status.running  { background: rgba(244,161,0,.15); color: #b37a00; }
.camp-status.completed{ background: rgba(6,194,112,.12); color: #029a59; }

/* ── Posts grid layout ── */
.posts-grid {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 860px) {
  .posts-grid { grid-template-columns: 1fr; }
}

/* ── Group list items ── */
.group-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.group-item:last-child { border-bottom: none; }
.group-item:hover { background: var(--bg); }

/* ── Check tags (checkbox pills) ── */
.check-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: .83rem;
  transition: all .15s;
  user-select: none;
  margin-bottom: 4px;
}
.check-tag:hover { border-color: var(--primary); color: var(--primary); }
.check-tag input { display: none; }
.check-tag:has(input:checked) {
  border-color: var(--primary);
  background: rgba(102,126,234,.1);
  color: var(--primary);
  font-weight: 600;
}

/* ── Radio options ── */
.radio-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .88rem;
  cursor: pointer;
}

/* ── Image URL rows ── */
.image-url-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.image-url-row input { flex: 1; }

/* ── Target section label ── */
.target-section-label {
  width: 100%;
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .05em;
  margin-bottom: 6px;
}

/* ── Post cards ── */
.post-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.post-content {
  font-size: .88rem;
  line-height: 1.55;
  margin: 8px 0;
  white-space: pre-wrap;
  max-height: 80px;
  overflow: hidden;
}
.post-status.draft     { background: #f0f2f8; color: #6c757d; }
.post-status.scheduled { background: rgba(23,162,184,.12); color: #0c5460; }
.post-status.published { background: rgba(6,194,112,.12);  color: #029a59; }
.post-status.daily     { background: rgba(102,126,234,.13); color: #5a67d8; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--card);
  border-radius: 12px;
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 2px 6px;
}
.modal-close:hover { color: var(--danger); }
.modal-body   { padding: 18px 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-msg {
  min-width: 260px;
  padding: 12px 16px;
  border-radius: 9px;
  color: #fff;
  font-size: .87rem;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  animation: slideIn .25s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast-msg.success { background: var(--success); }
.toast-msg.error   { background: var(--danger); }
.toast-msg.info    { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pulse-green { 0%,100% { box-shadow: 0 0 0 2px #bbf7d0; } 50% { box-shadow: 0 0 0 5px #4ade8044; } }

/* ── Log table ── */
.log-row.success td:nth-child(2) { color: var(--success); font-weight: 700; }
.log-row.error   td:nth-child(2) { color: var(--danger);  font-weight: 700; }

/* ── Sticky action column ── */
table thead th:last-child,
table tbody td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  box-shadow: -3px 0 6px rgba(0,0,0,.06);
}
table thead th:last-child { background: #f6f8fd; z-index: 3; }
table tbody td:last-child { background: var(--card); }
tbody tr:hover td:last-child { background: #f8f9ff; }

/* ── Misc ── */
.empty-state { text-align: center; padding: 40px 0; color: var(--muted); font-size: .9rem; }
.empty-state i { font-size: 2.5rem; margin-bottom: 10px; opacity: .4; display: block; }
.fw-bold { font-weight: 700; }
.text-muted { color: var(--muted); }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.d-none { display: none !important; }
.gap-2 { gap: 8px; }
.keywords-input-row { display: flex; gap: 6px; margin-top: 4px; }
.keywords-input-row input { flex: 1; }
.keyword-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.keyword-tag {
  background: rgba(67,97,238,.1);
  color: var(--primary);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: .75rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.keyword-tag button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: .8rem;
  padding: 0;
  line-height: 1;
  opacity: .7;
}
.keyword-tag button:hover { opacity: 1; }

/* ── Chatbot Groups ── */
.group-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.group-card-body { flex: 1; min-width: 0; }
.group-card-name { font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.group-card-meta { font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.group-card-pages { display: flex; flex-wrap: wrap; gap: 4px; }
.group-page-tag {
  background: rgba(67,97,238,.08);
  color: var(--primary);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: .75rem;
}
.group-card-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Filter bar */
#rule-group-filter .btn { border-radius: 20px; padding: 3px 14px; font-size: .8rem; }
#rule-group-filter .filter-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* FAQ items trong group modal */
.g-faq-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 7px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.g-faq-item-body { flex: 1; min-width: 0; }
.g-faq-q { font-size: .83rem; font-weight: 600; margin-bottom: 3px; }
.g-faq-a { font-size: .8rem; color: var(--muted); }
.g-faq-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Page checkboxes trong group modal */
.page-checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: .82rem;
  transition: border-color .15s;
}
.page-checkbox-item:hover { border-color: var(--primary); }
.page-checkbox-item input[type=checkbox] { accent-color: var(--primary); }

/* ── Video Upload ── */
.video-upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--bg);
  font-size: .88rem;
  color: var(--muted);
}
.video-upload-zone:hover, .video-upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(102, 126, 234, .06);
  color: var(--text);
}
.video-preview { margin-top: 10px; }

.platform-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: .85rem;
  transition: border-color .2s, background .2s;
  user-select: none;
}
.platform-toggle:has(input:checked) {
  border-color: var(--primary);
  background: rgba(102, 126, 234, .08);
}
.platform-toggle input[type=checkbox] { accent-color: var(--primary); }
.platform-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 5px;
  font-size: .75rem;
  color: #fff;
}
.platform-icon.fb { background: #1877F2; }
.platform-icon.tt { background: #000; }
.platform-icon.yt { background: #ff0000; }

.account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.account-item:last-child { border-bottom: none; }
