:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --good-text: #006300;
  --bad-text: #b42323;

  --s1: #2a78d6;          /* categorical slot 1 */
  --s2: #eb6834;          /* categorical slot 2 */
  --s3: #1baf7a;          /* categorical slot 3 */
  --part-a: #6250d6;      /* part-to-whole: Malaysian */
  --part-b: #eda100;      /* part-to-whole: foreign */
  --s-bench: #898781;     /* benchmark = de-emphasised neutral */
  --up: #1baf7a;
  --down: #e34948;
  --mid: #f0efec;         /* diverging neutral midpoint */
  --overlay-1: #52514e;   /* SMA 50 */
  --overlay-2: #6250d6;   /* SMA 200 */
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --good-text: #0ca30c;
    --bad-text: #e66767;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --part-a: #9085e9;
    --part-b: #c98500;
    --up: #199e70;
    --down: #e66767;
    --mid: #383835;
    --overlay-1: #c3c2b7;
    --overlay-2: #9085e9;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.05);
  --good-text: #0ca30c;
  --bad-text: #e66767;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --part-a: #9085e9;
  --part-b: #c98500;
  --up: #199e70;
  --down: #e66767;
  --mid: #383835;
  --overlay-1: #c3c2b7;
  --overlay-2: #9085e9;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }

header.top {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
header.top h1 { font-size: 24px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
header.top p { margin: 4px 0 0; color: var(--text-secondary); }
.updated { color: var(--text-muted); font-size: 12px; }

button { font: inherit; color: inherit; }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  position: sticky; top: 0; z-index: 5;
  background: var(--page); padding: 10px 0; margin-bottom: 8px;
}
.seg {
  display: inline-flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 2px; overflow-x: auto; max-width: 100%;
}
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 6px;
  cursor: pointer; color: var(--text-secondary); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button:hover { background: var(--wash); }
.seg button[aria-pressed="true"] {
  background: var(--text-primary); color: var(--surface); font-weight: 600;
}
.seg button .key { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.theme-btn {
  margin-left: auto; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; color: var(--text-secondary);
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.tile .label { color: var(--text-secondary); font-size: 12px; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.tile .value.hero { font-size: 48px; line-height: 1.05; letter-spacing: -0.02em; }
.tile .delta { font-size: 12px; margin-top: 2px; color: var(--text-secondary); }
.tile .delta.up { color: var(--good-text); }
.tile .delta.down { color: var(--bad-text); }
.tile.hero-tile { grid-column: span 2; }
@media (max-width: 520px) { .tile.hero-tile { grid-column: span 1; } .tile .value.hero { font-size: 40px; } }

.meter { position: relative; height: 8px; border-radius: 4px; background: var(--grid); margin: 10px 0 4px; }
.meter .pin { position: absolute; top: -3px; width: 4px; height: 14px; border-radius: 2px; background: var(--text-primary); transform: translateX(-2px); }
.meter-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } }

section.section-head { grid-column: 1 / -1; margin: 18px 0 -4px; }
section.section-head h2 { font-size: 16px; font-weight: 650; margin: 0; }
section.section-head p { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 16px 12px; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card h3 { font-size: 14px; font-weight: 600; margin: 0; }
.card .sub { color: var(--text-secondary); font-size: 12px; margin: 2px 0 0; }
.card .table-toggle {
  border: 1px solid var(--border); background: transparent; border-radius: 6px;
  padding: 3px 8px; font-size: 12px; color: var(--text-secondary); cursor: pointer; flex-shrink: 0;
}
.card .table-toggle:hover { background: var(--wash); }
.card .body { margin-top: 10px; position: relative; }
.card .body.loading { opacity: 0.5; }
.card .note { color: var(--text-muted); font-size: 11px; margin-top: 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; }
.legend i.line { width: 14px; height: 2px; border-radius: 1px; }
.legend i.rect { width: 10px; height: 10px; border-radius: 2px; }
.legend i.hollow { width: 10px; height: 10px; border-radius: 2px; border: 2px solid; background: transparent; }

svg.chart { display: block; width: 100%; overflow: visible; touch-action: pan-y; }
svg.chart text { font-family: var(--sans); font-size: 11px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
svg.chart text.end-label { fill: var(--text-secondary); font-size: 12px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  padding: 8px 10px; font-size: 12px; min-width: 140px; display: none;
}
.tooltip .t-title { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .t-row .k { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip .t-row .k i { width: 12px; height: 2px; border-radius: 1px; display: inline-block; }
.tooltip .t-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }

table.data { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 5px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
.table-scroll { max-height: 360px; overflow: auto; }

/* heatmap */
.heat { overflow-x: auto; }
.heat table { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: 11px; font-variant-numeric: tabular-nums; }
.heat th { color: var(--text-muted); font-weight: 500; padding: 2px 4px; }
.heat td { text-align: center; padding: 6px 2px; border-radius: 4px; min-width: 38px; cursor: default; }
.heat td.empty { background: transparent; }
.heat td.total { font-weight: 600; }

/* bar lists (shareholders) */
.hbars { display: grid; gap: 8px; }
.hbar-row { display: grid; grid-template-columns: minmax(0, 40%) 1fr; gap: 10px; align-items: center; font-size: 12px; }
.hbar-row .name { color: var(--text-secondary); overflow-wrap: anywhere; }
.hbar-track { display: flex; align-items: center; gap: 6px; }
.hbar { height: 14px; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-val { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.segbar { display: flex; gap: 2px; height: 28px; margin-top: 6px; }
.segbar div { border-radius: 4px; color: #fff; font-size: 12px; font-weight: 600; display: flex; align-items: center; padding-left: 8px; overflow: hidden; white-space: nowrap; }
.sh-company + .sh-company { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--grid); }
.sh-company h4 { margin: 0 0 8px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.sh-company h4 i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.empty-state { color: var(--text-muted); font-size: 13px; padding: 24px 0; text-align: center; }

footer { margin-top: 32px; color: var(--text-muted); font-size: 12px; }
footer a { color: var(--text-secondary); }
