:root {
  --bg: #0e1117;
  --panel: #141a23;
  --panel-2: #1a2230;
  --border: #242d3c;
  --text: #d9e1ee;
  --muted: #8493a8;
  --up: #ef232a;
  --down: #14b143;
  --gold: #f0b90b;
  --blue: #4da3ff;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------------- 顶栏 ---------------- */

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #151b26 0%, #11161f 100%);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  user-select: none;
}

.logo {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--gold);
}

.brand .sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
}

.manual {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.field.search { position: relative; }

input, .btn {
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

input {
  padding: 0 10px;
  transition: border-color .15s, background .15s;
}

input::placeholder { color: #5d6b80; }

input:focus {
  border-color: #3d5a80;
  background: #171e29;
}

#codeInput { width: 190px; }

input.date {
  width: 140px;
  color-scheme: dark;
}

.btn {
  padding: 0 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  white-space: nowrap;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: #36465e;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
  opacity: .38;
  cursor: not-allowed;
}

.btn.primary {
  background: #1d3a5c;
  border-color: #2c5a8a;
  color: #cfe6ff;
}

.btn.primary:hover:not(:disabled) {
  background: #244a74;
  border-color: #3773ad;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.strategy-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.strategy-pick select {
  height: 32px;
  max-width: 210px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  padding: 0 6px;
  outline: none;
}

.strategy-pick select:focus { border-color: #3d5a80; }

.reveal-group { display: flex; gap: 6px; }

.reveal { color: #e8d38a; }
.reveal:hover:not(:disabled) { background: #2a2415; border-color: #5c4a1d; }

/* ---------------- 信息栏 ---------------- */

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 14px 6px;
  gap: 8px;
}

.infobar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  min-height: 38px;
}

.title-wrap { min-width: 0; }

#stockTitle {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#stockTitle .code {
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
  margin-left: 6px;
}

#stockTitle .sep, #stockTitle .date {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

#stockTitle .masked { color: #b8c4d8; }

.st-note {
  font-size: 11.5px;
  color: var(--gold);
  margin-top: 2px;
  opacity: .9;
  min-height: 0;
  line-height: 1.3;
}

.badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid #2b3a4f;
  color: #9fb3cd;
  background: #16202c;
  white-space: nowrap;
}

.badge.st {
  color: #ffd666;
  border-color: #6a5318;
  background: #2a2210;
  font-weight: 700;
}

.badge.ok {
  color: #8fd3a8;
  border-color: #28553a;
  background: #12251a;
}

.badge.dim { color: #6f7f95; }

.badge.strategy {
  color: #8fd3ff;
  border-color: #2f5a7a;
  background: #122233;
  font-weight: 600;
}

.chip {
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid #2b3a4f;
  background: #16202c;
  color: #7f8da3;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}

.chip:hover { border-color: #3d5a80; color: #b8c7dd; }

.chip.active {
  color: #12161d;
  background: var(--gold);
  border-color: var(--gold);
  font-weight: 600;
}

.summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.sum {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 12px;
  background: #141c27;
  border: 1px solid #26313f;
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
}

.sum em {
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
}

.sum b { font-weight: 600; }

.sum .buy {
  color: #9fb0c7;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: #1b2532;
  border-radius: 4px;
  padding: 0 4px;
}

/* ---------------- 图表 ---------------- */

.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: radial-gradient(1200px 500px at 50% -10%, #141c28 0%, #0f131a 55%, #0d1117 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#chart {
  width: 100%;
  height: 100%;
  min-height: 320px;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(14, 17, 23, .55);
  backdrop-filter: blur(1px);
  font-size: 13px;
  color: var(--muted);
  z-index: 5;
}

/* 揭晓补数据时只在右下角显示小提示，不遮挡K线 */
.loading.inline {
  inset: auto 14px 30px auto;
  width: max-content;
  height: auto;
  padding: 5px 10px;
  border-radius: 7px;
  background: rgba(17, 23, 32, .92);
  border: 1px solid #2b3a4f;
  backdrop-filter: none;
  font-size: 11px;
  z-index: 6;
}

.loading.inline .spinner {
  width: 12px;
  height: 12px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #2b3a4f;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 底部 ---------------- */

.hint {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 4px;
  font-size: 11.5px;
  color: var(--muted);
}

.hint .keys { color: #58677c; white-space: nowrap; }

/* ---------------- 搜索下拉 ---------------- */

.suggest {
  position: absolute;
  top: 36px;
  left: 0;
  width: 280px;
  max-height: 320px;
  overflow-y: auto;
  background: #171f2b;
  border: 1px solid #2b3a4f;
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55);
  z-index: 20;
  padding: 4px;
}

.suggest[hidden],
.loading[hidden],
.toast[hidden] { display: none; }

.sug-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
}

.sug-item:hover { background: #223044; }

.sug-item .sug-code {
  color: var(--blue);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.sug-item .sug-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sug-item .sug-st {
  font-size: 10px;
  color: #ffd666;
  border: 1px solid #6a5318;
  border-radius: 3px;
  padding: 0 4px;
}

.sug-empty {
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ---------------- Tooltip ---------------- */

.tt { min-width: 200px; font-size: 12px; line-height: 1.65; }
.tt-h { font-weight: 600; margin-bottom: 4px; color: #e8eef8; }
.tt-grid { display: grid; grid-template-columns: 26px 1fr 26px 1fr; gap: 1px 6px; }
.tt-grid span { color: var(--muted); }
.tt-grid b { font-weight: 500; font-variant-numeric: tabular-nums; }
.tt-row { color: var(--muted); margin-top: 2px; }
.tt-row b { font-weight: 500; font-variant-numeric: tabular-nums; }
.tt-ma { margin-top: 4px; padding-top: 4px; border-top: 1px dashed #2a3444; color: #73839a; font-size: 11px; font-variant-numeric: tabular-nums; }
.tt-boll { margin-top: 2px; color: #73839a; font-size: 11px; font-variant-numeric: tabular-nums; }
.tt-st { margin-left: 6px; font-size: 10px; color: #ffd666; border: 1px solid #6a5318; border-radius: 3px; padding: 0 4px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 42px;
  transform: translateX(-50%);
  background: #241a1a;
  border: 1px solid #5b2a2a;
  color: #ffb4b4;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  z-index: 50;
  max-width: 80vw;
}

/* ---------------- 移动端 ---------------- */

@media (max-width: 900px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .brand { width: 100%; }
  .brand .sub { display: none; }
  .manual { flex: 1 1 100%; order: 3; }
  #codeInput { flex: 1 1 auto; width: auto; min-width: 0; }
  input.date { width: 122px; }
  .actions {
    flex: 1 1 100%;
    order: 2;
    margin-left: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .actions .btn { width: 100%; }
  .strategy-pick {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  .strategy-pick select {
    flex: 1;
    max-width: none;
  }
  #btnRandom { grid-column: 1; grid-row: 2; }
  #btnNext { grid-column: 2; grid-row: 2; }
  .reveal-group {
    grid-column: 1 / -1;
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .reveal-group .btn { padding: 0 4px; font-size: 12px; }
  main { padding: 8px 8px 4px; gap: 6px; }
  .infobar {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 6px 10px;
    min-height: 0;
  }
  .title-wrap { grid-column: 1 / -1; }
  .badges { grid-column: 1; }
  #btnBoll { grid-column: 2; justify-self: start; }
  #stockTitle { font-size: 15px; white-space: normal; }
  .summary { grid-column: 1 / -1; margin-left: 0; }
  .hint { font-size: 10.5px; }
  .hint .keys { display: none; }
  .suggest { width: min(280px, 82vw); }
}
