:root {
  --bg: #0b0e14;
  --bg-soft: #121722;
  --bg-card: #161c28;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8edf7;
  --text-dim: rgba(232, 237, 247, 0.55);
  --up: #f6465d;
  --down: #12b886;
  --flat: #97a3b6;
  --accent: #4dabf7;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* 关键：样式里给元素写了 display 会盖掉浏览器默认的 [hidden] { display: none }，
   导致 hidden 属性失效（弹层遮罩曾因此一直盖在页面上、吃掉所有点击）。 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI',
    sans-serif;
  font-size: 15px;
  overscroll-behavior-y: none;
  display: flex;
  flex-direction: column;
}

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

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

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: linear-gradient(180deg, rgba(22, 28, 40, 0.92), rgba(11, 14, 20, 0.6));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand h1 {
  font-size: 17px;
  margin: 0;
  letter-spacing: 2px;
  font-weight: 600;
}

.brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--flat);
  box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  transition: background 0.3s;
}

.brand-dot.live {
  background: var(--down);
  animation: pulse 2.4s infinite;
}

.brand-dot.error {
  background: var(--up);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(18, 184, 134, 0.5);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(18, 184, 134, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(18, 184, 134, 0);
  }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-dim);
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 19px;
  line-height: 1;
  padding: 7px 9px;
  border-radius: 10px;
  cursor: pointer;
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.07);
}

/* ---------- 自选列表 ---------- */

.view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(104px + var(--safe-bottom));
}

.watchlist {
  list-style: none;
  margin: 0;
  padding: 8px 12px 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.08s ease;
}

.row:active {
  transform: scale(0.985);
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-code {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  letter-spacing: 0.5px;
}

.row-price {
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 86px;
}

.row-price .p {
  font-size: 17px;
  font-weight: 600;
}

.row-price .c {
  font-size: 12px;
  margin-top: 3px;
}

.row-flag {
  font-size: 12px;
  color: var(--accent);
  opacity: 0.9;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 70px 30px;
  line-height: 1.8;
}

.empty-sub {
  font-size: 12.5px;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(62px + var(--safe-bottom));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(160deg, #3b82f6, #2563eb);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.42);
  cursor: pointer;
  z-index: 15;
}

.fab:active {
  transform: scale(0.94);
}

/* ---------- 详情 ---------- */

.detail-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 0;
}

.detail-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
}

.detail-title .code {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0.6px;
  margin-top: 2px;
}

/* 价格靠左，行情数据（今开昨收那一堆）跟在右边用小字排两列 */
.detail-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 14px 2px;
}

.detail-left {
  flex: none;
  min-width: 0;
}

.detail-quote {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.detail-quote .price {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.detail-quote .delta {
  font-size: 12.5px;
}

.quote-inline {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 8px;
  margin: 0;
  padding-top: 3px;
}

/* 今开/昨收/最高/最低：跟在股价下面，宽度和上面那行对齐 */
.quote-under {
  flex: none;
  width: 100%;
  padding-top: 5px;
}

.quote-inline .cell {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1px 4px;
  min-width: 0;
  font-size: 11px;
  line-height: 1.35;
}

.quote-inline .k {
  color: var(--text-dim);
  white-space: nowrap;
}

.quote-inline .v {
  margin-left: auto;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.periods {
  display: flex;
  gap: 6px;
  padding: 10px 14px 4px;
}

.periods button {
  flex: 1;
  padding: 7px 0;
  font-size: 13px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
}

.periods button.active {
  color: var(--text);
  background: rgba(77, 171, 247, 0.16);
  border-color: rgba(77, 171, 247, 0.45);
}

.indicator-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 8px 14px 0;
}

.chip-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.chip-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-right: 1px;
}

.chip-group button {
  padding: 4px 9px;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

.chip-group button.active {
  color: var(--text);
  background: rgba(77, 171, 247, 0.16);
  border-color: rgba(77, 171, 247, 0.45);
}

.chip-group button.is-dim {
  opacity: 0.45;
}

.scan-conditions {
  flex-wrap: wrap;
  gap: 6px;
}

.scan-conditions button {
  padding: 6px 10px;
  font-size: 12px;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row .field {
  flex: 1;
  min-width: 0;
}

.link {
  color: var(--accent);
  cursor: pointer;
}

.chart-wrap {
  position: relative;
  margin: 8px 8px 0;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  overflow: hidden;
}

#chart {
  display: block;
  width: 100%;
  height: 330px;
  touch-action: none;
}

/* ---------- 选股 ---------- */

.chips {
  display: flex;
  gap: 6px;
  padding: 10px 12px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chips button {
  flex: none;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
}

.chips button.active {
  color: var(--text);
  background: rgba(77, 171, 247, 0.16);
  border-color: rgba(77, 171, 247, 0.45);
}

.rank-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 12px 0;
}

.rank-toolbar .mini {
  flex: 1;
  padding: 8px 0;
  font-size: 12.5px;
}

.rank-summary {
  padding: 10px 14px 4px;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.6;
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 4px 12px 0;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.rank-row:active {
  transform: scale(0.99);
}

.rank-index {
  width: 20px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.rank-main {
  flex: 1;
  min-width: 0;
}

.rank-name {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex: none;
  min-width: 76px;
}

.rank-right .p {
  font-size: 15px;
  font-weight: 600;
}

.rank-right .c {
  font-size: 11.5px;
  margin-top: 3px;
}

.hit-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.hit-tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(77, 171, 247, 0.14);
  color: var(--accent);
}

/* ---------- 底部标签栏 ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  padding: 6px 0 calc(6px + var(--safe-bottom));
  background: rgba(18, 23, 34, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.tabbar button {
  flex: 1;
  padding: 7px 0;
  font-size: 12.5px;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.tabbar button.active {
  color: var(--accent);
  font-weight: 600;
}

.chart-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-dim);
  pointer-events: none;
  background: rgba(11, 14, 20, 0.72);
}

.chart-state[hidden] {
  display: none;
}

/* ---------- 弹层 ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
}

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: fade 0.18s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg-soft);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + var(--safe-bottom));
  animation: slide-up 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
}

.sheet-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}

.sheet-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 0 0 14px;
  line-height: 1.6;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

input,
select {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  font-family: inherit;
}

input:focus,
select:focus {
  border-color: rgba(77, 171, 247, 0.6);
}

.btn {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(160deg, #3b82f6, #2563eb);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
}

.btn:active {
  opacity: 0.86;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.btn.danger {
  background: rgba(246, 70, 93, 0.16);
  color: var(--up);
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.rule-list {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
}

.search-list {
  list-style: none;
  padding: 0;
  margin: 0 0 6px;
  max-height: 46vh;
  overflow-y: auto;
}

.search-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 12px;
  margin-bottom: 6px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
}

.search-item:active {
  background: rgba(255, 255, 255, 0.06);
}

.si-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.si-badge {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
}

.search-item.is-added .si-name {
  color: var(--text-dim);
}

.si-meta {
  font-size: 11.5px;
  color: var(--text-dim);
}

.search-empty {
  padding: 14px 4px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.chip-canvas-wrap {
  margin: 10px 0 0;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  overflow: hidden;
}

/* 筹码面板：只放切换按钮，贴在筹码图正下方那一列；数字由图表画在画布里的信息带 */
.chip-panel {
  display: flex;
  gap: 4px;
  /* margin-left:auto 才能把整块推到右边，右侧留白由 JS 按价格轴宽度设置 */
  margin: 6px 10px 0 auto;
}

.chip-range {
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 4px;
}

.chip-range button {
  padding: 3px 6px;
  font-size: 10.5px;
}

.rule {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 11px;
  margin-bottom: 8px;
}

.rule-body {
  flex: 1;
  min-width: 0;
}

.rule-title {
  font-size: 14px;
}

.rule-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 3px;
}

.rule-actions {
  display: flex;
  gap: 4px;
}

.mini {
  padding: 6px 9px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}

.mini[data-on='1'] {
  color: var(--down);
  border-color: rgba(18, 184, 134, 0.4);
}

.mini.del {
  color: var(--up);
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(30, 38, 54, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 11px;
  max-width: 84vw;
  text-align: center;
  z-index: 60;
  animation: fade 0.16s ease;
}

.toast[hidden] {
  display: none;
}

.boot-error {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(var(--safe-top) + 58px);
  z-index: 90;
  padding: 12px 14px;
  background: rgba(246, 70, 93, 0.14);
  border: 1px solid rgba(246, 70, 93, 0.4);
  border-radius: 12px;
  color: #ffd7dd;
  font-size: 13px;
  line-height: 1.6;
}
