:root {
    --bg: #F3F5FA;
    --surface: #FFFFFF;
    --surface-alt: #F8F9FC;
    --border: #E3E7EF;
    --border-strong: #D3D9E4;
    --table-head-bg: #DEE3EE;
    --text: #171B26;
    --text-muted: #626C80;
    --text-faint: #8B93A6;
    --accent: #3454D1;
    --accent-soft: #E9EDFC;

    --shopee: #EE6C37; --shopee-soft: #FDEBE2;
    --tiktok: #3DA84B; --tiktok-soft: #E5F5E7;
    --tokopedia: #2E7DE1; --tokopedia-soft: #E2EDFC;
    --lazada: #7C4DDC; --lazada-soft: #EFE8FC;

    --success: #2E9B57; --success-soft: #E4F5EA;
    --warning: #C77E0A; --warning-soft: #FBF0DD;
    --sev-high: #D9622A; --sev-high-soft: #FCE8DC;
    --critical: #D6455A; --critical-soft: #FBE6E9;
    --info: #2E6FE0; --info-soft: #E3EBFC;

    --shadow: 0 1px 2px rgba(23,27,38,.04), 0 8px 24px rgba(23,27,38,.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #10131C;
        --surface: #181C28;
        --surface-alt: #1E2330;
        --border: #2A3040;
        --border-strong: #363D50;
        --table-head-bg: #2A3244;
        --text: #E9ECF4;
        --text-muted: #9BA3B8;
        --text-faint: #6E7688;
        --accent: #7C93FF;
        --accent-soft: #232A47;

        --shopee: #FF8A5C; --shopee-soft: #3A2620;
        --tiktok: #63C96F; --tiktok-soft: #1B3020;
        --tokopedia: #6FA8FF; --tokopedia-soft: #1C2C42;
        --lazada: #A47BFF; --lazada-soft: #2A2140;

        --success: #4CC179; --success-soft: #17301F;
        --warning: #E8AE3C; --warning-soft: #332A15;
        --sev-high: #F0995A; --sev-high-soft: #3A2A18;
        --critical: #FF7086; --critical-soft: #3A1D22;
        --info: #6FA0FF; --info-soft: #1B2C4A;

        --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    }
    .brand-logo { filter: invert(1); }   /* logo is black on transparent */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 Inter, system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 700; text-wrap: balance; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.main { display: flex; flex-direction: column; min-width: 0; }
.content { flex: 1; min-width: 0; padding: 16px 22px 32px; }

/* ---------- sidebar ---------- */
.sidebar {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 22px;
    padding: 20px 14px 24px;
    background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 4px 8px 14px; border-bottom: 1px solid var(--border); }
.brand-logo { display: block; width: 112px; height: auto; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11.5px; color: var(--text-faint); }
.sidebar nav { display: flex; flex-direction: column; gap: 22px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: 0 10px 7px; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.nav-item {
    display: block; padding: 8px 10px 8px 24px; border: 1px solid transparent; border-radius: 8px;
    color: var(--text-muted); font-size: 13.3px;
}
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active {
    background: var(--accent-soft); color: var(--accent); font-weight: 600;
    border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}

/* ---------- top bar ---------- */
.topbar {
    display: flex; flex-direction: column; gap: 11px;
    padding: 13px 22px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-body { display: flex; flex-direction: column; gap: 11px; }
.topbar-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title { font-size: 21px; }
.page-meta { margin-top: 3px; color: var(--text-faint); font-size: 12.5px; }
.page-meta strong { color: var(--text); }
.page-meta .warn { color: var(--warning); }
.neg { color: var(--critical); }

.topbar-top { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
.sync-box { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sync-status { color: var(--text-faint); font-size: 12.3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-status.warn { color: var(--warning); }
.sync-status.error { color: var(--critical); }
.user { position: relative; }
.user summary { list-style: none; cursor: pointer; }
.user summary::-webkit-details-marker { display: none; }
.avatar {
    display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--lazada)); color: #fff; font-weight: 700;
}
.user-menu {
    position: absolute; right: 0; top: 42px; z-index: 40; min-width: 180px; padding: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 14px 34px rgba(0,0,0,.2);
}
.user-name { margin-bottom: 4px; padding: 8px 10px; border-bottom: 1px solid var(--border); font-weight: 600; }
.user-menu button { width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: none; text-align: left; }
.user-menu button:hover { background: var(--accent-soft); color: var(--accent); }

.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 9px; }
.segmented a { padding: 6px 16px; border-radius: 7px; color: var(--text-muted); font-weight: 600; font-size: 12.8px; }
.segmented a.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* ---------- marketplace tabs + toolbar ---------- */
.mp-tabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mp-tab {
    display: flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--border); border-radius: 100px;
    background: var(--surface-alt); color: var(--text-muted); font-weight: 600; font-size: 12.6px;
}
.mp-tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.mp-tab:disabled { opacity: .5; cursor: not-allowed; }
.mp-tab.active { color: #fff; border-color: transparent; }
.mp-tab.active .dot { background: rgba(255,255,255,.85); }
.mp-tab[data-c="shopee"].active { background: var(--shopee); }
.mp-tab[data-c="tiktok"].active { background: var(--tiktok); }
.mp-tab[data-c="lazada"].active { background: var(--lazada); }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search {
    flex: 1 1 240px; min-width: 200px; display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-alt);
}
.search svg { flex: none; color: var(--text-faint); }
.search input { width: 100%; border: 0; background: none; outline: none; }
.search input::placeholder { color: var(--text-faint); }
.filter, .col-toggle {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface-alt); color: var(--text); font-weight: 500;
}
.col-toggle { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.col-toggle.open { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

/* ---------- column picker ---------- */
.col-panel { margin-bottom: 14px; padding: 14px 16px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px; }
.col-panel h3 { margin-bottom: 10px; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.col-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px 18px; }
.col-check { display: flex; align-items: center; gap: 8px; font-size: 12.8px; }
.col-check input { flex: none; width: 15px; height: 15px; accent-color: var(--accent); }
.col-check small { color: var(--text-faint); }
.col-panel .hint { margin: 12px 0 0; font-size: 11.8px; color: var(--text-faint); }

/* ---------- table ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.table-card { position: relative; }
.table-card.loading .table-scroll { min-height: 260px; opacity: .45; pointer-events: none; }
.table-card.loading::after { content: ""; position: absolute; top: 200px; left: calc(50% - 16px); width: 32px; height: 32px; border: 3px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.table-scroll { max-height: 640px; overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th { position: sticky; z-index: 3; }
thead .group-row th { top: 0; padding: 8px 13px; border-bottom: 1px solid var(--border); font-size: 10.6px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.grp-product { background: var(--info-soft); color: var(--info); }
.grp-sales { background: var(--tokopedia-soft); color: var(--tokopedia); }
.grp-ads { background: var(--accent-soft); color: var(--accent); }
.grp-priority { background: color-mix(in srgb, var(--lazada) 14%, transparent); color: var(--lazada); }
.range-sep { color: var(--text-muted); }
thead .col-row th { top: 34px; padding: 9px 13px; background: var(--table-head-bg); border-bottom: 1px solid var(--border-strong); font-size: 11.7px; font-weight: 700; }
thead .col-row th[data-key] { cursor: pointer; user-select: none; }
thead .col-row th[data-key]:hover, thead .col-row th[aria-sort] { color: var(--accent); }
.sort-arrow { display: inline-block; width: 1em; font-size: 10px; text-align: center; opacity: .35; }
th[aria-sort] .sort-arrow { opacity: 1; }
tbody td { padding: 10px 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-alt); }
/* first column (SKU) stays put while scrolling sideways */
.col-row th:first-child, tbody td:first-child { position: sticky; left: 0; z-index: 2; border-right: 1px solid var(--border); }
.col-row th:first-child { z-index: 5; }
tbody td:first-child { background: var(--surface); }
tbody tr:hover td:first-child { background: var(--surface-alt); }
.sku { font-weight: 600; }
.dash { color: var(--text-faint); }

.state { padding: 32px; text-align: center; color: var(--text-muted); }
.state.error { color: var(--critical); }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12.5px; }

.pager { display: flex; align-items: center; gap: 4px; }
.pager[hidden] { display: none; }
.pg { min-width: 28px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text-muted); font-size: 12.5px; font-weight: 600; }
.pg:hover:not(:disabled) { background: var(--surface-alt); }
.pg.on { border-color: var(--accent); background: var(--accent); color: #fff; }
.pg:disabled { opacity: .4; cursor: default; }
.pg-gap { padding: 0 4px; color: var(--text-faint); }
.pg-size { margin-right: 10px; }
.pg-size select { padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: inherit; font-size: 12.5px; }

.btn-ghost, .btn-primary { padding: 7px 16px; border-radius: 7px; font-size: 12.5px; font-weight: 600; }
.btn-ghost { border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-primary { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .9; }
.btn-primary:disabled { opacity: .6; }

.mp-tag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 100px; font-size: 11.2px; font-weight: 600; }
.mp-tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.mp-shopee { background: var(--shopee-soft); color: var(--shopee); }
.mp-tiktok { background: var(--tiktok-soft); color: var(--tiktok); }
.mp-lazada { background: color-mix(in srgb, var(--lazada) 14%, transparent); color: var(--lazada); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 100px; font-size: 11.4px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.tone-critical { background: var(--critical-soft); color: var(--critical); }
.tone-high { background: var(--sev-high-soft); color: var(--sev-high); }
.tone-warning { background: var(--warning-soft); color: var(--warning); }
.tone-success { background: var(--success-soft); color: var(--success); }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-neutral { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }
.roas-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.roas-dot.off { background: var(--border-strong); }
.roas-dot.bad { background: var(--critical); }
.roas-cell { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }

/* ---------- mockup page ---------- */

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login { width: 100%; max-width: 380px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.login .brand { margin-bottom: 20px; padding: 0 0 16px; }
.login label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 12.8px; }
.login input[type=text], .login input[type=password] {
    display: block; width: 100%; margin-top: 5px; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface-alt); font-weight: 400;
}
.login .remember { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.login .remember input { accent-color: var(--accent); }
.login .btn-primary { width: 100%; padding: 10px; font-size: 13.5px; }
.login .error { margin: 0 0 14px; color: var(--critical); }

@media (max-width: 820px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
    .content { padding: 14px; }
    .topbar { padding: 13px 14px; }
}

/* ---------- sales report ---------- */
.sec { margin-bottom: 22px; }
.sec-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; margin-bottom: 10px; }
.sec-head h2 { font-size: 15px; }
.sec-head .sub { color: var(--text-faint); font-size: 12.3px; }
.sec-head .col-toggle { margin-left: auto; padding: 5px 12px; font-size: 12.5px; }
.sec-head .letter {
    display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
    background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 800;
}
.rt thead th { padding: 9px 13px; background: var(--table-head-bg); border-bottom: 1px solid var(--border-strong); font-size: 11.7px; font-weight: 700; }
.rt thead th.num { text-align: right; }
.rt tbody td { padding: 10px 13px; }
.rt tr.total td { font-weight: 700; background: var(--surface-alt); }
.mp-name { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.mp-name .dot { width: 8px; height: 8px; border-radius: 50%; }
.trend-checks { display: flex; flex-wrap: wrap; gap: 16px; padding: 12px 14px 4px; }
.pos { color: var(--success); }
p.hint { margin: 0; font-size: 11.8px; color: var(--text-faint); }

/* ---------- stock sales ---------- */
.st thead th { top: 0; padding: 9px 10px; background: var(--table-head-bg); border-bottom: 1px solid var(--border-strong); font-size: 11.7px; font-weight: 700; cursor: pointer; user-select: none; }
.st thead th:first-child { left: 0; z-index: 5; border-right: 1px solid var(--border); }
.st thead th:hover, .st thead th[aria-sort] { color: var(--accent); }
.st thead th.num { text-align: right; }
.st tbody td { padding: 9px 10px; }
.st thead th.wk { padding-right: 82px; }   /* clear the growth slot so the header sits over the number */
.st td .gr { display: inline-block; width: 62px; margin-left: 10px; text-align: left; font-size: 10.7px; font-weight: 500; color: var(--text-faint); }
.st .sub { display: block; margin-top: 1px; font-size: 9.7px; font-weight: 500; color: var(--text-faint); }

/* ---------- marketplace performance ---------- */
.mp-tab[data-c="all"].active { background: var(--accent); }
.pf thead th { position: sticky; top: 0; z-index: 3; padding: 9px 13px; background: var(--table-head-bg); border-bottom: 1px solid var(--border-strong); font-size: 11.7px; font-weight: 700; }
.pf thead th.num { text-align: right; }
.pf thead tr.weeks th { top: 34px; }
.pf thead th.month { text-align: center; border-left: 1px solid var(--border-strong); }
.pf tbody td { padding: 9px 13px; border-bottom: 1px solid var(--border); }
.pf th:first-child, .pf td:first-child { position: sticky; left: 0; z-index: 2; min-width: 280px; border-right: 1px solid var(--border); }
.pf thead th:first-child { z-index: 5; }
.pf tbody td:first-child { background: var(--surface); }
.pf tr.grp td { background: var(--surface-alt); font-weight: 700; }
.pf tr.item td:first-child { padding-left: 28px; }
.pf tr.flat td:first-child { font-weight: 700; }
.pf tr.na td { color: var(--text-faint); }
.pf .sub { display: block; margin-top: 1px; font-size: 9.7px; font-weight: 500; color: var(--text-faint); }
.pf td .why { margin-left: 8px; padding: 1px 7px; border-radius: 100px; background: var(--surface-alt); border: 1px solid var(--border); font-size: 10px; font-weight: 500; }
.pf tr.bold td { font-weight: 700; }

/* ---------- marketplace breakdown ---------- */
.bd-card { margin-bottom: 12px; }
.card-head { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 700; }
.channel-card { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; overflow: hidden; background: var(--surface); }
.channel-card-head { display: flex; align-items: center; gap: 8px; padding: 9px 14px; background: var(--surface-alt); font-size: 12.6px; font-weight: 700; }
.channel-card-head .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.channel-card-head .idx { color: var(--text-faint); font-weight: 500; font-size: 11.2px; }

/* ---------- KPI dictionary ---------- */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dict { border-collapse: separate; border-spacing: 0; }
.dict th, .dict td { white-space: nowrap; border-bottom: 1px solid var(--border); padding: 6px 10px; font-size: 11.6px; vertical-align: top; }
.dict td.kpi, .dict th.kpi { position: sticky; left: 0; z-index: 2; background: var(--surface); border-right: 1px solid var(--border); min-width: 170px; white-space: normal; }
.dict th { background: var(--table-head-bg); font-weight: 700; }
.dict th.grp { text-align: center; color: #fff; font-size: 12px; }
.dict th.ch { text-align: center; font-weight: 600; min-width: 110px; border-bottom: 1px solid var(--border-strong); }
.dict td.meta { color: var(--text-muted); white-space: normal; min-width: 110px; }
.dict td.calc { min-width: 190px; }
.dict tr.topic td { background: var(--surface-alt); font-weight: 700; }
.dict tr.bold td.kpi { font-weight: 700; }
.dict td.yes .check { color: var(--success); font-weight: 700; margin-right: 5px; }
.dict td.yes .local { color: var(--text-muted); }
.dict td.no { color: var(--text-faint); text-align: center; }
.dict .g-shopee { background: var(--shopee-soft); }
.dict .g-tiktok { background: var(--tiktok-soft); }
.dict .g-lazada { background: var(--lazada-soft); }
.rt tr.na td { color: var(--text-faint); }
.rt td .why, .pf td .why { margin-left: 8px; padding: 1px 7px; border-radius: 100px; background: var(--surface-alt); border: 1px solid var(--border); font-size: 10px; font-weight: 500; }
.channel-card .rt tbody td { padding: 9px 13px; }
.card-head .muted { margin-left: 6px; font-weight: 500; font-size: 11.5px; color: var(--text-faint); }
.contrib-mp { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.contrib-mp .dot { width: 8px; height: 8px; border-radius: 50%; }
.contrib-val { display: block; font-weight: 600; }
.col-month { grid-column: 1 / -1; margin-top: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.bd-donuts { display: flex; gap: 14px; flex-wrap: wrap; padding: 12px; }
.donut-card { flex: 1 1 200px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px; background: var(--surface-alt); border-radius: 10px; }
.donut-card h4 { margin: 0; font-size: 11.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.donut-center { font-size: 13px; font-weight: 700; fill: var(--text); }
.donut-legend { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.donut-legend .row { display: flex; justify-content: space-between; gap: 8px; font-size: 11.2px; }
.donut-legend .name { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.donut-legend .sw { width: 8px; height: 8px; border-radius: 50%; }
.donut-legend .pct { font-weight: 600; }
