:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e6e8ec;
  --brand: #2563eb;
  --brand-soft: #eaf0ff;
  --up: #e5322d;
  --down: #12a15a;
  --flat: #6b7280;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.04);
  --radius: 14px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1d212a;
    --text: #e8eaed;
    --muted: #9aa1ad;
    --border: #262b35;
    --brand: #6c9bff;
    --brand-soft: #1b2740;
    --shadow: none;
  }
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(64px + var(--safe-bottom));
  background: var(--bg);
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 8px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.topbar-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--flat);
}

.status-dot.live {
  background: var(--up);
  box-shadow: 0 0 0 3px rgba(229, 50, 45, 0.15);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

.switch input {
  display: none;
}

.switch .track {
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background 0.18s ease;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}

.switch input:checked + .track {
  background: var(--brand);
}

.switch input:checked + .track::after {
  transform: translateX(16px);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 16px;
}

.icon-btn:active {
  transform: scale(0.96);
}

/* ---------- 列表 ---------- */
.section {
  padding: 12px 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}

.row:last-child {
  border-bottom: none;
}

.row:active {
  background: var(--surface-2);
}

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

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

.row-code {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.row-right {
  text-align: right;
  flex-shrink: 0;
}

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

.pill {
  display: inline-block;
  min-width: 62px;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.pill.up {
  color: #fff;
  background: var(--up);
}

.pill.down {
  color: #fff;
  background: var(--down);
}

.pill.flat {
  color: var(--muted);
  background: var(--surface-2);
}

.up-text {
  color: var(--up);
}

.down-text {
  color: var(--down);
}

.flat-text {
  color: var(--flat);
}

.stale {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.stale::before {
  content: "延迟 ";
}

.row-del {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  display: none;
  place-items: center;
  flex-shrink: 0;
}

.app.editing .row-del {
  display: grid;
}

.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
}

.empty-title {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}

.btn:disabled {
  opacity: 0.55;
}

.btn.ghost {
  background: var(--surface-2);
  color: var(--text);
}

.btn.block {
  width: 100%;
}

.btn.danger {
  background: var(--surface-2);
  color: var(--up);
}

.btn.sm {
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 9px;
}

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.tabbar button {
  flex: 1;
  padding: 8px 0 6px;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tabbar button.active {
  color: var(--brand);
}

.tabbar .tab-icon {
  font-size: 18px;
  line-height: 1;
}

/* ---------- 搜索 ---------- */
.search-box {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}

.search-box input {
  flex: 1;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
}

.search-box input:focus {
  border-color: var(--brand);
}

.hint {
  padding: 8px 16px 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 详情 ---------- */
.detail {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  overflow-y: auto;
  display: none;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.detail.open {
  display: block;
}

.detail-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.detail-price {
  padding: 20px 16px 4px;
}

.detail-price .big {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
}

.detail-price .sub {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 16px;
}

.metric {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.metric .k {
  font-size: 11px;
  color: var(--muted);
}

.metric .v {
  margin-top: 2px;
  font-size: 15px;
  font-weight: 600;
}

.chart-card {
  margin: 0 16px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chart-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

canvas {
  display: block;
  width: 100%;
}

/* ---------- 我的 ---------- */
.profile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin: 16px;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
}

.actions {
  margin: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand h1 {
  font-size: 24px;
  margin: 0 0 6px;
  letter-spacing: 0.5px;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  margin-bottom: 14px;
}

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

.field input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
}

.field input:focus {
  border-color: var(--brand);
}

.form-error {
  min-height: 20px;
  font-size: 13px;
  color: var(--up);
  margin: 4px 0 10px;
}

.form-tip {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 16px;
}

/* ---------- 弹层 ---------- */
.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  display: none;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  display: none;
}

.sheet.open,
.sheet-mask.open {
  display: block;
}

.sheet h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

/* ---------- 管理页 ---------- */
.admin {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

.admin-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--surface-2);
  color: var(--muted);
}

.tag.on {
  background: var(--brand-soft);
  color: var(--brand);
}

.tag.off {
  background: rgba(229, 50, 45, 0.1);
  color: var(--up);
}

.tag.buy {
  background: rgba(229, 50, 45, 0.12);
  color: var(--up);
}

.tag.sell {
  background: rgba(18, 161, 90, 0.12);
  color: var(--down);
}

.signal-row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.signal-row:last-child {
  border-bottom: none;
}

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

.signal-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.signal-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.signal-reason {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}

/* ---------- 分组筛选 ---------- */
.chips {
  display: flex;
  gap: 8px;
  padding: 10px 16px 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.chip.active {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
}

/* ---------- 图表切换 ---------- */
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
}

.seg button {
  padding: 4px 12px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--muted);
}

.seg button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ---------- 拖拽 ---------- */
.app.editing .row {
  touch-action: none;
}

.row.dragging {
  background: var(--surface-2);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  border-radius: 10px;
}

.group-tag {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 6px;
  margin-left: 6px;
}

/* ---------- 同步进度 ---------- */
.sync-bar-wrap {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.sync-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.4s ease;
}

.date-input {
  height: 32px;
  padding: 0 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text);
}

.loading {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
