/* 涨幅与行业观察 · 样式
   移植自 aawen-hoga-quant/stock_dashboard/static/app.css，重排为分节写法并统一字号体系：
   正文 14 / 表格 13 / 辅助 12 / 面板标题 17 / 页面标题 26 / 指标数字 30。保留 navy 主色与红涨绿跌。 */

/* ---------- 设计 token ---------- */
:root {
  --navy: #17314f;
  --navy-dark: #10253e;
  --ink: #1f2d3d;
  --ink-2: #475569;
  --muted: #64748b;
  --subtle: #8391a3;
  --line: #e2e8f0;
  --line-soft: #eef2f6;
  --canvas: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --tint: #eef3f8;
  --red: #cf3e45;
  --green: #14805f;
  --focus: #9dbbe0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 37, 62, .04), 0 4px 16px rgba(16, 37, 62, .04);
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
          "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 150px; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
summary:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
svg { display: block; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link { position: fixed; top: -80px; left: 16px; z-index: 99; padding: 10px 18px; background: #fff; border-radius: var(--radius-sm); }
.skip-link:focus { top: 10px; }
.rise { color: var(--red) !important; }
.fall { color: var(--green) !important; }
.flat { color: var(--muted) !important; }

/* ---------- 顶栏 ---------- */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1440px; height: 100%; margin: 0 auto; padding: 0 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 600; color: var(--navy); }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--navy); color: #fff; }
.brand-mark svg { width: 20px; height: 20px; }
.brand-divider { margin: 0 12px; color: #cfd6df; font-weight: 400; }
.brand-section { font-weight: 500; color: var(--muted); }
.snapshot-badge { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.snapshot-dot { width: 7px; height: 7px; border-radius: 50%; background: #9aaac0; }
.topbar-date { margin-left: 4px; padding-left: 12px; border-left: 1px solid var(--line); color: var(--ink-2); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- 页面与标题 ---------- */
.page { max-width: 1440px; margin: 0 auto; padding: 28px 32px 20px; }
.global-error {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 20px; padding: 12px 16px; border: 1px solid #edd7bc; border-radius: var(--radius-sm);
  background: #fff8ec; color: #8a6a3e; font-size: 14px;
}
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 20px; }
.eyebrow { margin-bottom: 6px; font-size: 12px; font-weight: 600; letter-spacing: .14em; color: var(--subtle); }
.eyebrow span { margin: 0 6px; color: #c0c8d2; }
h1 { font-size: 26px; line-height: 1.3; font-weight: 650; letter-spacing: .02em; color: var(--navy-dark); }
.heading-description { margin-top: 6px; font-size: 14px; color: var(--muted); }
.as-of { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex-shrink: 0; }
.as-of-label { font-size: 12px; color: var(--muted); }
.as-of strong { font-size: 26px; line-height: 1.3; font-weight: 600; letter-spacing: .02em; color: var(--navy); font-variant-numeric: tabular-nums; }
.as-of-note { font-size: 12px; color: var(--subtle); }

/* ---------- 周期切换（滚动时吸附在顶栏下方） ---------- */
.period-bar {
  position: sticky; top: var(--topbar-h); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 24px;
  padding: 12px 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: rgba(255, 255, 255, .96); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.period-control { display: flex; align-items: center; gap: 16px; min-width: 0; }
.control-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.period-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.period-tab {
  padding: 7px 16px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink-2); font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, color .15s;
}
.period-tab:hover { background: #e9eff6; color: var(--navy); }
.period-tab.active { background: var(--navy); color: #fff; box-shadow: 0 2px 6px rgba(23, 49, 79, .18); }
.period-tab:disabled { opacity: .55; }
.window-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.calendar-icon svg { width: 16px; height: 16px; color: var(--subtle); }
.window-explainer { margin-left: 2px; padding-left: 10px; border-left: 1px solid var(--line); color: var(--subtle); }

/* ---------- 指标卡 ---------- */
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 20px 0 24px; }
.metric-card { padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.metric-index { font-size: 12px; letter-spacing: .06em; color: #b3bdc9; font-variant-numeric: tabular-nums; }
.metric-value { min-height: 39px; margin-top: 6px; font-size: 30px; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; color: var(--navy); font-variant-numeric: tabular-nums; }
.metric-value .unit { margin-left: 4px; font-size: 15px; font-weight: 500; letter-spacing: 0; color: var(--muted); }
.metric-value .percent-unit { margin-left: 1px; font-size: 20px; }
.metric-note { margin-top: 2px; font-size: 12px; color: var(--subtle); }
.metric-highlight { padding-top: 14px; border-top: 3px solid var(--navy); }
.metric-highlight .metric-note { font-size: 13px; font-weight: 500; color: var(--ink-2); }

/* ---------- 面板通用 ---------- */
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.panel { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px 14px; }
.section-kicker { margin-bottom: 2px; font-size: 12px; font-weight: 600; letter-spacing: .12em; color: var(--subtle); }
h2 { font-size: 17px; line-height: 1.45; font-weight: 650; color: var(--navy-dark); }
.count-badge { display: inline-block; margin-left: 8px; padding: 1px 8px; vertical-align: 2px; border-radius: 999px; background: var(--tint); color: #5f7892; font-size: 12px; font-weight: 500; line-height: 1.6; }
.panel-subtitle { margin-top: 2px; font-size: 13px; color: var(--muted); }
.panel-footnote { padding: 10px 20px; border-top: 1px solid var(--line-soft); background: var(--surface-2); font-size: 12px; line-height: 1.7; color: var(--muted); }

/* ---------- 筛选 ---------- */
.filters { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 0 20px 14px; }
.search-field { display: flex; align-items: center; flex: 1 1 220px; max-width: 320px; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.search-field:focus-within { border-color: #9fb6d0; background: #fff; box-shadow: 0 0 0 3px #e8eff7; }
.search-field svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--subtle); }
.search-field input { flex: 1; min-width: 0; padding: 0 0 0 8px; border: 0; background: none; outline: none; font-size: 14px; }
.search-field input::placeholder { color: #9aa5b3; }
.industry-filter { flex: 0 1 220px; min-width: 150px; }
.industry-filter select, .page-size-label select {
  width: 100%; height: 38px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; font-size: 14px; color: var(--ink-2); cursor: pointer;
}
.text-button { padding: 4px 2px; border: 0; background: none; font-size: 13px; color: #4f6f93; white-space: nowrap; }
.text-button:hover { color: var(--navy); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- 表格（表头在滚动容器内吸顶） ---------- */
.table-scroll { overflow: auto; border-top: 1px solid var(--line-soft); overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: #cfd8e3 transparent; }
.ranking-scroll { max-height: 640px; min-height: 200px; }
.industry-scroll { max-height: 520px; min-height: 160px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; line-height: 1.5; text-align: left; }
.data-table th {
  position: sticky; top: 0; z-index: 2; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: #f6f8fb; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; vertical-align: bottom;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.data-table tbody tr:nth-child(even) td { background: #fcfdfe; }
.data-table tbody tr:hover td { background: #f3f7fb; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tr.empty-row td, .data-table tr.empty-row:hover td { background: #fff; }
.data-table .numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.th-note { display: block; margin-top: 1px; font-size: 12px; font-weight: 400; line-height: 1.3; color: var(--subtle); }
.th-inline-note { margin-left: 2px; font-size: 12px; font-weight: 400; color: var(--subtle); }
.sort-button { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; font: inherit; color: inherit; }
.sort-button:hover, .sort-button.active { color: var(--navy); }
.sort-button:disabled { opacity: .5; }
.sort-arrow { font-size: 12px; font-weight: 400; color: #aab4c0; }
.sort-button.active .sort-arrow { color: var(--navy); }

.stock-table { min-width: 760px; }
.stock-table th:first-child, .stock-table td:first-child { width: 68px; padding-left: 20px; }
.stock-table th:last-child, .stock-table td:last-child { padding-right: 20px; }
.rank-number { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 24px; padding: 0 4px; border-radius: 6px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-number.top-rank { background: #fdf0e7; color: #b0683f; font-weight: 600; }
.rank-number.first-rank { background: #f8e7c9; color: #946520; }
.stock-name { font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.stock-code { font-size: 12px; letter-spacing: .03em; color: var(--subtle); font-variant-numeric: tabular-nums; }
.price-value { color: var(--ink-2); }
.return-value { font-size: 14px; font-weight: 600; }
.sector-label { display: inline-block; max-width: 180px; padding: 2px 8px; overflow: hidden; border-radius: 6px; background: #f1f4f8; color: var(--ink-2); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; vertical-align: middle; }

/* ---------- 分页 ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.pagination-controls { display: flex; align-items: center; gap: 8px; }
.page-size-label select { height: 32px; font-size: 13px; }
.page-button { min-width: 32px; height: 32px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; font-size: 18px; line-height: 1; color: var(--ink-2); }
.page-button:hover:not(:disabled) { background: #f1f5fa; }
.page-button:disabled { background: var(--surface-2); color: #c7ced8; }
.page-number { min-width: 48px; text-align: center; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- 本周期观察与阅读说明 ---------- */
.insight-column { display: flex; flex-direction: column; gap: 16px; }
.insight-panel { border-top: 3px solid var(--navy); }
.insight-panel .panel-heading { align-items: flex-start; padding: 16px 18px 6px; }
.insight-period { margin-top: 4px; padding: 2px 10px; border-radius: 999px; background: var(--tint); color: #5f7892; font-size: 12px; white-space: nowrap; }
.analysis-content { min-height: 160px; padding: 0 18px; }
.analysis-list { margin: 0; padding: 0; list-style: none; }
.analysis-list li { display: flex; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; line-height: 1.8; color: var(--ink-2); }
.analysis-list li:last-child { border-bottom: 0; }
.analysis-index { flex-shrink: 0; font-size: 12px; font-weight: 600; line-height: 25px; color: #98a9bd; font-variant-numeric: tabular-nums; }
.analysis-list p { flex: 1; min-width: 0; }
.insight-caption { padding: 12px 18px; border-top: 1px solid var(--line-soft); background: var(--surface-2); font-size: 12px; line-height: 1.7; color: var(--muted); }
.reading-card { padding: 16px 18px; border: 1px solid #e0e7ef; border-radius: var(--radius); background: #eef2f7; }
.reading-card h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; font-weight: 600; color: #435a73; }
.reading-icon { display: inline-grid; place-items: center; width: 18px; height: 18px; border: 1px solid #8fa2b9; border-radius: 50%; font: 600 12px/1 Georgia, serif; color: #6a809a; }
.reading-card p { margin-bottom: 8px; font-size: 13px; line-height: 1.8; color: var(--ink-2); }
.reading-card p strong { font-weight: 600; color: #3f566e; }
.snapshot-note { margin-top: 10px; padding-top: 10px; border-top: 1px solid #d9e1ea; font-size: 12px; line-height: 1.7; color: var(--muted); }

/* ---------- 行业分布 ---------- */
.industry-panel { margin-top: 24px; }
.segmented-control { display: flex; padding: 3px; border-radius: var(--radius-sm); background: #eef2f6; white-space: nowrap; }
.segmented-control button { padding: 6px 14px; border: 0; border-radius: 6px; background: none; font-size: 13px; color: var(--muted); }
.segmented-control button.active { background: #fff; color: var(--navy); font-weight: 600; box-shadow: 0 1px 3px rgba(20, 51, 83, .1); }
.industry-table { min-width: 900px; }
.industry-table th:first-child, .industry-table td:first-child { width: 200px; padding-left: 20px; }
.industry-table th:last-child, .industry-table td:last-child { padding-right: 20px; }
.industry-table th:nth-child(2) { width: 24%; min-width: 220px; }
.industry-name { font-size: 13px; color: var(--ink); white-space: nowrap; }
.industry-link { padding: 0; border: 0; background: none; text-align: left; font-size: 13px; font-weight: 500; color: #2f5680; white-space: nowrap; }
.industry-link:hover { color: var(--navy); text-decoration: underline; text-underline-offset: 3px; }
.bar-cell { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.bar-track { flex: 1; height: 8px; overflow: hidden; border-radius: 4px; background: #eef2f6; }
.bar-fill { height: 100%; min-width: 3px; max-width: 100%; border-radius: 4px; background: #a8bcd3; }
.bar-fill.leading { background: #4f76a3; }
.bar-count { flex-shrink: 0; width: 48px; text-align: right; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.bar-count span { font-size: 12px; color: var(--subtle); }
.representative-stocks { font-size: 13px; color: var(--ink-2); }

/* ---------- 口径说明与页脚 ---------- */
.methodology { margin-top: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.methodology summary { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; list-style: none; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.methodology summary::-webkit-details-marker { display: none; }
.methodology summary span { font-size: 18px; color: var(--subtle); transition: transform .15s; }
.methodology[open] summary span { transform: rotate(45deg); }
.methodology-body { padding: 0 20px 16px; font-size: 13px; line-height: 1.9; color: var(--muted); }
.methodology-body p + p { margin-top: 4px; }
.footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 16px; padding: 20px 0 8px; font-size: 12px; color: var(--subtle); }
.footer-dot { margin: 0 8px; color: #c3cbd5; }
.footer-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-variant-numeric: tabular-nums; }
#kb-version:empty { display: none; }

/* ---------- 加载、空态与错误 ---------- */
.table-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 160px; padding: 24px 16px; text-align: center; white-space: normal; font-size: 14px; color: var(--muted); }
.table-state strong { font-size: 15px; font-weight: 600; color: var(--ink-2); }
.table-state p { max-width: 360px; font-size: 13px; line-height: 1.8; }
.loader { width: 20px; height: 20px; border: 2px solid #e2e9f1; border-top-color: #5d7fa5; border-radius: 50%; animation: spin .8s linear infinite; }
.empty-symbol { width: 34px; height: 34px; border-radius: 50%; background: #eef2f6; color: #94a6ba; font-size: 18px; line-height: 34px; }
.retry-button { padding: 6px 14px; border: 1px solid #d5dfea; border-radius: var(--radius-sm); background: #fff; font-size: 13px; color: #4d6b8c; }
.retry-button:hover { background: #f1f5fa; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 中文断行：避免行尾孤字 ---------- */
.heading-description, .panel-footnote, .insight-caption, .analysis-list p, .reading-card p, .methodology-body p { text-wrap: pretty; }
.metric-note, .panel-subtitle { text-wrap: balance; }

/* ---------- 响应式 ---------- */
@media (max-width: 1280px) {
  .topbar-inner { padding: 0 24px; }
  .page { padding: 24px 24px 16px; }
  .content-grid { grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; }
  .metrics-grid { gap: 12px; }
  .period-tab { padding: 7px 12px; }
}
@media (max-width: 960px) {
  .content-grid { grid-template-columns: 1fr; }
  .insight-column { display: grid; grid-template-columns: minmax(0, 3fr) minmax(240px, 2fr); align-items: stretch; }
  .analysis-content { min-height: 0; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  :root { --topbar-h: 54px; }
  html { scroll-padding-top: 70px; }
  .topbar-inner { padding: 0 16px; }
  .brand-divider, .brand-section, .topbar-date { display: none; }
  .page { padding: 18px 16px 12px; }
  .page-heading { flex-direction: column; align-items: flex-start; gap: 10px; }
  h1 { font-size: 22px; }
  .as-of { flex-direction: row; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; text-align: left; }
  .as-of strong { font-size: 18px; }
  .period-bar { position: static; padding: 12px 14px; }
  .period-control { flex-direction: column; align-items: stretch; gap: 8px; width: 100%; }
  .period-tabs { flex-wrap: nowrap; overflow-x: auto; padding: 2px; scrollbar-width: none; }
  .period-tabs::-webkit-scrollbar { display: none; }
  .period-tab { flex: 0 0 auto; padding: 7px 12px; }
  .window-explainer { display: none; }
  .metrics-grid { gap: 10px; margin: 16px 0 18px; }
  .metric-card { padding: 12px 14px; }
  .metric-index { display: none; }
  .metric-value { min-height: 31px; font-size: 24px; }
  .metric-value .percent-unit { font-size: 16px; }
  .panel-heading { padding: 14px 16px 12px; }
  h2 { font-size: 16px; }
  .filters { padding: 0 16px 12px; }
  .search-field { flex-basis: 100%; max-width: none; }
  .industry-filter { flex: 1 1 auto; }
  .data-table th, .data-table td { padding-left: 10px; padding-right: 10px; }
  .stock-table { min-width: 600px; }
  .stock-table th:first-child, .stock-table td:first-child { width: 52px; padding-left: 16px; }
  .stock-table th:last-child, .stock-table td:last-child,
  .industry-table th:last-child, .industry-table td:last-child { padding-right: 16px; }
  .pagination { flex-direction: column; align-items: stretch; padding: 12px 16px; }
  .pagination-controls { justify-content: flex-end; }
  .pagination-controls .page-size-label { margin-right: auto; }
  .panel-footnote { padding: 10px 16px; }
  .insight-column { grid-template-columns: 1fr; }
  .reading-card { display: none; }
  .industry-panel .panel-heading { flex-direction: column; align-items: flex-start; }
  .industry-table { min-width: 720px; }
  .industry-table th:first-child, .industry-table td:first-child { width: 140px; padding-left: 16px; }
  .industry-table th:nth-child(2) { min-width: 170px; }
  .bar-cell { min-width: 150px; }
  .footer { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
