:root {
  --bg: #0b0e14;
  --card: #131722;
  --border: #1e2533;
  --text: #e6eaf2;
  --dim: #8b93a7;
  --up: #f0483e;      /* 红=放量/涨 */
  --down: #1fb86c;    /* 绿=缩量/跌 */
  --accent: #3b82f6;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }

#app { max-width: 640px; margin: 0 auto; padding: 12px 14px 30px; }

/* ---------- header ---------- */
header { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.hd-top { display: flex; justify-content: space-between; align-items: center; }
.hd-top h1 { font-size: 19px; font-weight: 700; letter-spacing: 0.5px; }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 20px; background: var(--card); color: var(--dim); border: 1px solid var(--border); }
.badge.live { color: var(--down); border-color: rgba(31,184,108,.4); }
.badge.warn { color: #f5a524; border-color: rgba(245,165,36,.4); }
.hd-sub { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--down); display: inline-block; }
.dot.off { background: var(--dim); }
.caliber { margin-left: auto; font-size: 11px; padding: 2px 8px; border-radius: 4px; background: rgba(59,130,246,.12); color: var(--accent); }

/* ---------- hero ---------- */
.hero { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 18px 14px; margin-bottom: 12px; }
.hero-label { font-size: 13px; color: var(--dim); margin-bottom: 4px; }
.hero-num { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; line-height: 1.15; }
.hero-num .unit { font-size: 17px; font-weight: 600; color: var(--dim); margin-left: 6px; }
.hero-delta { margin-top: 10px; display: flex; align-items: center; gap: 8px; }
.d-label { font-size: 13px; color: var(--dim); }
.d-val { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.d-arrow { font-size: 16px; }
.up { color: var(--up); }
.down { color: var(--down); }
.hero-compare { margin-top: 6px; font-size: 12px; color: var(--dim); }
.hero-compare b { color: var(--text); font-weight: 600; }
.warn { color: var(--warn, #e0a020); }
.hero-warn { margin-top: 8px; font-size: 12px; color: var(--warn, #e0a020); background: rgba(224,160,32,.10); border: 1px solid rgba(224,160,32,.35); border-radius: 8px; padding: 6px 10px; }
.mk-delta.warn { color: var(--warn, #e0a020); }

/* ---------- momentum ---------- */
.momentum { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; overflow-x: auto; }
.mom-item { flex: 1; min-width: 72px; text-align: center; }
.mom-label { font-size: 11px; color: var(--dim); margin-bottom: 3px; }
.mom-val { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mom-trend { flex: 1.3; text-align: right; font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }

/* ---------- charts ---------- */
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px 8px 4px; margin-bottom: 12px; }
.chart-title { font-size: 13px; color: var(--text); font-weight: 600; padding: 0 8px 4px; }
.unit2 { font-size: 11px; color: var(--dim); font-weight: 400; }
.chart { width: 100%; height: 220px; position: relative; }
.chart-err { color: #f5a524; font-size: 12px; text-align: center; padding: 20px 10px; }
.lwc-legend {
  position: absolute; top: 4px; left: 8px; z-index: 5;
  font-size: 11px; color: var(--dim); pointer-events: none;
  background: rgba(11,14,20,.55); padding: 2px 6px; border-radius: 4px;
  white-space: nowrap; max-width: 96%; overflow: hidden;
}

/* ---------- markets ---------- */
.markets { display: flex; gap: 8px; margin-bottom: 12px; }
.mk { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 10px; text-align: center; }
.mk-name { font-size: 12px; color: var(--dim); margin-bottom: 5px; }
.mk-cur { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mk-delta { font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- projection ---------- */
.proj { display: flex; gap: 8px; margin-bottom: 14px; }
.proj-item { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; text-align: center; }
.proj-label { font-size: 11px; color: var(--dim); margin-bottom: 5px; }
.proj-val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.proj-val .unit { font-size: 12px; color: var(--dim); }

/* ---------- footer ---------- */
footer { text-align: center; color: var(--dim); font-size: 11px; line-height: 1.7; padding-top: 4px; }
#stale-line { font-size: 12px; margin-bottom: 4px; }
#stale-line.warn { color: #f5a524; }
.foot-note { opacity: .75; }

/* ---------- TD 双九 ---------- */
.td-card { margin-top: 2px; padding-bottom: 10px; }
.chart-title-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 6px; }
.chart-title-row .chart-title { flex: 1 1 100%; }
.chart-controls { display: flex; flex: 1 1 100%; flex-direction: column; align-items: stretch; gap: 5px; min-width: 0; }
.index-switch, .timeframe-switch { display: inline-flex; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: rgba(255,255,255,.03); }
.index-switch { align-self: flex-end; }
.timeframe-switch { flex: 1 1 100%; width: 100%; box-sizing: border-box; justify-content: space-between; }
.chart-title-row > .timeframe-switch { flex-basis: 100%; }
.index-tab, .timeframe-tab { border: 0; border-radius: 6px; padding: 5px 8px; background: transparent; color: var(--dim); font-size: 11px; line-height: 1.2; cursor: pointer; white-space: nowrap; }
.timeframe-tab { flex: 1 1 auto; padding-left: 3px; padding-right: 3px; font-size: 10px; }
.index-tab.active, .timeframe-tab.active { background: var(--accent); color: #fff; box-shadow: 0 1px 5px rgba(59,130,246,.35); }
.index-tab:focus-visible, .timeframe-tab:focus-visible { outline: 2px solid #60a5fa; outline-offset: 1px; }
.chart-td { height: 300px; }
.td-key { display: flex; flex-wrap: wrap; gap: 7px 12px; padding: 2px 8px 6px; color: var(--dim); font-size: 10px; }
.td-key span { display: inline-flex; align-items: center; gap: 4px; }
.key-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.key-dot.one { background: #f59e0b; }
.key-dot.five { background: #a78bfa; }
.key-dot.both { background: #ff4d8d; box-shadow: 0 0 5px rgba(255,77,141,.8); }
.td-note { color: var(--dim); font-size: 10px; line-height: 1.5; padding: 3px 8px 0; }

/* ---------- 动态自选卡片 ---------- */
.watchlist-section { margin-top: 2px; }
.watchlist-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 2px 10px; }
.watchlist-heading h2 { font-size: 16px; line-height: 1.3; }
.watchlist-heading span { color: var(--dim); font-size: 10px; }
.add-stock-card { border: 1px solid rgba(59,130,246,.55); border-radius: 8px; padding: 7px 11px; background: rgba(59,130,246,.12); color: #8bb8ff; font-size: 12px; cursor: pointer; white-space: nowrap; }
.watchlist-empty { color: var(--dim); text-align: center; border: 1px dashed var(--border); border-radius: 12px; padding: 25px 10px; margin-bottom: 12px; font-size: 12px; }
.stock-card { padding-bottom: 10px; transition: border-color .2s, opacity .2s, transform .2s; }
.stock-card.pinned { border-color: rgba(59,130,246,.58); box-shadow: 0 0 0 1px rgba(59,130,246,.08); }
.stock-card.dragging { opacity: .76; transform: scale(.99); border-color: #60a5fa; z-index: 20; }
.stock-card.collapsed { padding-bottom: 8px; }
.stock-card.collapsed .stock-card-body { display: none; }
.stock-card-header { align-items: center; }
.drag-handle { width: 36px; min-height: 36px; flex: 0 0 36px; border: 1px solid var(--border); border-radius: 8px; background: rgba(255,255,255,.035); color: var(--dim); font-size: 20px; line-height: 1; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.drag-handle:active, .stock-card.dragging .drag-handle { cursor: grabbing; color: #8bb8ff; }
.drag-handle:focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }
.stock-card-title-line { display: flex; align-items: baseline; flex: 1 1 180px; flex-wrap: wrap; gap: 5px; padding: 0 4px 4px; }
.stock-name { font-size: 14px; font-weight: 650; }
.stock-card-actions { display: flex; flex: 1 1 100%; justify-content: flex-end; flex-wrap: wrap; gap: 6px; padding: 0 4px; }
.stock-action { min-height: 34px; border: 1px solid var(--border); border-radius: 7px; padding: 5px 9px; background: rgba(255,255,255,.03); color: var(--dim); font-size: 11px; cursor: pointer; }
.stock-action.pin[aria-pressed="true"] { color: #8bb8ff; border-color: rgba(59,130,246,.55); background: rgba(59,130,246,.12); }
.stock-action.delete { color: #f58b84; border-color: rgba(240,72,62,.3); }
.collection-status { margin: 3px 8px 7px; padding: 6px 8px; border-radius: 7px; background: rgba(31,184,108,.08); color: #7dd3a8; font-size: 10px; line-height: 1.5; }
.collection-status.warning { background: rgba(245,165,36,.11); color: #f5bd66; }
.status-state { font-weight: 700; }
.backfill-progress { margin: 5px 8px; color: var(--dim); font-size: 9px; line-height: 1.7; overflow-wrap: anywhere; }
.td-alert-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 7px 8px 3px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: rgba(255,255,255,.025); color: var(--dim); font-size: 11px; }
.td-alert-controls label { display: inline-flex; align-items: center; gap: 5px; }
.td-alert-toggle { accent-color: var(--accent); width: 16px; height: 16px; }
.td-alert-period { border: 1px solid #34405a; border-radius: 6px; padding: 5px 7px; background: #0b0e14; color: var(--text); font-size: 11px; }
.chart-stock { height: 340px; }
.key-dot.stock-top { background: var(--up); }
.key-dot.stock-bottom { background: var(--down); }

.stock-picker[hidden] { display: none; }
.stock-picker { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.stock-picker-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.68); }
.stock-picker-panel { position: relative; z-index: 1; width: min(640px, 100%); max-height: 78vh; overflow: auto; border: 1px solid var(--border); border-radius: 16px 16px 0 0; padding: 16px 14px calc(18px + env(safe-area-inset-bottom)); background: #131722; box-shadow: 0 -8px 30px rgba(0,0,0,.4); }
.stock-picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stock-picker-head h2 { font-size: 17px; }
.picker-close { width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(255,255,255,.07); color: var(--text); font-size: 23px; line-height: 1; cursor: pointer; }
#stock-search-input { width: 100%; border: 1px solid #34405a; border-radius: 10px; padding: 11px 12px; background: #0b0e14; color: var(--text); font-size: 15px; outline: none; }
#stock-search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59,130,246,.18); }
.stock-search-status { color: var(--dim); font-size: 11px; padding: 10px 2px 6px; }
.search-result { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 0; border-top: 1px solid var(--border); padding: 12px 4px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.search-result-name { font-size: 14px; font-weight: 600; }
.search-result-code { color: var(--dim); font-size: 12px; }
.search-result-market { color: #8bb8ff; font-size: 11px; }
.search-result:disabled { opacity: .45; cursor: wait; }

@media (min-width: 641px) {
  .stock-picker { align-items: center; padding: 20px; }
  .stock-picker-panel { border-radius: 16px; }
}

/* 上半导体、下银行，共用周期 */
.macd-card { padding-bottom: 16px; }
.macd-updated { font-size: 11px; color: var(--dim); line-height: 1.6; padding: 3px 4px; }
.macd-tabs { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; padding: 4px; margin: 10px 0 4px; border: 1px solid var(--border); border-radius: 10px; background: #191e29; }
.macd-tabs button { flex: 1; min-width: 0; border: 0; border-radius: 7px; padding: 9px 2px; background: transparent; color: var(--dim); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
.macd-tabs button.active { background: #3b82f6; color: white; }
.macd-tabs button:focus-visible { outline: 2px solid #8bb9ff; outline-offset: 2px; }
.industry-panel { padding-top: 12px; }
.industry-panel + .industry-panel { border-top: 1px solid #303849; margin-top: 12px; padding-top: 15px; }
.industry-title { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.industry-title h3 { font-size: 14px; font-weight: 600; }
.industry-state { font-size: 11px; }
.industry-chart { width: 100%; height: 340px; }
.industry-summary { min-height: 42px; padding: 4px; color: #b5bdcc; font-size: 11px; line-height: 1.7; font-variant-numeric: tabular-nums; }
.bank-indicator-key { display: flex; flex-wrap: wrap; gap: 16px; padding: 12px 4px 8px; font-size: 12px; }
.bank-dif { color: #e9d38a; }
.bank-dea { color: #ad93ed; }
.macd-note { padding: 0 4px; font-size: 11px; color: var(--dim); line-height: 1.7; }
@media (max-width: 600px) {
  .industry-chart { height: 320px; }
  .industry-summary { min-height: 58px; }
  .macd-tabs button { font-size: 11px; }
}

.industry-alert-head { display: flex; justify-content: space-between; gap: 8px; padding: 12px 4px 8px; color: var(--text); font-size: 12px; }
.industry-alert-status { color: var(--dim); font-size: 11px; }
.industry-alert-switches { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 0 3px 4px; }
.industry-alert-switches label { display: flex; align-items: center; justify-content: space-between; gap: 3px; padding: 8px 7px; color: var(--dim); font-size: 11px; background: #191e29; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.industry-alert-switches label:has(input:checked) { color: #dbeafe; border-color: #365c96; background: #19263b; }
.industry-alert-switches input { appearance: none; -webkit-appearance: none; width: 25px; height: 15px; flex: 0 0 25px; border-radius: 10px; background: #465065; position: relative; cursor: pointer; }
.industry-alert-switches input::after { content: ''; position: absolute; width: 11px; height: 11px; border-radius: 50%; top: 2px; left: 2px; background: #e6eaf2; transition: transform .12s; }
.industry-alert-switches input:checked { background: #3b82f6; }
.industry-alert-switches input:checked::after { transform: translateX(10px); }
.industry-alert-switches input:focus-visible { outline: 2px solid #8bb9ff; outline-offset: 3px; }
.industry-alert-switches input:disabled { opacity: .4; cursor: wait; }
@media (max-width: 600px) { .macd-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* 双图随可用屏幕高度压紧；提醒集中在底部，仅银行可控。 */
#macd-industries { display: flex; flex-direction: column; height: calc(100vh - 24px); height: calc(100dvh - 24px); min-height: 540px; max-height: 820px; padding: 8px 6px 6px; }
#macd-industries > .chart-title { flex: 0 0 auto; padding: 0 4px 2px; font-size: 12px; }
#macd-industries .macd-tabs { flex: 0 0 auto; margin: 4px 0 0; padding: 3px; gap: 2px; }
#macd-industries .macd-tabs button { padding: 5px 1px; font-size: 11px; }
#macd-industries .industry-panel { display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; padding-top: 4px; }
#macd-industries .industry-panel + .industry-panel { margin-top: 4px; padding-top: 5px; }
#macd-industries .industry-title { flex: 0 0 auto; line-height: 17px; }
#macd-industries .industry-title h3 { font-size: 12px; }
#macd-industries .industry-state { font-size: 10px; }
#macd-industries .macd-updated { display: none; }
#macd-industries .industry-summary { flex: 0 0 auto; min-height: 0; padding: 1px 4px; font-size: 10px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#macd-industries .industry-chart { flex: 1 1 0; height: auto; min-height: 110px; }
#bank-alert-controls { flex: 0 0 auto; }
#macd-industries .industry-alert-head { padding: 5px 4px 3px; font-size: 11px; }
#macd-industries .industry-alert-status { font-size: 10px; }
#macd-industries .industry-alert-switches { gap: 3px; padding-bottom: 0; }
#macd-industries .industry-alert-switches label { padding: 4px 5px; font-size: 10px; border-radius: 6px; }
#macd-industries .bank-indicator-key { flex: 0 0 auto; gap: 12px; padding: 4px 4px 2px; font-size: 10px; line-height: 14px; }
#macd-industries .macd-note { flex: 0 0 auto; font-size: 9px; line-height: 13px; }

.industry-history-bar { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 3px 4px 1px; font-size: 9px; color: var(--dim); }
.industry-history-bar > div { display: flex; gap: 3px; }
.industry-history-bar button { border: 1px solid #303b50; border-radius: 4px; padding: 2px 5px; background: transparent; color: var(--dim); font: inherit; cursor: pointer; }
.industry-history-bar button.active { background: #233b60; border-color: #3b82f6; color: #dbeafe; }

.tracking-page .watchlist-heading { margin: 12px 2px; }
.tracking-page #watchlist-count { font-size: 12px; color: var(--dim); font-weight: 400; }
.tracking-page .watchlist-heading > div > span { display: block; margin-top: 5px; line-height: 1.5; }
.tracking-page .chart-stock { height: clamp(240px, 40vh, 360px); }
