/* ==========================================================================
   Flower Paper — HKEX CCASS shareholding explorer
   Self-hosted, no CDN. Light + dark, both deliberately stepped.
   ========================================================================== */

:root {
  color-scheme: light;

  /* surfaces & ink */
  --page:            #f4f4f1;
  --surface-1:       #ffffff;
  --surface-2:       #faf9f6;
  --surface-sunken:  #f0efec;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --hairline:        rgba(11, 11, 11, 0.10);
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;

  /* categorical slots — fixed order, never cycled */
  --series-1: #2a78d6;  /* Mainland (A)  */
  --series-2: #eb6834;  /* Broker (B)    */
  --series-3: #1baf7a;  /* Custodian (C) */
  --series-4: #eda100;  /* Other         */
  --series-n: #898781;  /* Not in CCASS — deliberately neutral, it is a residual */

  /* sequential blue ramp (concentration meters) */
  --seq-250: #86b6ef;
  --seq-400: #3987e5;
  --seq-550: #1c5cab;

  /* status */
  --good:     #0ca30c;
  --critical: #d03b3b;
  --good-ink: #006300;

  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --focus-ring:  #2a78d6;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(11, 11, 11, 0.05), 0 1px 3px rgba(11, 11, 11, 0.04);
  --shadow-2: 0 2px 4px rgba(11, 11, 11, 0.05), 0 8px 24px rgba(11, 11, 11, 0.07);

  --sans: system-ui, -apple-system, "Segoe UI", "PingFang HK", "Microsoft JhengHei",
          "Noto Sans CJK HK", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --page:            #0d0d0d;
    --surface-1:       #1a1a19;
    --surface-2:       #202020;
    --surface-sunken:  #141413;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --hairline:        rgba(255, 255, 255, 0.10);
    --gridline:        #2c2c2a;
    --baseline:        #383835;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-n: #898781;

    --seq-250: #184f95;
    --seq-400: #3987e5;
    --seq-550: #86b6ef;

    --good-ink: #0ca30c;

    --accent:     #3987e5;
    --accent-ink: #08131f;
    --focus-ring: #86b6ef;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --page:            #0d0d0d;
  --surface-1:       #1a1a19;
  --surface-2:       #202020;
  --surface-sunken:  #141413;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --hairline:        rgba(255, 255, 255, 0.10);
  --gridline:        #2c2c2a;
  --baseline:        #383835;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-n: #898781;

  --seq-250: #184f95;
  --seq-400: #3987e5;
  --seq-550: #86b6ef;

  --good-ink: #0ca30c;

  --accent:     #3987e5;
  --accent-ink: #08131f;
  --focus-ring: #86b6ef;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* --- base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--page);
  overflow-x: hidden;
}

h1, h2, h3, p, figure { margin: 0; }

a { color: var(--accent); }

:where(button, input, select, a):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 72px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- masthead ------------------------------------------------------------ */

.masthead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--hairline);
}

.masthead__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
}
.brand__mark svg { width: 18px; height: 18px; display: block; }

.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.brand__sub {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.masthead__spacer { flex: 1 1 auto; }

.icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: 9px;
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.icon-btn svg { width: 17px; height: 17px; display: block; }

:root:not([data-theme="dark"]) .icon-btn__moon { display: none; }
:root[data-theme="dark"] .icon-btn__sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .icon-btn__sun { display: none; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .icon-btn__moon { display: block; }
}

/* --- search panel -------------------------------------------------------- */

.hero { padding: 40px 0 20px; }

.hero__title {
  font-size: clamp(24px, 4.4vw, 34px);
  font-weight: 680;
  letter-spacing: -0.025em;
  line-height: 1.15;
}
.hero__lede {
  margin-top: 8px;
  max-width: 62ch;
  color: var(--text-secondary);
  font-size: 15px;
}

.panel {
  margin-top: 22px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 18px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--symbol { flex: 1 1 240px; }
.field--date   { flex: 0 1 168px; }

.field__label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.field__opt { font-weight: 500; text-transform: none; letter-spacing: 0; opacity: 0.8; }

.input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input::placeholder { color: var(--text-muted); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.input--symbol {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.06em;
}
input[type="date"].input { font-variant-numeric: tabular-nums; }
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.8); }

.btn {
  height: 44px;
  padding: 0 20px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: filter 120ms ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn__spinner {
  width: 15px; height: 15px;
  border: 2px solid color-mix(in srgb, var(--accent-ink) 35%, transparent);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn__spinner { animation-duration: 2s; } }

.hint {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.chip {
  font: inherit;
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 3px 9px;
  color: var(--text-secondary);
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { color: var(--text-primary); border-color: var(--baseline); }

.alert {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  display: flex;
  gap: 9px;
  align-items: flex-start;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--critical) 12%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--critical) 45%, transparent);
}
.alert[hidden] { display: none; }
.alert svg { flex: none; width: 17px; height: 17px; margin-top: 1px; color: var(--critical); }

/* --- results ------------------------------------------------------------- */

.results[hidden] { display: none; }

.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin: 34px 0 4px;
}
.result-head__sym {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.result-head__name { font-size: 19px; font-weight: 600; color: var(--text-secondary); }
.result-head__meta { margin-left: auto; font-size: 13px; color: var(--text-muted); }

.section { margin-top: 26px; }

.section__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin-bottom: 12px;
}

.input--filter {
  margin-left: auto;
  height: 34px;
  width: min(280px, 100%);
  font-size: 13.5px;
  border-radius: var(--radius-sm);
}
.section__title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.section__note { font-size: 12.5px; color: var(--text-muted); }

/* stat tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 14px 15px;
  box-shadow: var(--shadow-1);
}
.tile__label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.tile__value {
  margin-top: 5px;
  font-size: 25px;
  font-weight: 660;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.tile__sub { margin-top: 2px; font-size: 12.5px; color: var(--text-secondary); }

/* concentration meters */
.meters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px 22px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 18px;
}
.meter__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}
.meter__label { font-size: 13px; color: var(--text-secondary); }
.meter__value {
  font-size: 17px;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
}
.meter__track {
  height: 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--seq-400);
  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.meter__fill--hot { background: var(--seq-550); }
.meter__foot { margin-top: 6px; font-size: 12px; color: var(--text-muted); }

/* composition bar */
.composition {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 18px;
}
.stack {
  display: flex;
  width: 100%;
  height: 34px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-sunken);
}
.stack__seg {
  position: relative;
  min-width: 2px;
  /* 2px surface gap between adjacent fills */
  box-shadow: 2px 0 0 0 var(--surface-1);
  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.stack__seg:last-child { box-shadow: none; }
.stack__seg:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -3px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin-top: 14px;
}
.legend__item {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: 13px;
  color: var(--text-secondary);
}
.legend__swatch {
  flex: none;
  width: 10px; height: 10px;
  border-radius: 3px;
  transform: translateY(1px);
}
.legend__pct {
  font-variant-numeric: tabular-nums;
  font-weight: 620;
  color: var(--text-primary);
}

/* --- tooltip ------------------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  padding: 8px 11px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--baseline);
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  max-width: 260px;
  opacity: 0;
  transition: opacity 90ms ease;
}
.tooltip[data-show="1"] { opacity: 1; }
.tooltip__title { font-weight: 650; display: flex; align-items: center; gap: 6px; }
.tooltip__row { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* --- data tables --------------------------------------------------------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* The participant list runs to hundreds of rows — keep it in its own scroller
   so it never buries the rest of the page. */
.table-scroll--tall {
  max-height: 60vh;
  min-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.fp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.fp-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 9px 14px;
  border-bottom: 1px solid var(--gridline);
}
.fp-table tbody th {
  text-align: left;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 8px 14px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
.fp-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--gridline);
  color: var(--text-primary);
}
.fp-table td.num, .fp-table th.num { text-align: right; }
.fp-table tbody tr:last-child td,
.fp-table tbody tr:last-child th { border-bottom: 0; }
.fp-table tbody tr:hover td,
.fp-table tbody tr:hover th { background: var(--surface-2); }
.fp-table .pos { color: var(--good-ink); }
.fp-table .neg { color: var(--critical); }
.fp-table .swatch {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 2px;
  margin-right: 8px;
  transform: translateY(0);
}

.empty {
  padding: 22px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* --- skeleton ------------------------------------------------------------ */

.skeleton[hidden] { display: none; }
.skeleton { display: grid; gap: 12px; margin-top: 34px; }
.skeleton__row {
  height: 78px;
  border-radius: var(--radius);
  background: linear-gradient(90deg,
      var(--surface-1) 0%,
      var(--surface-2) 40%,
      var(--surface-1) 80%);
  background-size: 300% 100%;
  border: 1px solid var(--hairline);
  animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton__row:nth-child(2) { height: 132px; }
.skeleton__row:nth-child(3) { height: 200px; }
@keyframes shimmer {
  0%   { background-position: 120% 0; }
  100% { background-position: -20% 0; }
}
@media (prefers-reduced-motion: reduce) { .skeleton__row { animation: none; } }

/* --- footer -------------------------------------------------------------- */

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

/* --- 404 ----------------------------------------------------------------- */

.notfound {
  min-height: 62vh;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
}
.notfound__code {
  font-family: var(--mono);
  font-size: 56px;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
}

@media (max-width: 620px) {
  .shell { padding: 0 14px 56px; }
  .field--date { flex: 1 1 140px; }
  .btn { flex: 1 1 100%; justify-content: center; }
  .result-head__meta { margin-left: 0; width: 100%; }
}
