/* Ranking — owner: ui-lab. Virtualized grid; rows are absolutely positioned and moved by transform. */

.rk-root {
  --rk-row-h: 46px;
  --rk-seg-compression: #6c8cff;
  --rk-seg-breakout: var(--up, #ff4d5e);
  --rk-seg-alignment: #c77dff;
  --rk-seg-volume: #f5b544;
  --rk-seg-probability: #43c6d9;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  color: var(--text, #e7edf8);
  font-size: var(--fs-sm, 12.5px);
}

/* ---------- toolbar */
.rk-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, rgba(150, 172, 230, 0.11));
}
.rk-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 1 260px;
  min-width: 180px;
}
.rk-search-icon {
  position: absolute;
  left: 10px;
  width: 11px;
  height: 11px;
  border: 1.6px solid var(--muted, #8190ac);
  border-radius: 50%;
  pointer-events: none;
}
.rk-search-icon::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 5px;
  height: 1.6px;
  background: var(--muted, #8190ac);
  transform: rotate(45deg);
}
.rk-search {
  font: inherit;
  width: 100%;
  height: 30px;
  padding: 0 30px 0 28px;
  border-radius: var(--r-md, 9px);
  border: 1px solid var(--border, rgba(150, 172, 230, 0.11));
  background: var(--panel-2, rgba(22, 32, 58, 0.72));
  color: var(--text);
  outline: none;
  transition: border-color var(--dur-1, 120ms), box-shadow var(--dur-1, 120ms);
}
.rk-search::placeholder { color: var(--faint, #56627c); }
.rk-search:focus { border-color: var(--accent, #6c8cff); box-shadow: 0 0 0 3px var(--accent-soft, rgba(108, 140, 255, 0.16)); }
.rk-search::-webkit-search-cancel-button { display: none; }
.rk-search-wrap kbd { position: absolute; right: 7px; pointer-events: none; }
.rk-search:focus + kbd,
.rk-search:not(:placeholder-shown) + kbd { display: none; }

.rk-quick { display: flex; flex-wrap: wrap; gap: 5px; }
.rk-chip,
.rk-lasso {
  font: inherit;
  font-size: var(--fs-xs, 11.5px);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--r-pill, 999px);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2, #b9c4da);
  cursor: pointer;
  transition: background var(--dur-1), color var(--dur-1), border-color var(--dur-1), opacity var(--dur-1);
}
.rk-chip b {
  font-weight: 500;
  font-family: var(--font-mono, ui-monospace);
  font-size: var(--fs-2xs, 10.5px);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.rk-chip:hover { border-color: var(--border-strong); color: var(--text); }
.rk-chip.on {
  background: var(--accent-soft, rgba(108, 140, 255, 0.16));
  border-color: var(--accent, #6c8cff);
  color: var(--accent-strong, #8aa4ff);
}
.rk-chip.on b { color: var(--accent-strong); }
.rk-chip.zero:not(.on) { opacity: 0.45; }
.rk-chip:focus-visible,
.rk-lasso:focus-visible,
.rk-sort:focus-visible,
.rk-btn:focus-visible,
.rk-star:focus-visible { outline: none; box-shadow: var(--ring); }
.rk-lasso {
  color: var(--warn, #f5b544);
  border-color: color-mix(in srgb, var(--warn, #f5b544) 50%, transparent);
  background: var(--warn-soft);
}
.rk-order {
  margin-left: auto;
  border: 1px solid var(--border, rgba(150, 172, 230, 0.16));
  background: color-mix(in srgb, var(--text) 3%, transparent);
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-xs);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.rk-order:hover { color: var(--text); }
.rk-order.on { color: var(--accent-strong, #8aa4ff); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.rk-order:focus-visible { outline: none; box-shadow: var(--ring); }
.rk-counter {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- grid */
.rk-scroller {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  outline: none;
  overscroll-behavior: contain;
  contain: strict;
}
.rk-head,
.rk-row {
  display: grid;
  grid-template-columns: var(--rk-cols);
  align-items: center;
  column-gap: 10px;
  padding: 0 14px;
  min-width: var(--rk-minw, 1380px);
  box-sizing: border-box;
}
.rk-head {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 34px;
  background: var(--panel-solid, #0d1427);
  border-bottom: 1px solid var(--border-strong);
  font-size: var(--fs-2xs, 10.5px);
  color: var(--muted);
  letter-spacing: 0.06em;
}
.rk-hcell { white-space: nowrap; overflow: hidden; }
.rk-hcell.num { text-align: right; }
.rk-sort {
  font: inherit;
  letter-spacing: inherit;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 4px;
  margin: 0 -4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.rk-hcell.num .rk-sort { flex-direction: row-reverse; }
.rk-sort:hover { color: var(--text); background: var(--panel-hover); }
.rk-hcell.sorted { color: var(--accent-strong, #8aa4ff); }
.rk-sort-ind { font-style: normal; font-size: 8px; }

.rk-body { position: relative; min-width: var(--rk-minw, 1380px); }
.rk-row {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: var(--rk-row-h);
  box-sizing: border-box;
  border-bottom: 1px solid var(--grid, rgba(150, 172, 230, 0.075));
  cursor: pointer;
  will-change: transform;
  transition:
    transform 420ms var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)),
    opacity 300ms var(--ease-out),
    background var(--dur-1, 120ms);
  contain: layout style;
}
.rk-row.odd { background: color-mix(in srgb, var(--text) 1.6%, transparent); }
.rk-row:hover { background: var(--panel-hover, rgba(34, 48, 84, 0.55)); }
.rk-row.moving { z-index: 1; }
.rk-divider {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  box-sizing: border-box;
  font-size: var(--fs-xs, 12px);
  color: var(--muted);
  background: color-mix(in srgb, var(--accent) 5%, var(--panel-solid, #0d1427));
  border-top: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-bottom: 1px solid var(--grid, rgba(150, 172, 230, 0.075));
  white-space: nowrap;
  overflow: hidden;
  z-index: 2;
  transition: transform 420ms var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}
.rk-divider b { color: var(--text); font-weight: 650; }
.rk-divider[data-group="passed"] b { color: var(--up); }
.rk-divider[data-group="early"] b { color: var(--warn); }
.rk-divider span { overflow: hidden; text-overflow: ellipsis; }
.rk-row.cursor { box-shadow: inset 2px 0 0 var(--accent, #6c8cff); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.rk-row.selected {
  background: var(--accent-soft, rgba(108, 140, 255, 0.16));
  box-shadow: inset 3px 0 0 var(--accent), 0 0 24px -12px var(--accent-glow);
}
.rk-cell { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.rk-cell.num { text-align: right; font-family: var(--font-mono, ui-monospace); font-size: var(--fs-xs, 11.5px); }

/* rank */
.c-rank { display: flex; align-items: baseline; gap: 5px; }
.rk-rank {
  font-family: var(--font-mono);
  font-size: var(--fs-md, 13.5px);
  font-weight: 600;
  min-width: 26px;
  text-align: right;
}
.rk-row.passed .rk-rank { color: var(--up); }
.rk-row.early .rk-rank { color: var(--warn); }
.rk-delta { font-family: var(--font-mono); font-size: 9.5px; }
.rk-delta.up { color: var(--up); }
.rk-delta.down { color: var(--down); }
.rk-delta.new {
  color: var(--accent-strong);
  padding: 0 4px;
  border-radius: 3px;
  background: var(--accent-soft);
}

/* star */
.rk-star {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--faint, #56627c);
  font-size: 14px;
  cursor: pointer;
  transition: color var(--dur-1), transform var(--dur-2) var(--ease-spring);
}
.rk-star:hover { color: var(--warn); transform: scale(1.2); }
.rk-star.on { color: var(--warn, #f5b544); text-shadow: 0 0 8px var(--warn); }

/* name */
.c-name { display: flex; flex-direction: column; justify-content: center; gap: 1px; }
.rk-name-top { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.rk-code { font-family: var(--font-mono); font-weight: 600; color: var(--text); }
.rk-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.rk-name-sub { display: flex; align-items: center; gap: 5px; font-size: var(--fs-2xs, 10.5px); color: var(--faint); min-width: 0; }
.rk-ind { overflow: hidden; text-overflow: ellipsis; }
.rk-mk {
  font-size: 9px;
  padding: 0 3px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  line-height: 13px;
}
.rk-mk.otc { color: #43c6d9; border-color: color-mix(in srgb, #43c6d9 40%, transparent); }

/* spark */
.c-spark { display: flex; align-items: center; }
.rk-spark { width: 84px; height: 28px; display: block; }

/* close */
.c-close { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.rk-close { font-size: var(--fs-sm); color: var(--text); }
.rk-chg { font-size: var(--fs-2xs); }

/* composite */
.c-composite { display: flex; align-items: center; gap: 8px; }
.rk-comp-num {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--fs-sm);
  min-width: 34px;
  text-align: right;
}
.rk-comp-bar {
  flex: 1;
  display: flex;
  height: 8px;
  min-width: 60px;
  border-radius: 4px;
  overflow: hidden;
  background: color-mix(in srgb, var(--text) 8%, transparent);
}
.rk-comp-bar .rk-seg { display: block; height: 100%; transition: width 420ms var(--ease-out); }
.rk-comp-bar .rk-seg + .rk-seg { box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.35); }
.rk-comp-bar .rk-seg[style*="width: 0%"] { box-shadow: none; }
.s-compression { background: var(--rk-seg-compression); }
.s-breakout { background: var(--rk-seg-breakout); }
.s-alignment { background: var(--rk-seg-alignment); }
.s-volume { background: var(--rk-seg-volume); }
.s-probability { background: var(--rk-seg-probability); }

/* prob gauge */
.c-prob { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.rk-gauge {
  --p: 0;
  --c: var(--flat);
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 360deg), color-mix(in srgb, var(--text) 10%, transparent) 0);
  flex-shrink: 0;
}
/* ring via mask so the centre always shows the row's own background (hover / selected / odd) */
.rk-gauge {
  -webkit-mask: radial-gradient(circle at center, transparent 5.5px, #000 6px);
  mask: radial-gradient(circle at center, transparent 5.5px, #000 6px);
}
.rk-gauge.up { --c: var(--up); }
.rk-gauge.down { --c: var(--down); }
.rk-prob { font-family: var(--font-mono); font-size: var(--fs-xs); min-width: 30px; text-align: right; }
.rk-prob-stack { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.rk-prob-sub { font-size: var(--fs-2xs, 11.5px); color: var(--muted); font-family: var(--font-sans); white-space: nowrap; }
.rk-prob-sub:empty { display: none; }
.c-prob.training .rk-gauge { display: none; }
.c-prob.training .rk-prob {
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  color: transparent;
  background: linear-gradient(90deg, var(--muted) 0%, var(--text) 50%, var(--muted) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: rk-shimmer 1.4s linear infinite;
}
@keyframes rk-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* fwd (time machine reveal) */
.rk-fwd { font-weight: 600; }

/* chips */
.c-chips { display: flex; gap: 4px; align-items: center; overflow: hidden; }
.rk-tag {
  flex-shrink: 0;
  font-size: 11.5px;
  padding: 1px 6px;
  border-radius: 4px;
  line-height: 16px;
  border: 1px solid transparent;
}
.rk-tag.t-hot { color: #fff; background: var(--up); box-shadow: 0 0 10px -3px var(--up); }
.rk-tag.t-warm { color: var(--warn); background: var(--warn-soft); }
.rk-tag.t-up { color: var(--up); background: var(--up-soft); }
.rk-tag.t-down { color: var(--down); background: var(--down-soft); }
.rk-tag.t-alert { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.rk-tag.t-flat { color: var(--muted); background: color-mix(in srgb, var(--muted) 10%, transparent); }

.c-vr .hi { color: var(--warn); font-weight: 600; }
.c-tv { color: var(--text-2); font-variant-numeric: tabular-nums; }
.c-tv .hi { color: var(--text); font-weight: 600; }
.c-spread .tight { color: var(--accent-strong); }
.c-risk { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; font-size: var(--fs-2xs); }
.rk-stop { color: var(--down); }
.rk-tgt { color: var(--up); }

.rk-root .up { color: var(--up); }
.rk-root .down { color: var(--down); }
.rk-root .flat { color: var(--flat); }

/* value flash */
.rk-cell.flash-up { animation: rk-flash-up 900ms var(--ease-out); }
.rk-cell.flash-down { animation: rk-flash-down 900ms var(--ease-out); }
@keyframes rk-flash-up {
  0% { background: color-mix(in srgb, var(--up) 38%, transparent); }
  100% { background: transparent; }
}
@keyframes rk-flash-down {
  0% { background: color-mix(in srgb, var(--down) 38%, transparent); }
  100% { background: transparent; }
}

/* ---------- empty / loading */
.rk-empty {
  position: absolute;
  left: 0;
  right: 0;
  top: 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 20px;
  text-align: center;
  color: var(--text-2);
}
.rk-empty[hidden] { display: none; }
.rk-empty-icon {
  font-size: 34px;
  line-height: 1;
  color: var(--faint);
  font-family: var(--font-mono);
}
.rk-empty strong { font-size: var(--fs-lg); color: var(--text); }
.rk-empty p { margin: 0; max-width: 460px; color: var(--muted); }
.rk-empty-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.rk-btn {
  font: inherit;
  font-size: var(--fs-xs);
  height: 28px;
  padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent, #050814);
  cursor: pointer;
  font-weight: 600;
}
.rk-btn.ghost { background: transparent; color: var(--text-2); border-color: var(--border-strong); font-weight: 400; }
.rk-trail {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--fs-2xs);
  color: var(--muted);
}
.rk-trail li {
  display: inline-flex;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
}
.rk-trail li + li::before { content: "→"; color: var(--faint); margin-right: 2px; }
.rk-trail li b { font-family: var(--font-mono); color: var(--text-2); }
.rk-trail li.culprit { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.rk-trail li.culprit b { color: var(--warn); }
.rk-empty.loading { gap: 0; padding: 0 14px; align-items: stretch; }
.rk-skel {
  height: var(--rk-row-h);
  border-bottom: 1px solid var(--grid);
  background: linear-gradient(90deg, transparent 0%, color-mix(in srgb, var(--text) 5%, transparent) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: rk-shimmer 1.3s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .rk-row, .rk-divider { transition: none; }
  .rk-cell.flash-up,
  .rk-cell.flash-down,
  .c-prob.training .rk-prob,
  .rk-skel { animation: none; }
}

@media (max-width: 640px) {
  .rk-toolbar { padding: 8px 10px; gap: 6px; }
  .rk-search-wrap { flex: 1 1 100%; }
  .rk-quick { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -10px; padding: 0 10px; }
  .rk-quick::-webkit-scrollbar { display: none; }
  .rk-chip { flex-shrink: 0; }
  .rk-head, .rk-row { padding: 0 10px; column-gap: 8px; }
}
@media (max-width: 640px) {
  .rk-comp-bar { min-width: 30px; }
  .rk-comp-num { min-width: 26px; font-size: var(--fs-xs); }
  .c-prob .rk-gauge { display: none; }
  .rk-prob-sub { display: none; }
  .rk-rank { min-width: 18px; }
  .rk-order { margin-left: 0; font-size: var(--fs-2xs, 11.5px); padding: 3px 8px; }
  .rk-divider span { display: none; }
  .rk-divider { padding: 0 10px; }
}

/* Extended breakout: score 0 by design — show a small "已延伸" tag inside the empty bar (integrator). */
.rk-extended .rk-comp-bar { position: relative; overflow: visible; height: 16px; background: none; border: 1px dashed color-mix(in srgb, var(--text) 18%, transparent); box-sizing: border-box; }
.rk-extended .rk-comp-bar::after {
  content: "已延伸";
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
  font-size: 11px; line-height: 1; letter-spacing: 0.04em; color: var(--muted, #8b93a7);
  white-space: nowrap; pointer-events: none;
}

/* security type chips / badges (ETF, ETN, 特別股, REITs, TDR) + leveraged / inverse flag */
.rk-types { padding-left: 8px; border-left: 1px solid var(--border, rgba(150, 172, 230, 0.11)); }
.rk-chip[hidden], .rk-ty[hidden], .rk-lev[hidden] { display: none; }
.rk-ty,
.rk-lev {
  font-size: 9px;
  padding: 0 3px;
  border-radius: 3px;
  line-height: 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent-strong);
  white-space: nowrap;
}
.rk-ty.t-etn { color: #c99bff; border-color: color-mix(in srgb, #c99bff 45%, transparent); }
.rk-ty.t-preferred { color: #e0b252; border-color: color-mix(in srgb, #e0b252 45%, transparent); }
.rk-ty.t-reit { color: #5cc8a8; border-color: color-mix(in srgb, #5cc8a8 45%, transparent); }
.rk-ty.t-tdr { color: #9aa7c7; border-color: color-mix(in srgb, #9aa7c7 45%, transparent); }
.rk-lev { color: var(--warn, #f0a03c); border-color: color-mix(in srgb, var(--warn, #f0a03c) 50%, transparent); font-weight: 600; cursor: help; }
.rk-short { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; text-align: left; font-size: var(--fs-xs, 12px); color: var(--text-2); }
.rk-short li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
@media (max-width: 900px) {
  .rk-types { border-left: 0; padding-left: 10px; }
}
