/* ============ 设计变量（统一 UI 基调） ============ */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e8eaed;
  --text: #1f2329;
  --text-sub: #8a9099;
  --text-weak: #b4b9c0;
  --brand: #2b6cff;
  --brand-weak: #eaf1ff;
  --up: #e23d3d;     /* 涨 红 */
  --up-bg: #fdecec;
  --down: #1aa260;   /* 跌 绿 */
  --down-bg: #e9f7f0;
  --flat: #8a9099;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(20, 30, 50, 0.06);
  --header-h: 50px;
  --tabs-h: 64px;
  --page-nav-h: 53px;
  /* 桌面端充分利用宽屏，行情分时与日 K 不再被 H5 宽度限制。 */
  --maxw: 1440px;
  --modal-maxw: 760px;
  --auth-modal-maxw: 520px;
  --page-pad: 12px;
  --fs: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: var(--fs); }

/* ============ 头部 ============ */
[data-app-header] {
  position: sticky; top: 0; z-index: 30;
  display: block;
}
.app-header {
  position: relative; z-index: 2;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  background: linear-gradient(135deg, #1f2a44, #2b3a5e);
  color: #fff;
  max-width: var(--maxw); margin: 0 auto;
}
.app-header__title { font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.app-header__right { display: flex; align-items: center; gap: 10px; }
.trade-status {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: rgba(255,255,255,.14); color: #d8e0f0;
}
.trade-status.is-open { background: rgba(26,162,96,.25); color: #b6f0d2; }
.role-btn {
  border: 1px solid rgba(255,255,255,.35);
  background: transparent; color: #fff;
  font-size: 12px; padding: 4px 12px; border-radius: 20px;
}
.role-btn.is-vip { background: #f0b429; border-color: #f0b429; color: #3a2a00; font-weight: 700; }
.role-btn.is-admin { background: #ff7a45; border-color: #ff7a45; color: #fff; font-weight: 700; }

/* ============ 因子板块 tab ============ */
.factor-tabs {
  position: sticky; top: calc(var(--header-h) + var(--page-nav-h)); z-index: 20;
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  max-width: var(--maxw); margin: 0 auto;
}
.factor-tabs[hidden] { display: none; }
.factor-tab,
.factor-tab:visited {
  flex: 0 1 auto;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  text-align: center;
  transition: .15s;
  font: inherit;
  cursor: pointer;
}
.factor-tab:not(.is-active):hover {
  background: var(--surface-hover);
  border-color: var(--brand);
}
.factor-tab:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}
.factor-tab.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.factor-tab__name { font-weight: 600; font-size: 13px; }
.factor-tab__meta { font-size: 11px; color: var(--text-sub); margin-top: 3px; }
.factor-tab.is-active .factor-tab__meta { color: rgba(255,255,255,.85); }
.factor-tab__count { color: var(--up); }
.factor-tab.is-active .factor-tab__count { color: #fff; }
.factor-tab__count--loading {
  display: inline-block;
  width: 1.5em;
  height: .7em;
  border-radius: 2px;
  background: currentColor;
  opacity: .18;
  vertical-align: -.05em;
}

/* 共振模式：多选中的 tab */
.factor-tab.is-resonance-selected {
  background: #e8f0fe;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(43,108,255,.25);
}
.factor-tab.is-resonance-selected .factor-tab__name { color: var(--brand); }
.factor-tab.is-resonance-selected .factor-tab__meta { color: var(--text-sub); }
.factor-tab.is-resonance-selected .factor-tab__count { color: var(--brand); font-weight: 700; }

/* ============ 工具条 ============ */
.toolbar { max-width: var(--maxw); margin: 0 auto; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.toolbar__row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.toolbar__row[hidden] { display: none; }
.toolbar__row:last-child { margin-bottom: 0; }
.field { display: flex; align-items: center; gap: 6px; }
.field[hidden] { display: none; }
.field__label { font-size: 12px; color: var(--text-sub); white-space: nowrap; }
.field__input, .search, .select {
  height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0 10px; background: var(--surface-2); color: var(--text); outline: none;
}
.field__input { width: 140px; }
.search { flex: 1; min-width: 0; }
.select { max-width: 150px; }

/* 日期导航：左右箭头紧贴日历框 */
.date-nav { display: flex; align-items: center; gap: 4px; }
.date-nav__btn {
  width: 30px; height: 34px; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  font-size: 18px; line-height: 1; display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.date-nav__btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); background: var(--surface); }
.date-nav__btn:disabled { opacity: .4; cursor: not-allowed; }
.date-nav .field { flex: 1; }
.chip {
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  white-space: nowrap;
}
.chip.is-on { background: var(--brand-weak); border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* ============ 游客横幅 ============ */
.guest-banner {
  width: min(100%, var(--maxw)); margin: 10px auto 0; padding: 10px 12px;
  background: #fff7e6; border: 1px solid #ffe0a3; border-radius: var(--radius-sm);
  color: #8a5a00; font-size: 12px; line-height: 1.5;
}

/* 所选交易日无股票数据提示（与 guest-banner 同列居中） */
.day-empty {
  width: min(100%, var(--maxw)); margin: 10px auto 0; padding: 10px 12px;
  background: #fff1f0; border: 1px solid #ffccc7; border-radius: var(--radius-sm);
  color: #a8071a; font-size: 13px; line-height: 1.5;
}

/* ============ 结果区 ============ */
.result { padding: 10px 0 40px; width: min(100%, var(--maxw)); margin: 0 auto; }
.result__meta { font-size: 12px; color: var(--text-sub); margin: 4px 0 10px; padding: 0 12px; }

/* ============ 股票列表（卡片式表格） ============ */
.stock-list { display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 960px) {
  .stock-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 0 16px; }
}
.stock-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
}
.stock-card__top { display: flex; align-items: baseline; justify-content: space-between; }
.stock-card__name { font-size: 15px; font-weight: 700; }
.stock-card__code { font-size: 11px; color: var(--text-sub); margin-left: 6px; }
.stock-score { font-size: 11px; color: var(--text-sub); margin-left: 8px; font-variant-numeric: tabular-nums; }
.stock-score.is-top, .score-top { color: var(--up); font-weight: 800; }
.stock-ranking { display: inline-block; min-width: 28px; margin-right: 6px; color: var(--brand); font-weight: 800; font-size: 12px; }
.stock-card__rate { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stock-card__grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px;
  margin-top: 8px; font-size: 12px;
}
.kv { display: flex; flex-direction: column; }
.kv__k { color: var(--text-sub); font-size: 11px; }
.kv__v { font-variant-numeric: tabular-nums; font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--brand-weak); color: var(--brand);
}
.tag--factor { background: #eef0f3; color: var(--text-sub); }
.stock-stars { margin-top: 7px; display: flex; gap: 2px; align-items: center; }
.stock-star { color: #c7cbd1; font-size: 17px; line-height: 1; }
.stock-star.is-on { color: #d99b00; }
.block-names .up { color: var(--up); }
.block-names .down { color: var(--down); }

/* 所属概念 → 点击跳转到概念板块全部股票（#/concept/<名称>） */
.concept-link {
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
.concept-link:hover { text-decoration: underline; border-bottom-color: var(--brand); }
.stock-chart-link { color: inherit; text-decoration: none; border-radius: 4px; }
.stock-chart-link:hover .stock-card__name,
.stock-chart-link:hover .stock-card__code { color: var(--brand); text-decoration: underline; }
/* 概念页表头的返回入口 */
.meta-back { color: var(--brand); text-decoration: none; margin-left: 4px; }
.meta-back:hover { text-decoration: underline; }

.ranking-controls { width: min(100%, var(--maxw)); margin: 0 auto; padding: 10px 0 4px; }
.ranking-controls__row { display: flex; align-items: end; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.ranking-stars { align-items: center; }
.ranking-pager { justify-content: center; align-items: center; color: var(--text-sub); font-size: 12px; }
/* 量化排名分页条：独立置于列表之后，与结果区同宽、居中并留出间距 */
.ranking-pager-wrap { width: min(100%, var(--maxw)); margin: 16px auto 32px; padding: 0; }
.ranking-pager-wrap[hidden] { display: none; }

.image-viewer { position: fixed; inset: 4vh 4vw; z-index: 1001; display: flex; align-items: center; justify-content: center; }
.image-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.image-viewer__close { position: absolute; top: 8px; right: 8px; background: #fff; }
.block-names { margin-top: 6px; font-size: 11px; color: var(--text-sub); line-height: 1.6; }

/* 涨跌色 */
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }
.up-bg { background: var(--up-bg); }
.down-bg { background: var(--down-bg); }

/* ============ 状态盒 ============ */
.state-box { text-align: center; color: var(--text-sub); padding: 40px 16px; font-size: 14px; }
.state-box.is-error { color: var(--up); }
/* 空数据状态：更醒目的提示（图标 + 加大字号） */
.state-box:empty { display: none; }
.state-box--info {
  text-align: left; padding: 20px 16px; margin: 12px 0;
  background: rgba(43,108,255,.06); border: 1px solid rgba(43,108,255,.18); border-radius: var(--radius);
  font-size: 13px; line-height: 1.6; color: var(--text);
}
.state-box__icon { font-size: 18px; margin-right: 6px; }
.state-box__sub { color: var(--text-sub); margin-top: 4px; font-size: 12px; }
/* 无限滚动哨兵（被 IntersectionObserver 观察，进入视口自动加载下一页） */
.scroll-sentinel { height: 1px; }
/* 到底提示 */
.list-end {
  text-align: center; color: var(--text-sub);
  padding: 18px 0 24px; font-size: 13px;
}

/* ============ 弹层 ============ */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain;
}
.modal[hidden] { display: none; }
.modal__mask { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal__panel {
  position: relative; width: 100%; max-width: var(--modal-maxw);
  background: var(--surface); border-radius: 16px;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  display: flex; flex-direction: column;
  animation: slideUp .22s ease;
}
@media (min-width: 640px) {
  .modal__panel { border-radius: 16px; margin: 16px; max-height: 80vh; }
  #authModal .modal__panel { max-width: var(--auth-modal-maxw); }
}
@keyframes slideUp { from { transform: translateY(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal__title { font-size: 15px; font-weight: 700; }
.modal__close { border: none; background: transparent; font-size: 22px; color: var(--text-sub); line-height: 1; }
.modal__body {
  min-height: 0; padding: 14px 16px; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.modal__actions { display: flex; gap: 10px; margin-top: 14px; }

/* 详情 */
.detail-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--surface-2); }
.detail-row__k { color: var(--text-sub); }
.detail-row__v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* 概念筛选 */
.concept-options { display: flex; flex-wrap: wrap; gap: 8px; }
.concept-opt {
  font-size: 12px; padding: 6px 12px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.concept-opt.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* 按钮 */
.btn { height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border); padding: 0 16px; font-weight: 600; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--ghost { background: var(--surface-2); }
.btn--block { width: 100%; margin-top: 6px; }
.login-err { color: var(--up); font-size: 12px; margin-top: 8px; }
.login-tip { color: var(--text-weak); font-size: 11px; margin-top: 10px; line-height: 1.5; }

/* 空态/加载的小动画 */
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 顶层页面导航 ============ */
.page-nav {
  position: relative; z-index: 1;
  display: flex; gap: 6px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  max-width: var(--maxw); margin: 0 auto;
}
.page-nav__btn {
  flex: 1 1 0; min-width: 0; height: 36px; padding: 0 8px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); text-align: center; line-height: 1.2;
  white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-weight: 700; font-size: 14px; letter-spacing: .15px;
  transition: background-color .15s, border-color .15s, color .15s;
}
.page-nav__btn:hover { background: var(--surface-hover); border-color: var(--brand); color: var(--text); }
.page-nav__btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 1px; }
.page-nav__btn.is-active {
  background: var(--up); border-color: var(--up); color: #fff; font-weight: 800;
  box-shadow: 0 2px 7px rgba(226, 61, 61, .22);
}
.page-nav__btn.is-active:hover { background: var(--up); border-color: var(--up); color: #fff; }
.page-nav__btn[hidden], .home-card[hidden] { display: none; }

/* 全局路由加载提示：固定在顶部导航下方，滚动到页面任意位置也能立即看到。 */
.route-loading {
  position: fixed;
  top: calc(var(--header-h) + var(--page-nav-h) + 7px);
  left: 50%;
  z-index: 29;
  width: min(calc(100% - 24px), calc(var(--maxw) - 24px));
  min-height: 44px;
  overflow: hidden;
  transform: translateX(-50%);
  border: 1px solid rgba(43,108,255,.28);
  border-radius: 10px;
  background: rgba(255,255,255,.97);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(20,30,50,.16);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.route-loading[hidden] { display: none; }
.route-loading__content {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px 11px;
  font-size: 13px;
  font-weight: 600;
}
.route-loading__progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  overflow: hidden;
  background: var(--brand-weak);
}
.route-loading__progress::after {
  content: '';
  display: block;
  width: 42%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--brand), #70a0ff, transparent);
  animation: route-loading-progress 1.1s ease-in-out infinite;
}
@keyframes route-loading-progress {
  from { transform: translateX(-105%); }
  to { transform: translateX(340%); }
}

@media (prefers-reduced-motion: reduce) {
  .route-loading__progress::after { width: 100%; animation: none; }
  .route-loading .spin { animation-duration: 1.4s; }
}

/* ============ 自选星标 ============ */
.stock-card__topright { display: flex; align-items: center; gap: 8px; }
.watch-btn {
  flex: 0 0 auto;
  width: 30px; height: 30px; line-height: 1;
  border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-weak);
  font-size: 16px; padding: 0; transition: .15s;
}
.watch-btn.is-on { color: #f0b429; border-color: #f0b429; background: #fff7e6; }
.watch-btn[aria-busy='true'] {
  position: relative;
  width: 30px; min-width: 30px; max-width: 30px; height: 30px;
  overflow: hidden;
  color: transparent;
  opacity: 1;
  cursor: wait;
}
.watch-btn[aria-busy='true']::after {
  content: '';
  position: absolute; inset: 6px;
  border: 2px solid rgba(127,135,145,.35); border-top-color: var(--brand);
  border-radius: 50%;
  animation: watch-btn-spin .7s linear infinite;
}
@keyframes watch-btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .watch-btn[aria-busy='true']::after { animation: none; border-right-color: var(--brand); }
}
.detail-actions { margin-top: 14px; }

/* ============ 移动端响应式（≤480px） ============ */
@media (max-width: 480px) {
  :root { --page-nav-h: 47px; }
  /* 头部：缩小标题和按钮 */
  .app-header__title { font-size: 14px; }
  .trade-status { font-size: 10px; padding: 2px 6px; }
  .role-btn { font-size: 11px; padding: 3px 8px; }

  /* 页面导航保持单行，避免吸顶高度变化导致下层内容覆盖。 */
  .page-nav { gap: 4px; padding: 7px 8px; flex-wrap: nowrap; }
  .page-nav__btn { height: 32px; padding: 0 3px; font-size: 12px; border-radius: 6px; }

  /* 因子 tab 行：自动换行 */
  .factor-tabs { gap: 6px; padding: 8px 10px; }
  .factor-tab {
    flex: 1 1 calc(33.33% - 4px);
    min-width: 0;
    padding: 7px 6px;
    border-radius: 6px;
  }
  .factor-tab__name { font-size: 12px; }
  .factor-tab__meta { font-size: 10px; }

  /* 工具栏日期区 */
  .toolbar { width: calc(100% - 20px); padding: 8px 0; }
  body[data-page="factor"] .toolbar__row:first-child { flex-wrap: wrap; }
  body[data-page="factor"] .date-nav { flex: 1 1 220px; min-width: 0; }
  body[data-page="factor"] .date-nav .field {
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
  }
  body[data-page="factor"] .date-nav .field__input { width: 100%; min-width: 0; }
  .date-nav input[type="date"] { font-size: 13px; }

  /* 股票卡片：紧凑 */
  .stock-card { padding: 8px 10px; border-radius: 10px; }
  .stock-card__name { font-size: 14px; }
  .stock-card__code { font-size: 11px; }
  .stock-card__rate { font-size: 14px; }
  .stock-card__grid { grid-template-columns: repeat(2, 1fr); gap: 5px 8px; }
  .chart-page, .resonance-page, .ranking-controls, .ranking-pager-wrap, .redeem-page { width: calc(100% - 20px); }
  .chart-page { padding: 10px 0 30px; }
  .kv__k { font-size: 11px; min-width: 56px; }
  .kv__v { font-size: 12px; }

  /* 结果元信息 */
  .result { width: calc(100% - 20px); padding: 8px 0 36px; }
  .chart-longhu__tables { grid-template-columns: 1fr; }
}
