/* ============================================================
   Haxmax Vgen — UI (Nền tảng + Cài đặt)
   Thuần CSS, hỗ trợ Light/Dark theme qua [data-theme]
   ============================================================ */

:root {
  --bg:            #f4f5f7;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --border:        #e6e8ec;
  --border-strong: #d7dae0;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --text-subtle:   #94a3b8;
  --primary:       #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft:  #eef2ff;
  --green:         #16a34a;
  --green-soft:    #dcfce7;
  --red:           #dc2626;
  --red-soft:      #fee2e2;
  --amber:         #b45309;
  --amber-soft:    #fef3c7;
  --shadow-sm:     0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-md:     0 4px 14px rgba(15, 23, 42, .08);
  --radius:        14px;
  --sidebar-w:     232px;
}

[data-theme="dark"] {
  --bg:            #0b1120;
  --surface:       #111827;
  --surface-2:     #0f172a;
  --border:        #1f2937;
  --border-strong: #2b3646;
  --text:          #e5e7eb;
  --text-muted:    #94a3b8;
  --text-subtle:   #64748b;
  --primary:       #6366f1;
  --primary-hover: #818cf8;
  --primary-soft:  #1e1b4b;
  --green:         #4ade80;
  --green-soft:    #14532d;
  --red:           #f87171;
  --red-soft:      #450a0a;
  --amber:         #fbbf24;
  --amber-soft:    #422006;
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md:     0 6px 20px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===================== LAYOUT ===================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  font-weight: 700;
}
.brand-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .18);
  transition: transform .3s cubic-bezier(.2, .7, .3, 1);
  flex: none;
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand:hover .brand-logo { transform: scale(1.08); }
.brand-name { font-size: 19px; color: var(--text); }
.brand-accent { color: var(--primary); }

.menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background .15s, color .15s;
  font-family: inherit;
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.active { background: var(--primary-soft); color: var(--primary); }
.menu-item svg { flex: none; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-subtle);
  border-top: 1px solid var(--border);
}
.social { display: flex; gap: 10px; }
.social-link { color: var(--text-subtle); display: inline-flex; transition: color .15s; }
.social-link:hover { color: var(--primary); }

/* ===================== TOPBAR ===================== */
.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 62px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.agent-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12.5px;
  font-weight: 600;
}
.agent-pill.off { background: var(--surface-2); color: var(--text-subtle); }
.agent-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 25%, transparent);
}

.lang-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.lang-btn {
  display: inline-flex;
  padding: 3px 6px;
  border: none;
  background: transparent;
  border-radius: 7px;
  cursor: pointer;
  opacity: .5;
  transition: opacity .15s, background .15s;
  line-height: 0;
}
.lang-btn svg { border-radius: 3px; display: block; }
.lang-btn:hover { opacity: .85; }
.lang-btn.active { opacity: 1; background: var(--surface); box-shadow: var(--shadow-sm); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun  { display: block; }

.user-email {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  background-size: 160% 160%;
  background-position: 0% 50%;
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 32%, transparent);
  transition: background-position .35s ease, box-shadow .2s, transform .08s;
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  background-size: 160% 160%;
  background-position: 100% 50%;
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 45%, transparent);
  transform: translateY(-1px);
}

.btn-outline { background: var(--surface); }

.btn-danger-soft {
  background: var(--red-soft);
  border-color: transparent;
  color: var(--red);
}
.btn-danger-soft:hover { background: color-mix(in srgb, var(--red-soft) 80%, var(--red) 8%); }

.btn-mini { padding: 6px 10px; font-size: 12.5px; }

/* ===================== CONTENT / PAGE ===================== */
.content { padding: 28px 32px 48px; }
.page { max-width: 940px; margin: 0 auto; }
.page[hidden] { display: none; }

.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.page-icon {
  display: grid; place-items: center;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  flex: none;
}
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.3px; }
.page-head p { margin: 3px 0 0; color: var(--text-muted); font-size: 14px; }

/* ===================== TABS ===================== */
.tabs {
  display: flex;
  gap: 26px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.tab {
  position: relative;
  padding: 12px 2px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===================== PLATFORM CARD ===================== */
.platform-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.platform-head { display: flex; align-items: flex-start; gap: 14px; }
.platform-icon {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  flex: none;
}
.platform-icon svg { display: block; }
.platform-titles { flex: 1; min-width: 0; }
.platform-titles h3 { margin: 0 0 3px; font-size: 16px; font-weight: 700; }
.platform-titles p { margin: 0; color: var(--text-muted); font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green  { background: var(--green-soft);  color: var(--green); }
.badge-indigo { background: var(--primary-soft); color: var(--primary); }
.badge.mini { padding: 2px 8px; font-size: 11px; }

.app-section { margin-top: 18px; }
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  color: var(--text-subtle);
  margin-bottom: 10px;
}

.app-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.app-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  flex-wrap: wrap;
}
.app-name { font-weight: 600; font-size: 14px; }
.app-meta {
  color: var(--text-subtle);
  font-size: 12px;
  margin-top: 2px;
  word-break: break-all;
}
.app-actions { display: flex; gap: 8px; flex: none; }

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.account-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  flex: none;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.account-name { font-weight: 600; font-size: 13.5px; }
.account-meta { color: var(--text-subtle); font-size: 12px; margin-top: 1px; }

.card-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ===================== CHANNELS TABLE ===================== */
.table-wrap { overflow-x: auto; }
.channels-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 620px;
}
.channels-table th {
  text-align: left;
  padding: 10px 14px;
  color: var(--text-subtle);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.channels-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.channels-table tr:last-child td { border-bottom: none; }
.cell-name { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.pf-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.fb-chip { background: rgba(24,119,242,.12); color: #1877f2; }
.yt-chip { background: rgba(255,0,0,.10); color: #e11d1d; }

/* ===================== SETTINGS ===================== */
.setting-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}
.setting-head {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 18px 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
}
.setting-head.static { cursor: default; }
.setting-icon {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 11px;
  flex: none;
}
.soft-indigo { background: var(--primary-soft); color: var(--primary); }
.soft-red    { background: var(--red-soft);     color: var(--red); }
.soft-green  { background: var(--green-soft);   color: var(--green); }

.setting-titles { flex: 1; min-width: 0; }
.setting-title {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.setting-desc { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.chevron { color: var(--text-subtle); flex: none; transition: transform .2s; }
.setting-card.open .chevron { transform: rotate(180deg); }

.info-list { border-top: 1px solid var(--border); }
.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13.5px;
}
.info-row:last-child { border-bottom: none; }
.info-val { color: var(--text); font-weight: 600; }
.info-yes { color: var(--green); }

.setting-body { display: none; padding: 4px 20px 20px; border-top: 1px solid var(--border); }
.setting-card.open .setting-body { display: block; }

.form-grid { display: grid; gap: 14px; margin-top: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-muted); }
.form-grid input,
.form-grid select,
.form-grid textarea {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-grid textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
.form-grid select { cursor: pointer; }
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ===================== TÌM NGÁCH ===================== */
.btn.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* Trang Tìm ngách rộng hơn để xếp 3-4 thẻ/dòng, giảm khoảng trắng 2 bên */
#page-niche { max-width: 1400px; }
/* Phan canh: the canh nhieu o chu -> tan dung het be ngang, khong de trong hai ben */
#page-scripts { max-width: 1600px; }

.niche-explore {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); margin-bottom: 18px;
}
.niche-explore-row { display: flex; flex-wrap: wrap; gap: 14px; }
.niche-sel { flex: 0 0 240px; }
.niche-explore label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-muted); }
.niche-explore input, .niche-explore select {
  padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.niche-explore select { cursor: pointer; }
.niche-explore input:focus, .niche-explore select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.niche-explore-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.niche-notice { font-size: 13px; font-weight: 500; border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; }
.niche-notice.ok   { background: var(--green-soft); color: var(--green); }
.niche-notice.warn { background: var(--amber-soft); color: var(--amber); }

.niche-src { margin-top: -2px; }

.niche-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.niche-card {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.niche-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.niche-titles h3 { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.3; }
.niche-subs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.niche-sub {
  font-size: 11.5px; font-weight: 500; color: var(--primary);
  background: var(--primary-soft); border-radius: 20px; padding: 3px 9px;
}
.niche-score { flex: none; text-align: center; min-width: 58px; }
.niche-score-num {
  font-size: 26px; font-weight: 800; line-height: 1; color: var(--primary);
}
.niche-score-lbl { font-size: 10.5px; color: var(--text-subtle); margin-top: 3px; }

.niche-flags { display: flex; flex-wrap: wrap; gap: 6px; }
.niche-flag { font-size: 11.5px; font-weight: 600; border-radius: 7px; padding: 4px 8px; white-space: nowrap; }
.niche-flag.ok   { background: var(--green-soft); color: var(--green); }
.niche-flag.warn { background: var(--amber-soft); color: var(--amber); }
.niche-flag.mid  { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.niche-desc { font-size: 13.5px; line-height: 1.55; color: var(--text-muted); }
.niche-note { font-size: 12.5px; line-height: 1.5; color: var(--text-subtle); }
.niche-note b { color: var(--text-muted); font-weight: 600; }

.niche-bars { display: flex; flex-direction: column; gap: 7px; }
.niche-bar { display: grid; grid-template-columns: 92px 1fr 22px; align-items: center; gap: 8px; }
.niche-bar-lbl { font-size: 12px; color: var(--text-muted); }
.niche-bar-track { height: 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.niche-bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 6px; }
.niche-bar-val { font-size: 12px; font-weight: 700; color: var(--text); text-align: right; }

.niche-money { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.niche-cpm {
  font-size: 12px; font-weight: 700; color: var(--green);
  background: var(--green-soft); border-radius: 7px; padding: 4px 9px;
}
.niche-monet { font-size: 12.5px; color: var(--text-muted); }

.niche-ideas { border-top: 1px solid var(--border); padding-top: 10px; }
.niche-ideas summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--primary); list-style: none;
}
.niche-ideas summary::-webkit-details-marker { display: none; }
.niche-ideas summary::before { content: "▸ "; }
.niche-ideas[open] summary::before { content: "▾ "; }
.niche-idea-list { margin: 10px 0 2px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.niche-idea-list li { font-size: 13px; line-height: 1.5; color: var(--text-muted); }

.niche-card-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: auto; }
.niche-save.is-saved { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ----- Đào sâu (detail) ----- */
.niche-detail-loading {
  margin-top: 20px; padding: 40px 24px; text-align: center;
  font-size: 14px; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
}
.detail-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 18px 0 6px; }
.detail-head h2 { font-size: 22px; font-weight: 800; color: var(--text); }
.detail-score { font-size: 13px; font-weight: 700; color: var(--primary); background: var(--primary-soft); border-radius: 20px; padding: 4px 12px; }
.detail-sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-top: 16px; box-shadow: var(--shadow-sm); }
.detail-sec-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.detail-text { font-size: 14px; line-height: 1.65; color: var(--text-muted); }
.detail-muted { font-size: 13.5px; color: var(--text-subtle); }
.detail-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.detail-chip { font-size: 12.5px; font-weight: 600; color: var(--primary); background: var(--primary-soft); border-radius: 8px; padding: 5px 10px; }
.detail-list { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.detail-list li { font-size: 14px; line-height: 1.55; color: var(--text-muted); }

.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.comp-card { border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px; background: var(--surface-2); }
.comp-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comp-stats { display: flex; gap: 14px; }
.comp-stat { display: flex; flex-direction: column; }
.comp-stat-v { font-size: 15px; font-weight: 800; color: var(--primary); }
.comp-stat-l { font-size: 10.5px; color: var(--text-subtle); }

.pillar { border: 1px solid var(--border); border-radius: 11px; margin-top: 10px; background: var(--surface-2); }
.pillar summary { cursor: pointer; font-size: 14px; font-weight: 700; color: var(--text); padding: 12px 14px; list-style: none; }
.pillar summary::-webkit-details-marker { display: none; }
.pillar summary::before { content: "▸ "; color: var(--primary); }
.pillar[open] summary::before { content: "▾ "; }
.pillar-vids { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 12px; }
.vid { border-top: 1px solid var(--border); padding-top: 10px; }
.vid-title { font-size: 13.5px; font-weight: 600; color: var(--text); line-height: 1.45; }
.vid-line { font-size: 12.5px; line-height: 1.5; color: var(--text-muted); margin-top: 3px; }
.vid-line b { color: var(--text); font-weight: 600; }
.vid-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.vid-script { margin-top: 0; }
.vid-marks { display: flex; gap: 6px; flex-wrap: wrap; }
.vid-mark { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-subtle); cursor: pointer; transition: all .12s; }
.vid-mark:hover { border-color: var(--border-strong); }
.vid-mark.on { background: #16a34a; border-color: #16a34a; color: #fff; font-weight: 600; }
.plan-more { margin-top: 14px; }

/* ----- Tab Đã lưu + So sánh ----- */
.tab-count { display: inline-block; min-width: 18px; padding: 0 5px; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; border-radius: 9px; background: var(--primary-soft); color: var(--primary); }
.niche-saved-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.niche-saved-hint { font-size: 13px; color: var(--text-muted); }
.niche-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.niche-check input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.niche-empty-msg { grid-column: 1 / -1; padding: 40px 24px; text-align: center; font-size: 14px; color: var(--text-subtle); border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.detail-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.compare-wrap { overflow-x: auto; margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius); }
.compare-table { border-collapse: collapse; width: 100%; min-width: 480px; font-size: 13.5px; }
.compare-table th, .compare-table td { padding: 10px 14px; text-align: center; border-bottom: 1px solid var(--border); }
.compare-table thead th { background: var(--surface-2); font-weight: 700; color: var(--text); }
.compare-table th.cmp-metric, .compare-table td.cmp-metric { text-align: left; font-weight: 600; color: var(--text-muted); background: var(--surface-2); position: sticky; left: 0; }
.compare-table td { color: var(--text); }
.compare-table td.cmp-best { background: var(--green-soft); color: var(--green); font-weight: 700; }

@media (max-width: 640px) {
  .niche-sel { flex: 1 1 100%; }
  .niche-grid { grid-template-columns: 1fr; }
  .comp-grid { grid-template-columns: 1fr 1fr; }
}

/* ===================== KỊCH BẢN ===================== */
.script-item { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin-bottom: 12px; box-shadow: var(--shadow-sm); overflow: hidden; }
.script-item-sum { cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; list-style: none; }
.script-item-sum::-webkit-details-marker { display: none; }
.script-item-sum::before { content: "▸"; color: var(--primary); font-weight: 700; flex: none; }
.script-item[open] .script-item-sum::before { content: "▾"; }
.script-item-title { flex: 1; font-size: 14.5px; font-weight: 700; color: var(--text); line-height: 1.4; }
.script-item-meta { font-size: 12px; color: var(--text-subtle); white-space: nowrap; }
.script-item-actions { display: flex; gap: 8px; padding: 0 16px 12px; }
.script-item-body {
  margin: 0; padding: 16px; border-top: 1px solid var(--border); background: var(--surface-2);
  max-height: 480px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 13.5px; line-height: 1.6; color: var(--text);
}
/* Caption dang bai theo nen tang */
.script-caps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--border); background: var(--surface); }
@media (max-width: 720px) { .script-caps { grid-template-columns: 1fr; } }
.script-cap { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.script-cap-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.script-cap-name { font-size: 12.5px; font-weight: 700; color: var(--text-subtle); }
.script-cap-body { margin: 0; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 13px; line-height: 1.55; color: var(--text); }
.script-gen { padding: 4px 20px 20px; }
.script-output { margin-top: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.script-output-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.script-output-title { font-size: 13px; font-weight: 700; color: var(--text); }
.script-model { font-size: 11.5px; font-weight: 500; color: var(--text-muted); margin-left: 6px; }
.script-output-body {
  margin: 0; padding: 16px 18px; max-height: 520px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 14px; line-height: 1.65; color: var(--text);
}
@media (max-width: 640px) { .script-gen { padding: 4px 16px 18px; } }

/* ===================== PHÂN CẢNH (storyboard) ===================== */
.btn.btn-xs { padding: 3px 8px; font-size: 12px; line-height: 1.2; }
.sb-title { font-size: 19px; font-weight: 800; color: var(--text); margin: 12px 0 4px; }
.sb-setrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 16px; }
.sb-hint { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.sb-select { padding: 7px 10px; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; outline: none; max-width: 100%; }
.sb-select:focus { border-color: var(--primary); }
.sb-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0; }
.sb-count { margin-left: auto; font-size: 12.5px; color: var(--text-subtle); }
.sb-count-warn { color: #d97706; font-weight: 600; }
.sb-buildhint { font-size: 12.5px; line-height: 1.5; color: var(--text-muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; margin: 0 0 14px; }
.sb-scenes { display: flex; flex-direction: column; gap: 12px; }
.sb-card { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.sb-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.sb-idx { font-size: 12.5px; font-weight: 800; color: var(--primary); }
.sb-card-ctrl { display: flex; gap: 6px; }
.sb-card-body { display: flex; gap: 14px; padding: 14px; }
.sb-card-pose { flex: none; width: 128px; display: flex; flex-direction: column; gap: 8px; }
.sb-pose-thumb { width: 128px; height: 128px; border-radius: 10px; border: 1px solid var(--border); background: repeating-conic-gradient(#e9edf3 0% 25%, #f6f8fb 0% 50%) 50% / 14px 14px; display: grid; place-items: center; overflow: hidden; }
[data-theme="dark"] .sb-pose-thumb { background: repeating-conic-gradient(#232c3a 0% 25%, #1a2130 0% 50%) 50% / 14px 14px; }
.sb-pose-thumb img { width: 100%; height: 100%; object-fit: contain; }
.sb-pose-none { font-size: 26px; color: var(--text-subtle); }
.sb-pose-sel { width: 128px; box-sizing: border-box; }
.sb-card-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.sb-field { display: flex; flex-direction: column; gap: 4px; }
/* Ten kenh — hang gon o khu dung video */
.sb-brandbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; margin: 0 0 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.sb-brandbar-lbl { font-size: 12.5px; font-weight: 700; color: var(--text-subtle); }
.sb-brandbar .sb-inp { width: auto; flex: 1; min-width: 160px; }
.sb-brandbar-msg { font-size: 12px; color: var(--text-muted); min-width: 56px; }
/* --- Thu gon canh: giau ruot, chi chua dong tom tat -> khoi cuon mai --- */
.sb-card.is-collapsed > *:not(.sb-card-top) { display: none; }
.sb-card.is-collapsed .sb-sum { display: flex; }
.sb-sum { display: none; align-items: center; gap: 8px; min-width: 0; flex: 1; font-size: 12.5px; color: var(--text-muted); }
.sb-sum-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-sum-tag { flex: none; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text-subtle); }
/* Cac o chu cua template: xep 2 cot cho do dai — man rong con nhieu cho */
.sb-gfx-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.sb-gfx-form .sb-field:has(textarea) { grid-column: 1 / -1; }
@media (max-width: 900px) { .sb-gfx-form { grid-template-columns: 1fr; } }
.sb-flabel { font-size: 11.5px; font-weight: 700; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .03em; }
.sb-narr, .sb-inp { width: 100%; box-sizing: border-box; padding: 9px 11px; font-size: 13.5px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; outline: none; font-family: inherit; }
.sb-narr { resize: vertical; line-height: 1.5; min-height: 62px; }
.sb-narr:focus, .sb-inp:focus { border-color: var(--primary); background: var(--surface); }
.sb-videobox { margin: 4px 0 18px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.sb-videobox-title { font-size: 14px; font-weight: 800; color: var(--text); }
.sb-video { width: 100%; max-width: 300px; aspect-ratio: 9 / 16; background: #000; border-radius: 10px; display: block; }
.sb-prop { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface-2); }
.sb-prop-thumb { width: 46px; height: 46px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); background: repeating-conic-gradient(#e9edf3 0% 25%, #f6f8fb 0% 50%) 50% / 10px 10px; }
[data-theme="dark"] .sb-prop-thumb { background: repeating-conic-gradient(#232c3a 0% 25%, #1a2130 0% 50%) 50% / 10px 10px; }
.sb-prop-hint { font-size: 12px; color: var(--text-subtle); }
.sb-graphic { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface-2); }
.sb-graphic-tag { font-size: 12px; font-weight: 800; color: #17a884; }
.sb-graphic-info { font-size: 12.5px; font-weight: 600; color: var(--text); }
.sb-gfx-editor { padding: 12px 14px; border-top: 1px solid var(--border); background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; }
.sb-gfx-actions { display: flex; gap: 8px; margin-top: 2px; }
.sb-audio { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface-2); }
.sb-audio-player { height: 34px; max-width: 260px; }
.sb-audio-stale { font-size: 12px; font-weight: 600; color: #d97706; }
[data-theme="dark"] .sb-audio-stale { color: #fbbf24; }
@media (max-width: 640px) {
  .sb-card-body { flex-direction: column; }
  .sb-card-pose, .sb-pose-thumb, .sb-pose-sel { width: 100%; }
  .sb-pose-thumb { height: 200px; }
  .sb-audio-player { max-width: 100%; flex: 1; }
}

/* ===================== MASCOT ===================== */
.mascot-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.mascot-topbar-hint { font-size: 14px; font-weight: 600; color: var(--text); }
.mascot-set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.mascot-set-card { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow-sm); }
.mascot-set-cover { width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; border: 1px solid var(--border); background: repeating-conic-gradient(#e9edf3 0% 25%, #f6f8fb 0% 50%) 50% / 16px 16px; display: grid; place-items: center; overflow: hidden; }
[data-theme="dark"] .mascot-set-cover { background: repeating-conic-gradient(#232c3a 0% 25%, #1a2130 0% 50%) 50% / 16px 16px; }
.mascot-set-cover img { width: 100%; height: 100%; object-fit: contain; }
.mascot-set-cover .mascot-pose-empty { font-size: 34px; }
.mascot-set-name { font-size: 15px; font-weight: 700; color: var(--text); }
.mascot-set-count { font-size: 12px; color: var(--text-subtle); }
.mascot-set-actions { display: flex; gap: 8px; margin-top: 4px; }
.mascot-set-actions .btn { flex: 1; justify-content: center; }
.mascot-set-actions .btn:last-child { flex: 0 0 auto; }
.mascot-set-head { display: flex; align-items: center; gap: 12px; margin: 14px 0 12px; }
.mascot-set-title { font-size: 20px; font-weight: 800; color: var(--text); }
.mascot-card label.btn { cursor: pointer; width: 100%; justify-content: center; }
.mascot-card > .btn { width: 100%; justify-content: center; }
.mascot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.mascot-card { display: flex; flex-direction: column; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; box-shadow: var(--shadow-sm); }
.mascot-pose-box { width: 100%; aspect-ratio: 1 / 1; border-radius: 10px; border: 1px solid var(--border); background: repeating-conic-gradient(#e9edf3 0% 25%, #f6f8fb 0% 50%) 50% / 16px 16px; display: grid; place-items: center; overflow: hidden; }
[data-theme="dark"] .mascot-pose-box { background: repeating-conic-gradient(#232c3a 0% 25%, #1a2130 0% 50%) 50% / 16px 16px; }
.mascot-pose-box img { width: 100%; height: 100%; object-fit: contain; }
.mascot-pose-empty { font-size: 22px; color: var(--text-subtle); }
.mascot-pose-label { font-size: 12.5px; font-weight: 600; color: var(--text); text-align: center; }
@media (max-width: 640px) { .mascot-grid { grid-template-columns: 1fr 1fr; } }
.mascot-modal-ov { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: grid; place-items: center; z-index: 1000; padding: 20px; }
.mascot-modal { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 16px 48px rgba(0,0,0,.28); padding: 18px; }
.mascot-modal-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.mascot-modal-input { width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 14px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 9px; outline: none; }
.mascot-modal-input:focus { border-color: var(--primary); }
.mascot-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ===================== TOAST ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--surface);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===================== MOBILE DRAWER (hidden on desktop) ===================== */
.topbar-left { display: none; align-items: center; gap: 10px; min-width: 0; }
.topbar-brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.menu-toggle { display: none; }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, visibility .25s;
  z-index: 35;
}
.backdrop.show { opacity: 1; visibility: visible; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }

  /* Sidebar -> off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 40;
    width: min(82vw, var(--sidebar-w));
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  body.drawer-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-md); }
  body.drawer-open { overflow: hidden; }

  /* Topbar */
  .topbar { padding: 0 12px; justify-content: space-between; gap: 8px; }
  .topbar-left { display: flex; }
  .menu-toggle { display: inline-grid; }
  .topbar-right { gap: 8px; min-width: 0; }
  .user-email { display: none; }
  .agent-pill span:last-child { display: none; }

  .content { padding: 20px 16px 40px; }
  .page { max-width: 100%; }
}

@media (max-width: 560px) {
  /* Topbar compaction — trạng thái Agent đã thể hiện qua màu nút bật/tắt */
  .agent-pill { display: none; }
  .topbar-brand { display: none; }
  .topbar .btn span { display: none; }
  .topbar .btn { padding: 9px; }
  .icon-btn { width: 40px; height: 40px; }

  /* Headings & cards gọn hơn */
  .page-head { gap: 12px; margin-bottom: 18px; }
  .page-icon { width: 46px; height: 46px; border-radius: 12px; }
  .page-head h1 { font-size: 20px; }
  .page-head p { font-size: 13px; }
  .platform-card { padding: 16px; }
  .setting-head { padding: 16px; }
  .setting-body { padding: 4px 16px 18px; }
  .info-row { padding: 13px 16px; gap: 10px; }
  .info-val { text-align: right; word-break: break-word; }

  /* App action buttons xuống hàng, không tràn */
  .app-card-head { flex-direction: column; align-items: stretch; }
  .app-actions { width: 100%; flex-wrap: wrap; }
  .card-footer .btn { flex: 1; justify-content: center; }

  /* Bảng "Danh sách kênh" -> thẻ xếp dọc */
  .channels-table { min-width: 0; }
  .channels-table thead { display: none; }
  .channels-table tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 2px;
    margin-bottom: 12px;
    background: var(--surface-2);
  }
  .channels-table tr:last-child { margin-bottom: 0; }
  .channels-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 14px;
    border: none;
  }
  .channels-table td::before {
    content: attr(data-label);
    color: var(--text-subtle);
    font-size: 12px;
    font-weight: 600;
  }
  .channels-table td:first-child {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
  }
  .channels-table td:first-child::before { display: none; }
}

/* ===================== LIVELY: MÀU & CHUYỂN ĐỘNG ===================== */
@keyframes shimmer  { to { background-position: 200% center; } }
@keyframes logoGrad { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes rise     { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulseDot {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px color-mix(in srgb, var(--green) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 0%, transparent); }
}

/* Brand: chữ gradient chuyển động */
.brand-name, .topbar-brand {
  color: var(--primary);
  background: linear-gradient(90deg, #6366f1 0%, #22d3ee 28%, #a855f7 55%, #6366f1 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 5s linear infinite;
}

/* Menu: nhích nhẹ khi hover */
.menu-item { transition: background .15s, color .15s, transform .15s; }
.menu-item:hover { transform: translateX(3px); }

/* Icon buttons: nút theme xoay, hamburger phóng nhẹ khi hover */
.icon-btn svg { transition: transform .35s cubic-bezier(.2, .7, .3, 1); }
#themeToggle:hover svg { transform: rotate(25deg) scale(1.08); }
.menu-toggle:hover svg { transform: scale(1.12); }

/* Chấm "Agent đang chạy" + badge kết nối: nhấp nháy như tín hiệu live */
.agent-pill:not(.off) .agent-dot { animation: pulseDot 2s ease-out infinite; }
.badge-green .dot { animation: pulseDot 2.6s ease-out infinite; }

/* Card: xuất hiện mượt (stagger) + nhấc lên khi hover */
.platform-card, .setting-card { animation: rise .5s cubic-bezier(.2, .7, .3, 1) backwards; }
.platform-card { transition: transform .25s cubic-bezier(.2, .7, .3, 1), box-shadow .25s; }
.platform-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.setting-card { transition: box-shadow .25s, transform .25s; }
.setting-card:hover { box-shadow: var(--shadow-md); }
.platform-card:nth-of-type(1), .setting-card:nth-of-type(1) { animation-delay: .02s; }
.platform-card:nth-of-type(2), .setting-card:nth-of-type(2) { animation-delay: .10s; }
.setting-card:nth-of-type(3) { animation-delay: .17s; }
.setting-card:nth-of-type(4) { animation-delay: .24s; }
.setting-card:nth-of-type(5) { animation-delay: .31s; }

/* Icon nền tảng: phóng nhẹ khi hover card */
.platform-icon { transition: transform .3s cubic-bezier(.2, .7, .3, 1); }
.platform-card:hover .platform-icon { transform: scale(1.1) rotate(-5deg); }

/* Tôn trọng người dùng tắt hiệu ứng chuyển động */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ===================== LOGIN ===================== */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 560px at 100% -10%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 60%),
    radial-gradient(900px 460px at -10% 110%, rgba(34, 211, 238, .16), transparent 60%),
    var(--bg);
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise .5s cubic-bezier(.2, .7, .3, 1) backwards;
}
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}
.login-brand .brand-name { font-size: 26px; font-weight: 700; }
.login-logo {
  width: 52px; height: 52px;
  border-radius: 13px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .18);
  flex: none;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.login-title { margin: 4px 0 0; font-size: 22px; font-weight: 700; text-align: center; }
.login-sub { margin: 0 0 6px; color: var(--text-muted); font-size: 13.5px; text-align: center; }
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.login-field input {
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.login-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: none;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  border-radius: 8px;
}
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.login-error {
  background: var(--red-soft);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
}
.login-submit { justify-content: center; padding: 12px; font-size: 14.5px; margin-top: 4px; }
.login-submit:disabled { opacity: .7; cursor: default; }

/* Thong bao trong Cai dat (doi mat khau...) */
.setting-msg {
  margin-top: 14px;
  padding: 10px 13px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
}
.setting-msg.ok  { background: var(--green-soft); color: var(--green); }
.setting-msg.err { background: var(--red-soft);   color: var(--red); }

/* badge co the an/hien theo trang thai (dua tren thuoc tinh hidden) */
.badge[hidden] { display: none; }

/* Danh sach model kham pha duoc */
.model-list-title { margin-top: 14px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.model-list {
  margin-top: 8px;
  max-height: 170px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.model-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}

/* Gan model cho tac vu */
.model-assign {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.model-assign-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 10px; }

.eleven-preview { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }
.eleven-preview-textlbl { display: block; margin-bottom: 10px; }
.eleven-preview-textlbl span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.eleven-preview-textlbl input { width: 100%; box-sizing: border-box; padding: 9px 11px; font-size: 13.5px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px; outline: none; }
.eleven-preview-textlbl input:focus { border-color: var(--primary); }
.eleven-preview-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.eleven-preview-hint { font-size: 12.5px; color: var(--text-subtle); }
#elevenPreviewAudio { margin-top: 12px; width: 100%; max-width: 360px; height: 38px; display: block; }

/* Nền tảng: trạng thái rỗng + form thêm App */
.app-empty {
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  color: var(--text-muted);
  font-size: 13.5px;
  text-align: center;
}
.app-form {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: var(--surface-2);
  margin-top: 4px;
}

/* Danh sách kênh: lưới thẻ */
.channels-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
#channelsCount { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
/* Tab Thống kê — theo mẫu bài đăng */
.stats-head { margin-bottom: 16px; }
.stats-head h2 { font-size: 19px; font-weight: 800; color: var(--text); margin: 0 0 3px; }
.stats-head p { font-size: 13px; color: var(--text-muted); margin: 0; }
.stats-toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.stats-toolbar-right { display: flex; gap: 10px; align-items: center; }
.stats-sort { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stats-sort-lbl { font-size: 13px; color: var(--text-muted); margin-right: 2px; }
.stats-sort .pill { font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; }
.stats-sort .pill:hover { border-color: var(--border-strong); }
.stats-sort .pill.active { background: var(--text); color: var(--surface); border-color: var(--text); font-weight: 600; }
.stats-toolbar .sb-select { min-width: 180px; }
.stats-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 640px) { .stats-summary { grid-template-columns: repeat(2, 1fr); } }
.stats-kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; text-align: center; }
.stats-kpi-num { font-size: 24px; font-weight: 800; color: var(--text); }
.stats-kpi-lbl { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stats-list { display: flex; flex-direction: column; gap: 12px; }
.stats-row { display: flex; align-items: center; gap: 18px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; transition: border-color .15s, box-shadow .15s; }
.stats-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.stats-main { flex: 1; min-width: 0; }
.stats-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; }
.stats-pill { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 6px; }
.stats-pill-yt { color: #d90000; background: rgba(255,0,0,.10); }
.stats-pill-fb { color: #1877F2; background: rgba(24,119,242,.12); }
.stats-date { font-size: 12.5px; color: var(--text-muted); }
.stats-ch { font-size: 12.5px; color: var(--text-subtle); }
.stats-title { font-size: 15px; font-weight: 700; color: var(--text); }
.stats-extra { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stats-link { display: inline-block; font-size: 12.5px; color: var(--primary); text-decoration: none; margin-top: 5px; }
.stats-link:hover { text-decoration: underline; }
.stats-badge { display: inline-block; font-size: 10px; font-weight: 700; color: #fff; background: #f43f5e; border-radius: 5px; padding: 1px 5px; margin-left: 6px; vertical-align: middle; }
.plat-logo { display: inline-flex; align-items: center; }
.plat-logo svg { display: block; }
.stats-plat { margin-right: 6px; vertical-align: middle; }
/* Dropdown tùy biến (có logo nền tảng thật) */
.cds { position: relative; min-width: 220px; }
.cds-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; cursor: pointer; text-align: left; }
.cds-btn:hover { border-color: var(--primary); }
.cds-cur { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.cds-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cds-chev { flex: none; color: var(--text-subtle); }
.cds-all { font-size: 16px; line-height: 1; }
.cds-menu { position: absolute; top: calc(100% + 4px); left: 0; min-width: 100%; max-height: 340px; overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.16); z-index: 30; padding: 5px; }
.cds-opt { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; font-size: 13px; color: var(--text); background: none; border: 0; border-radius: 7px; cursor: pointer; text-align: left; }
.cds-opt:hover { background: var(--surface-2); }
.cds-opt.sel { background: var(--primary-soft, rgba(99,102,241,.12)); font-weight: 600; }
.cds-group { display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-subtle); }
.stats-date { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.stats-metrics { flex: none; display: flex; gap: 22px; }
@media (max-width: 640px) { .stats-row { flex-direction: column; align-items: stretch; } .stats-metrics { gap: 16px; justify-content: space-between; } }
.stats-metric { text-align: center; min-width: 44px; }
.stats-metric-v { font-size: 13.5px; font-weight: 700; color: var(--text); white-space: nowrap; }
.stats-metric-l { font-size: 11px; color: var(--text-subtle); }
.stats-note { font-size: 12.5px; color: var(--text-muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 8px 12px; }
.stats-diagbox { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; overflow-x: auto; }
.stats-warn { font-size: 13px; line-height: 1.5; color: #92400e; background: #fef3c7; border: 1px solid #fcd34d; border-radius: 10px; padding: 11px 14px; margin-bottom: 14px; }
:root[data-theme="dark"] .stats-warn { color: #fcd34d; background: rgba(250,204,21,.08); border-color: rgba(250,204,21,.35); }
/* Bảng Thống kê bài đăng (giống Meta Business Suite) */
.posttbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); -webkit-overflow-scrolling: touch; }
.posttbl { border-collapse: collapse; width: 100%; min-width: 900px; font-size: 13px; }
.posttbl thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: 12px; text-align: right; padding: 12px 14px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.posttbl thead th.posttbl-prev { text-align: left; }
.posttbl tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; vertical-align: middle; }
.posttbl tbody tr:last-child td { border-bottom: 0; }
.posttbl tbody tr:hover { background: var(--surface-2); }
.posttbl-prev { text-align: left !important; min-width: 300px; position: sticky; left: 0; background: var(--surface); }
.posttbl thead th.posttbl-prev { background: var(--surface-2); z-index: 2; }
.posttbl tbody tr:hover .posttbl-prev { background: var(--surface-2); }
.posttbl-num { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.posttbl-post { display: flex; align-items: center; gap: 12px; }
.posttbl-thumb { flex: none; width: 46px; height: 62px; border-radius: 7px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.posttbl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.posttbl-meta { min-width: 0; }
.posttbl-title { display: block; font-weight: 600; color: var(--text); text-decoration: none; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.posttbl-title:hover { text-decoration: underline; color: var(--primary); }
.posttbl-date { font-size: 11.5px; color: var(--text-subtle); margin-top: 3px; }
/* Xu hướng: chủ đề nóng */
.trend-topics { margin-bottom: 16px; }
.trend-topics-lbl { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 10px; }
.trend-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.trend-chip { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 7px 12px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 10px; cursor: pointer; text-align: left; transition: border-color .15s, background .15s; }
.trend-chip:hover { border-color: var(--primary); background: var(--surface); }
.trend-chip-t { font-size: 13.5px; font-weight: 700; color: var(--text); }
.trend-chip-v { font-size: 11px; color: var(--text-subtle); }
.channel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
}
.channel-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.channel-head { display: flex; align-items: flex-start; gap: 12px; }
.channel-av { position: relative; width: 44px; height: 44px; flex: none; }
.channel-av .avatar { width: 44px; height: 44px; font-size: 14px; }
.ch-badge {
  position: absolute; right: -3px; bottom: -3px;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid var(--surface);
}
.ch-badge.fb { background: #1877F2; }
.ch-badge.yt { background: #FF0000; }
.channel-titles { flex: 1; min-width: 0; }
.channel-name { font-weight: 700; font-size: 14px; }
.channel-url { display: block; font-size: 12px; color: var(--primary); word-break: break-all; text-decoration: none; margin-top: 2px; }
.channel-url:hover { text-decoration: underline; }
.channel-foll { text-align: right; flex: none; }
.channel-foll-lbl { font-size: 11px; color: var(--text-subtle); white-space: nowrap; }
.channel-foll-val { font-weight: 700; font-size: 16px; margin-top: 2px; }
.channel-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.stat-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  background: var(--surface-2);
}
.stat-ic { color: var(--text-subtle); line-height: 0; }
.stat-ic svg { display: inline-block; }
.stat-val { font-weight: 700; font-size: 14px; margin-top: 4px; }
.stat-lbl { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; }
.sb-propprompt { flex: 1 1 100%; font-size: 11.5px; line-height: 1.45; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; max-height: 62px; overflow: auto; word-break: break-word; }
.sb-lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.sb-lib-item { position: relative; cursor: pointer; border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: var(--surface); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sb-lib-item:hover { border-color: var(--primary); }
.sb-lib-item img { width: 100%; height: 64px; object-fit: contain; }
.sb-lib-name { font-size: 10.5px; font-weight: 600; color: var(--text); text-align: center; line-height: 1.2; max-height: 26px; overflow: hidden; }
.sb-lib-del { position: absolute; top: 2px; right: 2px; padding: 1px 5px !important; }
