*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --good-text: #006300;
  --critical-text: #b3261e;
  --shadow: 0 6px 24px rgba(11, 11, 11, 0.10);
  --row-account: #e6e5df;
  --row-campaign: #f1f0ec;
  --row-adset: #f7f7f4;
  --row-hover: #ecebe6;
  --range: #e4eefb;
  --accent: #2470c9;
  --good-bg: #e3f3e1;
  --warning-bg: #fcf0d4;
  --critical-bg: #fbe5e3;
  --warning-text: #8f5c00;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.05);
    --series-1: #3987e5;
    --series-2: #d95926;
    --good-text: #0ca30c;
    --critical-text: #ff8a80;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    --row-account: #30302d;
    --row-campaign: #262624;
    --row-adset: #20201f;
    --row-hover: #2c2c2a;
    --range: #1d2c40;
    --accent: #2b6cc4;
    --good-bg: #14301a;
    --warning-bg: #352a10;
    --critical-bg: #3b1c1c;
    --warning-text: #fab219;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.05);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good-text: #0ca30c;
  --critical-text: #ff8a80;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  --row-account: #30302d;
  --row-campaign: #262624;
  --row-adset: #20201f;
  --row-hover: #2c2c2a;
  --range: #1d2c40;
  --accent: #2b6cc4;
  --good-bg: #14301a;
  --warning-bg: #352a10;
  --critical-bg: #3b1c1c;
  --warning-text: #fab219;
}

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--ring);
}
.brand { margin: 0; font-size: 16px; font-weight: 600; }
.brand-sub { color: var(--muted); font-weight: 500; }
main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 56px; }
.row, .filterbar, .card-head, .dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filterbar { margin-bottom: 16px; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 640px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
}

/* ---------- Controls ---------- */
button, select, input { font: inherit; color: inherit; }
button {
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--ring); background: var(--surface);
}
button:hover { background: var(--hover); }
button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); font-weight: 500; }
button.primary:hover { opacity: 0.88; }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--hover); }
button.danger { background: transparent; border-color: transparent; color: var(--critical-text); }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: progress; }
select, input:not([type="checkbox"]) {
  min-width: 0; max-width: 100%;
  padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--axis); background: var(--surface);
}
.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.inline select { padding: 4px 8px; }

/* ---------- Dropdown (pengganti select) ---------- */
.dd { position: relative; display: inline-flex; min-width: 0; }
.dd-trigger {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: min(340px, 62vw);
  border-color: var(--axis); border-radius: 10px; text-align: left; font-weight: 600;
}
.dd-prefix { flex: none; font-size: 12px; font-weight: 500; color: var(--muted); }
.dd-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-caret { flex: none; font-size: 10px; color: var(--muted); transition: transform 0.15s; }
.dd-trigger[aria-expanded="true"] .dd-caret { transform: rotate(180deg); }
.dd-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 25;
  min-width: 100%; width: max-content; max-width: min(400px, calc(100vw - 32px)); max-height: 340px; overflow-y: auto;
  padding: 6px; background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; box-shadow: var(--shadow);
}
.dd-menu:not([hidden]) { animation: pop-in 0.12s ease-out; }
.dd-option {
  display: flex; align-items: flex-start; gap: 8px; width: 100%;
  padding: 8px 12px 8px 8px; border: 0; border-radius: 8px; background: transparent; text-align: left; font-weight: 400;
}
.dd-option:hover, .dd-option:focus-visible { background: var(--hover); outline: none; }
.dd-option[aria-selected="true"] { background: var(--range); }
.dd-option[aria-selected="true"] .dd-label { font-weight: 600; }
.dd-check { flex: none; width: 16px; text-align: center; font-weight: 700; color: var(--accent); }
.dd-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.dd-sub { font-size: 12px; color: var(--muted); }

/* Pemilih project/event: dropdown + ikon roda (atur) dalam satu kotak. */
.picker { display: inline-flex; align-items: stretch; min-width: 0; border: 1px solid var(--axis); border-radius: 10px; background: var(--surface); }
.picker .dd-trigger { border: 0; border-radius: 9px 0 0 9px; background: transparent; padding: 7px 10px 7px 12px; }
.picker .dd-trigger:hover { background: var(--hover); }
.picker-gear {
  display: grid; place-items: center; width: 38px; padding: 0;
  border: 0; border-left: 1px solid var(--axis); border-radius: 0 9px 9px 0; background: transparent; color: var(--ink-2);
}
.picker-gear svg { width: 16px; height: 16px; transition: transform 0.3s; }
.picker-gear:hover { background: var(--hover); color: var(--ink); }
.picker-gear:hover svg { transform: rotate(45deg); }
@media (prefers-reduced-motion: reduce) { .picker-gear svg, .dd-caret { transition: none; } }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* ---------- Periode pantau + kalender ---------- */
.period { position: relative; }
.period-btn { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; border-color: var(--axis); border-radius: 10px; }
.period-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }
.period-btn svg { width: 16px; height: 16px; flex: none; color: var(--ink-2); }
.period-btn .caret { font-size: 10px; color: var(--muted); }
.popover {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 20;
  display: flex; overflow: hidden;
  background: var(--surface); border: 1px solid var(--ring); border-radius: 16px; box-shadow: var(--shadow);
}
.popover:not([hidden]) { animation: pop-in 0.14s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .popover:not([hidden]), .dd-menu:not([hidden]) { animation: none; } }

/* Pilihan cepat: satu baris per pilihan, tanggalnya rata kanan. */
.period-presets { display: flex; flex-direction: column; gap: 2px; width: 256px; padding: 12px; background: var(--plane); border-right: 1px solid var(--grid); }
.preset-label { white-space: nowrap; }
.preset {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 9px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left;
}
.preset:hover { background: var(--hover); }
.preset-date { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.preset[aria-pressed="true"] { background: var(--surface); font-weight: 600; box-shadow: inset 0 0 0 1px var(--ring), inset 3px 0 0 var(--accent); }
.preset[aria-pressed="true"] .preset-date { color: var(--ink-2); }
.preset:disabled { opacity: 0.45; cursor: not-allowed; }
.preset:disabled:hover { background: transparent; }

.period-cal { width: 316px; padding: 14px 16px; }
.cal-fields { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-field {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px;
  padding: 6px 10px; border: 1px solid var(--axis); border-radius: 10px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.cal-field-label { font-size: 11px; font-weight: 500; color: var(--muted); }
.cal-field.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cal-arrow { color: var(--muted); }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-title { font-weight: 600; font-size: 15px; }
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 50%; border-color: transparent; background: transparent; font-size: 18px; line-height: 1; color: var(--ink-2); }
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.icon-btn:disabled, .icon-btn:disabled:hover { opacity: 0.3; cursor: default; background: transparent; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: 4px; }
.cal-wd { padding: 6px 0; text-align: center; font-size: 11px; font-weight: 500; color: var(--muted); }
.cal-day { display: grid; place-items: center; height: 38px; padding: 0; border: 0; border-radius: 0; background: transparent; font-variant-numeric: tabular-nums; }
.cal-num { position: relative; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; }
/* Hover cukup di lingkaran angka; latar sel tetap milik pita rentang (aturan di bawah menimpa ini). */
.cal-day:hover { background-color: transparent; }
.cal-day:hover:not(:disabled) .cal-num { background: var(--hover); }
.cal-day:disabled { opacity: 1; color: var(--axis); cursor: default; }
/* Pita rentang; ujung kiri/kanan baris (Senin/Minggu) dibulatkan supaya tidak terpotong kaku. */
.cal-day.in-range { background: var(--range); }
.cal-day.range-start { background: linear-gradient(90deg, transparent 50%, var(--range) 50%); }
.cal-day.range-end { background: linear-gradient(90deg, var(--range) 50%, transparent 50%); }
.cal-day.range-start.range-end { background: transparent; }
.cal-grid > .in-range:nth-child(7n + 1) { border-radius: 19px 0 0 19px; }
.cal-grid > .in-range:nth-child(7n) { border-radius: 0 19px 19px 0; }
.cal-day.range-start .cal-num, .cal-day.range-end .cal-num,
.cal-day.range-start:hover .cal-num, .cal-day.range-end:hover .cal-num { background: var(--accent); color: #fff; font-weight: 600; }
.cal-day.is-today .cal-num { font-weight: 700; }
.cal-day.is-today .cal-num::after {
  content: ''; position: absolute; bottom: 4px; left: 50%;
  width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent);
}
.cal-day.is-today.range-start .cal-num::after, .cal-day.is-today.range-end .cal-num::after { background: #fff; }

.cal-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.cal-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--grid); }
.cal-foot #calSummary:not(.form-error) { color: var(--ink-2); }
.cal-foot button:disabled { cursor: not-allowed; }
@media (max-width: 760px) {
  .popover {
    position: fixed; top: 64px; left: 16px !important; right: 16px;
    flex-direction: column; max-height: calc(100vh - 80px); overflow-y: auto;
  }
  .period-presets { flex-direction: row; flex-wrap: wrap; gap: 6px; width: auto; border-right: 0; border-bottom: 1px solid var(--grid); }
  .preset { padding: 6px 12px; border: 1px solid var(--ring); border-radius: 999px; background: var(--surface); }
  .preset-date { display: none; }
  .preset[aria-pressed="true"] { box-shadow: inset 0 0 0 1px var(--accent); border-color: var(--accent); }
  .period-cal { width: auto; }
}

/* ---------- Empty & alerts ---------- */
.empty {
  text-align: center; padding: 56px 16px;
  background: var(--surface); border: 1px dashed var(--axis); border-radius: 14px;
}
.empty h2 { margin: 0; font-size: 17px; }
.empty p { max-width: 480px; margin: 8px auto 18px; color: var(--ink-2); }
.row.center { justify-content: center; }
.placeholder { padding: 40px 0; text-align: center; color: var(--ink-2); }
.demo-banner {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  margin-bottom: 16px; padding: 10px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--ring); border-left: 4px solid var(--series-1);
  color: var(--ink-2);
}
.demo-banner strong { color: var(--ink); }
.demo-text { flex: 1; min-width: 220px; }
.demo-tag { padding: 2px 8px; border-radius: 6px; background: var(--hover); color: var(--ink); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; }
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  margin-bottom: 12px; padding: 10px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--ring);
}
#report.is-loading #reportBody { opacity: 0.5; transition: opacity 0.2s; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: minmax(240px, 1fr) 3fr; gap: 12px; margin-bottom: 16px; }
@media (max-width: 900px) { .kpis { grid-template-columns: 1fr; } }
.hero, .tile, .card {
  background: var(--surface); border: 1px solid var(--ring); border-radius: 14px;
}
.hero { padding: 18px 20px; display: flex; flex-direction: column; justify-content: center; }
.hero-value { font-size: 56px; font-weight: 600; line-height: 1.05; margin: 6px 0 8px; }
.hero-text { margin: 0; color: var(--ink-2); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { padding: 14px 16px; min-width: 0; container-type: inline-size; }
.tile-label { color: var(--ink-2); font-size: 12px; font-weight: 500; }
/* Rupiah ditulis lengkap, jadi ukuran angka mengecil sendiri kalau kartunya sempit (mis. di HP). */
.tile-value { font-size: clamp(14px, 11.5cqi, 24px); font-weight: 600; margin: 4px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { color: var(--muted); font-size: 12px; }
@media (max-width: 480px) {
  .tiles { gap: 8px; }
  .tile { padding: 12px; }
  .hero-value { font-size: 48px; }
}
.tone-good { color: var(--good-text); }
.tone-bad { color: var(--critical-text); }



/* ---------- Cards & chart ---------- */
.card { padding: 16px 18px; margin-bottom: 16px; }

/* Dua kolom: grafik harian di kiri, Tracking Statistic di kanan (bertumpuk di layar sempit). */
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; margin-bottom: 16px; }
.split > .card { min-width: 0; margin-bottom: 0; }
@media (max-width: 1100px) { .split { grid-template-columns: minmax(0, 1fr); } }

.tracking-head { align-items: flex-start; }
.seg.seg-fill { display: flex; margin-bottom: 6px; }
.seg.seg-fill button { flex: 1; padding: 0 8px; }
.utm-table { table-layout: fixed; }
.utm-table th:not(:first-child) { width: 68px; }
.utm-table td { vertical-align: middle; }
.utm-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.utm-value.is-empty { color: var(--muted); font-style: italic; font-weight: 400; }
.utm-meta { color: var(--muted); font-weight: 400; }
.card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-head { margin-bottom: 12px; }
.legend { display: flex; gap: 14px; margin-left: 8px; font-size: 12px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.swatch.s1, .key.s1 { background: var(--series-1); }
.swatch.s2, .key.s2 { background: var(--series-2); }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar.s1 { fill: var(--series-1); }
.chart .bar.s2 { fill: var(--series-2); }
.chart .hit { fill: transparent; }
.chart .day { outline: none; }
.chart .day:hover .hit, .chart .day:focus .hit { fill: var(--hover); }
.chart .day:hover .bar, .chart .day:focus .bar { opacity: 0.85; }
.chart .empty-chart { fill: var(--muted); font-size: 13px; }

.tooltip {
  position: fixed; z-index: 30; pointer-events: none; min-width: 200px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--ring); box-shadow: var(--shadow);
  font-size: 12px;
}
.tip-title { font-weight: 600; margin-bottom: 6px; }
.tip-row { display: flex; align-items: center; gap: 8px; margin: 2px 0; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-row .muted { margin-left: auto; padding-left: 10px; }
.tip-meta { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--grid); color: var(--ink-2); }
.key { display: inline-block; width: 12px; height: 2px; border-radius: 1px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  padding: 8px 10px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 500; color: var(--ink-2);
  border-bottom: 1px solid var(--axis);
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.data:not(.ads) tbody tr:hover td { background: var(--hover); }
.num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 3px; font-size: 12px; color: var(--ink-2); font-weight: 400; }

/* ---------- Tabel performa: campaign → ad set → iklan ---------- */
.ads-head { margin-bottom: 14px; }
.ads-head h2 { font-size: 16px; }
.ads-summary, .card-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ads-summary:empty { display: none; }

/* Toolbar: satu bar; semua kontrol tingginya 34px dengan sudut, garis, dan latar yang sama. */
.ads-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px; margin-bottom: 14px;
  background: var(--plane); border: 1px solid var(--grid); border-radius: 12px;
}
/* Grupnya hanya penanda; kontrolnya ikut membungkus di bar yang sama, "Urutkan" selalu di kanan. */
.tool-group { display: contents; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px;
  border: 1px solid var(--axis); border-radius: 9px; background: var(--surface);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.tool-btn:hover { background: linear-gradient(var(--hover), var(--hover)), var(--surface); }
.tool-btn[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--range); }
.tool-icon { flex: none; width: 15px; height: 15px; color: var(--ink-2); }
.tool-dd-end { margin-left: auto; }
.tool-dd-end .dd-menu { left: auto; right: 0; }

/* Pilihan level: tombol di dalam satu "rel"; yang dipilih diberi latar biru tipis. */
.seg {
  display: inline-flex; align-items: center; gap: 2px; height: 34px; padding: 3px;
  border: 1px solid var(--axis); border-radius: 9px; background: var(--surface);
}
.seg-label { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px 0 6px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg button {
  height: 26px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.seg button:hover { background: var(--hover); color: var(--ink); }
.seg button[aria-pressed="true"], .seg button[aria-pressed="true"]:hover { background: var(--range); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent); }

/* Saklar "Hanya yang aktif tayang" (checkbox asli tetap ada untuk keyboard & pembaca layar). */
.switch { position: relative; padding: 0 12px 0 10px; font-weight: 500; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.switch-track { position: relative; flex: none; width: 30px; height: 18px; border-radius: 999px; background: var(--axis); transition: background-color 0.15s; }
.switch-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(12px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--series-1); outline-offset: 2px; }
.switch:has(input:checked) { color: var(--ink); border-color: var(--accent); }
@media (prefers-reduced-motion: reduce) { .switch-track, .switch-track::after { transition: none; } }

@media (max-width: 640px) {
  .ads-toolbar { flex-direction: column; align-items: stretch; }
  .tool-dd-end { margin-left: 0; }
  .tool-dd .dd-trigger { width: 100%; max-width: none; }
  .tool-dd .dd-value { flex: 1; }
  /* Di HP label level pindah ke baris sendiri, tombolnya dibagi rata. */
  .seg { flex-wrap: wrap; height: auto; }
  .seg-label { flex-basis: 100%; padding: 4px 6px 5px; }
  .seg button { flex: 1; }
  /* Kolom angka Tracking Statistic dirampingkan supaya nama UTM tetap terbaca. */
  table.utm-table th, table.utm-table td { padding-left: 6px; padding-right: 6px; }
  .utm-table th:not(:first-child) { width: 50px; }
  .utm-table th:last-child { width: 58px; }
}

table.ads th, table.ads td { padding: 10px 12px; vertical-align: middle; }
table.ads thead th { background-color: var(--surface); }
/* Header yang bisa diklik untuk mengurutkan; kolom yang aktif diberi panah. */
.th-sort {
  display: inline-flex; align-items: center; gap: 3px; padding: 0; border: 0; border-radius: 0;
  background: none; font: inherit; color: inherit; cursor: pointer; white-space: nowrap;
}
.th-sort:hover { background: none; color: var(--ink); text-decoration: underline dotted; text-underline-offset: 3px; }
th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--ink); font-weight: 600; }
.sort-arrow { color: var(--accent); }
.th-help { cursor: help; text-decoration: underline dotted var(--axis); text-underline-offset: 3px; }

/* Kolom nama tetap terlihat saat tabel digeser ke samping. */
table.ads th:first-child, table.ads td.name-cell {
  position: sticky; left: 0; z-index: 1;
  min-width: 290px; max-width: 380px;
  background-color: var(--surface);
  box-shadow: inset -1px 0 0 var(--grid);
}
table.ads tr.lvl-account td { background-color: var(--row-account); border-top: 2px solid var(--axis); }
table.ads tr.lvl-account .num { font-weight: 700; }
table.ads tr.lvl-account .node-name { font-size: 14px; font-weight: 700; }
table.ads tr.lvl-campaign td { background-color: var(--row-campaign); border-top: 1px solid var(--axis); }
table.ads tr.lvl-adset td { background-color: var(--row-adset); }
table.ads tbody tr:hover td { background-color: var(--row-hover); }
table.ads tr.lvl-campaign .num { font-weight: 600; }
table.ads td.roas { font-weight: 600; }
/* Indentasi + garis pohon: ad set menjorok dari campaign, iklan menjorok dari ad set. */
table.ads tr.lvl-adset .name-cell {
  padding-left: 32px;
  background-image: linear-gradient(var(--axis), var(--axis));
  background-size: 1px 100%; background-position: 18px 0; background-repeat: no-repeat;
}
table.ads tr.lvl-ad .name-cell {
  padding-left: 50px;
  background-image: linear-gradient(var(--axis), var(--axis)), linear-gradient(var(--axis), var(--axis));
  background-size: 1px 100%, 1px 100%; background-position: 18px 0, 38px 0; background-repeat: no-repeat;
}
/* Dikelompokkan per akun iklan: semua level menjorok satu tingkat lagi di bawah baris akun. */
#adsBody.grouped tr.lvl-campaign .name-cell {
  padding-left: 32px;
  background-image: linear-gradient(var(--axis), var(--axis));
  background-size: 1px 100%; background-position: 18px 0; background-repeat: no-repeat;
}
#adsBody.grouped tr.lvl-adset .name-cell {
  padding-left: 52px;
  background-image: linear-gradient(var(--axis), var(--axis)), linear-gradient(var(--axis), var(--axis));
  background-size: 1px 100%, 1px 100%; background-position: 18px 0, 38px 0;
}
#adsBody.grouped tr.lvl-ad .name-cell {
  padding-left: 70px;
  background-image: linear-gradient(var(--axis), var(--axis)), linear-gradient(var(--axis), var(--axis)), linear-gradient(var(--axis), var(--axis));
  background-size: 1px 100%, 1px 100%, 1px 100%; background-position: 18px 0, 38px 0, 58px 0; background-repeat: no-repeat;
}
.lvl-account .node-name .dot { display: none; }
.lvl-account .node-meta { padding-left: 18px; }

.node-name { display: flex; align-items: center; gap: 6px; font-weight: 500; line-height: 1.35; }
.node-name .dot { flex: none; margin: 0; vertical-align: 0; }
.dot.none { visibility: hidden; }
.node-text { min-width: 0; }
table.ads tr.lvl-campaign .node-name { font-weight: 600; font-size: 14px; }
table.ads tr.is-off .node-text { color: var(--ink-2); }
.node-toggle { padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.node-toggle:hover { background: none; }
.node-toggle:hover .node-text { text-decoration: underline; text-underline-offset: 3px; }
.chevron { width: 12px; flex: none; color: var(--ink-2); }
/* Keterangan di bawah nama, dipisah titik tengah. Menjorok sejajar dengan teks nama. */
.node-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; margin-top: 3px; padding-left: 31px; font-size: 12px; color: var(--ink-2); }
table.ads tr.lvl-ad .node-meta { padding-left: 13px; }
.total-row .node-meta { padding-left: 0; }
.node-meta > * + *::before { content: '·'; margin-right: 6px; color: var(--muted); }
.level-tag { font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.cell-sub { margin-top: 1px; font-size: 11px; font-weight: 400; color: var(--muted); }

/* Pill rekomendasi. */
.rec {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--hover); color: var(--ink);
}
.rec-icon { font-size: 11px; line-height: 1; }
.rec.good { background: var(--good-bg); }
.rec.good .rec-icon { color: var(--good-text); }
.rec.warning { background: var(--warning-bg); }
.rec.warning .rec-icon { color: var(--warning-text); }
.rec.critical { background: var(--critical-bg); }
.rec.critical .rec-icon { color: var(--critical-text); }
.rec.muted { font-weight: 500; color: var(--ink-2); }

/* Bar mini ROAS di bawah angkanya. */
.roas-bar { position: relative; width: 56px; height: 4px; margin: 6px 0 0 auto; border-radius: 2px; background: var(--grid); }
.roas-fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 2px; background: var(--muted); }
.roas-fill.good { background: var(--good); }
.roas-fill.warning { background: var(--warning); }
.roas-fill.critical { background: var(--critical); }
.roas-mark { position: absolute; top: -3px; bottom: -3px; width: 1px; margin-left: -0.5px; background: var(--ink-2); }

/* Baris total di bawah tabel. */
table.ads tfoot td { border-top: 2px solid var(--axis); border-bottom: 0; background-color: var(--surface); font-weight: 600; }
table.ads tfoot .node-meta { font-weight: 400; }
@media (max-width: 640px) {
  table.ads th:first-child, table.ads td.name-cell { min-width: 200px; max-width: 230px; }
  /* Kolom nama sempit: keterangan ditumpuk per baris, tanpa titik pemisah. */
  .node-meta { flex-direction: column; gap: 1px; }
  .node-meta > * + *::before { content: none; }
}
.ad-name { font-weight: 500; }
.ad-sub { margin-top: 2px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; background: var(--muted); }
.dot.good { background: var(--good); }
.dot.warning { background: var(--warning); }
.dot.critical { background: var(--critical); }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 500; }
.status-icon { width: 14px; text-align: center; font-size: 11px; }
.status.good .status-icon { color: var(--good); }
.status.warning .status-icon { color: var(--warning); }
.status.critical .status-icon { color: var(--critical); }
.status.muted { color: var(--ink-2); font-weight: 400; }
.status.muted .status-icon { color: var(--muted); }
.note { margin: 10px 0 0; }

/* ---------- Dialogs ---------- */
dialog {
  width: min(580px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--ring); border-radius: 16px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
/* Latar di belakang popup diburamkan dan digelapkan supaya fokus ke isi popup. */
dialog::backdrop { background: rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px; max-height: calc(100vh - 48px); overflow-y: auto; }
dialog h2 { margin: 0; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
fieldset { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 10px 12px; border: 1px solid var(--grid); border-radius: 10px; }
legend { padding: 0 4px; font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; font-weight: 400; color: var(--muted); }
code { font-size: 12px; padding: 1px 4px; border-radius: 4px; background: var(--hover); }
.checklist { display: flex; flex-direction: column; gap: 2px; max-height: 170px; overflow-y: auto; }
.checklist.tall { max-height: 240px; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; padding: 4px 2px; font-weight: 400; }
label.check input { margin-top: 3px; }
.grid2, .grid3 { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.form-error { margin: 0; color: var(--critical-text); font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------- Dialog project: kepala & kaki tetap, isi bisa di-scroll ---------- */
dialog.sheet { width: min(660px, calc(100vw - 32px)); }
dialog.sheet form { gap: 0; padding: 0; overflow: hidden; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--grid); }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 20px; }
.sheet-foot { display: flex; flex-direction: column; gap: 10px; padding: 12px 20px 16px; border-top: 1px solid var(--grid); }

/* ---------- Popup tabel lengkap (Tracking Statistic, data harian) ---------- */
dialog.view-dialog { width: min(720px, calc(100vw - 32px)); }
dialog.view-wide { width: min(940px, calc(100vw - 32px)); }
/* padding-bottom: ruang di bawah baris total supaya tidak menempel ke tepi popup. */
.view { display: flex; flex-direction: column; max-height: min(760px, calc(100vh - 48px)); padding-bottom: 14px; }
.view .sheet-head { align-items: flex-start; }
.view-tools { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--grid); }
.view-tools .seg.seg-fill { flex: 1 1 340px; margin: 0; }
dialog label.search {
  flex: 1 1 220px; flex-direction: row; align-items: center; gap: 8px; height: 34px; padding: 0 10px;
  border: 1px solid var(--axis); border-radius: 9px; background: var(--surface);
}
dialog label.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--range); }
.search input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; background: transparent; outline: none; }
.view-body { flex: 1; min-height: 0; overflow: auto; padding: 0 20px; }
/* Judul kolom menempel di atas dan baris total di bawah saat tabel di-scroll. */
.view-table thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.view-table tfoot td {
  position: sticky; bottom: 0; background: var(--surface); font-weight: 600;
  padding-top: 12px; padding-bottom: 12px; border-top: 2px solid var(--axis); border-bottom: 0; white-space: nowrap;
}
.view-table td { vertical-align: middle; }
.view-table th:not(:first-child) { width: 1%; }
.view-name { min-width: 180px; }
.utm-full { font-weight: 500; overflow-wrap: anywhere; }
.utm-full.is-empty { color: var(--muted); font-style: italic; font-weight: 400; }
@media (max-width: 640px) {
  .view .sheet-head, .view-tools { padding-left: 14px; padding-right: 14px; }
  .view-body { padding: 0 8px; }
  table.view-table th, table.view-table td { padding-left: 6px; padding-right: 6px; }
  .view-name { min-width: 110px; }
}
.view-dialog[open] { animation: pop-in 0.14s ease-out; }
@media (prefers-reduced-motion: reduce) { .view-dialog[open] { animation: none; } }
.form-section { display: flex; flex-direction: column; gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--grid); }
.form-section:last-child { border-bottom: 0; }
.section-head { display: flex; align-items: flex-start; gap: 12px; }
.section-title { flex: 1; min-width: 0; }
.section-title h3 { margin: 0; font-size: 15px; font-weight: 600; }
.section-title .hint { margin: 2px 0 0; }
.section-icon {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  color: var(--ink-2); background: var(--hover); border: 1px solid var(--ring);
}
.section-icon svg { width: 17px; height: 17px; }
.section-icon.accent { color: #fff; background: var(--accent); border-color: transparent; }

/* Lencana status koneksi: titik + teks, latar tipis sesuai status. */
.conn-status {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--hover); color: var(--ink-2);
}
.dot-mini { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.conn-status.good { background: var(--good-bg); color: var(--ink); }
.conn-status.good .dot-mini { background: var(--good); }
.conn-status.warning { background: var(--warning-bg); color: var(--ink); }
.conn-status.warning .dot-mini { background: var(--warning); }
.conn-status.critical { background: var(--critical-bg); color: var(--ink); }
.conn-status.critical .dot-mini { background: var(--critical); }

/* Kartu Business Manager. */
.conn-list { display: flex; flex-direction: column; gap: 10px; }
.conn-card { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--axis); border-radius: 12px; background: var(--plane); }
.conn-head { display: flex; align-items: center; gap: 10px; }
.conn-index {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  font-size: 11px; font-weight: 700; color: var(--ink-2); background: var(--surface); border: 1px solid var(--axis);
}
input.conn-label { flex: 1; min-width: 0; font-weight: 600; }
.conn-actions { display: flex; gap: 4px; }
button.danger-text { color: var(--critical-text); }
.conn-token { gap: 6px; }
.conn-card > .form-error, .conn-card > .hint { margin: 0; padding-left: 34px; }
.conn-card > .conn-token, .conn-card > .conn-accounts { margin-left: 34px; }
.conn-accounts { display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--grid); border-radius: 10px; background: var(--surface); }
.conn-accounts-head {
  display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px;
  font-size: 12px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--grid);
}
label.check.account {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--grid); font-size: 13px; cursor: pointer;
}
label.check.account:last-child { border-bottom: 0; }
label.check.account:hover { background: var(--hover); }
label.check.account input { margin: 0; }
.account-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-id { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.conn-empty { margin: 0; padding: 16px; text-align: center; font-size: 13px; color: var(--ink-2); border: 1px dashed var(--axis); border-radius: 12px; }
.add-btn { width: 100%; padding: 10px; border: 1px dashed var(--axis); border-radius: 12px; background: transparent; font-weight: 600; color: var(--ink-2); }
.add-btn:hover { border-color: var(--accent); color: var(--accent); background: transparent; }
/* Daftar campaign di dialog event, dikelompokkan per akun iklan. Judul grup menempel saat di-scroll. */
.camp-group { display: flex; flex-direction: column; }
.camp-group + .camp-group { margin-top: 8px; }
.camp-group-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; background: var(--surface); border-bottom: 1px solid var(--grid); font-size: 12px; font-weight: 600;
}
.camp-group-title { flex: 1; min-width: 0; }
.camp-group-bm { font-weight: 500; color: var(--muted); }
.camp-group-head .ghost.small { padding: 2px 8px; }

.help { font-size: 13px; color: var(--ink-2); }
.help summary { cursor: pointer; font-weight: 500; color: var(--ink); }
.help ol { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 0; padding-left: 20px; }

/* Input dengan satuan di depan/belakang (Rp, ×). Semua input aturan rata bawah. */
#projectRules .grid3 > label { justify-content: space-between; }
.affix { display: flex; align-items: stretch; overflow: hidden; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface); }
.affix input { flex: 1; min-width: 0; border: 0; border-radius: 0; background: transparent; }
.affix input:focus-visible { outline: none; }
.affix:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.affix-text { display: grid; place-items: center; padding: 0 10px; font-size: 13px; font-weight: 500; color: var(--muted); background: var(--hover); border-left: 1px solid var(--grid); }
.affix.pre .affix-text { border-left: 0; border-right: 1px solid var(--grid); }
@media (max-width: 560px) {
  .conn-head { flex-wrap: wrap; }
  input.conn-label { flex-basis: calc(100% - 34px); }
  .conn-status { margin-left: 34px; }
  .conn-actions { margin-left: auto; }
  .conn-card > .form-error, .conn-card > .hint { padding-left: 0; }
  .conn-card > .conn-token, .conn-card > .conn-accounts { margin-left: 0; }
  /* Ringkasan pindah ke bawah judul; ID akun turun ke bawah nama supaya nama tidak terpotong. */
  .section-head { flex-wrap: wrap; }
  #metaSummary { flex-basis: 100%; padding-left: 46px; }
  .conn-accounts-head { flex-direction: column; gap: 2px; }
  label.check.account { grid-template-columns: auto minmax(0, 1fr); row-gap: 1px; }
  label.check.account .account-name { white-space: normal; }
  label.check.account .account-id { grid-column: 2; }
}

/* ---------- Halaman login (dashboard di VPS) ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.login-card {
  display: flex; flex-direction: column; gap: 10px; width: min(400px, 100%); padding: 28px 26px 24px;
  background: var(--surface); border: 1px solid var(--ring); border-radius: 18px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.login-logo {
  display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: 12px;
  background: var(--range); color: var(--accent);
}
.login-logo svg { width: 22px; height: 22px; }
.login-field { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.pw-wrap {
  display: flex; align-items: center; height: 42px; padding: 0 4px 0 12px;
  border: 1px solid var(--axis); border-radius: 10px; background: var(--surface);
}
.pw-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--range); }
.pw-wrap input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; background: transparent; outline: none; font-size: 15px; }
.pw-toggle { padding: 6px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); font-size: 12px; font-weight: 600; }
.pw-toggle:hover { background: var(--hover); color: var(--ink); }
.login-btn { height: 42px; margin-top: 6px; font-size: 15px; font-weight: 600; }
.login-note { margin: 4px 0 0; }
