/* ===== Theme 2026 — refined dashboard look (loaded after dashboard.css) =====
   One neutral palette + one accent; colour only carries meaning (good / bad / watch).
   Font: Be Vietnam Pro (built for Vietnamese diacritics), tabular figures for numbers. */

:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-surface-alt: #f8f9fb;
    --color-surface-hover: #f1f3f7;
    --color-border: #e6e8ee;
    --color-border-accent: #d5d9e2;
    --color-text: #0f172a;
    --color-text-muted: #475569;
    --color-text-dim: #8a94a6;

    --color-accent: #2f5bea;
    --color-accent-hover: #2449c7;
    --color-accent-bg: #eef2ff;
    --color-success: #0f9d6b;
    --color-success-bg: #e7f7f0;
    --color-success-text: #0b7a53;
    --color-warn: #b7791f;
    --color-warn-bg: #fdf5e6;
    --color-warn-text: #92610f;
    --color-danger: #d9364f;
    --color-danger-bg: #fdecef;
    --color-danger-text: #c02640;

    --color-roas-good: #0b7a53;
    --color-roas-ok: #92610f;
    --color-roas-bad: #c02640;
    --color-roas-good-bg: #e7f7f0;
    --color-roas-ok-bg: #fdf5e6;
    --color-roas-bad-bg: #fdecef;

    --font-sans: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
    --shadow-md: 0 8px 24px -8px rgba(15, 23, 42, .12);
    --radius-card: 16px;
}
html.dark {
    --color-bg: #0b0f17;
    --color-surface: #121823;
    --color-surface-alt: #0f141d;
    --color-surface-hover: #182031;
    --color-border: #1f2735;
    --color-border-accent: #2b3547;
    --color-text: #e8ecf3;
    --color-text-muted: #a3aec2;
    --color-text-dim: #6b778c;

    --color-accent: #6d8bff;
    --color-accent-hover: #8aa2ff;
    --color-accent-bg: #1a2342;
    --color-success: #34d399;
    --color-success-bg: #0f2a21;
    --color-success-text: #34d399;
    --color-warn: #fbbf24;
    --color-warn-bg: #2b2110;
    --color-warn-text: #fbbf24;
    --color-danger: #fb7185;
    --color-danger-bg: #2d1319;
    --color-danger-text: #fb7185;

    --color-roas-good: #34d399;
    --color-roas-ok: #fbbf24;
    --color-roas-bad: #fb7185;
    --color-roas-good-bg: #0f2a21;
    --color-roas-ok-bg: #2b2110;
    --color-roas-bad-bg: #2d1319;

    --shadow-sm: none;
    --shadow-md: 0 12px 32px -12px rgba(0, 0, 0, .6);
}

body, html.dark body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-feature-settings: normal;
}
.app-container { max-width: none; margin-inline: auto; padding-inline: 12px; }  /* full width: wide tables need every pixel */
@media (min-width: 1024px) { .app-container { padding-inline: 16px; } }
.app-dim { color: var(--color-text-dim); }
.app-divider { background: var(--color-border); }

/* ---------- Header ---------- */
header.app-header, html.dark header.app-header {
    background: color-mix(in srgb, var(--color-surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--color-border);
}
.brand-mark {
    width: 30px; height: 30px; border-radius: 9px; color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(145deg, #3d68f5, #2447c9);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
}
#acc-multi-btn.acc-btn {
    height: 36px; padding: 0 30px 0 12px; border-radius: 10px;
    background: transparent; border: 1px solid transparent;
    font-size: 14px; font-weight: 600; color: var(--color-text);
    transition: background .15s, border-color .15s;
}
#acc-multi-btn.acc-btn:hover { background: var(--color-surface-alt); border-color: var(--color-border); }
#acc-multi-btn.acc-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }

.icon-btn {
    width: 36px; height: 36px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--color-text-muted); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--color-surface-hover); color: var(--color-text); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn:focus-visible, .avatar-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }

#btn-auto-refresh.refresh-pill {
    align-items: center; gap: 6px; height: 30px; padding: 0 10px; margin-right: 4px;
    border-radius: 999px; font-size: 12px; color: var(--color-text-dim);
    background: transparent; border: 1px solid transparent; transition: background .15s, border-color .15s;
}
#btn-auto-refresh.refresh-pill:hover { background: var(--color-surface-alt); border-color: var(--color-border); }
.refresh-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--color-text-dim); }
#btn-auto-refresh.auto-refresh-on { background: transparent; color: var(--color-text-dim); }
#btn-auto-refresh.auto-refresh-on .refresh-dot { background: var(--color-success); box-shadow: 0 0 0 3px var(--color-success-bg); }
#btn-auto-refresh.auto-refresh-off .refresh-label::after { content: ' (tắt)'; }
.refresh-time:not(:empty)::before { content: '· '; }

.upgrade-pill {
    display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; margin: 0 4px;
    border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap;
    color: var(--color-warn-text); background: var(--color-warn-bg);
    border: 1px solid color-mix(in srgb, var(--color-warn) 30%, transparent);
}
.upgrade-pill:hover { filter: brightness(.97); }
#btn-upgrade.hidden { display: none; }
.avatar-btn {
    width: 34px; height: 34px; border-radius: 999px; color: #fff; font-size: 13px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(145deg, #3d68f5, #1f3a93);
    box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 3px var(--color-border);
}

/* ---------- Page head + date range ---------- */
.page-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
@media (min-width: 1024px) { .page-head { flex-direction: row; align-items: flex-end; justify-content: space-between; } }
.page-title { font-size: 22px; line-height: 1.25; font-weight: 700; letter-spacing: -0.02em; color: var(--color-text); }
@media (min-width: 1024px) { .page-title { font-size: 26px; } }
.page-sub { margin-top: 2px; font-size: 13.5px; color: var(--color-text-muted); }
.range-bar { display: flex; align-items: center; gap: 8px; overflow-x: auto; margin-inline: -16px; padding-inline: 16px; scrollbar-width: none; }
.range-bar::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) { .range-bar { overflow: visible; margin: 0; padding: 0; } }

.seg {
    display: inline-flex; flex-shrink: 0; padding: 3px; gap: 2px; border-radius: 11px;
    background: var(--color-surface-alt); border: 1px solid var(--color-border);
}
.seg .date-preset, html.dark .seg .date-preset {
    padding: 6px 12px; border-radius: 8px; border: 0; background: transparent;
    font-size: 13px; font-weight: 500; color: var(--color-text-muted); white-space: nowrap;
    transition: background .15s, color .15s, box-shadow .15s;
}
.seg .date-preset:hover, html.dark .seg .date-preset:hover { color: var(--color-text); background: transparent; }
.seg .date-preset.active, html.dark .seg .date-preset.active {
    background: var(--color-surface); color: var(--color-text); border: 0;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 0 0 1px var(--color-border);
}
.range-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; white-space: nowrap;
    border-radius: 11px; font-size: 13px; font-weight: 500; color: var(--color-text);
    background: var(--color-surface); border: 1px solid var(--color-border); box-shadow: var(--shadow-sm);
}
.range-btn svg { color: var(--color-text-dim); }
.range-btn:hover { border-color: var(--color-border-accent); }
.range-btn.is-custom { border-color: var(--color-accent); color: var(--color-accent); }
.range-pop {
    position: fixed; z-index: 55; width: min(360px, calc(100vw - 32px)); padding: 14px;
    border-radius: 14px; background: var(--color-surface); border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
}
.date-preset.chip, html.dark .date-preset.chip {
    padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 500;
    background: var(--color-surface-alt); border: 1px solid var(--color-border); color: var(--color-text-muted);
}
.date-preset.chip.active, html.dark .date-preset.chip.active { background: var(--color-accent-bg); border-color: var(--color-accent); color: var(--color-accent); }
.range-input, html.dark .range-input {
    min-width: 0; flex: 1; height: 34px; padding: 0 8px; border-radius: 9px; font-size: 13px;
    background: var(--color-surface-alt); border: 1px solid var(--color-border); color: var(--color-text);
}
.range-input:focus { outline: 2px solid var(--color-accent); outline-offset: -1px; }
.btn-primary {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
    border-radius: 10px; font-size: 13.5px; font-weight: 600; color: #fff; background: var(--color-accent);
    transition: background .15s;
}
.btn-primary:hover { background: var(--color-accent-hover); }

/* ---------- KPI ---------- */
#kpi-cards.kpi-wrap { display: block; margin-bottom: 20px; }
#kpi-cards .kpi-card, html.dark #kpi-cards .kpi-card {
    background: transparent; border: 0; border-radius: 0; box-shadow: none; padding: 0; min-width: 0;
}
#kpi-cards .kpi-card:hover { transform: none; box-shadow: none; }
.kpi-hero-row {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-card); box-shadow: var(--shadow-sm); overflow: hidden;
}
@media (min-width: 1024px) { .kpi-hero-row { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
/* html.dark variants: the reset above carries html.dark too, so every override must match its weight */
#kpi-cards .kpi-hero, html.dark #kpi-cards .kpi-hero { padding: 16px 18px; border-left: 1px solid var(--color-border); }
#kpi-cards .kpi-hero:nth-child(odd), html.dark #kpi-cards .kpi-hero:nth-child(odd) { border-left: 0; }
#kpi-cards .kpi-hero:nth-child(n+3), html.dark #kpi-cards .kpi-hero:nth-child(n+3) { border-top: 1px solid var(--color-border); }
@media (min-width: 1024px) {
    #kpi-cards .kpi-hero, html.dark #kpi-cards .kpi-hero { padding: 20px 22px; border-top: 0; border-left: 1px solid var(--color-border); }
    #kpi-cards .kpi-hero:first-child, html.dark #kpi-cards .kpi-hero:first-child { border-left: 0; }
}
#kpi-cards .kpi-label, html.dark #kpi-cards .kpi-label {
    font-size: 13px; font-weight: 500; letter-spacing: 0; text-transform: none; line-height: 1.3;
    color: var(--color-text-muted); margin: 0;
}
#kpi-cards .kpi-hero .kpi-value, html.dark #kpi-cards .kpi-hero .kpi-value {
    margin-top: 6px; font-size: 24px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; color: var(--color-text);
}
@media (min-width: 1024px) { #kpi-cards .kpi-hero .kpi-value { font-size: 30px; } }
#kpi-cards .kpi-detail, html.dark #kpi-cards .kpi-detail { margin-top: 6px; font-size: 12px; line-height: 1.45; color: var(--color-text-dim); }
#kpi-cards .kpi-value.roas-good, #kpi-cards .kpi-value.acr-good { color: var(--color-roas-good) !important; }
#kpi-cards .kpi-value.roas-ok, #kpi-cards .kpi-value.acr-ok { color: var(--color-roas-ok) !important; }
#kpi-cards .kpi-value.roas-bad, #kpi-cards .kpi-value.acr-bad { color: var(--color-roas-bad) !important; }
.kpi-bar { height: 6px; margin-top: 12px; border-radius: 999px; background: var(--color-surface-hover); overflow: hidden; }
.kpi-bar > i { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--color-text-dim); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.kpi-bar > i.is-good { background: var(--color-success); }
.kpi-bar > i.is-ok { background: var(--color-warn); }
.kpi-bar > i.is-bad { background: var(--color-danger); }

.kpi-mini-row {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin-top: 12px;
    background: var(--color-border); border: 1px solid var(--color-border); border-radius: 14px; overflow: hidden;
}
@media (min-width: 640px) { .kpi-mini-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .kpi-mini-row { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
#kpi-cards .kpi-mini, html.dark #kpi-cards .kpi-mini { background: var(--color-surface); padding: 12px 16px; border: 0; }
#kpi-cards .kpi-mini .kpi-label { font-size: 12px; color: var(--color-text-dim); }
#kpi-cards .kpi-mini .kpi-value, html.dark #kpi-cards .kpi-mini .kpi-value {
    margin-top: 2px; font-size: 16px; font-weight: 600; color: var(--color-text);
}
#kpi-cards .kpi-mini .kpi-detail { margin-top: 2px; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#kpi-cards .kpi-warn { color: var(--color-warn-text); }
#tab-nav { flex: 0 1 auto; min-width: 0; }
#kpi-cards .kpi-mini:has(#kpi-orders-shopify) { cursor: pointer; }
#kpi-cards .kpi-mini:has(#kpi-orders-shopify):hover { background: var(--color-surface-alt); }

/* ---------- Data toolbar: tabs + search + scale alert ---------- */
.data-toolbar {
    display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}
@media (min-width: 1024px) { .data-toolbar { flex-direction: row; align-items: center; gap: 16px; } }
#tab-nav, html.dark nav#tab-nav { border: 0; margin: 0; }
#tab-nav .tab-btn, html.dark #tab-nav .tab-btn {
    padding: 12px 1px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: transparent;
    font-size: 14px; font-weight: 500; white-space: nowrap; color: var(--color-text-muted);
    transition: color .15s, border-color .15s;
}
#tab-nav .tab-btn:hover, html.dark #tab-nav .tab-btn:hover { color: var(--color-text); }
#tab-nav .tab-btn.active, html.dark #tab-nav .tab-btn.active { color: var(--color-text); border-bottom-color: var(--color-accent); font-weight: 600; }
.toolbar-right { display: flex; align-items: center; gap: 8px; padding-bottom: 10px; }
@media (min-width: 1024px) { .toolbar-right { margin-left: auto; padding-bottom: 6px; } }
.search-box {
    display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; flex: 1;
    border-radius: 10px; background: var(--color-surface); border: 1px solid var(--color-border);
    color: var(--color-text-dim); transition: border-color .15s, box-shadow .15s;
}
@media (min-width: 1024px) { .search-box { flex: none; width: 260px; } }
.search-box:focus-within { border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-bg); }
.search-box input, html.dark .search-box input {
    flex: 1; min-width: 0; border: 0 !important; outline: 0; background: transparent !important;
    font-size: 13.5px; color: var(--color-text); padding: 0; box-shadow: none !important;
}
.search-box input::placeholder { color: var(--color-text-dim); }
#scaling-control.scaling-control {
    display: flex; align-items: center; gap: 5px; height: 36px; padding: 0 10px; margin: 0; flex-shrink: 0;
    border-radius: 10px; background: var(--color-surface); border: 1px solid var(--color-border);
    font-size: 12.5px; color: var(--color-text-muted); white-space: nowrap;
}
.scale-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--color-warn); }
#scaling-control .scaling-input, html.dark #scaling-control .scaling-input {
    width: 40px; height: 24px; padding: 0 4px; text-align: center; border-radius: 6px;
    background: var(--color-surface-alt); border: 1px solid var(--color-border); color: var(--color-text);
    font-size: 12.5px; font-variant-numeric: tabular-nums;
}
#scaling-control .scaling-range { display: none; }  /* dates of the check window: too long for the toolbar */

/* Loading overlay follows the theme */
#loading-overlay { background: color-mix(in srgb, var(--color-bg) 60%, transparent) !important; }

@media (prefers-reduced-motion: reduce) {
    .kpi-bar > i, .icon-btn, .seg .date-preset { transition: none; }
}

/* ---------- Data tables (campaigns / ad sets / ads / countries) ---------- */
.table-wrapper, html.dark .table-wrapper {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-card); box-shadow: var(--shadow-sm);
}
.data-table, html.dark .data-table { font-size: 13px; font-variant-numeric: tabular-nums; }
.data-table thead th, html.dark .data-table thead th {
    padding: 8px 7px; font-size: 11px; font-weight: 600; letter-spacing: .02em;
    color: var(--color-text-dim); background: var(--color-surface); border-bottom: 1px solid var(--color-border);
}
.data-table thead th.sortable:hover, html.dark .data-table thead th.sortable:hover { color: var(--color-text); }
.data-table thead th.sorted-asc, .data-table thead th.sorted-desc { color: var(--color-accent) !important; }
/* Group labels: quiet text on a faint tint instead of coloured bars */
.column-group-row th { padding: 8px 10px 2px !important; font-size: 10.5px !important; letter-spacing: .06em; text-align: left; }
.group-shopify, html.dark .group-shopify { background: var(--color-surface) !important; color: var(--color-success-text) !important; border-bottom: 0 !important; }
.group-meta, html.dark .group-meta { background: color-mix(in srgb, var(--color-accent) 5%, var(--color-surface)) !important; color: var(--color-accent) !important; border-bottom: 0 !important; }
.group-spacer, html.dark .group-spacer { background: var(--color-surface) !important; border-bottom: 0 !important; }
.col-sep, html.dark .col-sep, thead .col-sep, .column-group-row .group-meta.col-sep { border-left: 1px solid var(--color-border) !important; }

.data-table tbody td, html.dark .data-table tbody td {
    padding: 8px 7px; color: var(--color-text); border-bottom: 1px solid color-mix(in srgb, var(--color-border) 70%, transparent);
}
.data-table tbody tr:nth-child(even) td, html.dark .data-table tbody tr:nth-child(even) td { background: var(--color-surface); }
.data-table tbody tr:hover td, html.dark .data-table tbody tr:hover td,
.data-table tbody tr:hover .sticky-col, html.dark .data-table tbody tr:hover .sticky-col { background: var(--color-surface-alt); }
.data-table .sticky-col, html.dark tbody .sticky-col, html.dark thead .sticky-col { background: var(--color-surface); }
.data-table .sticky-col, html.dark .data-table .sticky-col { box-shadow: 6px 0 8px -8px rgba(15, 23, 42, .18); }
.data-table tfoot td, html.dark .data-table tfoot td {
    padding: 9px 7px; font-weight: 600; color: var(--color-text);
    background: var(--color-surface-alt); border-top: 1px solid var(--color-border);
}

/* ROAS / ACR: colour the number, not the whole cell */
.roas-cell-good, .roas-cell-ok, .roas-cell-bad,
html.dark .roas-cell-good, html.dark .roas-cell-ok, html.dark .roas-cell-bad { background: transparent !important; font-weight: 600; }
.roas-good { color: var(--color-roas-good) !important; }
.roas-ok { color: var(--color-roas-ok) !important; }
.roas-bad, .acr-bad { color: var(--color-roas-bad) !important; }

/* Row actions: quiet icon buttons */
.compare-btn, html.dark .compare-btn {
    width: 24px; height: 24px; padding: 0; margin-left: 2px; border-radius: 7px;
    display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
    background: transparent; border: 1px solid transparent; color: var(--color-text-dim); font-size: 12px;
    transition: background .15s, color .15s, border-color .15s;
}
.compare-btn:hover, html.dark .compare-btn:hover { background: var(--color-accent-bg); color: var(--color-accent); border-color: transparent; }
.row-flag { display: inline-flex; vertical-align: middle; margin-left: 4px; color: var(--color-accent); }
.expand-toggle, html.dark .expand-toggle {
    width: 20px; height: 20px; border-radius: 6px; font-size: 12px; line-height: 1;
    background: var(--color-surface-alt); border: 1px solid var(--color-border); color: var(--color-text-muted);
}
.expand-toggle:hover, .expand-toggle.expanded { background: var(--color-accent-bg); border-color: transparent; color: var(--color-accent); }

/* Status switch */
.camp-toggle-slider, html.dark .camp-toggle-slider { background: var(--color-border-accent); }
.camp-toggle input:checked + .camp-toggle-slider { background: var(--color-success); }

/* Orders chip + budget */
.order-link, html.dark .order-link {
    padding: 2px 9px; border-radius: 999px; font-weight: 600; font-size: 12px;
    background: var(--color-accent-bg); color: var(--color-accent); text-decoration: none;
}
.order-link:hover, html.dark .order-link:hover { background: var(--color-accent); color: #fff; }
.budget-display { color: var(--color-text-muted); }
.budget-edit-btn, html.dark .budget-edit-btn {
    width: 22px; height: 22px; padding: 0; margin-left: 2px; border-radius: 6px; vertical-align: middle;
    display: inline-flex; align-items: center; justify-content: center; opacity: .55;
    background: transparent; border: 0; color: var(--color-text-dim);
}
.budget-edit-btn:hover { opacity: 1; background: var(--color-accent-bg); color: var(--color-accent); }

@media (max-width: 640px) {
    .data-table, html.dark .data-table { font-size: 12px; }
    .data-table tbody td, .data-table thead th { padding: 7px 8px; }
}

/* Phones: keep the name column readable while the numbers scroll */
@media (max-width: 640px) {
    .data-table .col-name { min-width: 168px; max-width: 200px; white-space: normal; line-height: 1.35; }
    .page-title { font-size: 20px; }
}

/* Laptops (≤1700px): tighter cells so the full Shopify + Meta table fits without sideways scrolling */
@media (max-width: 1700px) and (min-width: 641px) {
    .data-table, html.dark .data-table { font-size: 12.5px; }
    .data-table thead th, html.dark .data-table thead th,
    .data-table tbody td, html.dark .data-table tbody td,
    .data-table tfoot td, html.dark .data-table tfoot td { padding-left: 4px; padding-right: 4px; }
    .app-container { padding-inline: 10px; }
}
@media (max-width: 1600px) and (min-width: 641px) {
    .data-table, html.dark .data-table { font-size: 12px; }
    .data-table thead th, html.dark .data-table thead th { font-size: 10.5px; }
}

/* Row action icons: clearly visible (user feedback — used a lot, were too faint) */
.compare-btn, html.dark .compare-btn {
    width: 26px; height: 26px; margin-left: 3px;
    color: var(--color-accent); background: var(--color-accent-bg);
    border: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
}
.compare-btn svg { width: 15px; height: 15px; stroke-width: 2.2; }
.compare-btn:hover, html.dark .compare-btn:hover { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.expand-toggle, html.dark .expand-toggle {
    width: 22px; height: 22px; font-size: 15px; font-weight: 700;
    color: var(--color-accent); background: var(--color-accent-bg);
    border: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
}
.expand-toggle:hover, html.dark .expand-toggle:hover,
.expand-toggle.expanded, html.dark .expand-toggle.expanded { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.row-flag { width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 7px;
    background: var(--color-success-bg); color: var(--color-success); }
.row-flag svg { width: 14px; height: 14px; stroke-width: 2.4; }

/* Name cell: the name shrinks with "…", the action buttons never get clipped */
.data-table .col-name { min-width: 260px; max-width: 360px; }
.campaign-name-cell { display: flex; align-items: center; gap: 4px; min-width: 0; }
.campaign-name-cell > span:not(.row-flag):not([class*="badge"]) {
    flex: 1 1 auto; min-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.campaign-name-cell > :not(span), .campaign-name-cell > .row-flag, .campaign-name-cell > [class*="badge"] { flex-shrink: 0; }
@media (max-width: 640px) {
    .data-table .col-name { min-width: 200px; max-width: 230px; }
    .campaign-name-cell { flex-wrap: wrap; }
    .campaign-name-cell > span:not(.row-flag):not([class*="badge"]) { flex-basis: 100%; white-space: normal; }
}
html.dark .compare-btn, html.dark .expand-toggle {
    color: #b7c5ff; background: color-mix(in srgb, var(--color-accent) 22%, transparent);
    border-color: color-mix(in srgb, var(--color-accent) 55%, transparent);
}
html.dark .row-flag { background: color-mix(in srgb, var(--color-success) 22%, transparent); }
@media (max-width: 1440px) and (min-width: 641px) { .data-table .col-name { min-width: 230px; max-width: 290px; } }
.compare-btn, html.dark .compare-btn, .expand-toggle, .budget-edit-btn:hover { opacity: 1; }  /* old stylesheet dimmed them to 60% */

/* KPI: each number in its own rounded card (user preference) */
.kpi-hero-row { gap: 12px; background: transparent; border: 0; box-shadow: none; border-radius: 0; overflow: visible; }
.kpi-mini-row { gap: 10px; background: transparent; border: 0; border-radius: 0; overflow: visible; }
#kpi-cards .kpi-hero, html.dark #kpi-cards .kpi-hero,
#kpi-cards .kpi-hero:nth-child(odd), html.dark #kpi-cards .kpi-hero:nth-child(odd),
#kpi-cards .kpi-hero:nth-child(n+3), html.dark #kpi-cards .kpi-hero:nth-child(n+3),
#kpi-cards .kpi-hero:first-child, html.dark #kpi-cards .kpi-hero:first-child {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 16px; box-shadow: var(--shadow-sm);
}
#kpi-cards .kpi-mini, html.dark #kpi-cards .kpi-mini {
    border: 1px solid var(--color-border); border-radius: 14px; box-shadow: var(--shadow-sm);
}
#kpi-cards .kpi-hero, #kpi-cards .kpi-mini { transition: border-color .15s, transform .15s; }
@media (hover: hover) {
    #kpi-cards .kpi-hero:hover, #kpi-cards .kpi-mini:hover { border-color: var(--color-border-accent); }
}

/* Budget edit pencil: same prominent look as the other row actions (user feedback) */
.budget-edit-btn, html.dark .budget-edit-btn {
    width: 24px; height: 24px; margin-left: 4px; opacity: 1; border-radius: 7px;
    color: var(--color-accent); background: var(--color-accent-bg);
    border: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
}
.budget-edit-btn svg { width: 14px; height: 14px; stroke-width: 2.2; }
.budget-edit-btn:hover, html.dark .budget-edit-btn:hover { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
html.dark .budget-edit-btn {
    color: #b7c5ff; background: color-mix(in srgb, var(--color-accent) 22%, transparent);
    border-color: color-mix(in srgb, var(--color-accent) 55%, transparent);
}
/* Column picker (column-picker.js) */
.colp { position: relative; }
.colp-btn, html.dark .colp-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 10px;
    border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text-muted);
    font: 500 13px var(--font-sans); cursor: pointer; white-space: nowrap;
}
.colp-btn:hover, .colp-btn[aria-expanded="true"] { border-color: var(--color-accent); color: var(--color-accent); }
.colp-btn .cnt { color: var(--color-accent); font-weight: 600; }
.colp-pop {
    position: fixed; z-index: 80; display: grid; grid-template-columns: 1fr 2fr; gap: 4px 20px;
    width: 440px; max-height: calc(100vh - 140px); overflow-y: auto; max-width: calc(100vw - 32px); padding: 14px; border-radius: 14px;
    background: var(--color-surface); border: 1px solid var(--color-border); box-shadow: var(--shadow-md);
}
.colp-pop[hidden] { display: none; }
.colp-group.two { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; align-content: start; }
.colp-group.two .colp-title { grid-column: 1 / -1; }
.colp-title { font: 700 11px var(--font-sans); letter-spacing: .04em; text-transform: uppercase; color: var(--color-text-dim); margin-bottom: 6px; }
.colp-item { display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: 13px; color: var(--color-text); cursor: pointer; }
.colp-item input { width: 15px; height: 15px; accent-color: var(--color-accent); }
.colp-foot { grid-column: 1 / -1; border-top: 1px solid var(--color-border); padding-top: 10px; margin-top: 6px; }
.colp-foot button { background: none; border: 0; color: var(--color-accent); font: 600 13px var(--font-sans); cursor: pointer; padding: 0; }
/* ===== Shared popup look (budget editor, spend limit, budget history, order details) ===== */
.ui-backdrop { position: fixed; inset: 0; z-index: 99998; background: rgba(8, 12, 20, .55); }
.ui-pop {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 99999;
    width: 400px; max-width: calc(100vw - 32px); max-height: 86vh; max-height: 86dvh; overflow-y: auto;
    overscroll-behavior: contain; box-sizing: border-box;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border);
    border-radius: 16px; box-shadow: 0 24px 60px -12px rgba(0, 0, 0, .35); font-family: var(--font-sans);
}
.ui-pop.wide { width: 760px; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.ui-pop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.ui-pop.wide .ui-pop-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--color-border); }
.ui-pop-title { font-size: 15px; font-weight: 700; }
.ui-pop-sub { font-size: 12px; color: var(--color-text-dim); margin-top: 3px; max-width: 520px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-close { background: none; border: 0; padding: 4px; border-radius: 8px; cursor: pointer; color: var(--color-text-dim); line-height: 0; }
.ui-close:hover { background: var(--color-surface-hover); color: var(--color-text); }
.ui-link { font-size: 12px; font-weight: 600; color: var(--color-accent); text-decoration: none; white-space: nowrap; }
.ui-link:hover { text-decoration: underline; }
.ui-label { font-size: 12px; font-weight: 600; color: var(--color-text-muted); margin: 14px 0 6px; }
.ui-label.sm { font-size: 11px; margin: 0 0 4px; }
.ui-big { font-size: 22px; font-weight: 700; color: var(--color-accent); font-variant-numeric: tabular-nums; }
.ui-input {
    width: 100%; box-sizing: border-box; height: 40px; padding: 0 12px; border-radius: 10px;
    border: 1px solid var(--color-border-accent); background: var(--color-surface-alt); color: var(--color-text);
    font: 600 15px var(--font-sans); outline: none; color-scheme: light;
}
html.dark .ui-input { color-scheme: dark; }
.ui-input.sm { height: 34px; font-size: 13px; font-weight: 500; }
.ui-input:focus { border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-bg); }
.ui-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ui-chip {
    padding: 5px 11px; border-radius: 999px; cursor: pointer; font: 600 12px var(--font-sans);
    border: 1px solid var(--color-border-accent); background: var(--color-surface); color: var(--color-text-muted);
}
.ui-chip:hover { border-color: var(--color-accent); color: var(--color-accent); background: var(--color-accent-bg); }
.ui-chip.up { color: var(--color-success-text); }
.ui-chip.down { color: var(--color-danger-text); }
.ui-section {
    margin-top: 14px; padding: 12px 14px; border-radius: 12px;
    border: 1px solid var(--color-border); background: var(--color-surface-alt);
}
.ui-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-size: 13px; font-weight: 600; }
.ui-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ui-check input { width: 15px; height: 15px; accent-color: var(--color-accent); }
.ui-row { display: flex; gap: 8px; }
.ui-row > * { flex: 1; min-width: 0; }
.ui-status { font-size: 11.5px; color: var(--color-text-dim); min-height: 14px; margin: 8px 0; }
.ui-btn {
    height: 38px; padding: 0 16px; border-radius: 10px; cursor: pointer; font: 600 13px var(--font-sans);
    border: 1px solid var(--color-border-accent); background: var(--color-surface); color: var(--color-text);
}
.ui-btn:hover { border-color: var(--color-accent); color: var(--color-accent); }
.ui-btn:disabled { opacity: .6; cursor: default; }
.ui-btn.primary { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.ui-btn.primary:hover { background: var(--color-accent-hover); color: #fff; }
.ui-btn.soft { width: 100%; height: 34px; background: var(--color-accent-bg); color: var(--color-accent);
    border-color: color-mix(in srgb, var(--color-accent) 30%, transparent); }
.ui-btn.soft:hover { background: var(--color-accent); color: #fff; }
.ui-btn.danger { background: var(--color-danger-bg); color: var(--color-danger-text);
    border-color: color-mix(in srgb, var(--color-danger) 35%, transparent); }
.ui-btn.danger:hover { background: var(--color-danger); color: #fff; }
.ui-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.ui-foot.split > * { flex: 1; }

/* Budget history list */
.ui-hist-item { padding: 10px 0; border-bottom: 1px solid var(--color-border); font-size: 13px; }
.ui-hist-item:last-child { border-bottom: 0; }
.ui-hist-top { display: flex; justify-content: space-between; gap: 8px; }
.ui-hist-time { color: var(--color-text-dim); font-size: 11px; flex-shrink: 0; }
.ui-hist-note { color: var(--color-text-muted); font-size: 12px; margin-top: 2px; }
.t-up { color: var(--color-success-text); font-weight: 600; }
.t-down { color: var(--color-danger-text); font-weight: 600; }
.ui-empty { color: var(--color-text-dim); text-align: center; padding: 30px 0; font-size: 13px; }

/* Order details table */
.ui-pop-body { overflow: auto; flex: 1; }
.ui-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.ui-table th { position: sticky; top: 0; background: var(--color-surface-alt); color: var(--color-text-dim);
    font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; text-align: left;
    padding: 10px 12px; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.ui-table td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.ui-table tbody tr:hover td { background: var(--color-surface-hover); }
.ui-table .r { text-align: right; }
.ui-table .code { font-weight: 700; color: var(--color-accent); }
.ui-table tr.total td { font-weight: 700; background: var(--color-surface-alt); border-bottom: 0; }
.ui-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.ui-badge.good { background: var(--color-success-bg); color: var(--color-success-text); }
.ui-badge.warn { background: var(--color-warn-bg); color: var(--color-warn-text); }
.ui-badge.mute { background: var(--color-surface-hover); color: var(--color-text-muted); }
/* Above the sticky header and the demo banner; Dialog (confirm) still sits above this. */
#order-popup .ui-pop { z-index: 99999; }
#order-popup .ui-backdrop { z-index: 99998; }
.ui-section .ui-btn { width: 100%; height: 34px; }
html.dark .ui-pop { color-scheme: dark; }
.ui-status:empty { min-height: 0; margin: 10px 0 0; }
.ui-table tr.group td { background: var(--color-surface-alt); padding-top: 12px; padding-bottom: 8px; white-space: normal; }
.ui-table tr.group:hover td { background: var(--color-surface-alt); }
.ui-table tr.group .g-name { font-weight: 700; margin: 0 8px; }
.ui-table tr.group .g-meta { color: var(--color-text-muted); font-size: 12px; }
.ui-table tr.group.noutm .g-name { color: var(--color-warn-text); }.ui-pop.wide { width: 900px; }

/* Phones: keep the table, just make it fit — drop the row number, tighten cells, shorten the
   timestamp column. Anything left over still scrolls sideways inside the popup body. */
@media (max-width: 640px) {
    .ui-table { font-size: 11.5px; }
    .ui-table th, .ui-table td { padding: 6px 4px; }
    /* Header words set the column width: let them wrap so the numbers below decide it instead */
    .ui-table th { font-size: 9.5px; letter-spacing: 0; white-space: normal; line-height: 1.2; }
    .ui-table th:first-child, .ui-table td[data-label="#"] { display: none; }
    .ui-table td[data-label="Ngày tạo"] { font-size: 10.5px; line-height: 1.25; white-space: normal; min-width: 62px; }
    .ui-table .ui-badge { padding: 1px 6px; font-size: 10.5px; }
    .ui-table .risk-badge { padding: 1px 5px !important; font-size: 10px !important; white-space: normal !important; }
    .ui-table tr.total td:first-child[colspan] { display: table-cell; }
    .ui-pop.wide .ui-pop-head { padding: 14px 14px 12px; }
    .ui-pop-sub { white-space: normal; }
    /* Full-screen sheet anchored to the top: centring it with 100vh pushed the title and the ✕
       above the visible area on iOS, where 100vh includes the address bar. */
    #order-popup .ui-pop.wide {
        top: 0; left: 0; right: 0; transform: none;
        width: 100%; max-width: 100%; height: 100vh; height: 100dvh; max-height: 100dvh; border-radius: 0;
        padding-top: env(safe-area-inset-top, 0px);
    }
    #order-popup .ui-pop.wide .ui-pop-head { position: sticky; top: 0; z-index: 2; background: var(--color-surface); }
    /* Long country names push the table past the screen — keep the order code pinned while scrolling */
    .ui-table th:nth-child(2), .ui-table td[data-label="Mã đơn"] {
        position: sticky; left: 0; z-index: 1; background: var(--color-surface);
        box-shadow: 1px 0 0 var(--color-border);
    }
    .ui-table th:nth-child(2) { z-index: 3; background: var(--color-surface-alt); }
}
.ui-pop, .ui-pop-body { scrollbar-width: thin; scrollbar-color: var(--color-border-accent) transparent; }

/* Name-column resize handle: always visible (user feedback — used often, was hover-only 5px) */
.data-table th.col-name .col-name-resize, html.dark .data-table th.col-name .col-name-resize {
    width: 10px; right: -1px; top: 6px; bottom: 6px; border-radius: 4px; z-index: 12;
    background:
        radial-gradient(circle, color-mix(in srgb, var(--color-accent) 85%, transparent) 1.2px, transparent 1.6px)
        center / 4px 5px repeat-y,
        color-mix(in srgb, var(--color-accent) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
}
.data-table th.col-name .col-name-resize:hover, .data-table th.col-name .col-name-resize.dragging,
html.dark .data-table th.col-name .col-name-resize:hover, html.dark .data-table th.col-name .col-name-resize.dragging {
    background:
        radial-gradient(circle, #fff 1.2px, transparent 1.6px) center / 4px 5px repeat-y,
        var(--color-accent);
    border-color: var(--color-accent);
}
/* Help boxes in Settings › Công cụ (seeding, budget rules, ID map) */
.tool-help { margin-bottom: 16px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--color-accent) 30%, transparent);
    background: var(--color-accent-bg); color: var(--color-text); font-size: 13px; line-height: 1.6; }
.tool-help summary { cursor: pointer; padding: 10px 14px; font-weight: 700; color: var(--color-accent); list-style: none; }
.tool-help summary::-webkit-details-marker { display: none; }
.tool-help summary::after { content: '▾'; float: right; transition: transform .15s; }
.tool-help:not([open]) summary::after { transform: rotate(-90deg); }
.tool-help-body { padding: 0 14px 12px; }
.tool-help-body p { margin: 6px 0; }
.tool-help-body ol, .tool-help-body ul { margin: 4px 0 6px; padding-left: 20px; }
.tool-help-body ol { list-style: decimal; }
.tool-help-body ul { list-style: disc; }
.tool-help-body li { margin: 3px 0; }
.tool-help-body b { color: var(--color-text); }
html.dark .tool-help { background: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface)); }
/* Alert strips: creative-watch (purple) and auto budget changes (amber) use a tint like the green one,
   so the row text stays readable. */
.scaling-banner--purple { border-color: #a855f7; background: rgba(168, 85, 247, .12); }
.scaling-banner--purple .scaling-banner-title, .scaling-banner--purple .scaling-seq { color: #7c3aed; }
html.dark .scaling-banner--purple .scaling-banner-title, html.dark .scaling-banner--purple .scaling-seq { color: #c084fc; }
.scaling-banner--amber { border-color: #f59e0b; background: rgba(245, 158, 11, .10); }
.scaling-banner--amber .scaling-banner-title, .scaling-banner--amber .scaling-seq { color: #b45309; }
html.dark .scaling-banner--amber .scaling-banner-title, html.dark .scaling-banner--amber .scaling-seq { color: #fbbf24; }
.scaling-banner--purple .scaling-close, .scaling-banner--amber .scaling-close { color: inherit; }
