:root {
  --bg: #F7F7F8; --surface: #FFFFFF; --line: #E5E7EB; --ink: #1F2937; --muted: #6B7280;
  --accent: #C2410C; --accent-soft: #FFF3EC; --pos: #15803D; --pos-soft: #E9F7EE;
  --neg: #B91C1C; --neg-soft: #FEECEC; --warn-soft: #FEF6E0; --warn: #92600A;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, "Segoe UI", sans-serif; }
a { color: var(--accent); }
.side { position: fixed; inset: 0 auto 0 0; width: 224px; background: var(--surface); border-right: 1px solid var(--line); padding: 16px 10px; overflow-y: auto; }
.brand { font-weight: 700; font-size: 15px; padding: 2px 10px 14px; }
.side a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.side a:hover { background: var(--bg); }
.side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .sep { border-top: 1px solid var(--line); margin: 10px 0; }
main { margin-left: 224px; padding: 16px 24px 48px; }
.sale { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.sale b { color: var(--ink); font-weight: 600; }
.sale .pill { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; }
.sale .pill.now { background: var(--accent-soft); border-color: #F5C9AE; color: var(--accent); }
.top { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 10px; }
.temp { background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
h1 { font-size: 20px; margin: 14px 0 10px; }
h2 { font-size: 15px; margin: 24px 0 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; }
.profit-box { margin-bottom: 16px; }
.profit-title { font-weight: 650; font-size: 15px; margin-bottom: 10px; }
.profit-eq { display: grid; grid-template-columns: 1fr auto 1fr auto 1.2fr; gap: 12px; align-items: center; }
.profit-eq .k { color: var(--muted); font-size: 12px; }
.profit-eq .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.profit-eq .v.big { font-size: 28px; }
.profit-eq .muted { font-size: 12px; }
.profit-eq .op { font-size: 26px; color: var(--muted); font-weight: 300; }
.profit-foot { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; }
@media (max-width: 720px) { .profit-eq { grid-template-columns: 1fr; } .profit-eq .op { display: none; } }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.note { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 6px; padding: 9px 12px; margin: 10px 0; }
.note.ok { border-left-color: var(--pos); } .note.err { border-left-color: var(--neg); }
.note.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.bar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin: 8px 0 12px; }
label { font-size: 12px; color: var(--muted); display: grid; gap: 3px; }
input, select { font: inherit; padding: 6px 8px; border: 1px solid #D1D5DB; border-radius: 6px; background: #fff; color: var(--ink); }
input.bud { width: 112px; text-align: right; }
.btn { font: inherit; padding: 7px 13px; border-radius: 6px; border: 1px solid #D1D5DB; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #A63A0B; }
.btn.refresh { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn.refresh:hover { background: var(--accent-soft); }
.btn:disabled, .btn.primary:disabled { background: #F1F1F3; color: #6B7280; border-color: var(--line); cursor: not-allowed; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; background: #fff; text-decoration: none; color: var(--ink); font-size: 13px; }
.chip.on { background: var(--accent-soft); border-color: #F5C9AE; color: var(--accent); }
.tbl-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: 72vh; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; background: #F3F4F6; text-align: left; font-size: 12px; color: #374151; font-weight: 600; white-space: nowrap; cursor: pointer; user-select: none; z-index: 1; box-shadow: inset 0 -1px #D1D5DB; }
th[aria-sort="ascending"]::after { content: " ▲"; } th[aria-sort="descending"]::after { content: " ▼"; }
th[data-tip] { text-decoration: underline dotted #9CA3AF; text-underline-offset: 3px; }
th, td { padding: 7px 10px; }
/* Đường kẻ rõ: ngang giữa các dòng, dọc mờ giữa các cột để mắt dóng tiêu đề với số. */
td { border-top: 1px solid #E5E7EB; }
th + th, td + td { border-left: 1px solid #EEF0F2; }
tbody tr:nth-child(even) td { background: #FAFAFB; }
tr:hover td, tbody tr:nth-child(even):hover td { background: #FFF7F0; }
tfoot tr.total td { background: #F3F4F6; border-top: 2px solid #D1D5DB; font-weight: 600; position: sticky; bottom: 0; }
th.dragging { opacity: .4; } th.drop-before { box-shadow: inset 3px 0 var(--accent), inset 0 -1px #D1D5DB; }
.col-hide { display: none; }
.cols-menu { position: relative; }
.cols-menu summary { list-style: none; } .cols-menu summary::-webkit-details-marker { display: none; }
.cols-menu .cols-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 8px 10px; width: 260px; max-height: 60vh; overflow: auto; display: grid; gap: 2px; }
.cols-menu .cols-list label { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink); padding: 3px 2px; }
.cols-menu .cols-list .muted { font-size: 12px; margin-bottom: 4px; }
.num, .st { white-space: nowrap; }
.num { text-align: right; }
.tag { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 5px; font-size: 11px; margin-left: 5px; white-space: nowrap; }
.badge { border-radius: 4px; padding: 2px 7px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #EEF0F3; color: #374151; }
.a-TAT { background: var(--neg-soft); color: var(--neg); }
.a-TANG, .a-BAT_LAI { background: var(--pos-soft); color: var(--pos); }
.a-GIAM, .a-XEM_TAY { background: var(--warn-soft); color: var(--warn); }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 14px; }
/* Phân tích setup: khung gợi ý nổi bật trên đầu trang. */
.advice { background: var(--surface); border: 1px solid #F5C9AE; border-top: 4px solid var(--accent); border-radius: 10px; padding: 14px 16px; margin: 4px 0 16px; }
.advice-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.advice-head h2 { margin: 0 0 4px; font-size: 17px; }
.advice-head p { margin: 0 0 10px; }
.advice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; margin: 6px 0 10px; }
.advice-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #FCFCFD; }
.advice-item .k { font-size: 12px; color: var(--muted); }
.advice-item .v { font-size: 15px; font-weight: 650; margin: 2px 0; overflow-wrap: anywhere; }
.advice-item .muted { font-size: 12px; }
.advice-item.lv-hi { border-color: #BFE3CB; background: var(--pos-soft); }
.advice-item.lv-hi .v { color: var(--pos); }
.advice-item.lv-lo { opacity: .75; }
.recipe { background: var(--accent-soft); border-radius: 6px; padding: 8px 10px; margin: 0 0 8px; }
.top-camps { margin-top: 10px; }
.top-camps summary { cursor: pointer; margin-bottom: 8px; }
/* Biểu đồ cột HTML: chữ đúng cỡ trên mọi màn hình. */
.chart-panel { margin-top: 16px; }
.chart-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.chart-head .legend { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw.pos, .bc-bar.pos { background: #2F9E6A; } .sw.neg, .bc-bar.neg { background: #E2685A; } .bc-bar.neu { background: var(--accent); }
.bchart { padding-left: 52px; }
.bc-plot { position: relative; height: 220px; }
.bc-grid { position: absolute; left: 0; right: 0; border-top: 1px solid #EEF0F3; }
.bc-grid.zero { border-top: 1px solid #9CA3AF; z-index: 1; }
.bc-grid span { position: absolute; left: -52px; width: 44px; text-align: right; transform: translateY(-50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bc-cols { position: absolute; inset: 0; display: flex; gap: 2px; }
.bc-col { flex: 1; position: relative; min-width: 0; cursor: default; border-radius: 3px; }
.bc-col:hover { background: rgba(31, 41, 55, .06); }
.bc-bar { position: absolute; left: 50%; transform: translateX(-50%); width: min(70%, 26px); }
.bc-bar.pos, .bc-bar.neu { border-radius: 3px 3px 0 0; } .bc-bar.neg { border-radius: 0 0 3px 3px; }
.bc-val { position: absolute; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 600; white-space: nowrap; color: var(--ink); }
.bc-x { display: flex; gap: 2px; margin-top: 6px; }
.bc-x span { flex: 1; min-width: 0; font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; overflow: visible; }
#tip { position: fixed; display: none; background: #1F2937; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 5px; pointer-events: none; z-index: 20; }
.switch { position: relative; display: inline-block; width: 34px; height: 18px; vertical-align: middle; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #C9CDD3; border-radius: 99px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: #2563EB; }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input.changed + span { box-shadow: 0 0 0 2px #F59E0B; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #9CA3AF; vertical-align: 1px; }
.dot.on { background: var(--pos); } .dot.warn { background: #D97706; }
/* Bảng gọn: tên sản phẩm + dòng nhỏ tài khoản · page · người đăng */
td.prod { min-width: 190px; max-width: 280px; }
td.prod .sub { color: var(--muted); font-size: 12px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td.wrap { min-width: 180px; max-width: 320px; white-space: normal; font-size: 13px; }
.tag.new { background: #E8F0FE; color: #1D4ED8; }
.a-GIU { background: var(--warn-soft); color: var(--warn); }
.a-KHONG_CHI { background: var(--warn-soft); color: var(--warn); }
.a-DANG_TAT, .a-CHUA_DU, .a-KHONG_AP { background: #EEF0F3; color: var(--muted); }
/* Cột ghim khi cuộn ngang */
td.stick, th.stick { position: sticky; z-index: 1; background: var(--surface); }
tbody tr:nth-child(even) td.stick { background: #FAFAFB; }
tr:hover td.stick { background: #FFF7F0; }
th.stick { z-index: 3; background: #F3F4F6; }
.stick-last { box-shadow: inset -1px 0 #D1D5DB; }
/* Nhóm theo hành động */
tr.ghead td { cursor: pointer; font-size: 13px; padding: 6px 10px; border-top: 1px solid var(--line); user-select: none; }
tr.ghead .gl { position: sticky; left: 10px; }
tr.ghead .caret::before { content: "▾"; display: inline-block; width: 14px; }
tbody.collapsed tr.ghead .caret::before { content: "▸"; }
tbody.collapsed tr:not(.ghead), tbody.g-hide, tbody.s-empty, tr.s-hide { display: none; }
tbody tr.g-neg td, tbody tr.g-neg:hover td { background: var(--neg-soft); color: var(--neg); }
tbody tr.g-pos td, tbody tr.g-pos:hover td { background: var(--pos-soft); color: var(--pos); }
tbody tr.g-warn td, tbody tr.g-warn:hover td { background: var(--warn-soft); color: var(--warn); }
tbody tr.g-muted td, tbody tr.g-muted:hover td { background: #F3F4F6; color: var(--muted); }
tr.ghead:hover td { filter: brightness(.98); }
.chip { cursor: pointer; font: inherit; font-size: 13px; }
.chip.c-neg { border-color: #F5C2C2; color: var(--neg); }
.chip.c-pos { border-color: #BFE3CB; color: var(--pos); }
.chip.c-warn { border-color: #EBD9A6; color: var(--warn); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#groupChips { margin: 0 0 10px; }
.actbar { align-items: center; }
.actbar .grow { flex: 1; }
.tbl-tools { display: flex; gap: 10px; align-items: center; margin: 0 0 8px; flex-wrap: wrap; }
.tbl-search { width: 300px; max-width: 100%; }
/* Nút lọc theo tài khoản aff: một dòng riêng phía trên ô tìm. */
.tbl-tools .tbl-filter { flex-basis: 100%; order: -1; }
.tbl-tools .cols-menu { margin-left: auto; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.alerts { display: grid; gap: 6px; margin: 0 0 10px; }
.alert { background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 7px 12px; font-size: 13px; }
.alert b { font-weight: 600; }
.keys { font-size: 12px; margin: 8px 0 0; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: 12px/1.4 inherit; background: #fff; }
form.quiet { margin-top: 4px; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; }
.drop { display: block; font-size: 13px; margin-bottom: 14px; border: 2px dashed #D1D5DB; border-radius: 10px; padding: 26px; text-align: center; background: var(--surface); color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop b { color: var(--ink); font-size: 15px; display: block; margin-bottom: 4px; }
.drop-results { display: grid; gap: 6px; margin-top: 10px; }
ol.steps { margin: 6px 0 10px; padding-left: 20px; font-size: 13px; }
textarea { font: 13px/1.4 ui-monospace, Consolas, monospace; padding: 8px; border: 1px solid #D1D5DB; border-radius: 6px; }
.aff-group { margin-bottom: 22px; }
.aff-head { font-size: 16px; margin: 18px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--accent); }
.aff-head .muted { font-size: 13px; font-weight: 400; }
.aff-group .pack { margin-left: 14px; }
.pack-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.pack-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.pack-grid .k { color: var(--muted); font-size: 12px; }
.pack-grid .v { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pack-grid .muted { font-size: 12px; }
.meter { position: relative; height: 8px; background: #EEF0F3; border-radius: 99px; margin: 6px 0 4px; }
.meter span { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 99px; }
.meter.loss span { background: var(--neg); }
.meter i { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--ink); opacity: .55; }
.kpi { margin-top: 12px; padding: 8px 12px; background: var(--bg); border-radius: 6px; font-size: 13px; border-left: 3px solid var(--line); }
.kpi.pos { border-left-color: var(--pos); }
.kpi.warn { border-left-color: var(--warn); }
.kpi.neg { border-left-color: var(--neg); }
.badge.st-pos { background: var(--pos-soft); color: var(--pos); }
.badge.st-warn { background: var(--warn-soft); color: var(--warn); }
.badge.st-neg { background: var(--neg-soft); color: var(--neg); }
.pack-edit { margin-top: 8px; }
.pack-actions { display: flex; gap: 8px; align-items: center; }
.pack-actions form { margin: 0; }
.btn.danger { color: var(--neg); border-color: #F5C2C2; }
.btn.danger:hover { background: var(--neg-soft); }
.pack-edit summary { cursor: pointer; font-size: 12px; }
details.rules summary { cursor: pointer; }
details.rules[open] summary { margin-bottom: 10px; }
.rules-tbl { width: auto; margin-bottom: 4px; }
.rules-tbl th { cursor: default; position: static; }
.rules-tbl td { vertical-align: middle; }
.rules-tbl input[type=number] { width: 110px; text-align: right; }
label.pick-all-wrap { display: inline-flex; gap: 5px; align-items: center; font-size: inherit; color: inherit; cursor: pointer; }
label.inline { display: inline-flex; gap: 4px; align-items: center; font-size: 14px; color: var(--ink); margin-right: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.muted { color: var(--muted); }
.slots { display: flex; gap: 10px; flex-wrap: wrap; }
form.stack { display: grid; gap: 10px; max-width: 360px; }
.side form.logout { padding: 8px 10px; margin: 0; }
body.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box { width: 100%; max-width: 360px; margin: 0; }
.login-box h1 { margin-top: 0; }
.login-box form { display: grid; gap: 12px; }
.login-box input { font-size: 16px; padding: 8px 10px; }
@media (max-width: 720px) {
  .side { position: static; width: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  main { margin-left: 0; padding: 12px 16px 40px; }
  .top { flex-wrap: wrap; }
}
tr.hl td { background: #FFF7ED; font-weight: 600; }
