:root {
  --bg: #0E1117;
  --surface: #161B22;
  --surface-2: #1C222B;
  --border: #262D38;
  --text: #E6E8EB;
  --text-secondary: #8B96A5;
  --text-tertiary: #5B6472;
  --accent: #3B82F6;
  --up: #F5222D;
  --down: #00B578;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
}

button, input { font-family: inherit; }
button { cursor: pointer; }

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

/* ---------- 免责声明弹窗 ---------- */
.disclaimer-mask {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.disclaimer-mask.hidden { display: none; }
.disclaimer-box {
  width: 100%; max-width: 420px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px;
}
.disclaimer-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.disclaimer-text { font-size: 13px; line-height: 1.8; color: var(--text-secondary); margin-bottom: 20px; }
.disclaimer-btn {
  width: 100%; background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 10px 0; font-size: 14px; font-weight: 600;
}

/* ---------- 人机验证（拖动滑块） ---------- */
.captcha-mask {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.captcha-box {
  width: 100%; max-width: 340px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px;
}
.captcha-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.captcha-title { font-size: 14px; font-weight: 700; }
.captcha-close { background: none; border: none; color: var(--text-tertiary); font-size: 13px; cursor: pointer; padding: 4px; }
.captcha-close:hover { color: var(--text); }

.captcha-math.shake { animation: captcha-shake 0.4s ease; }
@keyframes captcha-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

.captcha-math-question { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 14px; font-variant-numeric: tabular-nums; }
.captcha-math-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.captcha-math-btn {
  padding: 10px 0; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 15px; font-weight: 600; font-family: inherit; font-variant-numeric: tabular-nums;
}
.captcha-math-btn:hover { border-color: var(--accent); }
.captcha-math-btn.correct { background: var(--down); border-color: var(--down); color: #fff; }
.captcha-math-btn.wrong { background: var(--up); border-color: var(--up); color: #fff; }

/* ---------- 顶部导航条 ---------- */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: linear-gradient(135deg, #3B82F6, #2563EB);
  color: #fff; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.search { position: relative; flex: 1; max-width: 420px; margin: 0 40px; }
.search input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 14px; color: var(--text); font-size: 13px; outline: none;
}
.search input::placeholder { color: var(--text-tertiary); }

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  max-height: 360px; overflow-y: auto; z-index: 50; display: none;
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
}
.search-results.open { display: block; }
.search-result-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: rgba(255,255,255,0.04); }
.sr-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sr-symbol { font-size: 13px; font-weight: 600; color: var(--text); }
.sr-name { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-market { font-size: 11px; color: var(--text-tertiary); background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 2px 7px; flex: none; }
.search-empty, .search-hint {
  padding: 12px 14px; font-size: 12px; color: var(--text-tertiary);
}
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.icon-btn { background: none; border: none; color: var(--text-secondary); display: flex; padding: 4px; }
.icon-btn.star { color: #F5A623; }

/* ---------- 行情摘要条 ----------
   关键点：name/价格/今开这些值都会跟着实时数据变长变短（股票名可能很长，价格位数会变），
   给每一块定死宽度 + 数字用等宽数字（tabular-nums），内容变化时不会带着后面的东西一起挪位置、
   也不会来回闪。开市状态单独占一行放在下面，不跟前面这几块抢位置。 */
.ticker {
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px 32px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.ticker-row { display: flex; align-items: center; gap: 32px; flex-wrap: wrap; }
.ticker-status-group { display: flex; align-items: center; gap: 80px; margin-left: 24px; flex-wrap: wrap; }

.ticker-id { display: flex; align-items: center; gap: 14px; width: 260px; flex: none; }
.ticker-id-text { min-width: 0; flex: 1; } /* min-width:0 是让里面的省略号生效的关键 */
.ticker-avatar {
  width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 700;
  overflow: hidden; flex: none; /* logo 的 SVG 自带方形底色，裁成圆角头像的形状 */
}
.ticker-avatar svg { width: 100%; height: 100%; display: block; }
.ticker-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ticker-name {
  font-size: 19px; font-weight: 700; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; /* 名字超长（ETF全称之类）截断，不撑破布局 */
}
.ticker-code { font-size: 12px; color: var(--text-tertiary); background: var(--surface-2); padding: 2px 7px; border-radius: 4px; flex: none; }
.ticker-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ticker-price { width: 300px; flex: none; }
.price-main { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.price-change { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.chg { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chg-pct { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.chg-pct.up { background: rgba(245, 34, 45, 0.12); }
.chg-pct.down { background: rgba(0, 181, 120, 0.12); }

.ticker-stats { display: flex; gap: 20px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; gap: 4px; min-width: 76px; }
.stat-label { font-size: 11px; color: var(--text-tertiary); }
.stat-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.market-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 12px; color: var(--text-secondary);
}
.market-status .ms-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-tertiary); flex: none; }
.market-status.open .ms-dot { background: var(--down); }
.market-status.closed .ms-dot { background: var(--up); }
.market-status .ms-sep { color: var(--text-tertiary); }

.live-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-tertiary); font-size: 11px; font-family: inherit;
}
.live-status .live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-tertiary); flex: none; }
.live-status.on { color: var(--down); border-color: rgba(0,181,120,0.3); }
.live-status.on .live-dot { background: var(--down); animation: live-pulse 1.2s ease-in-out infinite; }
.live-status.off { color: var(--up); cursor: pointer; }
.live-status.off .live-dot { background: var(--up); }
@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- 断线提醒 toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 18px; font-size: 13px; color: var(--text); box-shadow: 0 12px 28px rgba(0,0,0,0.4);
  z-index: 2000; opacity: 0; transition: opacity 0.25s ease;
}
.toast.show { opacity: 1; }

/* ---------- 一级页签 ---------- */
.tabs {
  display: flex; gap: 32px; padding: 0 32px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-secondary); font-size: 15px; font-weight: 500;
  padding: 16px 2px;
}
.tab-btn.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

/* ---------- 内容区 ---------- */
.content { padding: 24px 32px; background: var(--surface); min-height: calc(100vh - 64px - 96px - 53px); }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; }

.pill-group { display: flex; gap: 4px; }
.pill {
  font-size: 13px; padding: 6px 12px; border-radius: 6px; border: none;
  background: none; color: var(--text-secondary); font-weight: 500;
}
.pill.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
#finPeriods .pill.active, #finStatements .pill.active { background: var(--accent); color: #fff; }

/* ---------- 行情 K 线 ---------- */
.quote-layout { display: flex; gap: 14px; align-items: flex-start; }
.quote-main { flex: 1; min-width: 0; }
.kline-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 16px; }
.indicator-toggle.pill-group { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.indicator-toggle .pill { padding: 5px 10px; }
.overlay-legend, .sub-indicator-legend { display: flex; gap: 14px; font-size: 11px; color: var(--text-tertiary); }
.overlay-legend span, .sub-indicator-legend span { display: flex; align-items: center; gap: 5px; }
.overlay-legend { margin-bottom: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.chart-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px 8px;
  cursor: grab; touch-action: pan-y; user-select: none;
}
.chart-card.dragging { cursor: grabbing; }
/* 高度用 CSS 定死（跟 HTML height 属性值对应），不让 JS 每次重绘时改的内部像素缓冲区
   （给高分屏乘 devicePixelRatio 那步）反过来影响画布的显示高度——不然每重绘一次
   canvas.height 属性就被放大一次 dpr 倍，高分屏上图表会越刷越高。 */
#klineCanvas, #volCanvas, #indicatorCanvas { width: 100%; display: block; }
#klineCanvas { height: 360px; }
#volCanvas { height: 80px; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; }
#indicatorCanvas { height: 90px; margin-top: 4px; }
.sub-indicator-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 11px; color: var(--text-tertiary); }
.chart-hint { margin-top: 6px; font-size: 11px; color: var(--text-tertiary); }

.quote-side { width: 260px; flex: none; display: flex; flex-direction: column; gap: 16px; }
.utc-clock {
  display: inline-flex; align-items: center; gap: 6px; width: fit-content;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums;
}
.orderbook-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-tertiary); margin-bottom: 6px; }
.ob-row { position: relative; display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; }
.ob-row .bar { position: absolute; right: 0; top: 0; bottom: 0; z-index: 0; }
.ob-row span { position: relative; z-index: 1; }
.ob-row.spread { justify-content: center; padding: 6px 0; font-size: 15px; font-weight: 700; border-top: 1px dashed var(--border); border-bottom: 1px dashed var(--border); margin: 2px 0; }
.ob-empty { padding: 16px 0; font-size: 12px; color: var(--text-tertiary); text-align: center; }
.trade-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; color: var(--text-secondary); }

/* ---------- 公司介绍 ---------- */
.intro-empty { padding: 60px 0; text-align: center; font-size: 13px; color: var(--text-tertiary); }
.intro-layout { display: flex; gap: 20px; align-items: flex-start; }
.intro-main { flex: 2; }
.intro-text { font-size: 13px; line-height: 1.9; color: var(--text-secondary); margin: 0; white-space: pre-line; }
.index-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.index-tag {
  font-size: 12px; color: var(--text-secondary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px;
}
.intro-facts { width: 320px; flex: none; }
.fact-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.fact-row span:first-child { color: var(--text-tertiary); flex: none; }
.fact-row span:last-child { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fact-row a { color: var(--accent); text-decoration: none; }
.fact-row a:hover { text-decoration: underline; }
.fact-row:last-child { border-bottom: none; }

/* ---------- 新闻资讯 ---------- */
#newsFilters { margin-bottom: 16px; }
.news-item { display: flex; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.news-thumb { width: 100px; height: 72px; flex: none; border-radius: 8px; background: var(--surface-2); }
.news-body { flex: 1; min-width: 0; }
.news-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.news-summary { font-size: 12px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 8px; }
.news-meta { font-size: 11px; color: var(--text-tertiary); }

/* ---------- 财务数据 ---------- */
.fin-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.fin-chart { display: flex; align-items: flex-end; gap: 24px; height: 160px; overflow-x: auto; }
.fin-group { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: none; }
.fin-bars { display: flex; align-items: flex-end; gap: 4px; height: 130px; }
.fin-bar { width: 16px; border-radius: 2px 2px 0 0; }
.fin-group-label { font-size: 11px; color: var(--text-tertiary); }
.fin-legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12px; color: var(--text-tertiary); }
.fin-legend span { display: flex; align-items: center; gap: 5px; }

.table-card { padding: 0; overflow-x: auto; }
.fin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fin-table th, .fin-table td { padding: 12px 20px; text-align: right; white-space: nowrap; }
.fin-table th:first-child, .fin-table td:first-child { text-align: left; color: var(--text-tertiary); }
.fin-table thead th { background: var(--surface); color: var(--text-tertiary); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--border); }
.fin-table tbody tr { border-bottom: 1px solid var(--border); }
.fin-table tbody tr:last-child { border-bottom: none; }

/* ---------- 国家板块 / 行业涨跌幅 ---------- */
.perf-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 16px; }
.perf-scope { font-size: 12px; color: var(--text-tertiary); }
.perf-scope strong { color: var(--text); font-weight: 600; }
.perf-bars { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow-y: auto; padding-right: 4px; }
.perf-bar-row { display: grid; grid-template-columns: 170px 1fr 74px; align-items: center; gap: 12px; font-size: 12px; }
.perf-bar-name { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perf-bar-track { position: relative; height: 16px; background: var(--surface); border-radius: 3px; overflow: hidden; }
.perf-bar-track::before {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px;
  background: var(--border); z-index: 1;
}
.perf-bar-fill { position: absolute; top: 1px; bottom: 1px; border-radius: 2px; }
.perf-bar-fill.up { background: rgba(245, 34, 45, 0.7); }
.perf-bar-fill.down { background: rgba(0, 181, 120, 0.7); }
.perf-bar-value { text-align: right; font-weight: 600; }
.perf-table th:first-child, .perf-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- IPO ---------- */
.ipo-status { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.ipo-status-open { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.ipo-status-upcoming { background: rgba(245, 166, 35, 0.15); color: #F5A623; }
.ipo-status-waiting { background: var(--surface); color: var(--text-tertiary); border: 1px solid var(--border); }
.ipo-status-listed { background: rgba(0, 181, 120, 0.15); color: var(--down); }
