:root {
  --bg: #0b1220;
  --panel: #121c2e;
  --panel-2: #16223a;
  --line: #24344f;
  --text: #e6edf7;
  --muted: #8ba0bd;
  --accent: #4f8cff;
  --accent-2: #2fd2a3;
  --up: #ff5c6c;
  --down: #26c281;
  --warn: #ffb454;
  --bad: #ff7a7a;
  --radius: 10px;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
button:hover { border-color: var(--accent); }
button.primary { background: linear-gradient(135deg, #3b74e8, #4f8cff); border-color: transparent; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: #0d1728;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  color: var(--muted);
  background: #0d1728;
  border: 1px dashed var(--line);
  border-radius: 8px;
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
input[type="file"]::file-selector-button:hover { border-color: var(--accent); }
input[type="month"] { color-scheme: dark; }

/* ---------- login ---------- */
.login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #17305c 0%, #0b1220 55%);
}
.login-card {
  width: 360px;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
.login-card h1 { font-size: 19px; margin: 0 0 6px; }
.login-card p { color: var(--muted); font-size: 12px; margin: 0 0 22px; line-height: 1.6; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 22px; padding: 10px; }
.login-err { color: var(--bad); font-size: 12px; margin-top: 10px; min-height: 16px; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 15px; font-weight: 600; letter-spacing: .3px; }
.brand span { color: var(--accent); }
.topbar .meta { color: var(--muted); font-size: 12px; display: flex; gap: 14px; align-items: center; }
.topbar .spacer { flex: 1; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: #1b2942;
  color: var(--muted);
  border: 1px solid var(--line);
}
.pill.warn { color: var(--warn); border-color: #4a3a1c; background: #241b0c; }
.pill.bad { color: var(--bad); border-color: #4a1f24; background: #2a1216; }
.pill.ok { color: var(--accent-2); border-color: #16433a; background: #0d241f; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tabs { display: flex; gap: 4px; padding: 8px 20px 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  padding: 9px 18px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 14px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); background: var(--bg); }

main { flex: 1; overflow: auto; padding: 16px 20px 40px; }

.banner {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: #241b0c;
  border: 1px solid #4a3a1c;
  color: #ffd29a;
  font-size: 12.5px;
  line-height: 1.5;
}
.banner.info {
  background: #0e2233;
  border-color: #1e4b66;
  color: #9fcbe8;
}

/* ---------- skeleton ---------- */
.sk {
  background: linear-gradient(90deg, #141d31 25%, #1c2740 37%, #141d31 63%);
  background-size: 400% 100%;
  animation: sk-shimmer 1.3s ease-in-out infinite;
  border-radius: 7px;
}
@keyframes sk-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.sk-banner { height: 34px; margin-bottom: 14px; }
.sk-row { height: 30px; margin-bottom: 9px; }
.sk-line { height: 13px; margin-bottom: 9px; }
.sk-block { height: 300px; margin-bottom: 12px; }
.sk-card { height: 62px; margin-bottom: 10px; }
.w40 { width: 40%; }

/* ---------- layout ---------- */
/* 研究页三列不靠 stretch 自动等高：由 JS 以「中间 K 线列」为基准统一高度，
   见 app.js 的 alignResearchColumns()。其余栅格保持 stretch。 */
.grid-research {
  display: grid;
  grid-template-columns: 270px minmax(420px, 1fr) 360px;
  gap: 14px;
  align-items: start;
}
.grid-two { display: grid; grid-template-columns: minmax(420px, 1.4fr) minmax(320px, 1fr); gap: 14px; align-items: stretch; }
.grid-three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 12px;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.panel h2 .sub { font-weight: 400; color: #63799a; font-size: 11.5px; }

/* 卡片面板：高度由 JS 对齐到中间 K 线列，卡片区填充剩余空间并滚动，
   不再出现底部大片空白，也不会把整列撑得比 K 线更长。 */
.panel.cards-panel { display: flex; flex-direction: column; }
.panel.cards-panel > .cards { flex: 1 1 auto; min-height: 0; max-height: none; overflow: auto; }

/* ---------- list ---------- */
.filter-row { display: flex; gap: 8px; margin-bottom: 10px; }
.filter-row input { flex: 1; }
.filter-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
  margin: -2px 0 6px;
}
.filter-opt label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.filter-opt input[type="checkbox"] { accent-color: var(--accent); }
.etf-list { max-height: calc(100vh - 315px); overflow: auto; }
.etf-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.etf-item:hover { background: var(--panel-2); }
.etf-item.active { background: #16294a; border-color: #2d4c7d; }
.etf-item .name { font-size: 13px; }
.etf-item .code { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.etf-item .price { text-align: right; font-family: var(--mono); font-size: 13px; }
.etf-item .chg { text-align: right; font-family: var(--mono); font-size: 11.5px; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

/* 数据新鲜度：份额滞后于日线时显式标出，不能让「没数据」看起来像「没异动」 */
.note-lag { color: var(--warn); }
.note-ok { color: var(--muted); }

/* ---------- cards ---------- */
.cards { display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 315px); overflow: auto; }
.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--panel-2);
  cursor: pointer;
  /* 卡片统一高度，底部对齐：名称长短、副标题有无都不再让卡片高低不齐 */
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.card:hover { border-color: #35507a; }
.card .head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
/* 名称与副标题都单行省略：换行会让卡片高度不一致，底部就对不齐了 */
.card .title {
  font-size: 13px; font-weight: 600; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card > .tiny {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .reason { color: #b7c6dc; font-size: 12px; line-height: 1.6; }
.card .reason li { margin: 2px 0; }
.card ul { margin: 6px 0 0; padding-left: 16px; }
.card .foot { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card .foot button { padding: 4px 9px; font-size: 12px; }

.state {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
  color: var(--muted);
}
.state.LOGIC_VALID, .state.ENTER_CANDIDATE { color: #7fd6ff; border-color: #1e4b66; background: #0e2433; }
.state.RISK_RISING, .state.TRIGGERED_REVIEW { color: var(--warn); border-color: #4a3a1c; background: #241b0c; }
.state.THESIS_INVALIDATED { color: var(--bad); border-color: #4a1f24; background: #2a1216; }
.state.UNABLE_TO_EVALUATE { color: #9aa7bb; border-color: #333f52; background: #1a2231; }
.state.WAIT_TRIGGER { color: #a6b8d4; border-color: #2b3a52; background: #16202f; }

/* 业务动作标签：买入 / 卖出 / 持有 / 观察 / 待确认 */
.act {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: .5px;
}
.act-buy { color: #ff8b96; border-color: #5a1f26; background: #2a1216; }
.act-hold { color: #7fd6ff; border-color: #1e4b66; background: #0e2433; }
.act-sell { color: #5fddb0; border-color: #16433a; background: #0d241f; }
.act-watch { color: #a6b8d4; border-color: #2b3a52; background: #16202f; }
.act-pending { color: #9aa7bb; border-color: #333f52; background: #1a2231; }
.act-change { color: #ffb454; font-weight: 600; }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
}
.stat .k { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.stat .v { font-size: 20px; font-family: var(--mono); }
.stat .s { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 7px 8px; border-bottom: 1px solid #1b2740; font-family: var(--mono); font-size: 12px; }
td.txt { font-family: inherit; font-size: 12.5px; }
tr:hover td { background: #142035; }
.num { text-align: right; }

.empty { color: var(--muted); font-size: 12.5px; padding: 18px 4px; line-height: 1.7; }
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; color: var(--muted); }
.mono { font-family: var(--mono); }

#chart-k { width: 100%; height: 500px; }
#chart-heat { width: 100%; height: 190px; }

.ind-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--mono);
  font-size: 26px;
  line-height: 1.1;
  margin-bottom: 4px;
}
.ind-unit { font-size: 12px; color: var(--muted); font-family: inherit; }
.ind-chart { height: 150px; width: 100%; }

.legend-note { font-size: 11.5px; color: var(--muted); margin-top: 8px; line-height: 1.7; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.form-grid label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.form-grid input, .form-grid select { width: 100%; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 11px 16px;
  border-radius: 10px;
  background: #14324a;
  border: 1px solid #2d6a8f;
  color: #d8ecff;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
}
.toast.err { background: #3a1519; border-color: #7a2a32; color: #ffd7da; }

.score-bar { height: 6px; border-radius: 3px; background: #1b2740; overflow: hidden; }
.score-bar > i { display: block; height: 100%; background: linear-gradient(90deg, #4f8cff, #2fd2a3); }

.carousel-ctl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 400;
}
.carousel-ctl button {
  padding: 1px 7px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}
.carousel-ctl button:hover { color: var(--text); border-color: var(--accent); }
.carousel-pager {
  font-family: var(--mono);
  font-size: 11px;
  color: #63799a;
  min-width: 62px;
  text-align: right;
}
.carousel {
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior: contain;
  overflow: hidden;
}
.carousel::-webkit-scrollbar { display: none; }
.carousel-track {
  will-change: transform;
  backface-visibility: hidden;
}

@media (max-width: 1240px) {
  .grid-research { grid-template-columns: 1fr; }
  .grid-two { grid-template-columns: 1fr; }
  .etf-list, .cards { max-height: none; }
}

/* ---------------------------------------------------------------- sentiment */
.sent-hero { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin: 6px 0 14px; }
.sent-temp { min-width: 150px; padding: 12px 18px; border-radius: 10px; border: 1px solid var(--line); background: #0d1728; }
.sent-temp .v { font-size: 44px; line-height: 1.05; font-family: var(--mono); }
.sent-temp .v .unit { font-size: 20px; opacity: .6; margin-left: 2px; }
.sent-temp .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.sent-temp.ok .v { color: #26c281; }
.sent-temp.warn .v { color: #ffb454; }
.sent-temp.bad .v { color: #ff5c6c; }
.sent-hero-text { flex: 1 1 320px; min-width: 260px; }
.sent-meaning { font-size: 13px; line-height: 1.7; color: #c3d1e6; }
.sent-dist { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
#chart-sentiment { width: 100%; height: 320px; margin-top: 6px; }

#chart-idx { width: 100%; height: 620px; margin-top: 8px; }
.inline-select { margin-left: 10px; padding: 4px 10px; border-radius: 6px;
  background: #0d1728; color: #e6edf7; border: 1px solid #24344f; font-size: 12.5px; }
.idx-hero { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin: 8px 0 4px; }
.idx-scores { display: flex; gap: 10px; flex-wrap: wrap; flex: 1 1 340px; }
.idx-score { display: flex; flex-direction: column; gap: 2px; min-width: 84px;
  padding: 8px 12px; border: 1px solid #24344f; border-radius: 8px; background: #0d1728; }
.idx-score .k { font-size: 11px; color: var(--muted); }
.idx-score .v { font-size: 17px; font-family: var(--mono); }
.idx-score .w { font-size: 10.5px; color: #4f8cff; }

/* ---------- 盘面概览（量能 + 板块资金热力图） ---------- */
.bd-top { display: grid; grid-template-columns: 1.25fr repeat(4, 1fr); gap: 10px; margin-bottom: 10px; }
.bd-amount, .bd-asset {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: var(--panel-2);
}
.bd-amount .k, .bd-asset .k { font-size: 12px; color: var(--muted); }
.bd-amount .v { font-size: 26px; font-family: var(--mono); font-weight: 600; margin: 2px 0; }
.bd-amount .v .u { font-size: 13px; margin-left: 3px; color: var(--muted); }
.bd-amount .s { font-size: 12px; }
.bd-asset .v { font-size: 22px; font-family: var(--mono); font-weight: 600; margin: 2px 0; }
.bd-asset .s { font-size: 12px; font-family: var(--mono); }

.bd-capital {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 14px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); font-size: 12px; color: var(--muted);
}
.bd-capital .k { color: var(--fg); font-weight: 600; }
.bd-capital .item b { font-family: var(--mono); }

.board-tabs { display: inline-flex; gap: 4px; margin-left: 8px; }
.btab {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; padding: 2px 9px; font-size: 12px; cursor: pointer;
}
.btab.active { color: var(--fg); border-color: #2d4c7d; background: #16294a; }

.heat-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.heat-block { min-width: 0; }
.heat-title { font-size: 12.5px; color: var(--up); margin-bottom: 6px; }
.heat-title.out { color: var(--down); }
.heat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.heat {
  border-radius: 6px; padding: 10px 6px; text-align: center;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  min-height: 74px;
}
.heat .hn { font-size: 12.5px; color: var(--fg); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heat .hv { font-size: 15px; font-family: var(--mono); color: #fff; font-weight: 600; }
.heat .hv .u { font-size: 10px; margin-left: 1px; opacity: .85; }
.heat .hp { font-size: 11.5px; font-family: var(--mono); color: rgba(255,255,255,.9); }
.heat .hp.up { color: #ffd7db; }
.heat .hp.down { color: #c9f0dd; }

@media (max-width: 1180px) {
  .bd-top { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 980px) {
  .bd-top { grid-template-columns: 1fr 1fr; }
  .heat-wrap { grid-template-columns: 1fr; }
  .heat-grid { grid-template-columns: repeat(3, 1fr); }
}

.sector-heat { width: 100%; height: 520px; }
@media (max-width: 980px) { .sector-heat { height: 420px; } }
