/*
 * M3-F Overnight Theme
 * Theme IDs only: dark-default | light  (sf-theme / SfThemeManager)
 * A Structure → themeable surfaces
 * B Business → inflow/outflow/signal frozen
 * C Product Personality → amber/gold/warm night (NOT a second theme system)
 */

:root {
  color-scheme: dark;
  /* C — Product Personality (warm overnight identity) */
  --overnight-accent: #ff8a24;
  --overnight-accent-2: #ffb25d;
  --overnight-glow: rgba(255, 126, 24, 0.18);
  --overnight-warm-line: rgba(255, 148, 55, 0.17);
  --overnight-medal-1-a: #ffd789;
  --overnight-medal-1-b: #f89b29;
  --overnight-medal-2-a: #eee6df;
  --overnight-medal-2-b: #a99c91;
  --overnight-medal-3-a: #e4a578;
  --overnight-medal-3-b: #9c5433;
  --overnight-brand-ink: #160a00;

  /* A — Theme Structure (Dark = production warm-dark baseline) */
  --bg: #080706;
  --bg-soft: #100e0c;
  --panel: #15120f;
  --panel-2: #1b1713;
  --line: var(--overnight-warm-line);
  --line-soft: rgba(255, 255, 255, 0.07);
  --orange: var(--overnight-accent);
  --orange-2: var(--overnight-accent-2);
  --orange-glow: var(--overnight-glow);
  --text: #f6efe8;
  --muted: #9c8f83;
  --surface-topbar: rgba(8, 7, 6, 0.88);
  --surface-tab: rgba(21, 18, 15, 0.8);
  --surface-tab-active: linear-gradient(180deg, rgba(255, 126, 24, .16), rgba(255, 126, 24, .055));
  --surface-avail: linear-gradient(145deg, rgba(28, 21, 16, .95), rgba(15, 13, 11, .96));
  --surface-metric: linear-gradient(150deg, rgba(29, 24, 20, .96), rgba(17, 14, 12, .96));
  --surface-rank-card: rgba(18, 15, 13, .88);
  --surface-rank-row: linear-gradient(145deg, #1a1613, #110f0d);
  --surface-subtab: #0d0b0a;
  --surface-medal: #0b0908;
  --surface-score-track: #282018;
  --surface-mobile-back: rgba(22, 14, 8, .92);
  --border-mobile-back: rgba(255, 148, 55, .32);
  --text-mobile-back: #f6efe8;
  --text-tab-title: #cbbcaf;
  --text-tab-icon: #836c59;
  --text-cell: #e6dad0;
  --text-cell-label: #74675d;
  --text-timeline: #c7b8aa;
  --text-footer: #62574f;
  --text-metric-dim: #6f6258;
  --text-head: #786b61;
  --hover-row: rgba(255, 126, 24, .045);

  /* B — Business Semantic FROZEN */
  --inflow: #ff5265;
  --outflow: #30c987;
  --watch: #d3b58f;
  --inflow-value: #ff7381;
  --signal-strong-fg: #ff7b88;
  --signal-strong-bg: rgba(255, 82, 101, .12);
  --signal-strong-bd: rgba(255, 82, 101, .26);

  --radius: 16px;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* Light = 暖色金融研究台（非冷白蓝页） */
html[data-theme="light"] {
  color-scheme: light;
  --overnight-accent: #e67a18;
  --overnight-accent-2: #c45f0a;
  --overnight-glow: rgba(230, 122, 24, 0.12);
  --overnight-warm-line: rgba(180, 110, 40, 0.22);
  /* Light：ink 保持深色可读；暖色按钮上的字单独用 cream */
  --overnight-brand-ink: #160a00;

  --bg: #f3eee8;
  --bg-soft: #ebe4db;
  --panel: #faf7f2;
  --panel-2: #f5f0e9;
  --line: var(--overnight-warm-line);
  --line-soft: rgba(80, 60, 40, 0.10);
  --orange: var(--overnight-accent);
  --orange-2: var(--overnight-accent-2);
  --orange-glow: var(--overnight-glow);
  --text: #2a241c;
  --muted: #62564a;
  --surface-topbar: rgba(250, 247, 242, 0.92);
  --surface-tab: rgba(255, 252, 248, 0.92);
  --surface-tab-active: linear-gradient(180deg, rgba(230, 122, 24, .14), rgba(230, 122, 24, .05));
  --surface-avail: linear-gradient(145deg, #faf6f0, #f3ebe2);
  --surface-metric: linear-gradient(150deg, #fbf8f3, #f4efe8);
  --surface-rank-card: #faf7f2;
  --surface-rank-row: linear-gradient(145deg, #fbf8f4, #f3eee6);
  --surface-subtab: #efe8df;
  --surface-medal: #ebe3d8;
  --surface-score-track: #e5dcd0;
  --surface-mobile-back: rgba(250, 247, 242, .94);
  --border-mobile-back: rgba(180, 110, 40, .28);
  --text-mobile-back: #2a241c;
  --text-tab-title: #4a4036;
  --text-tab-icon: #9a8068;
  --text-cell: #2a241c;
  --text-cell-label: #8a7c6e;
  --text-timeline: #6e6256;
  --text-footer: #8a7c6e;
  --text-metric-dim: #8a7c6e;
  --text-head: #8a7c6e;
  --hover-row: rgba(230, 122, 24, .06);

  /* B frozen — same hue */
  --inflow: #ff5265;
  --outflow: #30c987;
  --watch: #8a6d45;
  --inflow-value: #e04555;
  --signal-strong-fg: #c23b45;
  --signal-strong-bg: rgba(255, 82, 101, .10);
  --signal-strong-bd: rgba(255, 82, 101, .28);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(760px 420px at 96% -8%, var(--overnight-glow), transparent 62%),
    radial-gradient(500px 360px at -10% 22%, rgba(121, 53, 10, 0.13), transparent 68%),
    var(--bg);
}
html[data-theme="light"] body {
  background:
    radial-gradient(760px 420px at 96% -8%, rgba(230, 122, 24, 0.10), transparent 62%),
    radial-gradient(500px 360px at -10% 22%, rgba(180, 120, 70, 0.08), transparent 68%),
    var(--bg);
}
/* Desktop shell 主区：暖色人格覆盖壳层冷蓝渐变（非第二 Theme） */
body.has-desktop-shell:has([data-testid="overnight-root"]) {
  background:
    radial-gradient(760px 420px at 96% -8%, var(--overnight-glow), transparent 62%),
    radial-gradient(500px 360px at -10% 22%, rgba(121, 53, 10, 0.13), transparent 68%),
    var(--bg) !important;
  color: var(--text) !important;
}
html[data-theme="light"] body.has-desktop-shell:has([data-testid="overnight-root"]) {
  background:
    radial-gradient(760px 420px at 96% -8%, rgba(230, 122, 24, 0.10), transparent 62%),
    radial-gradient(500px 360px at -10% 22%, rgba(180, 120, 70, 0.08), transparent 68%),
    var(--bg) !important;
}
body.has-desktop-shell .page-shell,
body.has-desktop-shell .desktop-main:has([data-testid="overnight-root"]) {
  color: var(--text);
}
body.has-desktop-shell .desktop-main:has([data-testid="overnight-root"]) {
  background: transparent !important;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.v2-mobile-back {
  display: none;
  position: fixed;
  left: 12px;
  top: calc(10px + env(safe-area-inset-top));
  z-index: 90;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-mobile-back);
  border-radius: 999px;
  color: var(--text-mobile-back);
  background: var(--surface-mobile-back);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  backdrop-filter: blur(10px);
}

.page-shell { width: min(100%, 1460px); margin: 0 auto; padding: 0 12px 28px; }
.topbar {
  min-height: 56px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; z-index: 20;
  background: var(--surface-topbar); backdrop-filter: blur(16px);
}
.brand { display: inline-flex; gap: 9px; align-items: center; color: var(--text); text-decoration: none; font-weight: 750; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px;
  color: var(--overnight-brand-ink); font-weight: 900;
  background: linear-gradient(135deg, var(--orange-2), var(--orange));
  box-shadow: 0 0 24px var(--overnight-glow);
}
.topbar-meta { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 10px var(--orange); }

main { padding-top: 16px; }
.hero { display: grid; gap: 18px; padding: 6px 2px 18px; }
.eyebrow { margin: 0 0 6px; color: var(--orange); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.hero h1 { margin: 0; font-size: clamp(34px, 8vw, 64px); letter-spacing: -.055em; line-height: .98; color: var(--text); }
.hero-copy { margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.timeline { display: flex; align-items: center; gap: 8px; color: var(--text-timeline); font-size: 11px; white-space: nowrap; overflow-x: auto; padding-bottom: 2px; }
.timeline i { min-width: 24px; height: 1px; background: linear-gradient(90deg, var(--orange), transparent); position: relative; }
.timeline i::after { content: ""; position: absolute; right: 0; top: -2px; width: 5px; height: 5px; border-radius: 50%; background: var(--orange); }

.primary-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 14px; }
.primary-tab {
  min-width: 0; display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 12px 8px; border: 1px solid var(--line-soft); border-radius: 14px;
  color: var(--muted); background: var(--surface-tab); cursor: pointer;
}
.primary-tab span:last-child { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.primary-tab b { color: var(--text-tab-title); font-size: 14px; }
.primary-tab small { display: none; margin-top: 3px; color: var(--muted); font-size: 10px; }
.tab-icon { font-size: 20px; color: var(--text-tab-icon); }
.primary-tab.active {
  border-color: rgba(255, 138, 36, .55);
  background: var(--surface-tab-active);
  box-shadow: inset 0 1px 0 rgba(255, 195, 130, .12), 0 12px 30px rgba(0, 0, 0, .08);
}
html[data-theme="light"] .primary-tab.active {
  border-color: rgba(230, 122, 24, .45);
  box-shadow: inset 0 1px 0 rgba(255, 195, 130, .25), 0 8px 20px rgba(120, 70, 20, .08);
}
.primary-tab.active b, .primary-tab.active .tab-icon { color: var(--orange-2); }
.module-panel { display: none; }
.module-panel.active { display: block; animation: panel-in .2s ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateY(5px); } }

.availability-card {
  display: flex; align-items: center; gap: 14px; min-height: 148px; margin-bottom: 12px;
  padding: 22px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-avail);
}
.availability-card[hidden] { display: none; }
.availability-icon {
  display: grid; place-items: center; flex: 0 0 auto; width: 42px; height: 42px;
  border: 1px solid rgba(255, 138, 36, .35); border-radius: 14px;
  color: var(--orange-2); background: rgba(255, 138, 36, .1); font-weight: 900;
}
.availability-card p { margin: 0 0 5px; color: var(--orange-2); font-size: 11px; }
.availability-card h2 { margin: 0 0 7px; font-size: 20px; color: var(--text); }
.availability-card div > span { color: var(--muted); font-size: 12px; }
.availability-notes {
  display: grid; gap: 7px; margin: 10px 0 0; padding: 0;
  list-style: none; color: var(--muted); font-size: 12px; line-height: 1.55;
}
.availability-notes li { position: relative; padding-left: 14px; }
.availability-notes li::before {
  content: ""; position: absolute; left: 0; top: .68em;
  width: 5px; height: 5px; border-radius: 50%; background: var(--orange);
}

.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 12px; }
.metrics-grid[hidden], .ranking-card[hidden] { display: none; }
.metric-card {
  min-width: 0; padding: 13px; border: 1px solid var(--line-soft); border-radius: 14px;
  background: var(--surface-metric); position: relative; overflow: hidden;
}
.metric-card::after { content: ""; position: absolute; left: 0; bottom: 0; width: 48%; height: 2px; background: var(--orange); opacity: .75; }
.metric-card.tone-inflow::after { background: var(--inflow); }
.metric-card.tone-outflow::after { background: var(--outflow); }
.metric-label { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-value { margin-top: 8px; font-size: clamp(21px, 6vw, 30px); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.04em; color: var(--text); }
.tone-inflow .metric-value { color: var(--inflow-value); }
.tone-outflow .metric-value { color: var(--outflow); }
.tone-active .metric-value { color: var(--orange-2); }
.metric-value small { margin-left: 4px; font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.metric-change { display: flex; gap: 5px; margin-top: 8px; font-size: 10px; color: var(--orange-2); }
.metric-change span { color: var(--text-metric-dim); }

.ranking-card { border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface-rank-card); overflow: hidden; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 14px 11px; }
.section-head h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; color: var(--text); }
.mock-badge { padding: 4px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--orange); background: rgba(255, 126, 24, .08); font-size: 9px; font-weight: 900; letter-spacing: .14em; }
.update-chip { padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--orange-2); background: rgba(255, 126, 24, .07); font-size: 10px; font-weight: 750; white-space: nowrap; }
.subtabs { display: flex; gap: 5px; padding: 0 12px 12px; }
.subtab { flex: 1; border: 0; border-radius: 9px; padding: 9px 11px; color: var(--muted); background: var(--surface-subtab); cursor: pointer; font-size: 12px; }
.subtab.active { color: var(--overnight-brand-ink); font-weight: 800; background: linear-gradient(135deg, var(--orange-2), var(--orange)); }
/* Light：橙底上用奶油色字；面板上的 ink 仍走深色 brand-ink */
html[data-theme="light"] .subtab.active,
html[data-theme="light"] .brand-mark {
  color: #fff8f0;
}
html[data-theme="light"] .entity-link,
html[data-theme="light"] .entity-link strong {
  color: var(--text);
}
html[data-theme="light"] .entity-link:hover {
  color: var(--orange);
}
html[data-theme="light"] .eyebrow,
html[data-theme="light"] .cell-label,
html[data-theme="light"] .metric-dim {
  color: var(--muted);
  opacity: 1;
}
html[data-theme="light"] .rank-row,
html[data-theme="light"] .avail-card,
html[data-theme="light"] .metric-card {
  border-color: var(--line);
}
html[data-theme="light"] .subtab {
  color: var(--muted);
  background: var(--surface-subtab);
  border-color: var(--line-soft);
}
html[data-theme="light"] .subtab:hover {
  color: var(--text);
  border-color: var(--line);
}
.ranking-stage { padding: 0 10px 10px; }
.rank-scroll { overflow-x: auto; scrollbar-color: #4c3420 transparent; }
html[data-theme="light"] .rank-scroll { scrollbar-color: #c4a882 transparent; }
.ranking-table { display: grid; gap: 8px; }
.ranking-head { display: none; }
.ranking-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 8px; padding: 13px 12px;
  border: 1px solid var(--line-soft); border-radius: 13px; background: var(--surface-rank-row);
}
.ranking-row.is-top { border-color: rgba(255, 138, 36, .32); box-shadow: inset 3px 0 0 rgba(255, 138, 36, .7); }
.cell { min-width: 0; color: var(--text-cell); font-size: 12px; font-variant-numeric: tabular-nums; }
.cell::before { content: attr(data-label); display: block; margin-bottom: 4px; color: var(--text-cell-label); font-size: 9px; }
.kind-rank, .kind-identity, .kind-name { align-self: center; }
.kind-rank { grid-column: 1; }
.kind-identity, .kind-name { grid-column: 2; }
.kind-identity strong, .kind-name strong { display: block; font-size: 14px; color: var(--text); }
.kind-identity small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.rank-medal { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; color: var(--muted); background: var(--surface-medal); font-weight: 800; }
.rank-1 { color: #221205; background: linear-gradient(135deg, var(--overnight-medal-1-a), var(--overnight-medal-1-b)); box-shadow: 0 0 18px rgba(248, 155, 41, .22); }
.rank-2 { color: #1b1917; background: linear-gradient(135deg, var(--overnight-medal-2-a), var(--overnight-medal-2-b)); }
.rank-3 { color: #20120b; background: linear-gradient(135deg, var(--overnight-medal-3-a), var(--overnight-medal-3-b)); }
.is-inflow { color: var(--inflow); }
.is-outflow { color: var(--outflow); }
.is-flat { color: var(--muted); }
.score-value { color: var(--orange-2); font-weight: 750; }
.score-track { display: block; height: 3px; margin-top: 6px; border-radius: 9px; overflow: hidden; background: var(--surface-score-track); }
.score-track b { display: block; height: 100%; background: linear-gradient(90deg, #a84910, var(--orange)); }
.score-track.hot b { background: linear-gradient(90deg, #ff493f, #ff9b36); }
.heat-score { color: var(--orange-2); font-size: 17px; }
.signal { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.signal-strong { color: var(--signal-strong-fg); background: var(--signal-strong-bg); border: 1px solid var(--signal-strong-bd); }
.signal-split { color: var(--orange-2); background: rgba(255, 138, 36, .10); border: 1px solid rgba(255, 138, 36, .25); }
.signal-watch { color: var(--watch); background: rgba(211, 181, 143, .08); border: 1px solid rgba(211, 181, 143, .18); }
.empty-state { padding: 48px 14px; text-align: center; color: var(--muted); border: 1px dashed var(--line-soft); border-radius: 12px; }
.empty-state.is-error { color: var(--inflow); }
footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; padding: 14px 2px; color: var(--text-footer); font-size: 10px; line-height: 1.6; border-top: 1px solid var(--line-soft); }

@media (min-width: 560px) {
  .page-shell { padding-left: 20px; padding-right: 20px; }
  .primary-tab small { display: block; }
  .metrics-grid { gap: 12px; }
  .metric-card { padding: 16px; }
}

@media (max-width: 919px) {
  .v2-mobile-back { display: inline-flex; }
  .page-shell { padding-top: 42px; }
}

@media (min-width: 920px) {
  .v2-mobile-back { display: none !important; }
}

@media (min-width: 820px) {
  .topbar { min-height: 64px; }
  main { padding-top: 24px; }
  .hero { grid-template-columns: 1fr auto; align-items: end; padding: 10px 4px 22px; }
  .timeline { justify-content: flex-end; }
  .primary-tabs { width: min(620px, 100%); gap: 10px; }
  .metrics-grid { grid-template-columns: repeat(4, 1fr); }
  .section-head { padding: 18px 18px 12px; }
  .subtabs { width: 370px; padding-left: 16px; }
  .ranking-stage { padding: 2px 14px 14px; }
}

@media (max-width: 559px) {
  footer { flex-direction: column; }
  .section-head { align-items: flex-end; }
}

@media (min-width: 1040px) {
  .ranking-table { min-width: 1120px; gap: 0; }
  .ranking-head, .ranking-row { display: grid; align-items: center; }
  .ranking-head { padding: 10px 12px; color: var(--text-head); font-size: 10px; border-bottom: 1px solid var(--line-soft); }
  .ranking-row { grid-template-columns: none; gap: 0; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line-soft); border-radius: 0; background: transparent; }
  .ranking-row:hover { background: var(--hover-row); }
  .ranking-row.is-top { box-shadow: inset 2px 0 0 rgba(255, 138, 36, .75); }
  .ranking-head > div, .cell { padding-right: 12px; }
  .cell::before { display: none; }
  .kind-rank, .kind-identity, .kind-name { grid-column: auto; }
  .layout-dark-stocks .ranking-head, .layout-dark-stocks .ranking-row { grid-template-columns: 52px 150px 74px 74px 105px 105px 105px 118px minmax(120px,1fr) 76px; }
  .layout-dark-sectors { min-width: 1210px; }
  .layout-dark-sectors .ranking-head, .layout-dark-sectors .ranking-row { grid-template-columns: 52px 145px 74px 105px 105px 105px 78px 105px minmax(125px,1fr) 76px; }
  .layout-heat-stocks .ranking-head, .layout-heat-stocks .ranking-row { grid-template-columns: 52px 160px 90px 115px 135px 115px minmax(140px,1fr) 100px; }
  .layout-heat-sectors .ranking-head, .layout-heat-sectors .ranking-row { grid-template-columns: 52px 170px 115px 95px 145px 130px minmax(150px,1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; scroll-behavior: auto !important; }
}
.entity-link {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.entity-link:hover strong,
.entity-link:focus-visible strong {
  color: var(--orange);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.entity-link:focus-visible {
  outline: 2px solid rgba(255, 159, 67, 0.55);
  outline-offset: 3px;
  border-radius: 3px;
}
