/* x-compass v3.0 — Tokyo Night Trading Terminal
   - 配色: Tokyo Night Storm 变体
   - 字体: IBM Plex Sans (display/body) + JetBrains Mono (mono/numbers)
   - 布局: Bento Grid 不对称布局
   - 动效: 交错入场 + 数字平滑过渡
*/

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;700&family=IBM+Plex+Mono:wght@400;500;700&family=JetBrains+Mono:wght@400;500;700;800&family=Playfair+Display:wght@700;900&display=swap');

:root {
  /* Tokyo Night Storm 配色 */
  --bg-primary: #24283b;
  --bg-secondary: #1f2335;
  --bg-elevated: #2a2f45;
  --bg-deep: #16161e;

  --border: #3b4261;
  --border-strong: #565f89;
  --border-muted: #292e42;

  --text: #c0caf5;
  --text-muted: #9aa5ce;
  --text-dim: #565f89;
  --text-inverse: #1a1b26;

  /* 强调色（IDE 风格尖锐对比） */
  --accent-blue: #7aa2f7;
  --accent-cyan: #7dcfff;
  --accent-green: #9ece6a;
  --accent-red: #f7768e;
  --accent-yellow: #e0af68;
  --accent-purple: #bb9af7;
  --accent-orange: #ff9e64;

  /* A 股涨跌（红涨绿跌惯例） */
  --a-up: #f7768e;        /* 红涨 */
  --a-up-bg: rgba(247, 118, 142, 0.08);
  --a-down: #9ece6a;      /* 绿跌 */
  --a-down-bg: rgba(158, 206, 106, 0.08);
  --a-flat: #565f89;
  --a-flat-bg: rgba(86, 95, 137, 0.06);

  /* 字体 */
  --font-display: 'IBM Plex Sans', 'PingFang SC', sans-serif;
  --font-body: 'IBM Plex Sans', 'PingFang SC', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', 'SF Mono', monospace;

  /* 节奏 */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 24px rgba(122, 162, 247, 0.15);
}

/* ========== 全局 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse 60% 50% at 15% 0%, rgba(122, 162, 247, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 85% 100%, rgba(187, 154, 247, 0.06) 0%, transparent 60%),
    var(--bg-primary);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'kern' 1, 'liga' 1, 'tnum' 1;
}

/* 全局数字等宽（避免股价 16.49 抖动） */
.tbl td, .metric-value, .data-num { font-variant-numeric: tabular-nums; }

.container { max-width: 1320px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }

/* ========== Header（顶部品牌区） ========== */
.header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.5rem;
  padding: 1.25rem 0 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-muted);
  animation: fadeDown 0.5s ease;
}

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text-inverse);
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-text p {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* 日期选择器（中央） */
.date-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.4rem 0.5rem;
}

.date-picker button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--r-sm);
  transition: all 0.15s;
}

.date-picker button:hover { color: var(--accent-blue); background: rgba(122, 162, 247, 0.1); }

.date-picker input {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.9rem;
  outline: none;
  width: 115px;
  text-align: center;
  color-scheme: dark;
}

.date-picker button.today {
  background: var(--accent-blue);
  color: var(--text-inverse);
  font-weight: 700;
  font-size: 0.7rem;
  padding: 0.25rem 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.date-picker button.today:hover { background: var(--accent-cyan); color: var(--text-inverse); }

/* 状态指示器（右上） */
.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-dot {
  width: 8px; height: 8px;
  background: var(--accent-green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ========== Tabs（导航条） ========== */
.tabs {
  display: flex;
  gap: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.3rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab-btn {
  flex: 1;
  padding: 0.65rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: var(--r-sm);
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.tab-btn:hover { color: var(--text); background: rgba(122, 162, 247, 0.06); }

.tab-btn.active {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  color: var(--text-inverse);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(122, 162, 247, 0.3);
}

.tab-content { display: none; }
.tab-content.active {
  display: block;
  animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== Bento Grid 容器 ========== */
.bento {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: minmax(80px, auto);
  gap: 1rem;
}

/* 卡片入场动效（交错） */
.bento > * {
  opacity: 0;
  animation: fadeSlideIn 0.55s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.bento > *:nth-child(1) { animation-delay: 0.05s; }
.bento > *:nth-child(2) { animation-delay: 0.12s; }
.bento > *:nth-child(3) { animation-delay: 0.19s; }
.bento > *:nth-child(4) { animation-delay: 0.26s; }
.bento > *:nth-child(5) { animation-delay: 0.33s; }
.bento > *:nth-child(6) { animation-delay: 0.40s; }
.bento > *:nth-child(7) { animation-delay: 0.47s; }
.bento > *:nth-child(8) { animation-delay: 0.54s; }

/* Bento 卡片通用 */
.bento-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.25rem 1.4rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.bento-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent-blue);
  opacity: 0.6;
  transition: opacity 0.25s;
}

.bento-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.bento-card:hover::before { opacity: 1; }

.bento-card.accent-red::before { background: var(--accent-red); }
.bento-card.accent-green::before { background: var(--accent-green); }
.bento-card.accent-yellow::before { background: var(--accent-yellow); }
.bento-card.accent-purple::before { background: var(--accent-purple); }
.bento-card.accent-cyan::before { background: var(--accent-cyan); }
.bento-card.accent-orange::before { background: var(--accent-orange); }

.card-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-label .tag {
  background: rgba(122, 162, 247, 0.1);
  color: var(--accent-blue);
  padding: 0.1rem 0.45rem;
  border-radius: var(--r-sm);
  font-size: 0.6rem;
  font-weight: 700;
}

/* ========== 选股 Tab — Bento 不对称布局 ========== */
/* 顶部 3 个 metric 大卡（不等宽） */
.metric-hero {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.metric-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.25rem;
  position: relative;
  overflow: hidden;
  transition: all 0.25s ease;
}

.metric-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.metric-card.primary {
  background: linear-gradient(135deg, rgba(122, 162, 247, 0.12), rgba(187, 154, 247, 0.06));
  border-color: rgba(122, 162, 247, 0.3);
}

.metric-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.55rem;
}

.metric-value {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.02em;
  transition: color 0.4s ease;
}

.metric-value.huge { font-size: 3.5rem; font-weight: 900; }
.metric-value.up { color: var(--a-up); }
.metric-value.down { color: var(--a-down); }
.metric-value.flat { color: var(--text-muted); }

.metric-sub {
  margin-top: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ========== Tables ========== */
.tbl-wrap {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.tbl th {
  text-align: left;
  padding: 0.7rem 0.85rem;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
}

.tbl td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-muted);
  color: var(--text);
  vertical-align: middle;
  font-family: var(--font-body);
}

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

.tbl tr:hover td { background: var(--bg-elevated); }

.tbl td.num { font-family: var(--font-mono); text-align: right; font-weight: 500; }
.tbl td.center { text-align: center; }

.tbl td.up { color: var(--a-up); font-weight: 700; }
.tbl td.down { color: var(--a-down); font-weight: 700; }
.tbl td.flat { color: var(--text-muted); }

.tbl td strong, .tbl td b { color: var(--text); font-weight: 700; }

.tbl td code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--bg-deep);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--accent-cyan);
}

/* ========== Group Section（选股子分组） ========== */
.bento-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.4rem;
  margin-bottom: 1rem;
  position: relative;
}

.bento-group::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-blue), transparent);
  opacity: 0.4;
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.group-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.group-desc {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* ========== Empty / Loading / Error ========== */
.empty, .loading, .error-state {
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

.empty .icon { font-size: 3rem; margin-bottom: 0.75rem; opacity: 0.5; }
.empty h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}
.empty p { font-size: 0.85rem; line-height: 1.7; }
.empty p.reason { color: var(--text-dim); margin-top: 0.75rem; font-size: 0.75rem; }

/* Skeleton（骨架屏） */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1rem;
  grid-column: 1 / -1;
}

.skeleton-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-lg);
  padding: 1.25rem;
  min-height: 100px;
}

.skeleton-bar {
  background: linear-gradient(90deg, var(--bg-elevated) 0%, var(--border) 50%, var(--bg-elevated) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.8s linear infinite;
  border-radius: 4px;
  height: 12px;
  margin-bottom: 0.55rem;
}

.skeleton-bar.short { width: 40%; }
.skeleton-bar.med { width: 70%; }
.skeleton-bar.long { width: 90%; }
.skeleton-bar.tall { height: 28px; }

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

.error-state .icon { font-size: 2rem; margin-bottom: 0.5rem; color: var(--accent-red); }
.error-state h3 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent-red);
  margin-bottom: 0.4rem;
}

.retry-btn {
  margin-top: 1rem;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  color: var(--text-inverse);
  border: none;
  padding: 0.55rem 1.4rem;
  border-radius: var(--r-md);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  transition: transform 0.2s;
}
.retry-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow); }

/* ========== Deep Dive（markdown 渲染） ========== */
.md-body {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.75rem 2rem;
  font-family: var(--font-body);
}

.md-body h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 1.25rem 0 0.65rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.md-body h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 1.1rem 0 0.5rem;
  color: var(--accent-blue);
  border-bottom: 1px solid var(--border-muted);
  padding-bottom: 0.4rem;
}

.md-body h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0.85rem 0 0.4rem;
  color: var(--accent-cyan);
}

.md-body p {
  margin-bottom: 0.7rem;
  color: var(--text);
  line-height: 1.75;
}

.md-body ul, .md-body ol {
  margin: 0.5rem 0 0.85rem 1.5rem;
  color: var(--text);
}

.md-body li { margin-bottom: 0.3rem; }

.md-body code {
  background: var(--bg-deep);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-cyan);
  border: 1px solid var(--border-muted);
}

.md-body blockquote {
  border-left: 3px solid var(--accent-purple);
  padding: 0.55rem 0.9rem;
  margin: 0.7rem 0;
  color: var(--text-muted);
  background: var(--bg-deep);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-style: italic;
}

.md-body strong { color: var(--text); font-weight: 700; }
.md-body .tbl { margin: 0.85rem 0; }

/* ========== Timeline ========== */
.timeline {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0.4rem 0 0.85rem;
  margin-bottom: 0.5rem;
}

.timeline-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.55rem 0.9rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-family: var(--font-body);
  transition: all 0.2s;
}

.timeline-item.done {
  border-color: var(--accent-green);
  color: var(--accent-green);
  background: rgba(158, 206, 106, 0.06);
}

.timeline-item.current {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: rgba(122, 162, 247, 0.1);
  box-shadow: 0 0 12px rgba(122, 162, 247, 0.3);
}

.timeline-item .time {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

/* ========== Responsive（不对称 Bento 在小屏退化） ========== */
@media (max-width: 1024px) {
  .header { grid-template-columns: 1fr; gap: 1rem; }
  .brand { justify-content: center; }
  .date-picker { justify-self: center; }
  .status-badge { justify-self: center; }
  .metric-hero { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .container { padding: 1rem 0.75rem 3rem; }
  .brand-text h1 { font-size: 1.2rem; }
  .metric-hero { grid-template-columns: 1fr; }
  .metric-value { font-size: 1.75rem; }
  .metric-value.huge { font-size: 2.5rem; }
  .tabs { width: 100%; }
  .tab-btn { padding: 0.55rem 0.75rem; font-size: 0.75rem; flex: 0 0 auto; }
  .tbl { font-size: 0.74rem; }
  .tbl th, .tbl td { padding: 0.45rem 0.4rem; }
  .md-body { padding: 1rem 1.1rem; }
  .bento { gap: 0.65rem; }
}