/* APS dashboard theme. Every color is a token here; light and dark swap in one place. */

:root {
  color-scheme: light;
  --brand: #0533BD;            /* APS logo blue */
  --brand-hover: #0429A3;
  --brand-ink: #0533BD;        /* brand-colored text and links */
  --brand-soft: #E9EEFC;       /* tinted fills: active rows, pills */
  --on-brand: #FFFFFF;

  --page: #F4F5F9;
  --card: #FFFFFF;
  --card-2: #F7F8FB;
  --border: #E5E7EF;
  --border-strong: #D3D7E3;
  --ink: #0B0D17;
  --ink-2: #454B5E;
  --muted: #7F8598;
  --grid: #EEF0F5;
  --axis: #D3D7E3;

  --up-bg: #E6F6EC;   --up-ink: #067A35;
  --down-bg: #FDEBEB; --down-ink: #BF2B2B;
  --flat-bg: #EFF0F4; --flat-ink: #646A7E;
  --warn-bg: #FEF3DC; --warn-ink: #8A5A00;
  --live: #12A150;

  /* Chart series. Validated as a set (colorblind separation, contrast) for this surface.
     Slot 1 is the logo blue lifted into the chart lightness band. */
  --s1: #1E4FD6; --s2: #EB6834; --s3: #1BAF7A;

  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .16);
  --radius: 14px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #2F55E4; --brand-hover: #4166EE; --brand-ink: #93AAFF;
    --brand-soft: rgba(91, 124, 245, .16); --on-brand: #FFFFFF;
    --page: #0A0C12; --card: #12151E; --card-2: #181C27;
    --border: #232837; --border-strong: #2E3446;
    --ink: #F2F3F7; --ink-2: #B8BDCC; --muted: #7C8296;
    --grid: #1D2230; --axis: #2E3446;
    --up-bg: rgba(18, 161, 80, .16);  --up-ink: #43D886;
    --down-bg: rgba(229, 72, 72, .16); --down-ink: #FF8E8E;
    --flat-bg: #1E2230; --flat-ink: #9AA0B3;
    --warn-bg: rgba(250, 178, 25, .16); --warn-ink: #FAC75A;
    --live: #2BC56B;
    --s1: #4D72F2; --s2: #D95926; --s3: #199E70;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #2F55E4; --brand-hover: #4166EE; --brand-ink: #93AAFF;
  --brand-soft: rgba(91, 124, 245, .16); --on-brand: #FFFFFF;
  --page: #0A0C12; --card: #12151E; --card-2: #181C27;
  --border: #232837; --border-strong: #2E3446;
  --ink: #F2F3F7; --ink-2: #B8BDCC; --muted: #7C8296;
  --grid: #1D2230; --axis: #2E3446;
  --up-bg: rgba(18, 161, 80, .16);  --up-ink: #43D886;
  --down-bg: rgba(229, 72, 72, .16); --down-ink: #FF8E8E;
  --flat-bg: #1E2230; --flat-ink: #9AA0B3;
  --warn-bg: rgba(250, 178, 25, .16); --warn-ink: #FAC75A;
  --live: #2BC56B;
  --s1: #4D72F2; --s2: #D95926; --s3: #199E70;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  background: var(--page); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 16px; }
.logo { height: 30px; width: auto; display: block; }
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: block; }
}
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.updated { font-size: 12.5px; color: var(--muted); margin-right: 4px; white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--card);
  font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--border-strong); background: var(--card-2); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-icon { width: 34px; padding: 0; justify-content: center; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

/* ---------- Page head ---------- */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 24px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.eyebrow {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.live {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  background: var(--up-bg); color: var(--up-ink); font-size: 12px; font-weight: 600;
  letter-spacing: 0; text-transform: none;
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--live); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(18, 161, 80, .5); } 70% { box-shadow: 0 0 0 6px rgba(18, 161, 80, 0); } 100% { box-shadow: 0 0 0 0 rgba(18, 161, 80, 0); } }
@media (prefers-reduced-motion: reduce) { .live i { animation: none; } }
h1 { font-size: 32px; line-height: 1.15; font-weight: 800; letter-spacing: -.02em; }
.sub { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.sub b { font-weight: 600; color: var(--ink); }
.sub .note { color: var(--brand-ink); font-weight: 600; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: 11px; background: var(--card-2); }
.seg button {
  height: 30px; padding: 0 13px; border: 0; border-radius: 8px; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Groups and cards ---------- */
#sections { transition: opacity .2s; }
#sections.is-loading { opacity: .55; pointer-events: none; }
.group-head { display: flex; align-items: center; gap: 14px; margin: 34px 0 12px; }
.group-head h2 { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.group-head .rule { flex: 1; height: 1px; background: var(--border); }
.group-head .group-note { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-full, .grid > .card:only-child { grid-column: 1 / -1; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.card-head h3 { font-size: 15px; font-weight: 700; }
.card-head p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.info {
  margin-left: auto; flex: none; width: 24px; height: 24px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 50%; background: transparent;
  font-size: 12px; font-weight: 700; font-style: italic; font-family: Georgia, serif; color: var(--muted); cursor: pointer;
}
.info:hover, .info[aria-expanded="true"] { color: var(--brand-ink); border-color: var(--brand-ink); }
.how { margin: -6px 0 16px; padding: 10px 12px; border-radius: 9px; background: var(--card-2); font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }
.placeholder { padding: 28px 16px; border-radius: 10px; background: var(--card-2); text-align: center; font-size: 13px; color: var(--muted); }
.empty { padding: 24px 8px; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- Status (errors, first load) ---------- */
.status { margin-top: 28px; }
.status-card { max-width: 520px; margin: 40px auto; text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px 28px; box-shadow: var(--shadow); }
.status-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.status-card p { color: var(--ink-2); margin-bottom: 16px; }
.spinner { width: 28px; height: 28px; margin: 0 auto 12px; border: 3px solid var(--grid); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.foot { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 18px; }

/* ---------- Customize panel ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(10, 12, 20, .32); }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(380px, 100vw);
  display: flex; flex-direction: column; background: var(--card); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.panel-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 16px; font-weight: 700; }
.panel-head .btn { margin-left: auto; }
.panel-body { flex: 1; overflow-y: auto; padding: 8px 20px 20px; }
.panel-intro { font-size: 13px; color: var(--ink-2); margin: 10px 0 4px; }
.panel-group { margin-top: 18px; }
.panel-group h3 { font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--grid); cursor: pointer; }
.toggle span { flex: 1; font-size: 13.5px; font-weight: 500; }
.toggle input { appearance: none; -webkit-appearance: none; position: relative; width: 36px; height: 21px; margin: 0; flex: none; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .15s; }
.toggle input:checked { background: var(--brand); }
.toggle input:checked::after { transform: translateX(15px); }
.panel-actions { display: flex; gap: 8px; margin-top: 18px; }
.panel-foot { padding: 16px 20px 20px; border-top: 1px solid var(--border); background: var(--card-2); }
.panel-foot label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 6px; }
.panel-foot p { font-size: 12px; color: var(--muted); margin-top: 8px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--card); color: var(--ink-2); font: 12px ui-monospace, Consolas, monospace; }

/* ---------- KPI tiles (Part 3) ---------- */
.card.bare { background: none; border: 0; box-shadow: none; padding: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 15px 16px 14px; min-width: 0; }
.tile-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 6px; }
.tile-value { font-size: 25px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; white-space: nowrap; }
.spark { width: 64px; height: 26px; flex: none; overflow: visible; }
.tile-foot { display: flex; align-items: center; gap: 7px; margin-top: 8px; font-size: 12px; color: var(--muted); min-width: 0; }
.tile-foot span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { flex: none; display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 700; line-height: 1.5; font-variant-numeric: tabular-nums; }
.pill.up { background: var(--up-bg); color: var(--up-ink); }
.pill.down { background: var(--down-bg); color: var(--down-ink); }
.pill.flat { background: var(--flat-bg); color: var(--flat-ink); }
.kpi-note { margin-top: 10px; font-size: 12.5px; color: var(--muted); }

/* ---------- Charts (Part 3) ---------- */
.chart-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-item b { color: var(--ink); font-weight: 700; }
.key-line { width: 14px; height: 3px; border-radius: 2px; }
.key-box { width: 10px; height: 10px; border-radius: 3px; }
.chart-box { position: relative; height: 240px; }
.mini-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.mini-stats div { min-width: 0; }
.mini-stats span { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.mini-stats b { display: block; font-size: 17px; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; }

.view-toggle { display: inline-flex; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--card-2); margin-left: auto; }
.view-toggle button { height: 24px; padding: 0 9px; border: 0; border-radius: 6px; background: transparent; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; }
.view-toggle button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* Plain data table, used by "Table" views and list sections */
.table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { position: sticky; top: 0; background: var(--card); text-align: left; padding: 7px 10px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--grid); color: var(--ink-2); white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.strong { color: var(--ink); font-weight: 600; }

/* ---------- Ranked lists and funnel (Part 4) ---------- */
.rank-scroll { overflow-x: auto; }
.rank-row { display: grid; grid-template-columns: var(--cols); align-items: baseline; column-gap: 14px; }
.rank-head { padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.rank-head span { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.rank-head span:not(:first-child), .rank-val { text-align: right; }
.rank-item { padding: 9px 0 8px; border-bottom: 1px solid var(--grid); }
.rank-item:last-child { border-bottom: 0; }
.rank-name { min-width: 0; font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-name small { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.rank-val { font-size: 13px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-val b { color: var(--ink); font-weight: 700; }
.rank-bar { height: 5px; margin-top: 7px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: 3px; }
.link-btn { margin-top: 10px; padding: 0; border: 0; background: none; font-size: 13px; font-weight: 700; color: var(--brand-ink); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.funnel { display: flex; flex-direction: column; gap: 14px; }
.funnel-step-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.funnel-step-top span { font-size: 13.5px; font-weight: 600; }
.funnel-step-top b { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.funnel-step-top em { font-style: normal; font-size: 12.5px; color: var(--muted); margin-left: 6px; font-weight: 600; }
.funnel-bar { height: 12px; margin-top: 6px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.funnel-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 2px; }
.funnel-drop { margin-top: 4px; font-size: 12px; color: var(--muted); }
.callout { margin-top: 16px; padding: 10px 12px; border-radius: 9px; background: var(--brand-soft); color: var(--ink); font-size: 12.5px; }
.callout b { font-weight: 700; }

/* ---------- Audience, heatmap, orders, health (Part 5) ---------- */
.audience { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 18px; align-items: center; }
.donut-box { position: relative; height: 170px; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center b { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.donut-center span { font-size: 11.5px; color: var(--muted); }
.key-list { display: flex; flex-direction: column; gap: 10px; }
.key-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: baseline; gap: 4px 10px; font-size: 13px; }
.key-row .key-box { align-self: center; }
.key-row b { font-weight: 700; font-variant-numeric: tabular-nums; }
.key-row em { font-style: normal; color: var(--muted); font-size: 12.5px; min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.key-row small { grid-column: 2 / -1; font-size: 11.5px; color: var(--muted); margin-top: -4px; }
.sub-head { margin: 22px 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stack { display: flex; gap: 2px; height: 14px; }
.stack i { display: block; height: 100%; }
.stack i:first-child { border-radius: 4px 0 0 4px; }
.stack i:last-child { border-radius: 0 4px 4px 0; }
.stack i:only-child { border-radius: 4px; }
.stack-labels { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.stack-labels span { display: inline-flex; align-items: center; gap: 7px; }
.stack-labels b { color: var(--ink); }

.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; }
.heat .hd { font-size: 10.5px; color: var(--muted); text-align: left; white-space: nowrap; line-height: 14px; }
.heat .rl { font-size: 11.5px; font-weight: 600; color: var(--muted); line-height: 1; align-self: center; }
.heat .cell { aspect-ratio: 1; min-height: 10px; border-radius: 3px; background: var(--grid); }
.heat .cell:hover { outline: 2px solid var(--ink); outline-offset: -1px; }
.heat-scale { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 11.5px; color: var(--muted); }
.heat-scale i { width: 90px; height: 8px; border-radius: 4px; }

.status-badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 6px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-badge svg { width: 12px; height: 12px; flex: none; }
.st-good { background: var(--up-bg); color: var(--up-ink); }
.st-warn { background: var(--warn-bg); color: var(--warn-ink); }
.st-bad { background: var(--down-bg); color: var(--down-ink); }
.st-off { background: var(--flat-bg); color: var(--flat-ink); }
.data-table tr.muted td { color: var(--muted); }
.table-note { margin-top: 10px; font-size: 12px; color: var(--muted); }

.foot .health-item { display: inline-flex; align-items: center; gap: 7px; }
.foot .health-item b { color: var(--ink-2); font-weight: 600; }

@media (max-width: 1000px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .audience { grid-template-columns: minmax(0, 1fr); }
  .heat { grid-template-columns: 28px repeat(24, minmax(0, 1fr)); gap: 1px; }
  .heat .hd { font-size: 9px; }
}
@media (max-width: 600px) {
  .mini-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 22px; }
}

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .topbar-inner { padding: 10px 16px; }
  .logo { height: 24px; }
  .updated { display: none; }
  .page { padding: 20px 16px 40px; }
  h1 { font-size: 26px; }
  .group-head .group-note { display: none; }
  .card { padding: 16px; }
  .btn-label { display: none; }
  .seg { width: 100%; }
  .seg button { flex: 1; }
}
