/* ================================================================
   板块资金流 — 全局样式
   ================================================================ */

/* ── CSS 变量 — 白色主色调 ──────────────────────────────────── */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-2: #666666;
  --text-3: #999999;
  --border: #eeeeee;
  --red: #e74c3c;
  --red-bg: rgba(231, 76, 60, 0.06);
  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.06);
  --primary: #3b82f6;
  --primary-bg: rgba(59, 130, 246, 0.06);
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --max-w: 960px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --surface: #1a1a1a;
    --text: #e0e0e0;
    --text-2: #999999;
    --text-3: #666666;
    --border: #2a2a2a;
    --red: #f87171;
    --red-bg: rgba(248, 113, 113, 0.08);
    --green: #4ade80;
    --green-bg: rgba(74, 222, 128, 0.08);
    --primary: #60a5fa;
    --primary-bg: rgba(96, 165, 250, 0.08);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

/* ── Reset / Base ────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── 顶部栏 ─────────────────────────────────────────────────── */
.topbar {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
  padding: 14px 16px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.logo {
  font-size: 1.5rem;
  line-height: 1;
}

.topbar__brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.updated {
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ── 按钮 ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--primary-bg);
  border-color: var(--primary);
  color: var(--primary);
}

.btn:active {
  transform: scale(0.97);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
}

.btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn--primary:hover {
  opacity: 0.9;
  color: #fff;
}

.btn--refreshing {
  pointer-events: none;
  opacity: 0.5;
}

/* ── Tab 导航 ────────────────────────────────────────────────── */
.tabs {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
  padding: 0 16px;
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--primary);
}

.tab--active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── 控制条 ─────────────────────────────────────────────────── */
.controls {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.control__label {
  font-size: 0.82rem;
  color: var(--text-2);
  white-space: nowrap;
}

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

.control--inline {
  margin-left: auto;
}

.select {
  padding: 4px 8px;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

/* 分段按钮（流入 / 流出） */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg__btn {
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg__btn + .seg__btn {
  border-left: 1px solid var(--border);
}

.seg__btn--active {
  background: var(--primary);
  color: #fff;
}

.seg__btn:not(.seg__btn--active):hover {
  background: var(--primary-bg);
  color: var(--primary);
}

/* Checkbox */
.checkbox {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ── 设置面板 ─────────────────────────────────────────────────── */
.btn--icon {
  padding: 5px;
  border: none;
  background: transparent;
  color: var(--text-2);
  line-height: 1;
}

.btn--icon:hover {
  color: var(--primary);
  background: var(--primary-bg);
}

.settings {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: flex-end;
}

.settings[hidden] {
  display: none;
}

.settings__overlay {
  flex: 1;
  background: rgba(0, 0, 0, 0.2);
}

.settings__body {
  width: 300px;
  max-width: 85vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.settings__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.settings__head h2 {
  font-size: 1rem;
  font-weight: 700;
}

.setting {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.setting__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.setting__checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.chk-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}

.chk-label .checkbox {
  width: 13px;
  height: 13px;
}

/* ── 主题手动覆盖 ─────────────────────────────────────────────── */
html[data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-2: #666666;
  --text-3: #999999;
  --border: #eeeeee;
  --red: #e74c3c;
  --red-bg: rgba(231, 76, 60, 0.06);
  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.06);
  --primary: #3b82f6;
  --primary-bg: rgba(59, 130, 246, 0.06);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

html[data-theme="dark"] {
  --bg: #111111;
  --surface: #1a1a1a;
  --text: #e0e0e0;
  --text-2: #999999;
  --text-3: #666666;
  --border: #2a2a2a;
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.08);
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.08);
  --primary: #60a5fa;
  --primary-bg: rgba(96, 165, 250, 0.08);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

/* ── 涨幅颜色风格：美股（绿涨红跌） ─────────────────────────── */
html[data-color-style="us"] .cell-change--up {
  color: var(--green);
}
html[data-color-style="us"] .cell-change--down {
  color: var(--red);
}
html[data-color-style="us"] .cell-flow--pos {
  color: var(--green);
}
html[data-color-style="us"] .cell-flow--neg {
  color: var(--red);
}
html[data-color-style="us"] .pct-bar__fill--pos {
  background: var(--green);
}
html[data-color-style="us"] .pct-bar__fill--neg {
  background: var(--red);
}
html[data-color-style="us"] .card__main.cell-flow--pos {
  color: var(--green);
}
html[data-color-style="us"] .card__main.cell-flow--neg {
  color: var(--red);
}
html[data-color-style="us"] .card b.cell-flow--pos {
  color: var(--green);
}
html[data-color-style="us"] .card b.cell-flow--neg {
  color: var(--red);
}

/* ── 主内容区 ──────────────────────────────────────────────── */
.list {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
  padding: 0 16px 24px;
  flex: 1;
}

/* 桌面：表格 */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.table th {
  padding: 10px 10px;
  text-align: right;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text-2);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table th:first-child,
.table td:first-child {
  text-align: left;
  padding-left: 14px;
}

.table td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background: var(--primary-bg);
}

/* 名称列 */
.cell-name {
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 涨跌幅 */
.cell-change {
  font-weight: 600;
}

.cell-change--up {
  color: var(--red);
}

.cell-change--down {
  color: var(--green);
}

/* 主力金额 */
.cell-flow {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cell-flow--pos {
  color: var(--red);
}

.cell-flow--neg {
  color: var(--green);
}

/* 占比进度条 */
.pct-bar-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pct-bar {
  width: 48px;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.pct-bar__fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.pct-bar__fill--pos {
  background: var(--red);
}

.pct-bar__fill--neg {
  background: var(--green);
}

/* 移动端：卡片 */
.cards {
  display: grid;
  gap: 10px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  gap: 3px 12px;
}

.card__name {
  grid-column: 1 / -1;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card__change {
  font-size: 0.88rem;
  font-weight: 600;
}

.card__main {
  grid-column: 1 / -1;
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 2px 0;
}

.card__detail {
  font-size: 0.78rem;
  color: var(--text-2);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.card__detail span {
  white-space: nowrap;
}

/* ── 加载骨架屏 ─────────────────────────────────────────────── */
.skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.skeleton__row {
  height: 36px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ── 空态 / 错误态 ──────────────────────────────────────────── */
.state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-2);
}

.state__msg {
  margin-bottom: 12px;
  font-size: 0.92rem;
}

/* ── 底部 ────────────────────────────────────────────────────── */
.footer {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
  padding: 12px 16px;
  font-size: 0.72rem;
  color: var(--text-3);
  text-align: center;
}

/* ── 响应式 ──────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .cards {
    display: none;
  }
  .table-wrap {
    display: block;
  }
}

@media (max-width: 767px) {
  .table-wrap {
    display: none;
  }
  .cards {
    display: grid;
  }
  .topbar__brand h1 {
    font-size: 1rem;
  }
  /* 控制条紧凑排列 */
  .controls {
    gap: 8px;
  }
  .control--inline {
    margin-left: 0;
  }
}
