/* AdFlow Pro — design tokens (Jinja + Tailwind CDN)
   Primary aligned with TikTok pink. Include after Tailwind or @layer. */
:root {
  /* RC polish 26/11: chữ/nút đạt WCAG AA. #FE2C55 chỉ còn cho trang trí không chứa chữ (logo, viền, vạch, chấm). */
  --af-brand: #FE2C55;            /* trang trí: logo, vạch stepper, viền chọn */
  --af-primary: #E11D48;          /* nền nút chính (chữ trắng 4.70:1), link trên nền trắng (4.70:1) */
  --af-primary-hover: #BE123C;    /* hover/active nút (chữ trắng 6.29:1); chữ hồng trên nền xám/hồng nhạt (≥5.36:1) */
  --af-primary-text: #BE123C;     /* chữ hồng trên nền tint/canvas */
  --af-primary-soft: rgba(225, 29, 72, 0.1);
  --af-ink: #161823;
  --af-muted: #4B5563;           /* RC polish: 6.87:1 trên canvas #F3F4F6 (trước 4.39) */
  --af-border: #E5E7EB;
  --af-canvas: #F3F4F6;
  --af-surface: #FFFFFF;
  --af-success: #15803D;          /* RC polish: 4.57:1 trên #DCFCE7, 5.02:1 trên trắng (trước #16A34A 3.0) */
  --af-success-bg: #DCFCE7;
  --af-warning: #D97706;
  --af-warning-bg: #FEF3C7;
  --af-danger: #DC2626;
  --af-danger-bg: #FEE2E2;
  --af-info: #2563EB;
  --af-info-bg: #DBEAFE;
  --af-radius: 0.75rem;
  --af-radius-sm: 0.5rem;
  --af-font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --af-nav-w: 12rem;
  --af-summary-w: 18rem;
}

body.af-body {
  font-family: var(--af-font);
  background: var(--af-canvas);
  color: var(--af-ink);
}

/* Buttons */
.af-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  font-size: 0.875rem; font-weight: 500; line-height: 1.25rem;
  padding: 0.5rem 1rem; border-radius: var(--af-radius-sm);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
}
.af-btn-primary { background: var(--af-primary); color: #fff; }
.af-btn-primary:hover { background: var(--af-primary-hover); }
.af-btn-secondary { background: #fff; color: var(--af-ink); border-color: var(--af-border); }
.af-btn-secondary:hover { background: var(--af-canvas); }
.af-btn-ghost { background: transparent; color: var(--af-muted); }
.af-btn-danger { background: var(--af-danger); color: #fff; }
.af-btn-sm { padding: 0.25rem 0.625rem; font-size: 0.8125rem; }
.af-btn:disabled, .af-btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

/* Inputs */
.af-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.375rem; }
.af-hint { font-size: 0.75rem; color: var(--af-muted); margin-top: 0.25rem; }
.af-input, .af-select, .af-textarea {
  width: 100%; font-size: 0.875rem; padding: 0.5rem 0.75rem;
  border: 1px solid #D1D5DB; border-radius: var(--af-radius-sm); background: #fff;
}
.af-input:focus, .af-select:focus, .af-textarea:focus {
  outline: none; border-color: var(--af-primary);
  box-shadow: 0 0 0 3px var(--af-primary-soft);
}
.af-input.is-error { border-color: var(--af-danger); }
.af-error { font-size: 0.75rem; color: var(--af-danger); margin-top: 0.25rem; }

/* Card */
.af-card {
  background: var(--af-surface); border: 1px solid var(--af-border);
  border-radius: var(--af-radius); padding: 1.25rem;
}
.af-card-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.75rem; }

/* Badges / status pills */
.af-badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.75rem; font-weight: 500; padding: 0.125rem 0.5rem;
  border-radius: 9999px; white-space: nowrap;
}
.af-badge-ok { background: var(--af-success-bg); color: var(--af-success); }
.af-badge-warn { background: var(--af-warning-bg); color: var(--af-warning); }
.af-badge-err { background: var(--af-danger-bg); color: var(--af-danger); }
.af-badge-info { background: var(--af-info-bg); color: var(--af-info); }
.af-badge-muted { background: var(--af-canvas); color: var(--af-muted); border: 1px solid var(--af-border); }
.af-badge-lock { background: #F3E8FF; color: #7C3AED; }

/* Table */
.af-table-wrap { overflow: auto; border: 1px solid var(--af-border); border-radius: var(--af-radius); background: #fff; }
.af-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.af-table th {
  text-align: left; font-weight: 600; background: var(--af-canvas);
  padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--af-border);
  position: sticky; top: 0; z-index: 1;
}
.af-table td { padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--af-border); vertical-align: middle; }
.af-table tr:hover td { background: #FAFAFA; }
.af-table tr.is-blocked td { background: var(--af-warning-bg); }
.af-table code { font-size: 0.75rem; color: var(--af-muted); }

/* Segmented control */
.af-seg { display: inline-flex; border: 1px solid #D1D5DB; border-radius: var(--af-radius-sm); overflow: hidden; }
.af-seg button {
  font-size: 0.875rem; padding: 0.5rem 1rem; background: #fff; border: 0; cursor: pointer; color: var(--af-muted);
}
.af-seg button.is-active { background: var(--af-primary); color: #fff; }

/* Shell */
.af-topbar {
  height: 3.5rem; background: #fff; border-bottom: 1px solid var(--af-border);
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem; position: sticky; top: 0; z-index: 30;
}
.af-brand { font-weight: 600; font-size: 1.125rem; }
.af-brand span { color: var(--af-brand); } /* logotype: miễn trừ WCAG 1.4.3 */
.af-sidenav {
  width: var(--af-nav-w); background: #fff; border-right: 1px solid var(--af-border);
  padding: 0.75rem; flex-shrink: 0;
}
.af-sidenav a {
  display: block; padding: 0.5rem 0.75rem; border-radius: var(--af-radius-sm);
  font-size: 0.875rem; color: var(--af-muted); text-decoration: none;
}
.af-sidenav a:hover { background: var(--af-canvas); color: var(--af-ink); }
.af-sidenav a.is-active { background: var(--af-primary-soft); color: var(--af-primary-text); font-weight: 500; }
.af-sidenav a.is-locked { opacity: 0.55; }
.af-footer-sticky {
  position: fixed; bottom: 0; left: 0; right: 0; height: 4rem;
  background: #fff; border-top: 1px solid var(--af-border);
  display: flex; align-items: center; gap: 0.75rem; padding: 0 1.5rem; z-index: 40;
}

/* Lock / upgrade affordance */
.af-locked-overlay {
  position: relative;
}
.af-locked-overlay::after {
  content: "Nâng cấp để mở";
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.72); backdrop-filter: blur(1px);
  font-size: 0.8125rem; font-weight: 500; color: #7C3AED; border-radius: inherit;
}

/* ===== Jinja drop-in additions (AdFlow templates) ===== */
.af-shell { display: flex; min-height: calc(100vh - 3.5rem); }
.af-main { flex: 1; min-width: 0; }
.af-sidenav { position: sticky; top: 3.5rem; height: calc(100vh - 3.5rem); overflow-y: auto; }
.af-sidenav .af-nav-section { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: .05em; color: var(--af-muted); padding: 0.75rem 0.75rem 0.25rem; }
.af-sidenav span.is-disabled {
  display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.75rem;
  font-size: 0.875rem; color: #9CA3AF; cursor: not-allowed;
}
.af-sidenav a { display: flex; align-items: center; gap: .5rem; }
.af-soon { font-size: 0.625rem; font-weight: 600; padding: 0 .375rem; border-radius: 9999px; background: var(--af-canvas); border: 1px solid var(--af-border); color: #9CA3AF; }

/* Flash alerts */
.af-alert { display: flex; gap: .75rem; align-items: flex-start; padding: .625rem .875rem; border-radius: var(--af-radius-sm); font-size: .875rem; border: 1px solid transparent; margin-bottom: .5rem; }
.af-alert-success { background: var(--af-success-bg); color: #166534; border-color: #BBF7D0; }
.af-alert-danger  { background: var(--af-danger-bg);  color: #991B1B; border-color: #FECACA; }
.af-alert-warning { background: var(--af-warning-bg); color: #92400E; border-color: #FDE68A; }
.af-alert-info    { background: var(--af-info-bg);    color: #1E40AF; border-color: #BFDBFE; }
.af-alert-close { margin-left: auto; background: none; border: 0; font-size: 1.1rem; line-height: 1; cursor: pointer; color: inherit; opacity: .6; }
.af-alert-close:hover { opacity: 1; }

/* Small inputs / checks */
.af-input-sm { padding: 0.3rem 0.5rem; font-size: 0.8125rem; }
.af-check { width: 1rem; height: 1rem; accent-color: var(--af-primary); vertical-align: middle; cursor: pointer; }
.af-btn-outline { background: #fff; color: var(--af-primary); border-color: var(--af-primary); }
.af-btn-outline:hover { background: var(--af-primary-soft); color: var(--af-primary-text); }
.af-btn-success { background: var(--af-success); color: #fff; }
.af-btn-warning { background: #fff; color: var(--af-warning); border-color: #FCD34D; }
.af-btn-warning:hover { background: var(--af-warning-bg); }
.af-btn-danger-outline { background: #fff; color: var(--af-danger); border-color: #FCA5A5; }
.af-btn-danger-outline:hover { background: var(--af-danger-bg); }
.af-table.af-table-compact td, .af-table.af-table-compact th { padding: .5rem .625rem; white-space: nowrap; }
.af-table tr.is-hidden { display: none; }

/* Choice cards (radio styled as Ads Manager option cards) */
.af-choice { display: block; position: relative; border: 1px solid #D1D5DB; border-radius: var(--af-radius-sm); padding: .625rem .75rem; cursor: pointer; background: #fff; }
.af-choice:hover { border-color: #9CA3AF; }
.af-choice input { position: absolute; opacity: 0; pointer-events: none; }
.af-choice:has(input:checked) { border-color: var(--af-primary); box-shadow: 0 0 0 3px var(--af-primary-soft); }
.af-choice .af-choice-title { font-size: .875rem; font-weight: 600; }
.af-choice .af-choice-desc { font-size: .75rem; color: var(--af-muted); margin-top: .125rem; }
.af-pill-check { display: inline-flex; align-items: center; gap: .375rem; padding: .3rem .7rem; border: 1px solid #D1D5DB; border-radius: 9999px; font-size: .8125rem; cursor: pointer; background: #fff; user-select: none; }
.af-pill-check:has(input:checked) { border-color: var(--af-primary); background: var(--af-primary-soft); color: var(--af-primary-text); font-weight: 500; }
.af-pill-check input { accent-color: var(--af-primary); }

/* Wizard (template_edit) */
.af-wizard { display: grid; grid-template-columns: 12rem minmax(0,1fr) 17rem; gap: 0; align-items: start; }
.af-steps { position: sticky; top: 3.5rem; height: calc(100vh - 3.5rem); background: #fff; border-right: 1px solid var(--af-border); padding: 1rem .75rem; overflow-y: auto; }
.af-step { display: block; padding: .5rem .75rem; border-left: 3px solid transparent; border-radius: 0 var(--af-radius-sm) var(--af-radius-sm) 0; color: var(--af-muted); text-decoration: none; font-size: .875rem; }
.af-step:hover { background: var(--af-canvas); color: var(--af-ink); }
.af-step.is-active { border-left-color: var(--af-brand); background: var(--af-primary-soft); color: var(--af-ink); font-weight: 600; }
.af-step-num { display: inline-flex; width: 1.25rem; height: 1.25rem; align-items: center; justify-content: center; border-radius: 9999px; background: var(--af-canvas); font-size: .6875rem; margin-right: .375rem; }
.af-step.is-active .af-step-num { background: var(--af-primary); color: #fff; }
.af-substep { display: block; padding: .25rem .75rem .25rem 2.4rem; font-size: .8125rem; color: var(--af-muted); text-decoration: none; }
.af-substep:hover { color: var(--af-primary); }
.af-summary { position: sticky; top: 3.5rem; height: calc(100vh - 3.5rem); overflow-y: auto; background: #fff; border-left: 1px solid var(--af-border); padding: 1rem; }
.af-summary dl { display: grid; grid-template-columns: auto 1fr; gap: .375rem .75rem; font-size: .8125rem; }
.af-summary dt { color: var(--af-muted); }
.af-summary dd { text-align: right; font-weight: 500; word-break: break-word; }
.af-section { scroll-margin-top: 4.5rem; }
.af-level { font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--af-primary); }
.af-footer-bar { position: sticky; bottom: 0; z-index: 20; background: #fff; border-top: 1px solid var(--af-border); display: flex; align-items: center; gap: .75rem; padding: .75rem 1.5rem; }
@media (max-width: 1100px) {
  .af-wizard { grid-template-columns: minmax(0,1fr); }
  .af-steps, .af-summary { position: static; height: auto; border: 0; border-bottom: 1px solid var(--af-border); }
}

/* Full-height white rail behind the sticky sidenav */
@media (min-width: 768px) {
  .af-shell { background: linear-gradient(to right, #fff calc(var(--af-nav-w) - 1px), var(--af-border) calc(var(--af-nav-w) - 1px), var(--af-border) var(--af-nav-w), transparent var(--af-nav-w)); }
  .af-nav-compact { --af-nav-w: 3.5rem; }
}
/* Compact (icon-only) app nav — used by the wizard page to give the form more room */
.af-nav-compact .af-sidenav { width: var(--af-nav-w); padding: .75rem .5rem; }
.af-nav-compact .af-sidenav .af-nav-label,
.af-nav-compact .af-sidenav .af-nav-section,
.af-nav-compact .af-sidenav span.is-disabled { display: none; }
.af-nav-compact .af-sidenav a { justify-content: center; padding: .6rem 0; }
.af-nav-compact .af-sidenav a svg { width: 1.25rem; height: 1.25rem; }
/* bulk_mapping: row with warnings (o.errors) but not blocked (o.precheck empty) — still runs */
.af-table tr.is-warning td:first-child { box-shadow: inset 3px 0 0 var(--af-warning); }
.af-table tr.is-blocked td:first-child { box-shadow: inset 3px 0 0 var(--af-danger); }

/* Objective picker (template_edit) */
[hidden] { display: none !important; }
.af-obj-card { padding: .625rem .75rem; }
.af-obj-icon { flex-shrink: 0; width: 2rem; height: 2rem; border-radius: .5rem; display: inline-flex; align-items: center; justify-content: center; background: var(--af-canvas); color: var(--af-muted); }
.af-obj-card:has(input:checked) .af-obj-icon { background: var(--af-primary-soft); color: var(--af-primary-text); }
.af-obj-card.is-disabled { opacity: .5; cursor: not-allowed; background: #FAFAFA; }
.af-obj-card.is-disabled:hover { border-color: #D1D5DB; }
/* Objective rules: locked choices */
.af-choice.is-disabled { opacity: .5; cursor: not-allowed; background: #FAFAFA; }
.af-choice.is-disabled:hover { border-color: #D1D5DB; }
.af-lock-hint { color: #B45309; }
.af-select.is-locked { background-color: #F9FAFB; color: #374151; }
.af-select option:disabled { color: #9CA3AF; }
/* License-locked nav item */
.af-sidenav a.is-locked { opacity: 1; color: #9CA3AF; }
.af-sidenav a.is-locked svg { opacity: .6; }
.af-sidenav a.is-locked:hover { color: #6B7280; }
.af-nav-lock { margin-left: auto; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; line-height: 1;
  padding: 2px 5px; border-radius: 9999px; background: #F3F4F6; border: 1px solid #E5E7EB; filter: grayscale(.2); }
.af-nav-compact .af-sidenav a { position: relative; }
.af-nav-compact .af-nav-lock { position: absolute; top: 1px; right: 2px; margin: 0; padding: 1px 3px; font-size: 9px; }

/* ==========================================================================
   Ads Manager layout (adflow-pro-ux-adsmanager, 25/11/2026) — appended; nothing above changed.
   ========================================================================== */
.af-am-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.af-level-toggle button { padding: .375rem .875rem; }
.af-level-toggle button:focus-visible, .af-tierbar button:focus-visible, .af-switch:focus-visible, .af-token:focus-visible,
.af-chip-x:focus-visible { outline: 2px solid var(--af-primary); outline-offset: 2px; }
.af-adv-tag { display: inline-block; margin-left: .25rem; font-size: .625rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--af-info); background: var(--af-info-bg); border-radius: 999px; padding: 0 .4rem; vertical-align: middle; }

/* Basic level: advanced-only blocks hidden (display only — inputs stay enabled and submit their defaults) */
.af-am-form[data-level="basic"] [data-adv] { display: none !important; }
/* display-only conditions from data-af-show-when */
.af-am-form .af-off { display: none !important; }

/* Tiers: one visible at a time once JS runs; without JS everything stays visible */
.af-tierbar { display: flex; gap: .25rem; list-style: none; margin: 0; padding: .25rem; background: #fff; border: 1px solid var(--af-border); border-radius: var(--af-radius); }
.af-tierbar li { flex: 1; }
.af-tierbar li[hidden] { display: none; }
.af-tierbar button { width: 100%; display: flex; align-items: center; justify-content: center; gap: .5rem; padding: .5rem .75rem; border: 0; background: transparent;
  border-radius: var(--af-radius-sm); font-size: .875rem; font-weight: 500; color: var(--af-muted); cursor: pointer; }
.af-tierbar button[aria-current="step"] { background: var(--af-primary-soft); color: var(--af-primary-text); }
.af-tierbar .af-step-num { width: 1.25rem; height: 1.25rem; font-size: .7rem; }
.af-js .af-tier:not(.is-current) { display: none; }
.af-tier > * + * { margin-top: 1rem; }
.af-step-anchor:focus { outline: none; }
@media (min-width: 1101px) { .af-tierbar { display: none; } }

/* CBO switch */
.af-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; margin-bottom: 1rem;
  border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); background: var(--af-canvas); }
.af-switch { position: relative; flex: none; width: 2.75rem; height: 1.5rem; border-radius: 999px; border: 0; background: #D1D5DB; cursor: pointer; transition: background .15s; }
.af-switch[aria-checked="true"] { background: var(--af-primary); }
.af-switch-knob { position: absolute; top: .1875rem; left: .1875rem; width: 1.125rem; height: 1.125rem; border-radius: 999px; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.af-switch[aria-checked="true"] .af-switch-knob { transform: translateX(1.25rem); }

/* Segmented radio (gender) */
.af-seg-radio label { position: relative; }
.af-seg-radio input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.af-seg-radio span { display: block; font-size: .875rem; padding: .5rem 1rem; background: #fff; color: var(--af-muted); border-right: 1px solid #D1D5DB; }
.af-seg-radio label:last-child span { border-right: 0; }
.af-seg-radio input:checked + span { background: var(--af-primary); color: #fff; }
.af-seg-radio input:focus-visible + span { outline: 2px solid var(--af-primary); outline-offset: -2px; }

/* Name variable tokens */
.af-token-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem; margin-top: .5rem; }
.af-token { font-size: .75rem; padding: .125rem .5rem; border: 1px dashed #D1D5DB; border-radius: 999px; background: #fff; color: var(--af-ink); cursor: pointer; }
.af-token:hover { border-color: var(--af-primary); color: var(--af-primary); }

/* Searchable select (af-combo) */
.af-combo { position: relative; }
.af-combo-box { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem; min-height: 2.5rem; padding: .25rem .5rem;
  border: 1px solid #D1D5DB; border-radius: var(--af-radius-sm); background: #fff; cursor: text; }
.af-combo-box:focus-within { border-color: var(--af-primary); box-shadow: 0 0 0 3px var(--af-primary-soft); }
.af-combo-chips { display: contents; list-style: none; margin: 0; padding: 0; }
.af-combo-input { flex: 1; min-width: 10rem; border: 0; outline: none; font-size: .875rem; padding: .25rem; background: transparent; }
.af-chip { display: inline-flex; align-items: center; gap: .25rem; font-size: .8125rem; padding: .125rem .25rem .125rem .5rem;
  background: var(--af-primary-soft); color: var(--af-ink); border-radius: 999px; }
.af-chip.is-unknown { background: var(--af-warning-bg); }
.af-chip-x { border: 0; background: transparent; color: var(--af-muted); cursor: pointer; width: 1.25rem; height: 1.25rem; border-radius: 999px; line-height: 1; font-size: 1rem; }
.af-chip-x:hover { background: rgba(0,0,0,.06); color: var(--af-ink); }
.af-combo-list { position: absolute; z-index: 30; left: 0; right: 0; margin-top: .25rem; max-height: 16rem; overflow-y: auto; list-style: none; padding: .25rem;
  background: #fff; border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); box-shadow: 0 8px 24px rgba(22,24,35,.12); }
.af-combo-opt { display: flex; justify-content: space-between; gap: .75rem; padding: .5rem .625rem; border-radius: .375rem; font-size: .875rem; cursor: pointer; }
.af-combo-opt small { color: var(--af-muted); font-size: .75rem; }
.af-combo-opt.is-active, .af-combo-opt:hover { background: var(--af-canvas); }
.af-combo-opt.is-free { color: var(--af-warning); }
.af-combo-empty { padding: .5rem .625rem; font-size: .875rem; color: var(--af-muted); }
.af-combo-status:empty { display: none; }
@media (prefers-reduced-motion: reduce) { .af-switch, .af-switch-knob { transition: none; } }
@media (max-width: 640px) {
  .af-footer-bar { flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; }
  .af-footer-bar .af-btn { flex: 1 1 auto; white-space: nowrap; padding: .5rem .625rem; }
  .af-footer-back { display: none; }          /* same link stays at the top of the step nav */
}

/* Vị trí tối ưu hóa: Pixel + Sự kiện tối ưu hóa nằm trong card Nhóm quảng cáo đầu tiên (như Ads Manager) */
.af-card-subtitle { font-size: .9375rem; font-weight: 600; margin-bottom: .5rem; display: flex; align-items: center; gap: .25rem; }
.af-optloc-pixel { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--af-border); }
/* rev3: không có ô «Vị trí tối ưu hóa» → khối Pixel đứng ngay trước «Mục tiêu tối ưu hóa» trong «Đặt giá thầu và tối ưu hóa» */
#slot-pixel-delivery > .af-optloc-pixel { margin: 0 0 1.25rem; padding: 0 0 1rem; border-top: 0; border-bottom: 1px solid var(--af-border); }

/* ===== M2 · Bật/tắt & ngân sách hàng loạt (campaigns_manage / bulk_edit_*) — thêm vào cuối, không đổi class cũ ===== */
.af-tabs { display: flex; gap: .25rem; overflow-x: auto; white-space: nowrap; border-bottom: 1px solid var(--af-border); margin-bottom: 1rem; }
.af-tab { padding: .625rem 1rem; font-size: .875rem; font-weight: 500; color: var(--af-muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.af-tab:hover { color: var(--af-ink); }
.af-tab[aria-current="page"] { color: var(--af-ink); border-bottom-color: var(--af-brand); font-weight: 600; }
.af-tab .af-tab-count { margin-left: .375rem; font-size: .75rem; color: var(--af-muted); font-weight: 500; }
.af-filterbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem; margin-bottom: .75rem; }
.af-filterbar .af-field { min-width: 11rem; }
.af-filterbar .af-label { font-size: .75rem; color: var(--af-muted); margin-bottom: .25rem; }
/* Thanh thao tác hàng loạt (dính trên bảng như Ads Manager) */
.af-bulkbar { position: sticky; top: 3.5rem; z-index: 15; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  background: #fff; border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); padding: .5rem .75rem; margin-bottom: .5rem; }
.af-bulkbar.has-selection { border-color: var(--af-primary); box-shadow: 0 0 0 3px var(--af-primary-soft); }
.af-bulkbar-count { font-size: .875rem; font-weight: 600; min-width: 7rem; }
.af-bulkbar .af-sep { width: 1px; align-self: stretch; background: var(--af-border); margin: 0 .25rem; }
/* Badge đủ tương phản AA (chữ đậm trên nền nhạt) cho Guard / kết quả */
.af-pill { display: inline-flex; align-items: center; gap: .25rem; font-size: .75rem; font-weight: 600; padding: .125rem .5rem; border-radius: 9999px; white-space: nowrap; border: 1px solid transparent; }
.af-pill-ok    { background: #DCFCE7; color: #166534; border-color: #BBF7D0; }
.af-pill-warn  { background: #FEF3C7; color: #92400E; border-color: #FDE68A; }
.af-pill-block { background: #FEE2E2; color: #991B1B; border-color: #FECACA; }
.af-pill-info  { background: #DBEAFE; color: #1E40AF; border-color: #BFDBFE; }
.af-pill-muted { background: #F3F4F6; color: #374151; border-color: #E5E7EB; }
.af-dot { width: .5rem; height: .5rem; border-radius: 9999px; display: inline-block; background: currentColor; }
.af-num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.af-arrow { color: #9CA3AF; padding: 0 .25rem; }
.af-delta-up { color: #B91C1C; font-weight: 600; }
.af-delta-down { color: #166534; font-weight: 600; }
.af-reasons { margin: .25rem 0 0; padding: 0; list-style: none; font-size: .75rem; color: #374151; }
.af-reasons li::before { content: "• "; color: #9CA3AF; }
.af-table tr.is-warn td:first-child { box-shadow: inset 3px 0 0 #D97706; }
.af-table tr.is-guard-block td { background: #FEF2F2; }
.af-table tr.is-guard-block td:first-child { box-shadow: inset 3px 0 0 var(--af-danger); }
.af-table th.af-num { text-align: right; }
.af-table tr.is-selected td { background: #FFF1F4; }
.af-table tr.is-row-error td:first-child { box-shadow: inset 3px 0 0 var(--af-danger); }
.af-table th.af-th-check, .af-table td.af-td-check { width: 2.5rem; text-align: center; }
.af-table .af-sub, .af-sub { display: block; font-size: .75rem; color: #4B5563; }
/* Thẻ tổng hợp */
.af-stat { background: #fff; border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); padding: .75rem 1rem; }
.af-stat-label { font-size: .75rem; color: var(--af-muted); }
.af-stat-value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: .125rem; }
.af-stat.is-ok .af-stat-value { color: #166534; } .af-stat.is-warn .af-stat-value { color: #92400E; } .af-stat.is-block .af-stat-value { color: #991B1B; }
/* Dialog (native <dialog>, showModal → nền inert, Esc đóng) */
.af-dialog { border: 0; padding: 0; border-radius: var(--af-radius); width: min(36rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); box-shadow: 0 24px 64px rgba(22,24,35,.28); color: var(--af-ink); }
.af-dialog::backdrop { background: rgba(22,24,35,.45); }
.af-dialog-head { display: flex; align-items: flex-start; gap: .75rem; padding: 1rem 1.25rem .75rem; border-bottom: 1px solid var(--af-border); }
.af-dialog-title { font-size: 1.0625rem; font-weight: 600; }
.af-dialog-body { padding: 1rem 1.25rem; overflow-y: auto; }
.af-dialog-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1.25rem; border-top: 1px solid var(--af-border); background: #FAFAFA; border-radius: 0 0 var(--af-radius) var(--af-radius); }
.af-dialog-x { margin-left: auto; background: none; border: 0; font-size: 1.25rem; line-height: 1; color: var(--af-muted); cursor: pointer; padding: .25rem; border-radius: .375rem; }
.af-dialog-x:hover { background: var(--af-canvas); color: var(--af-ink); }
/* Radio dạng phân đoạn (thay .af-seg button để có ngữ nghĩa radio) */
.af-seg-radio { display: inline-flex; border: 1px solid #D1D5DB; border-radius: var(--af-radius-sm); overflow: hidden; }
.af-seg-radio label { position: relative; font-size: .875rem; padding: .5rem .875rem; background: #fff; color: #374151; cursor: pointer; border-right: 1px solid #E5E7EB; }
.af-seg-radio label:last-child { border-right: 0; }
.af-seg-radio input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.af-seg-radio label:has(input:checked) { background: var(--af-primary); color: #fff; font-weight: 500; }
.af-seg-radio label:has(input:focus-visible) { outline: 2px solid var(--af-ink); outline-offset: -3px; }
.af-input-affix { display: flex; align-items: stretch; }
.af-input-affix .af-input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.af-input-affix .af-affix { display: inline-flex; align-items: center; padding: 0 .75rem; font-size: .8125rem; color: #374151; background: #F9FAFB; border: 1px solid #D1D5DB; border-left: 0; border-radius: 0 var(--af-radius-sm) var(--af-radius-sm) 0; }
.af-readback { font-size: .8125rem; color: #374151; margin-top: .375rem; font-variant-numeric: tabular-nums; }
.af-readback strong { color: var(--af-ink); }
.af-callout { border-radius: var(--af-radius-sm); padding: .625rem .75rem; font-size: .8125rem; border: 1px solid; }
.af-callout-warn { background: #FFFBEB; border-color: #FDE68A; color: #78350F; }
.af-callout-block { background: #FEF2F2; border-color: #FECACA; color: #7F1D1D; }
.af-callout-info { background: #EFF6FF; border-color: #BFDBFE; color: #1E3A8A; }
/* Trạng thái tải / rỗng */
.af-empty { text-align: center; padding: 3rem 1rem; color: var(--af-muted); }
.af-empty-title { font-size: 1rem; font-weight: 600; color: var(--af-ink); margin-bottom: .25rem; }
.af-spinner { width: 1rem; height: 1rem; border-radius: 9999px; border: 2px solid currentColor; border-right-color: transparent; display: inline-block; animation: af-spin .8s linear infinite; vertical-align: -2px; }
@keyframes af-spin { to { transform: rotate(360deg); } }
.af-skeleton { background: linear-gradient(90deg, #F3F4F6 25%, #E5E7EB 37%, #F3F4F6 63%); background-size: 400% 100%; animation: af-shimmer 1.4s ease infinite; border-radius: .375rem; height: .875rem; }
@keyframes af-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
[aria-busy="true"] .af-btn-label-idle { display: none; }
.af-btn-label-busy { display: none; }
[aria-busy="true"] .af-btn-label-busy { display: inline-flex; align-items: center; gap: .375rem; }
.af-table-loading tbody { opacity: .45; pointer-events: none; }
.af-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.af-focus-ring:focus-visible, .af-bulkbar .af-btn:focus-visible, .af-dialog .af-btn:focus-visible, .af-tab:focus-visible { outline: 2px solid var(--af-ink); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .af-spinner, .af-skeleton { animation: none; } }
@media (max-width: 640px) {
  .af-bulkbar { top: 3.5rem; }
  .af-bulkbar-count { min-width: 0; width: 100%; }
  .af-filterbar .af-field { min-width: 0; flex: 1 1 45%; }
  .af-seg-radio label { padding: .5rem .625rem; }
}

/* ===================== Onboarding pack (26/11/2026): lần chạy đầu, kết nối TikTok qua broker, Trợ giúp, Giới thiệu ===================== */
.af-onb-steps { display: flex; gap: .5rem; list-style: none; margin: 0; padding: 0; counter-reset: none; }
.af-onb-step { flex: 1 1 0; display: flex; align-items: center; gap: .5rem; padding: .5rem .25rem; border-top: 3px solid var(--af-border); font-size: .8125rem; color: var(--af-muted); min-width: 0; }
.af-onb-step-num { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 1.5rem; height: 1.5rem; border-radius: 999px; background: var(--af-canvas); color: var(--af-muted); font-size: .75rem; font-weight: 600; }
.af-onb-step.is-current { border-top-color: var(--af-brand); color: var(--af-ink); font-weight: 600; }
.af-onb-step.is-current .af-onb-step-num { background: var(--af-primary); color: #fff; }
.af-onb-step.is-done { border-top-color: var(--af-success); color: var(--af-ink); }
.af-onb-step.is-done .af-onb-step-num { background: var(--af-success-bg); color: var(--af-success); }
.af-onb-step.is-skipped .af-onb-step-num { background: var(--af-warning-bg); color: var(--af-warning); }
.af-onb-step-note { font-weight: 400; color: var(--af-muted); font-size: .75rem; }
.af-onb-step-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-onb-card { padding: 1.75rem; }
.af-onb-title { font-size: 1.375rem; font-weight: 700; letter-spacing: -.01em; }
.af-onb-title:focus, .af-onb-state-title:focus { outline: none; }
.af-onb-lead { color: #4B5563; margin-top: .25rem; margin-bottom: 1.25rem; font-size: .9375rem; }
.af-onb-values { display: grid; gap: .75rem; margin: 0 0 1.25rem; padding: 0; list-style: none; }
@media (min-width: 768px) { .af-onb-values { grid-template-columns: repeat(3, 1fr); } }
.af-onb-values li { display: flex; gap: .625rem; padding: .875rem; border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); font-size: .875rem; }
.af-onb-values li p { color: var(--af-muted); font-size: .8125rem; margin-top: .125rem; }
.af-onb-value-ic { flex: none; width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center; border-radius: .5rem; background: var(--af-primary-soft); }
.af-onb-prep { padding: .875rem 1rem; background: var(--af-canvas); border-radius: var(--af-radius-sm); }
.af-onb-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--af-border); }
.af-onb-dl { display: grid; grid-template-columns: max-content 1fr; gap: .375rem 1rem; font-size: .875rem; }
.af-onb-dl dt { color: var(--af-muted); }
.af-onb-lic { padding: 1rem; border: 1px solid #BBF7D0; background: #F0FDF4; border-radius: var(--af-radius-sm); }
.af-onb-details { border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); padding: .75rem 1rem; }
.af-onb-details > summary { cursor: pointer; font-size: .875rem; font-weight: 600; list-style-position: inside; }
.af-onb-details > summary:focus-visible { outline: 2px solid var(--af-ink); outline-offset: 2px; border-radius: .25rem; }
.af-onb-code { display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .75rem; background: var(--af-canvas); border: 1px solid var(--af-border); border-radius: .375rem; padding: .375rem .5rem; word-break: break-all; }
.af-onb-tiktok { padding: .75rem 1.25rem; font-size: 1rem; }
.af-onb-howto { list-style: decimal; padding-left: 1.25rem; margin: 1rem 0 .75rem; font-size: .875rem; color: #374151; }
.af-onb-howto li + li { margin-top: .25rem; }
.af-onb-state { display: flex; gap: .875rem; padding: 1rem; border-radius: var(--af-radius-sm); border: 1px solid var(--af-border); }
.af-onb-state-wait { background: #FFF7F9; border-color: #FBCFE8; }
.af-onb-state-ok { background: #F0FDF4; border-color: #BBF7D0; }
.af-onb-state-error { background: #FEF2F2; border-color: #FECACA; }
.af-onb-state-warn { background: #FFFBEB; border-color: #FDE68A; }
.af-onb-icon-warn { background: var(--af-warning-bg); color: var(--af-warning); }
.af-onb-state-title { font-size: 1rem; font-weight: 600; }
.af-onb-state-icon { flex: none; width: 2.25rem; height: 2.25rem; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; }
.af-onb-icon-ok { background: var(--af-success-bg); color: var(--af-success); }
.af-onb-icon-err { background: var(--af-danger-bg); color: var(--af-danger); }
.af-onb-acc-list { list-style: none; padding: 0; margin: 0; border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); background: #fff; }
.af-onb-acc-list li { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; font-size: .875rem; min-width: 0; }
.af-onb-acc-list li + li { border-top: 1px solid var(--af-border); }
.af-onb-acc-dot { width: .5rem; height: .5rem; border-radius: 999px; background: var(--af-success); flex: none; }
.af-onb-check { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.af-onb-check li { display: flex; gap: .625rem; align-items: flex-start; font-size: .875rem; padding: .625rem .75rem; border-radius: var(--af-radius-sm); }
.af-onb-check li > span { flex: none; width: 1.375rem; height: 1.375rem; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; }
.af-onb-check li.is-ok { background: #F0FDF4; } .af-onb-check li.is-ok > span { background: var(--af-success-bg); color: var(--af-success); }
.af-onb-check li.is-todo { background: #FFFBEB; } .af-onb-check li.is-todo > span { background: var(--af-warning-bg); color: var(--af-warning); }
.af-onb-next { display: block; padding: .875rem 1rem; border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); text-decoration: none; color: var(--af-ink); transition: border-color .15s, box-shadow .15s; }
.af-onb-next:hover, .af-onb-next:focus-visible { border-color: var(--af-primary); box-shadow: 0 0 0 3px var(--af-primary-soft); outline: none; }
.af-onb-next b { display: block; font-size: .875rem; } .af-onb-next span { display: block; font-size: .8125rem; color: var(--af-muted); margin-top: .125rem; }
.af-onb-pw { display: flex; gap: .375rem; align-items: center; }
.af-onb-rules { list-style: none; padding: 0; margin: .375rem 0 0; font-size: .75rem; color: var(--af-muted); display: grid; gap: .125rem; }
.af-onb-rules li::before { content: "○ "; } .af-onb-rules li.is-ok { color: var(--af-success); } .af-onb-rules li.is-ok::before { content: "✓ "; }
.af-btn.is-disabled, .af-btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.af-help-toc { list-style: none; margin: 0; padding: 0; }
.af-help-toc a { display: block; padding: .4rem .625rem; border-radius: .375rem; font-size: .875rem; color: #374151; text-decoration: none; border-left: 3px solid transparent; }
.af-help-toc a:hover { background: var(--af-canvas); }
.af-help-toc a.is-active { background: var(--af-primary-soft); border-left-color: var(--af-brand); color: var(--af-ink); font-weight: 600; }
.af-help-toc a:focus-visible, .af-help-pager a:focus-visible { outline: 2px solid var(--af-ink); outline-offset: 2px; }
.af-help-body { font-size: .9375rem; line-height: 1.6; color: #1F2937; }
.af-help-body > p, .af-help-body > ol, .af-help-body > ul, .af-help-body > dl { margin-bottom: .875rem; }
.af-help-body ol { list-style: decimal; padding-left: 1.25rem; } .af-help-body ul { list-style: disc; padding-left: 1.25rem; }
.af-help-body li + li { margin-top: .25rem; }
.af-help-body h3 { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 .5rem; }
.af-help-body code { font-size: .8125rem; background: var(--af-canvas); padding: .05rem .3rem; border-radius: .25rem; }
.af-help-fig { margin: .625rem 0 .875rem; } .af-help-fig img { max-width: 100%; height: auto; border: 1px solid var(--af-border); border-radius: var(--af-radius-sm); }
.af-help-fig figcaption { font-size: .75rem; color: var(--af-muted); margin-top: .25rem; }
.af-help-faq dt { font-weight: 600; margin-top: .75rem; } .af-help-faq dd { color: #4B5563; }
.af-help-pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--af-border); font-size: .875rem; }
.af-help-pager a { color: var(--af-primary); text-decoration: none; font-weight: 500; }
@media (max-width: 640px) {
  .af-onb-card { padding: 1.125rem; }
  .af-onb-step-label { display: none; } .af-onb-step.is-current .af-onb-step-label { display: inline; }
}
@media (prefers-reduced-motion: reduce) { .af-onb-next { transition: none; } }

/* ---------- RC polish 26/11 (WCAG AA ≥4.5:1 cho chữ; token af-*) ---------- */
.af-btn-primary:active, .af-seg button.is-active:hover { background: var(--af-primary-hover); }
.af-btn-outline:active { background: var(--af-primary-soft); color: var(--af-primary-text); }
/* chữ phụ Tailwind (gray-400 2.54:1, gray-500 4.39:1 trên canvas) → token muted; html* tăng độ ưu tiên hơn CSS Tailwind CDN chèn sau */
html .text-gray-400, html .text-gray-500 { color: var(--af-muted); }
html .text-green-600 { color: #15803D; }
.af-arrow { color: var(--af-muted); }
/* badge: giữ nền, chữ đậm thêm một bậc */
.af-badge-warn { color: #B45309; }
.af-badge-ok { color: #15803D; }
.af-badge-err { color: #B91C1C; }
.af-badge-info { color: #1D4ED8; }
/* checkbox trong bảng: vùng bấm 44×44px, hình vẫn 16px, không đổi bố cục (margin âm) */
.af-hit { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; margin: -0.875rem; cursor: pointer; border-radius: var(--af-radius-sm); vertical-align: middle; }
.af-hit:hover { background: var(--af-primary-soft); }
.af-hit .af-check { margin: 0; }
/* focus ring rõ cho mọi nút (trước: vòng mặc định của trình duyệt) — #161823 trên trắng 17:1, trên nút #E11D48 ≥3:1 nhờ offset */
.af-btn:focus-visible { outline: 2px solid var(--af-ink); outline-offset: 2px; }

/* QL-31/32: chip lọc trạng thái TK + callout kết quả đọc */
.af-callout-ok { background: #F0FDF4; border-color: #BBF7D0; color: #14532D; }
a.af-chip { text-decoration: none; padding: .125rem .5rem; border: 1px solid transparent; background: #F3F4F6; }
a.af-chip:hover { border-color: var(--af-border); }
a.af-chip:focus-visible { outline: 2px solid var(--af-primary); outline-offset: 2px; }
a.af-chip.af-chip-on { background: var(--af-primary-soft); border-color: var(--af-primary); font-weight: 600; }
a.af-chip-active { box-shadow: inset 3px 0 0 #16A34A; }
a.af-chip-limited { box-shadow: inset 3px 0 0 #D97706; }
a.af-chip-dead { box-shadow: inset 3px 0 0 #DC2626; }
a.af-chip-pending { box-shadow: inset 3px 0 0 #2563EB; }
a.af-chip-unknown { box-shadow: inset 3px 0 0 #9CA3AF; }

/* QL-28: ô chọn sự kiện tối ưu kiểu Ads Manager */
.af-evt-combo { position: relative; }
.af-evt-trigger { width: 100%; text-align: left; cursor: pointer; }
.af-evt-panel { position: absolute; z-index: 40; left: 0; right: 0; margin-top: .25rem; background: #fff; border: 1px solid var(--af-border);
  border-radius: var(--af-radius-sm); box-shadow: 0 8px 24px rgba(22,24,35,.14); }
.af-evt-search { padding: .5rem .5rem .25rem; }
.af-evt-tabs { display: flex; gap: 1.25rem; padding: 0 .75rem; border-bottom: 1px solid var(--af-border); }
.af-evt-tabs button { background: none; border: 0; padding: .5rem 0; font-size: .875rem; color: #6B7280; border-bottom: 2px solid transparent; cursor: pointer; }
.af-evt-tabs button.is-on { color: var(--af-ink); font-weight: 600; border-bottom-color: var(--af-ink); }
.af-evt-list { list-style: none; margin: 0; padding: .25rem; max-height: 16rem; overflow-y: auto; }
.af-evt { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .5rem .625rem; border-radius: .375rem;
  font-size: .875rem; color: var(--af-ink); cursor: pointer; }
.af-evt:not(.is-disabled):hover, .af-evt:not(.is-disabled):focus { background: #F3F4F6; outline: none; }
.af-evt.is-picked { background: var(--af-primary-soft); }
.af-evt.is-inactive .af-evt-name { color: #9CA3AF; }
.af-evt.is-active .af-evt-name { color: var(--af-ink, #161823); }
.af-evt-dot { flex: none; display: inline-block; width: .5rem; height: .5rem; border-radius: 9999px; background: #22C55E; vertical-align: middle; }
.af-evt.is-disabled { cursor: not-allowed; }
.af-evt.is-disabled .af-evt-name { color: #C4C8CE; }
.af-evt-name { display: flex; flex-direction: column; }
.af-evt-sub { font-size: .75rem; color: #9CA3AF; }
.af-evt-chip { flex: none; font-size: .75rem; font-weight: 600; padding: .125rem .5rem; border-radius: .25rem; background: #F3F4F6; color: #6B7280; }
.af-evt-chip.is-active { background: #DCFCE7; color: #15803D; }
.af-evt-empty { padding: .75rem; font-size: .875rem; color: #6B7280; }
.af-evt-warn { margin: 0 .75rem .25rem; font-size: .75rem; color: #92400E; }
.af-evt-foot { display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; border-top: 1px solid var(--af-border); }
.af-evt-note { font-size: .75rem; color: #9CA3AF; }
.af-evt-foot { justify-content: space-between; }
.af-evt-help { font-size: .75rem; color: #6B7280; cursor: help; }
.af-evt.is-picked .af-evt-name { font-weight: 600; }

/* UX-R1: chip trạng thái kết nối TikTok trên thanh trên cùng (ngắt kết nối nằm ở Cài đặt) */
.af-conn-chip { display: inline-flex; align-items: center; gap: .4rem; font-size: .8125rem; font-weight: 500; padding: .3rem .7rem;
  border-radius: 999px; border: 1px solid var(--af-border); color: var(--af-ink); text-decoration: none; white-space: nowrap; }
.af-conn-chip:hover { background: #F9FAFB; }
.af-conn-dot { width: .5rem; height: .5rem; border-radius: 999px; background: #9CA3AF; }
.af-conn-chip.is-on .af-conn-dot { background: #16A34A; box-shadow: 0 0 0 3px #DCFCE7; }
.af-conn-chip.is-off { border-color: #FCD34D; background: #FFFBEB; color: #92400E; }
.af-conn-chip.is-off .af-conn-dot { background: #F59E0B; }

/* UX-R1: khối gập (kết nối/BC ở trang TKQC) */
.af-collapse > .af-collapse-summary { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; cursor: pointer; list-style: none; }
.af-collapse > .af-collapse-summary::-webkit-details-marker { display: none; }
.af-collapse > .af-collapse-summary::before { content: "▸"; color: #9CA3AF; transition: transform .15s; }
.af-collapse[open] > .af-collapse-summary::before { transform: rotate(90deg); }
.af-collapse-hint { margin-left: auto; font-size: .8125rem; color: var(--af-primary, #E11D48); }
.af-collapse[open] .af-collapse-hint { display: none; }

/* UX-R1: ô kéo thả file */
.af-drop { position: relative; border: 1.5px dashed #CBD5E1; border-radius: var(--af-radius-sm, .5rem); background: #F9FAFB;
  padding: .9rem 1rem; text-align: center; transition: border-color .15s, background .15s; }
.af-drop:hover, .af-drop.is-over { border-color: var(--af-brand, #FE2C55); background: #FFF1F3; }
.af-drop:focus-within { outline: 2px solid var(--af-brand, #FE2C55); outline-offset: 2px; }
.af-drop-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.af-drop-title { font-size: .875rem; color: var(--af-ink); }
.af-drop-link { color: var(--af-primary, #E11D48); font-weight: 600; text-decoration: underline; }
.af-drop-hint { font-size: .75rem; color: #6B7280; margin-top: .15rem; }
.af-drop-list { list-style: none; margin: .5rem 0 0; padding: 0; text-align: left; }
.af-drop-list li { display: flex; justify-content: space-between; gap: .75rem; font-size: .8125rem; padding: .25rem .5rem; background: #fff;
  border: 1px solid var(--af-border); border-radius: .375rem; margin-top: .25rem; }
.af-drop-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-drop-size { color: #6B7280; flex: none; }
.af-drop-err { font-size: .8125rem; color: #B91C1C; margin-top: .35rem; text-align: left; }
.af-drop-err:empty { display: none; }
.af-uploading { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 9999; background: var(--af-ink, #161823);
  color: #fff; font-size: .875rem; padding: .7rem 1.1rem; border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

/* UX-R1: thanh nút cuối form mẫu không xuống dòng ở màn 1366px */
.af-footer-bar .af-btn { white-space: nowrap; }
@media (max-width: 1440px) { .af-footer-bar > span.text-xs { display: none !important; } .af-footer-bar > span.text-xs + .af-btn { margin-left: auto; } }

/* Bảng TKQC lớn (~1000 dòng): trình duyệt chỉ dựng các dòng đang thấy trên màn hình. */
.af-tbody-lazy > tr { content-visibility: auto; contain-intrinsic-size: auto 41px; }

/* Thanh tải trang (af-nav.js) */
#af-navbar { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 9999; background: #FE2C55; opacity: 0; pointer-events: none; }
#af-navbar.is-on { opacity: 1; animation: af-nav 8s cubic-bezier(.1,.7,.2,1) forwards; }
@keyframes af-nav { 0% { width: 0; } 10% { width: 35%; } 100% { width: 92%; } }
@media (prefers-reduced-motion: reduce) { #af-navbar.is-on { animation: none; width: 60%; } }
