:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #10151c;
  --panel-2: #151b24;
  --line: #263241;
  --line-soft: rgba(84, 103, 128, 0.34);
  --text: #eef3f7;
  --muted: #8f9cab;
  --green: #00c070;
  --red: #ff4d5d;
  --amber: #f5b642;
  --cyan: #48c7ff;
  --orange: #ff8a3d;
  --blue: #4c7dff;
  --font: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(72, 199, 255, 0.08), transparent 32%),
    radial-gradient(circle at 88% 12%, rgba(255, 138, 61, 0.1), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

button,
input {
  font: inherit;
}

.terminal-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr) 306px;
  gap: 12px;
  height: 100vh;
  padding: 12px;
}

.left-rail,
.right-rail {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  /* 屏幕矮时侧栏内部滚动; 否则内容被 body 的 overflow:hidden 裁掉且无法查看 */
  overflow-y: auto;
  scrollbar-width: thin;
}

.brand-block,
.panel,
.chart-desk {
  border: 1px solid var(--line);
  background: rgba(16, 21, 28, 0.9);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

.brand-block {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 92px;
  padding: 16px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(72, 199, 255, 0.5);
  background: linear-gradient(145deg, rgba(72, 199, 255, 0.22), rgba(245, 182, 66, 0.12));
  color: #dff6ff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  letter-spacing: 0;
}

.brand-block p,
.meta-line,
.panel label,
.quote-strip,
.structure-text,
.signal-list {
  color: var(--muted);
}

.brand-block p {
  margin-top: 6px;
  font-size: 12px;
}

.main-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.main-nav a {
  border: 1px solid var(--line-soft);
  background: #0a1017;
  color: var(--muted);
  padding: 9px 10px;
  text-align: center;
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
}

.main-nav a.active,
.main-nav a:hover {
  border-color: var(--cyan);
  background: #0d2432;
  color: var(--text);
}

.panel {
  padding: 14px;
}

.panel-title {
  margin-bottom: 12px;
  color: #d7e7f4;
  font-size: 13px;
  font-weight: 800;
}

.command-panel label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
}

input[type="text"],
#codeInput {
  width: 100%;
  border: 1px solid #344354;
  background: #080c12;
  color: var(--text);
  outline: none;
  padding: 11px 12px;
}

#codeInput:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(72, 199, 255, 0.18);
}

button {
  border: 1px solid rgba(72, 199, 255, 0.7);
  background: #122638;
  color: #effaff;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  background: #17344e;
}

.period-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin-top: 9px;
  border: 1px solid var(--line);
  background: var(--line);
}

.period-tabs button {
  min-height: 34px;
  border: 0;
  background: #0b1118;
  color: #a9b8c7;
  font-size: 12px;
}

.period-tabs button.active {
  background: #172b3b;
  color: #effaff;
  box-shadow: inset 0 -2px 0 var(--cyan);
}

.watch-button {
  width: 100%;
  margin-top: 9px;
  padding: 9px 10px;
  border-color: rgba(245, 182, 66, 0.72);
  background: #1b1a11;
  color: #ffe2a1;
}

.watch-button.active {
  border-color: rgba(255, 77, 93, 0.78);
  background: #241216;
  color: #ffc6cc;
}

.update-button {
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
}

.update-button {
  border-color: rgba(72, 199, 255, 0.68);
  background: #101c27;
  color: #dff6ff;
}

.cleanup-button {
  min-width: 90px;
  margin: 0;
  padding: 8px 12px;
  border-color: rgba(255, 190, 92, 0.62);
  background: #21180c;
  color: #ffe2a1;
  white-space: nowrap;
}

.update-button:disabled,
.cleanup-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.update-status {
  min-height: 18px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.watch-header {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  color: #d7e7f4;
  font-size: 13px;
  font-weight: 800;
}

.watch-header small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.quick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.quick-list button {
  display: grid;
  gap: 2px;
  min-width: 66px;
  padding: 7px 8px;
  border-color: #303c4b;
  background: #0b1118;
  color: #b8c7d8;
  font-size: 12px;
  text-align: left;
}

.quick-list button.active {
  border-color: var(--amber);
  color: #fff0cc;
}

.quick-list button strong {
  color: #e6f5ff;
  font-size: 12px;
  line-height: 1.1;
}

.quick-list button span {
  max-width: 72px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-watch {
  width: 100%;
  border: 1px dashed var(--line);
  color: var(--muted);
  padding: 12px;
  font-size: 12px;
  line-height: 1.6;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 10px 0;
  font-size: 13px;
}

.toggle input {
  accent-color: var(--cyan);
}

.range-row {
  display: grid;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
}

.chart-desk {
  display: grid;
  grid-template-rows: 82px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.desk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(72, 199, 255, 0.1), rgba(245, 182, 66, 0.05));
}

.desk-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.meta-line {
  margin-bottom: 5px;
  font-size: 12px;
}

h2 {
  font-size: 24px;
  letter-spacing: 0;
}

.quote-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  font-size: 12px;
}

.quote-strip span {
  border: 1px solid var(--line);
  background: rgba(7, 9, 13, 0.62);
  padding: 8px 10px;
}

.chart-panel {
  display: grid;
  grid-template-rows: minmax(0, 3.2fr) minmax(150px, 1fr);
  min-height: 0;
  padding: 12px;
  gap: 10px;
}

canvas {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  cursor: grab;
  touch-action: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    #080c12;
  background-size: 54px 42px;
}

canvas.dragging {
  cursor: grabbing;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stats-grid div {
  border: 1px solid var(--line-soft);
  background: #0a1017;
  padding: 12px;
}

.stats-grid span {
  display: block;
  color: #f6fbff;
  font-size: 22px;
  font-weight: 800;
}

.stats-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.structure-text {
  min-height: 108px;
  font-size: 13px;
  line-height: 1.8;
}

.signal-panel {
  min-height: 180px;   /* 压到比这更矮就让侧栏滚动, 而不是把列表挤没 */
  flex: 1;
}

.signal-list {
  display: grid;
  max-height: 100%;
  overflow: auto;
  gap: 8px;
  padding-right: 2px;
  font-size: 12px;
}

.signal-card {
  border-left: 3px solid var(--line);
  background: #0a1017;
  padding: 9px 10px;
}

.signal-card.buy {
  border-left-color: var(--red);
}

.signal-card.sell {
  border-left-color: var(--green);
}

.signal-card strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--text);
}

.signal-card strong em {
  border: 1px solid rgba(245, 182, 66, 0.72);
  background: rgba(245, 182, 66, 0.12);
  color: #ffd47b;
  padding: 2px 5px;
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.signal-card.resonance {
  background: linear-gradient(90deg, rgba(245, 182, 66, 0.11), #0a1017 52%);
}

.error-text {
  color: #ff7b86;
}

.screener-desk {
  min-width: 0;
}

.board-list {
  display: grid;
  align-content: start;
  max-height: 100%;
  gap: 6px;
  overflow: auto;
  padding-right: 3px;
}

.board-card {
  border: 1px solid var(--line-soft);
  background: #0a1017;
  color: var(--text);
  padding: 7px 9px;
  text-align: left;
  cursor: pointer;
}

.board-card strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

.board-card em {
  border: 1px solid var(--line-soft);
  color: var(--muted);
  padding: 2px 5px;
  font-size: 11px;
  font-style: normal;
}

.board-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.board-card.selected {
  border-color: var(--cyan);
  background: rgba(72, 199, 255, 0.11);
}

.selected-board-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.selected-board-pill {
  border: 1px solid var(--amber);
  background: rgba(245, 182, 66, 0.1);
  color: #ffd47b;
  padding: 7px 9px;
  font-weight: 800;
  cursor: pointer;
}

.settings-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.settings-input {
  width: 100%;
  border: 1px solid #344354;
  background: #080c12;
  color: var(--text);
  padding: 10px;
  font-weight: 800;
}

.results-table-wrap {
  height: 100%;
  overflow: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.results-table th,
.results-table td {
  border-bottom: 1px solid var(--line-soft);
  padding: 9px 8px;
  text-align: left;
  white-space: nowrap;
}

.results-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #101820;
  color: var(--muted);
  font-weight: 800;
}

.results-table tbody tr {
  cursor: pointer;
}

.results-table tbody tr:hover,
.results-table tbody tr.active-row {
  background: rgba(72, 199, 255, 0.1);
}

.score-cell {
  color: #ffd47b;
  font-weight: 900;
}

.risk-cell {
  color: #ff7b86;
  font-weight: 900;
}

.empty-cell,
.empty-watch {
  color: var(--muted);
  padding: 12px;
}

.secondary-action {
  margin-top: 12px;
}

/* ---- 选股工作台: 两阶段流水线 ---- */

.screener-shell {
  grid-template-columns: 330px minmax(820px, 1fr) 330px;
}

.screener-stack {
  display: grid;
  grid-template-rows: minmax(150px, 0.85fr) minmax(0, 2fr);
  gap: 12px;
  min-height: 0;
  padding: 12px;
}

.stage-panel,
.results-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.title-tag {
  border: 1px solid var(--line-soft);
  background: #0a1017;
  color: var(--muted);
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 400;
}

.title-tag.warn-tag {
  border-color: rgba(245, 182, 66, 0.7);
  color: #ffd47b;
}

.hint {
  margin: 6px 0 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.hint b,
.legend b {
  color: #d7e7f4;
}

.hint code {
  color: #ffd47b;
  font-size: 11px;
}

.callout {
  margin-bottom: 10px;
  border-left: 3px solid var(--amber);
  background: rgba(245, 182, 66, 0.07);
  color: #cdb98d;
  padding: 9px 10px;
  font-size: 11px;
  line-height: 1.7;
}

.callout.warn b {
  color: #ffd47b;
}

.board-picker-panel {
  display: grid;
  grid-template-rows: auto auto auto auto auto auto minmax(0, 1fr) auto;
  min-height: 380px;   /* 保证搜索框/标签/列表可见; 屏幕矮时靠侧栏滚动 */
  flex: 1;
  overflow: hidden;
}

.pill-label {
  width: 100%;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
}

.selected-board-list:not(:empty) {
  margin: 10px 0 4px;
}

.board-card.hit {
  border-color: rgba(245, 182, 66, 0.62);
}

.stats-grid.four-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stats-grid.four-row span {
  font-size: 19px;
}

.legend {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.85;
}

.legend hr {
  margin: 8px 0;
  border: 0;
  border-top: 1px solid var(--line-soft);
}

.good-cell {
  color: #6fe0a8;
}

.muted-cell {
  color: var(--muted);
}

.board-cell {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-table tbody tr:has(.empty-cell) {
  cursor: default;
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .terminal-shell {
    grid-template-columns: 260px minmax(720px, 1fr);
    height: auto;
    min-height: 100vh;
  }

  .right-rail {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .signal-panel {
    min-height: 220px;
  }
}

@media (max-width: 860px) {
  .terminal-shell,
  .right-rail {
    grid-template-columns: 1fr;
  }

  .chart-desk {
    min-height: 720px;
  }
}

/* ---------------- 登录浮层 + 用户徽标(auth.js 注入) ---------------- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 10, 0.86);
  backdrop-filter: blur(4px);
}
.login-overlay[hidden] {
  display: none;
}
.login-card {
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 30px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.login-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--cyan);
  text-align: center;
  margin-bottom: 6px;
}
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.login-card input {
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}
.login-card input:focus {
  border-color: var(--cyan);
}
.login-card button {
  margin-top: 6px;
  padding: 11px;
  background: var(--cyan);
  color: #04202e;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.login-card button:hover {
  filter: brightness(1.08);
}
.login-error {
  min-height: 18px;
  font-size: 13px;
  color: var(--red);
  text-align: center;
}
.user-badge {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 14px;
  background: rgba(16, 21, 28, 0.9);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}
.user-badge[hidden] {
  display: none;
}
.user-badge #userName {
  color: var(--text);
  font-weight: 600;
}
.user-badge #logoutBtn {
  padding: 4px 10px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.user-badge #logoutBtn:hover {
  color: var(--red);
  border-color: var(--red);
}
