:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --text: #e7e9ee; --muted: #8b93a3; --accent: #fe2c55; --accent2: #25f4ee;
  --good: #2ecc71; --warn: #f1c40f; --bad: #ff5c5c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, "Sukhumvit Set", "Noto Sans Thai", system-ui, sans-serif; }
header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { width: 40px; height: 40px; object-fit: contain; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); }
.badge.demo { background: #3a2f10; color: var(--warn); }
.badge.live { background: #12321f; color: var(--good); }
nav { display: flex; gap: 4px; }
.tab { background: none; color: var(--muted); border: 0; padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; }
.tab.active { background: var(--panel2); color: var(--text); }
main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }

button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
button.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
button:hover { filter: brightness(1.1); }
button.sm { padding: 4px 10px; font-size: 12px; }
input, select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: inherit; }
input:focus, select:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar #search { flex: 1; min-width: 160px; }
.spacer { flex: 1; }
.range { display: flex; gap: 6px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: #2a1520; border: 1px solid #5a2236; padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
.bulk span { margin-right: 8px; font-weight: 600; }
.bulk button { padding: 5px 12px; background: var(--panel2); border: 1px solid var(--line); }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; background: var(--panel); }
th.sorted::after { content: " ▾"; }
th.sorted.asc::after { content: " ▴"; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 32px; }
.cname { font-weight: 600; }
.ctype { font-size: 11px; color: var(--muted); }
.roi.good { color: var(--good); } .roi.mid { color: var(--warn); } .roi.bad { color: var(--bad); }
.editable { cursor: pointer; border-bottom: 1px dashed var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { display: none; }
.switch span { width: 38px; height: 22px; background: var(--line); border-radius: 99px; position: relative; transition: .2s; flex: none; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { left: 19px; }
.switch small { color: var(--muted); }

.templates { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.templates button { background: var(--panel2); border: 1px dashed var(--line); color: var(--muted); font-weight: 500; }
.rules { display: grid; gap: 10px; }
.rule { display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; flex-wrap: wrap; }
.rule .desc { flex: 1; min-width: 220px; }
.rule .desc b { display: block; }
.rule .desc small { color: var(--muted); display: block; }
.rule .desc small.sched { color: var(--accent2); }
dialog small.muted { font-size: 12px; }
dialog label.check { display: flex; align-items: center; gap: 8px; color: var(--text); margin: 4px 0 0; cursor: pointer; }
dialog label.check input { width: auto; display: inline; margin: 0; }
dialog .row label { margin-bottom: 0; }
.rule.off { opacity: .55; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(600px, 94vw); max-height: 92vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 14px; }
dialog label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
dialog label input, dialog label select { display: block; width: 100%; margin-top: 4px; color: var(--text); }
dialog .row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
dialog .row > * { flex: 1 1 0; min-width: 0; }
dialog .row > .c-op { flex: 0 0 72px; }
dialog .row > .c-unit, dialog .row > select[name="actionUnit"], dialog .row > .c-del { flex: 0 0 auto; }
.cond-row + .cond-row { position: relative; margin-top: 18px; }
.cond-row + .cond-row::before { content: attr(data-join); position: absolute; top: -17px; left: 2px; font-size: 11px; color: var(--accent2); }
.match-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.match-row select { flex: 1; }
/* fieldsets default to min-width:min-content, which pushes rows past the dialog edge */
dialog fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 12px; padding: 10px 12px; min-width: 0; }
dialog legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
dialog > form > input { width: 100%; margin-bottom: 12px; }
.checklist { max-height: 160px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 12px; }
.checklist label { display: flex; gap: 8px; align-items: center; margin: 4px 0; color: var(--text); }
.checklist input { width: auto; display: inline; margin: 0; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; }
#toast.show { opacity: 1; }
#toast.err { border-color: var(--bad); color: var(--bad); }
.log-type { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--panel2); }
.log-type.rule { color: var(--accent2); } .log-type.error { color: var(--bad); } .log-type.manual, .log-type.bulk { color: var(--warn); }

.notice { background: #3a2f10; border: 1px solid #6b5518; color: var(--warn); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.notice a, .card a:not(.btn) { color: var(--accent2); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 14px; max-width: 760px; }
.card h3 { margin: 0 0 8px; }
.card label { display: block; color: var(--muted); font-size: 13px; flex: 1; min-width: 220px; }
.card label select, .card label input { display: block; width: 100%; margin-top: 4px; }
.row2 { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.ok { color: var(--good); }
a.btn { background: var(--accent); color: #fff; border-radius: 8px; padding: 8px 14px; font-weight: 600; text-decoration: none; display: inline-block; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 4px; word-break: break-all; }

@media (max-width: 640px) {
  header, main { padding-left: 16px; padding-right: 16px; }
  dialog { padding: 18px 16px; }
  dialog fieldset { padding: 10px; }
  /* condition row: metric on its own line, then op / value / unit */
  dialog .row > .c-metric { flex: 1 1 calc(100% - 52px); }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .v { font-size: 17px; }
}
.star-col { width: 28px; padding-left: 0; padding-right: 0; text-align: center; }
.star { background: none; border: 0; padding: 2px 4px; font-size: 18px; line-height: 1; color: var(--muted); cursor: pointer; }
.star.on { color: #f5c542; }
.star:hover { color: #f5c542; filter: none; }
.account-sel { margin-left: 4px; font-size: 13px; padding: 4px 8px; max-width: 220px; }
.acc-list { display: grid; gap: 8px; }
.acc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.acc-row.current { border-color: var(--good); }
.acc-info { flex: 1; min-width: 200px; }
.acc-info b { display: block; }
.acc-info small { color: var(--muted); }
.card label.acc-name { margin: 4px 0 8px; }

/* ---------- reports ---------- */
:root { --s-gmv: #3987e5; --s-cost: #d95926; --grid: #262a33; }
.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-head h3 { margin: 0; font-size: 15px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .ax { fill: var(--muted); font-size: 11px; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dl { font-size: 11px; fill: var(--text); }
.chart .xh { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.tip { position: absolute; pointer-events: none; background: #0b0d11; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; white-space: nowrap; z-index: 3; box-shadow: 0 6px 18px rgba(0,0,0,.4); }
.tip b { display: block; margin-bottom: 4px; }
.tip div { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 4px; }
.table-wrap.flat { border: 0; background: none; }
#rpDaily tfoot td, #rpTop tfoot td { font-weight: 700; border-top: 1px solid var(--line); }


.rp-custom { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.scope-active label { color: var(--text); }
.scope-active label::first-letter { color: var(--good); }

.bill-box { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.bill-box .kv { display: flex; justify-content: space-between; gap: 12px; margin: 2px 0; }
.bill-box .kv b { font-variant-numeric: tabular-nums; }
.bill-bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.bill-bar i { display: block; height: 100%; background: var(--s-gmv, #3987e5); border-radius: 99px; }
.bill-bar i.warn { background: var(--warn); }
.bill-bar i.over { background: var(--bad); }
/* switches inside cards: beat the generic ".card label" / ".card label input" rules */
.card label.switch { display: inline-flex; align-items: center; gap: 10px; flex: none; min-width: 0; color: var(--text); font-size: 14px; }
.card label.switch input { display: none; }
.card label.switch small { font-size: 12px; }
/* same height for inputs and selects in a card row */
.card .row2 input, .card .row2 select { height: 38px; }

.card label.tg-field { display: block; max-width: 520px; margin-bottom: 12px; }
.card label.tg-field b { display: block; color: var(--text); font-size: 14px; }
.card label.tg-field small { display: block; color: var(--muted); }
.card label.tg-field small a { color: var(--accent2); margin-left: 6px; }
.card label.tg-field input { height: 40px; margin-top: 6px; }

/* create GMV Max campaign — laid out like TikTok Ads Manager's "สร้างแคมเปญ" */
.create-btn { background: #2b8a7e; }
dialog.cpage { width: min(1200px, 98vw); max-width: none; height: 96vh; max-height: 96vh; padding: 0; background: var(--bg); }
dialog.cpage form { height: 100%; overflow: auto; padding: 18px 22px 24px; }
.cp-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.cp-head h2 { margin: 0; font-size: 24px; }
.cp-back { font-size: 18px; padding: 6px 12px; }
.cp-loading { padding: 40px 0; text-align: center; }
.cp-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.cp-side { position: sticky; top: 0; }
@media (max-width: 900px) { .cp-grid { grid-template-columns: 1fr; } .cp-side { position: static; } }
.cp-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.cp-card h3 { margin: 0 0 10px; font-size: 17px; }
.cp-sub { color: var(--muted); font-size: 13px; margin: 12px 0 4px; }
.cp-types, .cp-two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.cp-two { margin-bottom: 0; }
@media (max-width: 560px) { .cp-types, .cp-two { grid-template-columns: 1fr; } }
.cp-opt { display: block; margin: 0 !important; cursor: pointer; }
.cp-opt input { display: none !important; }
.cp-opt span { display: block; height: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 12px 40px; background: var(--panel2); position: relative; }
.cp-opt span::before { content: ""; position: absolute; left: 14px; top: 15px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.cp-opt b { display: block; color: var(--text); font-size: 15px; }
.cp-opt small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.cp-opt input:checked + span { border-color: #2b8a7e; box-shadow: 0 0 0 1px #2b8a7e inset; }
.cp-opt input:checked + span::before { border-color: #2b8a7e; background: radial-gradient(#2b8a7e 45%, transparent 50%); }
.cp-opt.off, .cp-opt input:disabled + span { opacity: .5; cursor: not-allowed; }
.cp-opt .warnline { color: var(--warn); }
.tag { font-style: normal; font-size: 11px; background: #2d2f5c; color: #a9a6ff; padding: 1px 6px; border-radius: 6px; margin-left: 4px; }
.cp-hint { background: var(--panel2); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.cp-hint:empty { display: none; }
.cp-hint .rec { display: flex; align-items: center; gap: 8px; margin-top: 6px; cursor: pointer; color: var(--text); }
.cp-hint .rec input { width: auto; margin: 0; }
.cp-money { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.cp-money input { border: 0; flex: 1; background: none; font-size: 16px; }
.cp-money span { padding: 0 12px; color: var(--muted); }
.cp-row-toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--panel2); border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.cp-row-toggle b { display: block; }
.cp-row-toggle small { display: block; color: var(--muted); font-size: 12px; }
.cp-row-toggle.off { opacity: .55; }
.cp-pro { border-color: #6b5a1e; background: linear-gradient(180deg, rgba(241,196,15,.08), var(--panel) 60%); }
.cp-kv { display: flex; gap: 8px; font-size: 13px; margin: 2px 0; }
.cp-kv span { color: var(--muted); min-width: 120px; }
.cp-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; position: sticky; bottom: 0; }
.cp-foot #cSubmit { background: #2b8a7e; padding: 9px 26px; }
.cp-side .kv { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 3px 0; }
.cp-side .kv span { color: var(--muted); }
.cp-side .kv b { text-align: right; }
.cp-side hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }
.c-products { margin-top: 10px; }
.c-products .checklist { max-height: 240px; }
.checklist label.off { opacity: .5; cursor: not-allowed; }
.checklist label small { color: var(--muted); }
.c-ids img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.c-warn { font-size: 12px; color: var(--warn); line-height: 1.6; margin: 0 0 12px; }
.c-warn:empty { display: none; }
.c-summary { font-size: 13px; line-height: 1.8; border-color: #2b8a7e; }
.c-summary b { color: var(--text); }

.cp-step { font-weight: 600; font-size: 15px; margin: 18px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.cp-card h3 + .cp-step { border-top: 0; padding-top: 0; margin-top: 4px; }
.cp-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.cp-sep { width: 1px; height: 28px; background: var(--line); }
.cp-drop { background: var(--panel2); color: var(--text); border: 1px solid var(--line); font-weight: 500; min-width: 180px; text-align: left; display: inline-flex; justify-content: space-between; gap: 10px; }
.cp-drop:disabled { opacity: .5; cursor: not-allowed; min-width: 0; }
.cp-panel { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; }
.cp-panel .checklist { margin: 6px 0 0; background: var(--panel); }
.cp-adv summary { color: var(--muted); cursor: pointer; margin: 6px 0; }
.cp-na { color: var(--muted); text-decoration: underline dotted; cursor: not-allowed; }
.cp-tog { display: flex; gap: 12px; align-items: flex-start; margin: 10px 0; }
.cp-tog .switch { margin-top: 2px; }
.cp-tog b { display: block; }
.cp-tog small { display: block; color: var(--muted); font-size: 12px; }
.cp-tog input:disabled + span { opacity: .6; cursor: not-allowed; }

.ctype.spu { margin-top: 1px; }
.spu-id { cursor: pointer; border-bottom: 1px dotted var(--muted); }
.spu-id:hover { color: var(--text); }
.copy-ic { background: none; border: 0; padding: 2px 4px; margin-left: 4px; color: var(--muted); cursor: pointer; vertical-align: -2px; border-radius: 4px; }
.copy-ic:hover { color: var(--text); background: var(--panel2); }

/* ---- phones & small tablets: keep KPI row and campaign table inside the screen ---- */
.kpi .v { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: clamp(16px, 1.7vw, 22px); }
@media (min-width: 1000px) { .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (min-width: 641px) and (max-width: 999px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1280px) {
  main { padding-left: 14px; padding-right: 14px; }
  #tab-campaigns th, #tab-campaigns td { padding: 8px 7px; font-size: 13px; }
  #tab-campaigns th { font-size: 11.5px; }
  /* let the campaign name wrap instead of pushing the numbers off-screen */
  #tab-campaigns td:nth-child(3) { white-space: normal; min-width: 170px; max-width: 260px; }
  #tab-campaigns .cname { font-size: 13.5px; line-height: 1.3; }
  #tab-campaigns .ctype { font-size: 11px; }
  #tab-campaigns .ctype.spu { overflow-wrap: anywhere; }
  #tab-campaigns .switch span { width: 34px; height: 20px; }
  #tab-campaigns .switch span::after { width: 14px; height: 14px; }
  #tab-campaigns .switch input:checked + span::after { left: 17px; }
  #tab-campaigns .sm { padding: 5px 9px; font-size: 12px; }
}
/* portrait phones: each campaign becomes a card (name + switch on top, numbers in a 3-column grid) */
@media (max-width: 640px) {
  #tab-campaigns .table-wrap { background: none; border: 0; overflow: visible; }
  #tab-campaigns table, #tab-campaigns tbody { display: block; width: 100%; }
  #tab-campaigns thead tr { display: flex; align-items: center; padding: 0 4px 8px; }
  #tab-campaigns thead th { display: none; border: 0; padding: 0; }
  #tab-campaigns thead th:first-child { display: flex; align-items: center; gap: 6px; }
  #tab-campaigns thead th:first-child::after { content: "เลือกทั้งหมด"; color: var(--muted); font-weight: 400; }
  #tab-campaigns tbody tr { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
  #tab-campaigns tbody td { border: 0; padding: 0 !important; white-space: normal; font-size: 13px; }
  #tab-campaigns tbody td:nth-child(1), #tab-campaigns tbody td:nth-child(2) { grid-column: span 1; }
  #tab-campaigns tbody td:nth-child(3) { grid-column: span 8; max-width: none; min-width: 0; }
  #tab-campaigns tbody td:nth-child(4) { grid-column: span 2; text-align: right; }
  #tab-campaigns tbody td.num { grid-column: span 4; text-align: left; display: flex; flex-direction: column; background: var(--panel2); border-radius: 8px; padding: 6px 8px !important; }
  #tab-campaigns tbody td.num::before { content: attr(data-l); color: var(--muted); font-size: 10.5px; }
  #tab-campaigns tbody td:last-child { grid-column: span 8; text-align: right; }
  #tab-campaigns tbody td.empty { grid-column: 1 / -1; text-align: center; }
}
@media (max-width: 640px) { nav { overflow-x: auto; width: 100%; } .tab { white-space: nowrap; flex: none; } }

.clock-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: -4px 0 12px; }
.clock-bar #refresh { padding: 10px 16px; font-size: 15px; }
.clock { text-align: right; line-height: 1.1; }
.clock-t { font-size: clamp(28px, 4vw, 44px); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.clock-d { color: var(--muted); font-size: 14px; margin-top: 2px; }
#refresh .spin-ic { display: inline-block; }
#refresh.busy .spin-ic { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#lastUpd { font-variant-numeric: tabular-nums; }

.cp-pick { width: 100%; margin-top: 10px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); font-weight: 500; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; text-align: left; }
.cp-pick-l { display: flex; align-items: center; gap: 8px; }
.cp-pick-l img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.cp-pick-ic { color: var(--muted); font-size: 18px; border-left: 1px solid var(--line); padding-left: 10px; }
#cLivePanel { margin-top: 8px; }
.cp-protect { background: rgba(37,244,238,.07); border: 1px solid rgba(37,244,238,.25); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.cp-protect summary { cursor: pointer; list-style: none; }
.cp-protect summary b { display: block; }
.cp-protect summary small { display: block; color: var(--muted); font-size: 12px; }
.cp-protect .big { color: var(--accent2); font-size: 22px; }
.cp-protect .cp-two { margin-top: 10px; }
.cp-mini { background: var(--panel); border-radius: 8px; padding: 10px 12px; }
.cp-mini b { display: block; font-size: 14px; }
.cp-mini small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.cp-mini .big2 { font-size: 18px; }
.cp-info { background: rgba(57,135,229,.15); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-top: 10px; }

.cp-src { display: flex; align-items: center; gap: 8px; margin: 4px 0 6px; }
.cp-src img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.cp-step-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cp-tog-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.cp-tog-inline input:disabled + span { opacity: .6; }
.cp-vbar select { min-width: 0; }
.cp-vids { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; margin: 8px 0; }
.cp-vid { position: relative; }
.cp-vid .cov { aspect-ratio: 9 / 16; border-radius: 8px; background: var(--panel2) center / cover no-repeat; position: relative; overflow: hidden; }
.cp-vid .cov::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.85); font-size: 22px; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.cp-vid .dur { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 99px; z-index: 1; }
.cp-vid .cap { font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-pager { display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.cp-pager button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); padding: 4px 10px; font-weight: 500; min-width: 34px; }
.cp-pager button.on { border-color: #2b8a7e; box-shadow: 0 0 0 1px #2b8a7e inset; }
.cp-pager button:disabled { opacity: .4; }
.cp-vid .cov.playing::after { display: none; }
.cp-vid[data-url]:not([data-url=""]) { cursor: pointer; }
#cVidPager { justify-content: center; }

.cp-vid .pick { position: absolute; top: 6px; right: 6px; z-index: 2; width: 20px; height: 20px; margin: 0; accent-color: #2b8a7e; cursor: pointer; }
.cp-vid.sel .cov { box-shadow: 0 0 0 2px #2b8a7e; }
.cp-pref { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 4px 0 8px; font-size: 13px; position: sticky; bottom: 70px; z-index: 3; }
.cp-pref span { color: var(--muted); }
.cp-pref span b { color: var(--text); font-size: 15px; }

.danger-btn { background: #8e2433 !important; color: #fff !important; }
.danger-btn:disabled { opacity: .45; cursor: not-allowed; }
.del-list { margin: 8px 0 12px 18px; padding: 0; max-height: 220px; overflow: auto; font-size: 13px; line-height: 1.7; }
.del-list small { color: var(--muted); }

.ren-ic { background: none; border: 0; padding: 0 4px; color: var(--muted); font-size: 13px; cursor: pointer; opacity: 0; transition: opacity .15s; }
tr:hover .ren-ic, .ren-ic:focus { opacity: 1; }
@media (hover: none) { .ren-ic { opacity: .7; } }
.ren-ic:hover { color: var(--text); }
.bill-cal { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 10px; }
.card .bill-cal label { flex: 1; min-width: 200px; }
.bill-cal button { height: 38px; }

.kpi .cmp { font-size: 11.5px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .cmp b { font-weight: 600; }
.kpi .cmp .up { color: var(--good); }
.kpi .cmp .down { color: var(--bad); }

.dlv { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 13px; }
.dlv i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dlv.on i { background: var(--good); }
.dlv.warn i { background: var(--warn); }
.dlv.off { color: var(--muted); }
.dlv-note { font-size: 11px; color: var(--muted); white-space: normal; max-width: 180px; margin-top: 2px; line-height: 1.3; }
@media (max-width: 640px) { #tab-campaigns tbody td.st { grid-column: span 12; } }
.dlv.bad i { background: var(--bad); }

.code-card { max-width: none; }
.code-results, .code-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.code-item { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.code-item.bad { border-color: rgba(255,92,92,.5); }
.code-item.done { border-color: #2b8a7e; }
.code-item .cov { aspect-ratio: 9 / 16; background: var(--panel) center / cover no-repeat; position: relative; cursor: pointer; }
.code-item .cov .dur { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 99px; }
.code-item .cov.playing .dur { display: none; }
.code-item .meta { padding: 8px 10px; font-size: 12px; line-height: 1.45; display: flex; flex-direction: column; gap: 2px; }
.code-item .who { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; }
.code-item .who img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; }
.code-item .cap { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.code-item .st { font-weight: 600; }
.code-item .st.ok { color: var(--good); }
.code-item .st.err { color: var(--bad); }
.code-item .code { font-family: ui-monospace, monospace; font-size: 10.5px; color: var(--muted); word-break: break-all; }
.code-item .id { font-size: 10.5px; color: var(--muted); }
.code-err { grid-column: 1 / -1; }

.ad-top { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.ad-top .cov { width: 72px; aspect-ratio: 9 / 16; border-radius: 8px; background: var(--panel2) center / cover no-repeat; flex: none; }
.ad-goal { margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chips label { margin: 0 !important; cursor: pointer; }
.chips input { display: none !important; }
.chips span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); color: var(--text); font-size: 13px; }
.chips input:checked + span { border-color: #2b8a7e; box-shadow: 0 0 0 1px #2b8a7e inset; color: #7fd9cc; }
.code-item .adbtn { margin-top: 6px; background: #2b8a7e; padding: 5px 10px; font-size: 12px; }
textarea { font: inherit; }

/* product picker rows (like TikTok's product table) */
.prod-table { border: 1px solid var(--line); border-radius: 8px; max-height: 420px; overflow: auto; background: var(--panel); }
.prod-head, .prod-row { display: grid; grid-template-columns: 24px minmax(200px, 1fr) 90px 80px; gap: 10px; align-items: center; padding: 8px 12px; }
.prod-head { position: sticky; top: 0; z-index: 1; background: var(--panel); color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.prod-head span:nth-child(n+3) { text-align: right; }
.prod-row { border-bottom: 1px solid var(--line); cursor: pointer; margin: 0; color: var(--text); }
.prod-row:last-child { border-bottom: 0; }
.prod-row:hover { background: rgba(127,127,127,.06); }
.prod-row.off { opacity: .5; cursor: not-allowed; }
.prod-row input { width: auto; margin: 0; }
.prod-main { display: flex; gap: 10px; align-items: center; min-width: 0; }
.prod-main img, .prod-noimg { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; flex: none; background: var(--line); }
.prod-txt { display: flex; flex-direction: column; min-width: 0; }
.prod-txt b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prod-txt small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prod-txt em { font-style: normal; color: #c9a227; }
.prod-tag i { font-style: normal; font-size: 12px; padding: 3px 8px; border-radius: 6px; background: rgba(45,180,150,.15); color: #3fc1a0; display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.prod-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.prod-date { color: var(--muted); font-size: 13px; }
@media (max-width: 900px) {
  .prod-head { display: none; }
  .prod-row { grid-template-columns: 24px 1fr auto; row-gap: 4px; }
  .prod-main { grid-column: 2 / 4; }
  .prod-row .prod-num { display: none; }
}

/* affiliate form submissions (เจนโค้ด tab) */
.aff-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.aff-tags i { font-style: normal; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: rgba(45,180,150,.15); color: #3fc1a0; }
.aff-tags i.hot { background: rgba(240,170,60,.15); color: #e0a040; }
.aff-acts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.aff-acts .adbtn { margin: 0; }
.aff-acts .aff-pick { display: inline-flex; flex-direction: row; align-items: center; gap: 4px; width: auto; margin: 0; font-size: 12px; color: var(--muted); }
.aff-acts .aff-pick input { width: 16px !important; height: 16px; margin: 0 !important; flex: none; }
.aff-set { display: grid; gap: 10px; margin-top: 10px; max-width: 560px; }
.aff-set label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.aff-set label.aff-on { display: flex; align-items: center; gap: 8px; color: var(--text); }
.aff-set label.aff-on input { width: auto; }
#affCard h3 select.sm { padding: 4px 8px; font-size: 13px; width: auto; }

.aff-logo { display: grid; gap: 6px; }
.aff-logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.aff-logo-row img { width: 64px; height: 64px; object-fit: contain; background: #fff; border-radius: 8px; padding: 4px; }
.aff-set label.aff-up { display: inline-flex; cursor: pointer; padding: 5px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); }
#affList.code-list { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
#affList .code-item .meta { font-size: 13px; }
#affList .code-item .code { word-break: break-all; }
@media (max-width: 640px) { #affList.code-list { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.code-acts { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.code-acts .adbtn { flex: 1; margin: 0; }
.code-item .bound-at { color: var(--text); }

/* product categories of bound videos */
.code-cats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cat-chip { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 99px; padding: 5px 14px; font-size: 13px; cursor: pointer; }
.cat-chip span { color: var(--muted); margin-left: 4px; }
.cat-chip.on { background: #2b8a7e; border-color: #2b8a7e; color: #fff; }
.cat-chip.on span { color: rgba(255,255,255,.8); }
.code-item select.cat-pick { width: 100%; padding: 4px 6px; font-size: 12px; margin: 2px 0; background: var(--panel); }
.code-item .cat-auto { font-size: 10.5px; color: var(--muted); margin-top: -2px; }

/* pick several bound videos → one campaign / ad group, one ad each */
.code-selbar { position: sticky; top: 64px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; padding: 8px 12px; border: 1px solid #2b8a7e; border-radius: 10px; background: var(--panel2); }
.code-selbar #codeSelN { font-weight: 600; }
.code-acts .code-pick { display: inline-flex; flex-direction: row; align-items: center; gap: 4px; width: auto !important; min-width: 0 !important; margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; cursor: pointer; flex: none; }
.code-pick input { width: 16px !important; height: 16px; margin: 0 !important; }
.code-item.picked { border-color: #2b8a7e; box-shadow: 0 0 0 2px rgba(43,138,126,.5); }
#adCov { position: relative; }
#adCov[data-more]:not([data-more=""])::after { content: attr(data-more); position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
#adCap { white-space: pre-line; }

/* แผนโฆษณา tab */
.plan-table td.num, .plan-table th.num { text-align: right; white-space: nowrap; }

.pl-levels { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 10px; }
.pl-levels button { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 8px 16px; font-size: 14px; cursor: pointer; }
.pl-levels button.on { background: rgba(43,138,126,.2); border-color: #2b8a7e; color: #5fd3c2; font-weight: 600; }
.pl-crumb { margin-left: 8px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.plan-table a.pl-drill { color: inherit; text-decoration: none; }
.plan-table a.pl-drill:hover b { text-decoration: underline; color: #5fd3c2; }
.plan-table td.pl-nm b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: normal; word-break: break-word; }
.plan-table td.pl-nm .dlv-note { white-space: normal; word-break: break-word; }

.pl-name { display: flex; gap: 10px; align-items: flex-start; }
.pl-thumb { width: 44px; height: 58px; border-radius: 6px; background: var(--panel2) center / cover no-repeat; flex: none; display: grid; place-items: center; text-decoration: none; }
.pl-thumb i { width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 9px; font-style: normal; display: grid; place-items: center; padding-left: 2px; }
#plFoot td { position: sticky; bottom: 0; background: var(--panel2); border-top: 2px solid var(--line); }
.plan-table td.num .dlv-note { white-space: nowrap; max-width: 140px; margin-left: auto; overflow: hidden; text-overflow: ellipsis; }
.plan-table th.num { white-space: normal; min-width: 70px; }

.pl-create { margin-left: auto; font-weight: 700; padding-left: 18px; padding-right: 18px; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; max-height: 55vh; overflow: auto; margin-top: 10px; }
#pickDlg label.pick-item { display: flex; gap: 10px; align-items: center; margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; color: var(--text); }
#pickDlg label.pick-item.on { border-color: #2b8a7e; background: rgba(43,138,126,.12); }
.pick-item input { width: 16px !important; height: 16px; margin: 0 !important; flex: none; }
.pick-cov { width: 48px; height: 64px; border-radius: 6px; background: var(--panel2) center / cover no-repeat; flex: none; position: relative; }
.pick-cov i { position: absolute; left: 3px; bottom: 3px; font-size: 10px; font-style: normal; background: rgba(0,0,0,.6); color: #fff; border-radius: 99px; padding: 0 5px; }
.pick-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 13px; }
.pick-meta small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-meta em { font-style: normal; font-size: 11px; color: #3fc1a0; }

.budget-pair { display: flex; align-items: stretch; margin-top: 4px; }
.budget-pair select { width: auto; flex: none; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.budget-pair input { flex: 1; min-width: 0; border-radius: 0; border-left: 0; }
.budget-pair i { font-style: normal; display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; color: var(--text); background: var(--panel); }
#adBudgetHint { display: block; margin-top: 4px; }
.ad-budget-at { display: block; margin-top: 6px; } .ad-budget-at select { width: 100%; }
.pl-ren { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 14px; } .pl-ren:hover { color: #5fd3c2; }

.pl-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; padding: 8px 12px; border: 1px solid #2b8a7e; border-radius: 10px; background: var(--panel2); }
.pl-bulk select { width: auto; padding: 6px 10px; }
.pl-bulk #plDel { color: var(--bad); }
.plan-table .pl-ck { width: 34px; text-align: center; }
.plan-table .pl-ck input { width: 16px !important; height: 16px; margin: 0; }
.plan-table tr.pl-on td { background: rgba(43,138,126,.08); }

.plan-table .pl-sw { width: 64px; }
.plan-table .pl-st { white-space: nowrap; }
.plan-table td.pl-st .dlv { white-space: nowrap; }
.plan-table th, .plan-table td { padding-left: 10px; padding-right: 10px; vertical-align: middle; }
.pl-title { display: flex; align-items: flex-start; gap: 4px; } .pl-title .pl-ren { flex: none; margin-top: 1px; }
.plan-table th.pl-sw, .plan-table td.pl-sw, .plan-table .pl-ck { width: 1%; white-space: nowrap; padding-right: 4px; }
.plan-table th.pl-nm, .plan-table td.pl-nm { width: 1%; min-width: 0; max-width: none; }
.plan-table td.pl-nm .pl-name { width: max-content; max-width: 300px; }
.plan-table th.pl-st, .plan-table td.pl-st { width: 1%; padding-left: 12px; }

.pl-bud { background: none; border: 1px dashed transparent; border-radius: 8px; color: inherit; font: inherit; text-align: right; padding: 4px 8px; cursor: pointer; display: inline-flex; flex-direction: column; align-items: flex-end; position: relative; }
.pl-bud:hover { border-color: var(--line); background: rgba(127,127,127,.06); }
.pl-bud .pl-bud-ic { position: absolute; left: -14px; top: 4px; font-size: 12px; color: var(--muted); opacity: 0; }
.pl-bud:hover .pl-bud-ic { opacity: 1; color: #5fd3c2; }

.live-link { color: var(--muted); padding: 8px 14px; border-radius: 8px; text-decoration: none; white-space: nowrap; flex: none; }
.live-link:hover { background: var(--panel2); color: var(--text); }
