/* Dashboard. Màu, chữ, phông nền và chuyển cảnh dùng chung nằm ở tokens.css.
   Quy ước: lam nhạt = điều hướng và mục đang chọn; mật ong = hành động chính; bạc hà / mật ong / mâm xôi = ổn / nên để ý / cần xem ngay. */
:root { --top-h: 56px; --ctx-h: 52px; --stick: var(--top-h); } /* --stick: tổng chiều cao phần đang dính ở mép trên */
html { scroll-padding-top: calc(var(--stick) + 16px); }
body { font-size: 14px; line-height: 1.5; }
h1, h2, h3, p { margin: 0; }
h2 { font-family: var(--display); font-size: 18px; font-weight: 600; letter-spacing: .005em; margin-bottom: 10px; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Điều khiển */
input, button, select { font: inherit; color: inherit; }
input[type=date], input[type=datetime-local], input[type=text], input[type=password], input[type=search], select {
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--field); min-height: 36px;
  transition: border-color .2s, box-shadow .2s;
}
input:hover, select:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
option { background: var(--card-solid); color: var(--ink); }
input[type=checkbox] { accent-color: var(--honey); width: 16px; height: 16px; }

button { position: relative; border: 1px solid transparent; background: linear-gradient(135deg, #ffd56f, var(--honey) 45%, var(--honey-2)); color: var(--on-honey); border-radius: 10px; padding: 6px 16px; min-height: 36px; cursor: pointer; font-weight: 650;
  box-shadow: 0 8px 22px -10px color-mix(in srgb, var(--honey) 80%, transparent), 0 1px 0 rgba(255, 255, 255, .45) inset;
  transition: transform .15s var(--ease), box-shadow .25s, filter .2s, border-color .2s, background-color .2s, color .2s; }
button:hover { filter: brightness(1.06); box-shadow: 0 12px 28px -10px color-mix(in srgb, var(--honey) 95%, transparent), 0 1px 0 rgba(255, 255, 255, .45) inset; }
button:active { transform: translateY(1px) scale(.985); }
button.ghost { background: var(--card); color: var(--ink); border-color: var(--line); box-shadow: none; }
button.ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; box-shadow: 0 0 0 4px var(--accent-soft); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button.link, button.text-btn { border: 0; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; font-weight: 650; white-space: nowrap; box-shadow: none; }
button.link, button.text-btn.danger { color: var(--bad); }
button.link:hover, button.text-btn:hover { text-decoration: underline; text-underline-offset: 3px; filter: none; box-shadow: none; }
button.busy { padding-left: 36px; }
button.busy .ico { display: none; }
button.busy::before { content: ""; position: absolute; left: 13px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Nút chọn dạng dải: ô chọn trượt tới vị trí mới (fx.js đo vị trí; không có JS thì tô nền nút đang chọn) */
.seg { position: relative; display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.seg::before { content: ""; position: absolute; top: 3px; bottom: 3px; left: 0; width: var(--tw, 0); transform: translateX(var(--tx, 0)); border-radius: 9px; opacity: 0;
  background: var(--accent-soft); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent) inset, 0 6px 18px -8px var(--accent);
  transition: transform .38s var(--ease), width .38s var(--ease); }
.seg.has-thumb::before { opacity: 1; }
.seg.no-anim::before { transition: none; }
.seg button { z-index: 1; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 650; box-shadow: none; min-height: 30px; padding: 4px 14px; white-space: nowrap; }
.seg button:hover { color: var(--ink); filter: none; box-shadow: none; }
.seg button[aria-selected=true] { color: var(--ink); }
.seg:not(.has-thumb) button[aria-selected=true] { background: var(--accent-soft); }

/* Thanh trên: mỏng, một dòng, luôn dính. Chỉ có tên, chế độ xem, Kết nối và nút sáng/tối */
.top { display: flex; gap: 12px; align-items: center; padding: 9px 24px; min-height: 56px; position: sticky; top: 0; z-index: 6; view-transition-name: topbar;
  background: color-mix(in srgb, var(--bg) 68%, transparent); -webkit-backdrop-filter: blur(18px) saturate(1.5); backdrop-filter: blur(18px) saturate(1.5); border-bottom: 1px solid var(--line-soft); }
html.theme-vt .top, html.theme-vt .ctx { view-transition-name: none; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; font-family: var(--display); font-size: 19px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; }
.connect-btn { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; flex: none; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 650; text-align: center; font-variant-numeric: tabular-nums; }
.count:empty { display: none; }
.connect-btn[aria-selected=true] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Thanh ngữ cảnh: Page đang xem, khoảng ngày, lần cập nhật. Dùng chung cho Đơn giản và Nâng cao */
.ctx { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 24px; border-bottom: 1px solid var(--line-soft); view-transition-name: ctxbar; }
body[data-view=connect] .ctx { display: none; }
.page-pick { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.page-pick select { max-width: 260px; font-weight: 650; color: var(--ink); }
.range-custom { display: flex; align-items: center; gap: 8px; }
.sync { display: flex; align-items: center; gap: 10px; margin-left: auto; }
#sync-btn { display: inline-flex; align-items: center; gap: 7px; }
@media (min-width: 900px) and (min-height: 700px) {
  /* Màn đủ rộng và đủ cao: thanh ngữ cảnh dính theo, để đổi ngày ngay cả khi đang ở cuối trang */
  :root { --stick: calc(var(--top-h) + var(--ctx-h)); }
  .ctx { position: sticky; top: var(--top-h); z-index: 5; background: color-mix(in srgb, var(--bg) 74%, transparent); -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4); }
  body[data-view=connect] { --stick: var(--top-h); }
}

.banner { margin: 14px 24px 0; padding: 10px 14px; border-radius: 12px; font-size: 13px; border: 1px solid var(--line-soft); }
.banner.live { background: var(--accent-soft); color: var(--accent); }
.banner.sample { background: var(--sample-soft); color: var(--sample); border: 1px dashed color-mix(in srgb, var(--sample) 60%, transparent); }
.banner.blocked { background: var(--warn-soft); color: var(--warn); }
/* Ghi chú độ phủ dữ liệu đã có trong dòng mô tả của Đơn giản; màn Kết nối không cần dải thông báo */
body[data-view=simple] .banner.live, body[data-view=connect] .banner { display: none; }

/* Chế độ xem */
.view { display: none; padding: 22px 24px 8px; }
body[data-view=simple] #view-simple, body[data-view=connect] #view-connect { display: block; }
body[data-view=advanced] #view-advanced { display: grid; }
.narrow { max-width: 920px; margin: 0 auto; }
.narrow > * + * { margin-top: 16px; }

/* Thẻ kính (.card, .kpi, .sheet): nền, viền và viền sáng theo con trỏ nằm ở tokens.css */
.card { border-radius: 16px; padding: 18px; }
.kpi { border-radius: 16px; padding: 16px; }
.sheet { border-radius: 18px; padding: 20px 22px; }
.sheet > * + * { margin-top: 10px; }

/* Phần giải thích gập sẵn ("Cách tính") và khối gập lớn (form, bảng phụ) */
summary { list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }
summary::before { content: ""; flex: none; display: inline-block; width: 6px; height: 6px; margin: 0 9px 2px 2px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .2s var(--ease); }
details[open] > summary::before { transform: rotate(45deg); }
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
details.how { font-size: 13px; }
details.how > summary { display: inline-block; color: var(--accent); font-weight: 650; padding: 2px 0; }
details.how > summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.how-body { margin-top: 6px; padding: 10px 14px; border-radius: 10px; background: var(--line-soft); color: var(--muted); max-width: 92ch; }
.how-body > * + * { margin-top: 6px; }
.how-body ul { margin: 0; padding-left: 18px; }
.how-body li + li { margin-top: 4px; }
.how-body b { color: var(--ink); font-weight: 650; }
.how-body .chips { margin: 0; }
details.fold { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); }
details.fold > summary { font-weight: 650; padding: 4px 0; }
details.fold > summary:hover { color: var(--accent); }
details.fold[open] > summary { margin-bottom: 12px; }
:is(.table-wrap, .bars, .chips, p) + details.how, .how + .table-wrap { margin-top: 10px; }

/* Đơn giản: một câu, danh sách việc, rồi dòng hội thoại */
.headline { font-family: var(--display); font-size: clamp(26px, 3.3vw, 40px); line-height: 1.16; font-weight: 600; letter-spacing: -.005em; max-width: 26em; margin: 6px 0 0; text-wrap: balance; }
.headline.tone-bad { color: var(--bad); }
.headline.tone-good { color: var(--good); }
#simple-meta:empty, #simple-extra:empty, #simple-body:empty { display: none; }
#simple-body > * + *, #simple-extra > * + * { margin-top: 16px; }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sheet-head h2 { margin: 0; }
.lead { font-size: 15px; max-width: 68ch; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sheet.empty { padding-left: 124px; min-height: 124px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop stop-color='%23FFD166'/%3E%3Cstop offset='1' stop-color='%23FF5D8F'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect x='4' y='4' width='24' height='6' rx='3' fill='url(%23g)'/%3E%3Crect x='6' y='12' width='20' height='6' rx='3' fill='url(%23g)' opacity='.75'/%3E%3Cpath d='M8 20h14a3 3 0 0 1 0 6h-7l-5 3.5V26H8a3 3 0 0 1 0-6z' fill='url(%23g)' opacity='.5'/%3E%3C/svg%3E"), linear-gradient(180deg, var(--card), var(--card-2)); background-repeat: no-repeat; background-position: 24px 50%, 0 0; background-size: 76px 76px, auto; }

.brief { list-style: none; margin: 0; padding: 0; }
.brief-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto 18px; gap: 6px 16px; align-items: center; padding: 14px 10px; margin: 0 -10px; border-radius: 12px; transition: background-color .25s; }
.brief-row.is-link { cursor: pointer; }
.brief-row.is-link:hover { background: var(--card-hi); }
.brief-row + .brief-row { box-shadow: 0 -1px 0 var(--line-soft); }
.brief-row.is-link:hover, .brief-row.is-link:hover + .brief-row { box-shadow: none; }
.brief-ico { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--line-soft); color: var(--muted); }
.brief-ico .ico { width: 21px; height: 21px; }
.brief-row h3 { font-size: 15px; margin: 2px 0; }
.brief-row p { color: var(--muted); max-width: 62ch; }
button.row-link { border: 0; background: none; color: inherit; padding: 0; min-height: 0; font-weight: 650; box-shadow: none; text-align: left; white-space: normal; border-radius: 4px; }
button.row-link:hover { filter: none; box-shadow: none; }
button.row-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.chev { color: var(--muted); transition: transform .25s var(--ease), color .2s; }
.brief-row.is-link:hover .chev { transform: translateX(3px); color: var(--accent); }
.brief-value { font-family: var(--display); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; line-height: 1.1; }
.brief-value.is-text { font-size: 19px; white-space: normal; max-width: 8.5em; line-height: 1.2; }
.brief-value .unit { font-family: var(--text); font-size: 13px; font-weight: 500; color: var(--muted); }
.tone-tag { font-size: 12px; font-weight: 650; }
.brief-row.tone-bad .tone-tag, .brief-row.tone-bad .brief-value { color: var(--bad); }
.brief-row.tone-bad .brief-ico { background: var(--bad-soft); color: var(--bad); animation: pulse 2.4s ease-out 3; } /* nháy ba lần lúc mới vẽ rồi đứng yên */
.brief-row.tone-warn .tone-tag { color: var(--warn); }
.brief-row.tone-warn .brief-ico { background: var(--warn-soft); color: var(--warn); }
.brief-row.tone-good .tone-tag { color: var(--good); }
.brief-row.tone-good .brief-ico { background: var(--good-soft); color: var(--good); }
.brief-row.tone-info .tone-tag { color: var(--muted); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 12px transparent; } }
body.quiet .brief-row.tone-bad .brief-ico { animation: none; }
.findings { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.findings li { padding-left: 12px; border-left: 3px solid var(--warn); }
.findings li.tone-bad { border-left-color: var(--bad); }

/* Dòng hội thoại (flow.js): hình minh họa cho các số ở trên, nên thấp và nằm sau danh sách việc */
.flow { padding: 0; overflow: hidden; }
.flow > * + * { margin-top: 0; }
.flow-head { display: flex; align-items: baseline; gap: 6px 14px; flex-wrap: wrap; padding: 14px 22px 0; }
.flow-head h2 { margin: 0; font-size: 15px; }
.flow-cap:empty { display: none; }
.flow-head .how { margin-left: auto; }
.flow-head .how[open] { flex-basis: 100%; }
.flow canvas { display: block; width: 100%; height: 96px; }
.flow-stages { list-style: none; margin: 0; padding: 0 0 14px; display: grid; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); text-align: center; }
.flow-stage { padding: 0 6px; }
.flow-stage + .flow-stage { border-left: 1px dashed var(--line-soft); }
.flow-stage b { display: block; font-family: var(--display); font-size: clamp(19px, 2.6vw, 25px); font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.flow-stage .name { display: block; font-weight: 650; font-size: 13px; }
.flow-stage .share { display: block; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.flow-stage.lead b { color: var(--honey); }
:root[data-theme=light] .flow-stage.lead b { color: var(--warn); }
.flow-stage.order b { color: var(--good); }

/* Kết nối */
.tok-form label { font-weight: 650; }
.tok-line { display: flex; gap: 10px; }
.tok-line input { flex: 1; min-width: 0; min-height: 48px; font-size: 15px; font-family: "Cascadia Mono", Consolas, monospace; border-radius: 12px; }
.tok-line button { min-height: 48px; padding: 0 24px; border-radius: 12px; }
.hint { min-height: 18px; color: var(--honey); font-weight: 650; }
:root[data-theme=light] .hint { color: var(--accent); }
.tok-opts { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; color: var(--muted); }
.tok-opts label { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.form-msg:empty { display: none; }
.form-msg { padding: 9px 12px; border-radius: 10px; }
.form-msg.tone-good { background: var(--good-soft); color: var(--good); }
.form-msg.tone-bad { background: var(--bad-soft); color: var(--bad); }
.form-msg.tone-info { background: var(--line-soft); color: var(--muted); }
#reports > * + * { margin-top: 10px; }
.conn-list { list-style: none; margin: 0; padding: 0; }
.conn { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 12px 0; flex-wrap: wrap; }
.conn + .conn { border-top: 1px solid var(--line-soft); }
.conn-kind { font-size: 12px; color: var(--muted); }
.conn-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.guides { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.guide { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 14px; padding: 14px; border-radius: 14px; border: 1px solid var(--line-soft); background: var(--card-2); }
.guide-ico { grid-row: 1 / span 2; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; background: var(--line-soft); color: var(--muted); }
.guide-ico .ico { width: 22px; height: 22px; }
.guide.on .guide-ico { background: linear-gradient(135deg, #ffd56f, var(--honey-2)); color: var(--on-honey); box-shadow: 0 10px 22px -10px var(--honey); }
.guide dt { font-weight: 650; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.guide dd { margin: 0; max-width: 72ch; grid-column: 2; }
.guide-state { font-size: 12px; font-weight: 650; color: var(--muted); }
.guide.on .guide-state { color: var(--good); }

/* Nâng cao: cột tab bên trái, mỗi tab một nhóm việc */
.adv { grid-template-columns: 214px minmax(0, 1fr); gap: 22px; align-items: start; padding-top: 18px; }
.adv > main { min-width: 0; }
.tab { display: grid; gap: 18px; min-width: 0; animation: tab-in .22s ease both; }
@keyframes tab-in { from { opacity: 0; } }
.adv-nav { position: sticky; top: calc(var(--stick) + 16px); display: grid; gap: 2px; }
.adv-nav a { position: relative; display: flex; align-items: center; gap: 10px; color: var(--muted); text-decoration: none; padding: 9px 12px; border-radius: 10px; font-weight: 650; transition: background-color .2s, color .2s; }
.adv-nav a:hover { background: var(--line-soft); color: var(--ink); }
.adv-nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.adv-nav a[aria-selected=true] { background: var(--accent-soft); color: var(--ink); }
.adv-nav a[aria-selected=true] .ico { color: var(--honey); }
:root[data-theme=light] .adv-nav a[aria-selected=true] .ico { color: var(--accent); }
.adv-nav a[aria-selected=true]::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: linear-gradient(180deg, var(--honey), var(--berry)); }
.adv-nav .count { margin-left: auto; background: var(--bad-soft); color: var(--bad); }
@media (max-width: 899px) {
  /* Màn hẹp: dải tab nằm ngang và dính ngay dưới thanh trên */
  :root { --stick: calc(var(--top-h) + 54px); }
  .adv { grid-template-columns: minmax(0, 1fr); gap: 14px; padding-top: 0; }
  .adv-nav { top: var(--top-h); z-index: 4; display: flex; overflow-x: auto; gap: 6px; margin: 0 -24px; padding: 9px 24px; scrollbar-width: none;
    background: color-mix(in srgb, var(--bg) 78%, transparent); -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4); border-bottom: 1px solid var(--line-soft); }
  .adv-nav::-webkit-scrollbar { display: none; }
  .adv-nav a { flex: none; white-space: nowrap; background: var(--card); border: 1px solid var(--line-soft); padding: 6px 12px; }
  .adv-nav a[aria-selected=true] { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
  .adv-nav a[aria-selected=true]::before { display: none; }
  .adv-nav .count { margin-left: 0; }
  body:not([data-view=advanced]) { --stick: var(--top-h); }
}

.card-head { margin-bottom: 10px; }
.card-head > * + * { margin-top: 4px; }
.card-head.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-head.row > * + * { margin-top: 0; }
.card-head.row h2 { margin: 0; }
.card-head h2 { margin-bottom: 0; }
.kpis-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; } /* năm ô vừa một hàng ở màn 1280 */
.kpis-grid > .how { grid-column: 1 / -1; }
.kpis details.fold { margin-top: 12px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .value { font-family: var(--display); font-size: 31px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 4px 0 2px; line-height: 1.15; }
.kpi .frac { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi .text-btn { padding-left: 0; margin-top: 2px; }
.slim-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--muted); }
.card.slim { padding-top: 14px; padding-bottom: 14px; }
.card.slim h2 { font-size: 15px; margin-bottom: 4px; }

.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; margin-left: 4px; white-space: nowrap; font-weight: 600; }
.badge.ok { background: var(--good-soft); color: var(--good); }
.badge.small_sample { background: var(--warn-soft); color: var(--warn); }
.badge.no_data, .badge.not_configured, .badge.no_field { background: var(--line-soft); color: var(--muted); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.table-wrap { overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 9px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 650; white-space: nowrap; }
tbody tr { transition: background-color .15s; }
tbody tr:hover { background: var(--line-soft); }
td.n { white-space: nowrap; }
td .pct { font-weight: 650; }
td .frac, p .frac { color: var(--muted); font-size: 12px; display: block; }
td .frac.nw { white-space: nowrap; }
td .frac.tone-bad { color: var(--bad); }
.act .fb-line { margin-top: 4px; }
tr.unassigned td { color: var(--muted); font-style: italic; }
table.sticky-first th { white-space: normal; vertical-align: bottom; min-width: 88px; }
/* Bảng rộng: cột đầu dính lại khi cuộn ngang để luôn biết đang đọc dòng nào */
table.sticky-first th:first-child, table.sticky-first td:first-child { position: sticky; left: 0; z-index: 1; min-width: 150px; background: var(--card-solid); box-shadow: 1px 0 0 var(--line-soft); }
button.sort { display: inline-flex; align-items: baseline; gap: 6px; border: 0; background: none; padding: 0; min-height: 0; box-shadow: none; color: var(--accent); font-size: 12px; font-weight: 650; }
button.sort:hover { filter: none; box-shadow: none; text-decoration: underline; text-underline-offset: 3px; }
.sort-dir { font-weight: 400; color: var(--muted); }
.wait-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0 6px; overflow-x: auto; scrollbar-width: none; }
.more-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 12px; }

.vform { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.vform label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.vform .grow { flex: 1 1 220px; }
.vform p { width: 100%; }
.vform p:empty { display: none; }
.vlist { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.vlist li { font-size: 13px; }
#version-list li { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding: 6px 0; border-top: 1px solid var(--line-soft); }
#version-list li b { font-weight: 650; }

/* Biểu đồ: cột và thanh mọc lên một lần khi có số mới; lúc tự tải lại định kỳ (body.quiet) thì đứng yên */
.bars { display: grid; gap: 10px; }
.bars + p { margin-top: 8px; }
.barrow { display: grid; grid-template-columns: 170px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.bartrack { background: var(--line-soft); border-radius: 999px; height: 12px; overflow: hidden; }
.barfill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--honey)); transform-origin: 0 50%; animation: grow-x .9s var(--ease) both; }
@keyframes grow-x { from { transform: scaleX(0); } }
#responder + .table-wrap { margin-top: 14px; }
#staff-note, #tags-note { margin-top: 10px; }
#staff-note:empty, #tags-note:empty { display: none; }
.note { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 12px; }
.note.info { background: var(--line-soft); color: var(--muted); }

/* Dòng đọc số: rê chuột hoặc chạm vào cột/ô thì số hiện ở đây (dùng được cả trên màn cảm ứng) */
.readout { min-height: 18px; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.daily { display: flex; align-items: flex-end; gap: 3px; height: 160px; border-bottom: 1px solid var(--line); padding-top: 8px; }
.daily .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; min-width: 3px; position: relative; height: 100%; cursor: crosshair; }
.daily .col .all { display: flex; flex-direction: column; justify-content: flex-end; background: var(--bar2); border-radius: 4px 4px 0 0; overflow: hidden; transform-origin: 50% 100%; animation: grow-y .7s var(--ease) both; animation-delay: calc(var(--i, 0) * 16ms); transition: filter .15s; }
.daily .col .rep { background: linear-gradient(180deg, var(--honey), var(--accent)); }
.daily .col:hover .all { filter: brightness(1.35) saturate(1.2); }
@keyframes grow-y { from { transform: scaleY(0); } }
.daily-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
body.quiet .barfill, body.quiet .daily .col .all, body.quiet .heat { animation: none; }

.kv { display: grid; grid-template-columns: 260px 1fr; gap: 4px 12px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
ul.issues { margin: 6px 0; padding-left: 18px; }
ul.issues li.blocker { color: var(--warn); }
ul.issues li.error { color: var(--bad); }
footer { padding: 18px 24px 30px; text-align: center; }

.cmp-cell { min-width: 200px; }
.cmp { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; font-size: 12px; margin-top: 3px; }
.cmp-name { color: var(--muted); min-width: 72px; }
.verdict { font-weight: 650; border-radius: 6px; padding: 0 6px; white-space: nowrap; }
.verdict.up { background: var(--good-soft); color: var(--good); }
.verdict.down { background: var(--bad-soft); color: var(--bad); }
.verdict.flat { background: var(--warn-soft); color: var(--warn); }
.verdict.na { background: transparent; color: var(--muted); font-weight: 400; font-style: italic; padding: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: 999px; padding: 2px 11px; font-size: 12px; }
/* Bản đồ nhiệt: app.js đặt --a (0..1) và loại ô; màu lấy theo giao diện sáng/tối */
.heat-table { border-collapse: separate; border-spacing: 3px; width: 100%; }
.heat-table th, .heat-table td { border: 0; padding: 0; }
.heat-table tbody tr:hover { background: none; }
.heat-table .heat { --c: var(--good); text-align: center; font-size: 11px; height: 26px; min-width: 22px; border-radius: 6px; font-variant-numeric: tabular-nums; cursor: crosshair;
  background: color-mix(in srgb, var(--c) calc(var(--a, 0) * 100%), var(--line-soft)); animation: fade-in .6s ease both; transition: box-shadow .15s; }
.heat-table .heat.k-f { --c: var(--berry); }
.heat-table .heat.k-s { --c: var(--honey); }
.heat-table .heat.hot { color: var(--on-heat); font-weight: 650; }
.heat-table .heat:hover { box-shadow: 0 0 0 2px var(--ink); }
@keyframes fade-in { from { opacity: 0; } }
.heat-table .heat-h { text-align: center; font-size: 10px; color: var(--muted); font-weight: 400; }
.heat-table .heat-label { text-align: left; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; padding-right: 8px; }
.sub-h { margin-top: 16px; color: var(--muted); }
.sub-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-top: 16px; }
.sub-head .sub-h { margin-top: 0; }
.sub-head .how[open] { flex-basis: 100%; }
.bc-account > * + * { margin-top: 10px; }
.bc-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.bc-tools input { min-width: 220px; }
.bc-score { margin-top: 10px; }
.bc-score > * + * { margin-top: 6px; }
.bc-score td:first-child { white-space: nowrap; }

/* Thông báo trong trang (thay hộp thoại của trình duyệt): góc dưới, tự tắt, có thể kèm nút Hoàn tác */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 30; display: grid; gap: 8px; width: min(440px, calc(100vw - 36px)); }
.toast { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-radius: 14px; background: var(--card-solid); border: 1px solid var(--line); box-shadow: var(--shadow); animation: toast-in .28s var(--ease) both; }
.toast > span { flex: 1; min-width: 0; }
.toast.tone-bad { border-color: color-mix(in srgb, var(--bad) 70%, transparent); }
.toast.tone-good { border-color: color-mix(in srgb, var(--good) 70%, transparent); }
.toast .toast-x { color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 8px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 640px) {
  /* Màn hẹp: thanh trên vẫn dính nhưng gọn lại (ẩn chữ, giữ biểu tượng); thanh ngữ cảnh xếp dọc và cuộn theo trang */
  .top { padding: 8px 14px; gap: 8px; }
  .brand-name, .connect-btn .btn-text { display: none; }
  .connect-btn { padding: 6px 10px; }
  .ctx { padding: 10px 14px; gap: 8px; }
  .page-pick { width: 100%; }
  .page-pick select { max-width: none; flex: 1; min-width: 0; }
  .seg.range { width: 100%; }
  .seg.range button { flex: 1; padding: 4px 6px; }
  .range-custom { width: 100%; }
  .range-custom input { flex: 1; min-width: 0; }
  .sync { width: 100%; margin-left: 0; justify-content: space-between; }
  .view { padding: 16px 14px 8px; }
  .adv { padding-top: 0; }
  .banner { margin: 12px 14px 0; }
  .adv-nav { margin: 0 -14px; padding: 9px 14px; }
  .flow-stages { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 12px; padding-top: 4px; }
  .flow-stage + .flow-stage { border-left: 0; }
  .flow canvas { height: 84px; }
  .flow-head { padding: 12px 16px 0; }
  .barrow { grid-template-columns: 104px 1fr 92px; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: 6px; }
  .brief-row { grid-template-columns: auto minmax(0, 1fr) auto 14px; gap: 6px 10px; }
  .brief-ico { width: 36px; height: 36px; border-radius: 11px; }
  .brief-value { font-size: 24px; }
  .brief-value.is-text { font-size: 16px; max-width: 6em; }
  .chev { width: 14px; height: 14px; }
  .tok-line { flex-direction: column; }
  .sheet { padding: 16px; }
  .card { padding: 14px; }
  .sheet.empty { padding-left: 16px; padding-top: 96px; background-position: 16px 16px, 0 0; background-size: 64px 64px, auto; }
  .kpis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 25px; }
  table.sticky-first th:first-child, table.sticky-first td:first-child { min-width: 112px; }
  table.wide { min-width: 600px; } /* bảng nhiều cột: cuộn ngang trong khung thay vì ép chữ thành từng từ một dòng */
  .toasts { right: 12px; bottom: 12px; width: calc(100vw - 24px); }
}

/* Kết nối Meta: Admin của mỗi tổ chức tự chọn tài khoản quảng cáo và Page của công ty mình */
.meta-box .tok-line { margin-top: 10px; }
.meta-fold { margin-top: 10px; }
.meta-fold > summary { cursor: pointer; font-weight: 600; }
.asset-group { margin: 12px 0; }
.asset-group h4 { margin: 0 0 6px; font-size: 14px; }
.asset-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--field); }
.asset-list li + li { border-top: 1px solid var(--line-soft); }
.asset-list .check { display: flex; gap: 8px; align-items: baseline; padding: 7px 10px; margin: 0; }
.asset-name { flex: 1 1 auto; }

/* Bảng quảng cáo Meta */
.meta-ads-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.meta-ads-bar .small { flex: 1 1 240px; }
tr.row-warn td { background: var(--warn-soft); }

/* Doanh thu va ROAS theo quang cao (hang 1) */
b.good, .n b.good { color: var(--good); }
b.bad, .n b.bad { color: var(--bad); }
.margin-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--line-soft); }
.margin-form label { font-size: 13px; font-weight: 600; }
.margin-form input { width: 110px; }
.margin-form .small { flex: 1 1 220px; }
/* Doi soat chi phi Pancake - Meta (hang 2) */
.recon-sum { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.recon-sum .pill { border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; font-size: 13px; }
.recon-sum .pill b { font-variant-numeric: tabular-nums; }
td.diff-ok { color: var(--muted); }
td.diff-bad b { color: var(--bad); }
tr.row-one-side td { background: var(--line-soft); }
tr.row-ai td { background: var(--good-soft); }
#ai-split select { padding: 4px 8px; }
/* Suc khoe dong bo (hang 8) */
.health-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; display: grid; gap: 4px; }
.health-row.state-loi { border-color: var(--bad); background: var(--bad-soft); }
.health-row.state-canh_bao { border-color: var(--warn); background: var(--warn-soft); }
.health-why { margin: 2px 0 0 18px; font-size: 13px; }
.health-why .bad { color: var(--bad); }
.runstrip { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.runstrip .run { font-size: 11px; border-radius: 5px; padding: 1px 7px; background: var(--line-soft); color: var(--muted); }
.runstrip .run-ok { background: var(--good-soft); color: var(--good); }
.runstrip .run-partial { background: var(--warn-soft); color: var(--warn); }
.runstrip .run-error, .runstrip .run-blocked { background: var(--bad-soft); color: var(--bad); }

/* Kết nối: hỏi lại trước khi tạo token Page, ghi chú lỗi ở từng dòng */
.conn-ask { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); }
.conn-ask p { margin: 0 0 8px; }
.small.tone-bad { color: var(--bad); }
