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

:root {
  --primary: #e83929;
  --primary-light: #ff6b5a;
  --green: #00a854;
  --green-light: #00c76e;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* === Header === */
.header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo {
  font-size: 20px;
  white-space: nowrap;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}
.logo:hover { opacity: 0.8; }

/* Search */
.search-box {
  flex: 1;
  display: flex;
  gap: 8px;
  position: relative;
}
.search-box input {
  flex: 1;
  padding: 10px 16px;
  border: 2px solid var(--border);
  border-radius: 24px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  background: var(--bg);
}
.search-box input:focus {
  border-color: var(--primary);
  background: #fff;
}
.search-box button {
  padding: 10px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.search-box button:hover { background: #cc3022; }

.search-results {
  max-width: 1200px;
  margin: 0 auto 0;
  padding: 0 16px 12px;
  max-height: 360px;
  overflow-y: auto;
}
.search-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s;
}
.search-item:hover { background: var(--bg); }
.search-item .s-name { font-weight: 600; font-size: 14px; }
.search-item .s-code { color: var(--text-secondary); font-size: 13px; }

/* === Welcome === */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
  gap: 32px;
}

/* === 市场仪表盘 === */
.market-dashboard {
  width: 100%;
  max-width: 1000px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

/* 市场标签页 */
.market-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: #fafbfc;
}
.market-tab {
  flex: 1;
  padding: 12px 20px;
  border: none;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.market-tab:hover { color: var(--text); background: #f0f1f5; }
.market-tab.active {
  color: var(--primary);
  background: #fff;
}
.market-tab.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
}

/* 左右双栏布局 */
.market-body {
  display: flex;
  min-height: 420px;
}
.market-left {
  width: 240px;
  min-width: 200px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: #fafbfc;
  overflow-y: auto;
  max-height: 500px;
}
.ml-header {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fafbfc;
  z-index: 1;
}

/* 指数列表 */
.indices-list {
  padding: 0;
}
.indices-list-loading {
  padding: 24px 16px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}
.indices-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #f0f1f5;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
}
.indices-list-item:last-child { border-bottom: none; }
.indices-list-item:hover { background: #eef1f5; }
.indices-list-item.active {
  background: #fff;
  border-left: 3px solid var(--primary);
  padding-left: 13px;
}
.il-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.il-price {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-left: 8px;
}
.il-change {
  font-size: 12px;
  font-weight: 600;
  min-width: 56px;
  text-align: right;
  margin-left: 6px;
}

/* 右栏：详情面板 */
.market-right {
  flex: 1;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 420px;
}
.detail-empty {
  text-align: center;
  color: var(--text-secondary);
}
.detail-empty-icon { font-size: 40px; margin-bottom: 8px; opacity: 0.5; }
.detail-empty-text { font-size: 14px; }

.detail-content {
  width: 100%;
}
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.detail-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.detail-code {
  font-size: 12px;
  color: var(--text-secondary);
}
.detail-time {
  font-size: 12px;
  color: var(--text-secondary);
}
.detail-price-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}
.detail-price {
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.detail-change-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.detail-change-amt {
  font-size: 15px;
  font-weight: 600;
}
.detail-change-pct {
  font-size: 14px;
  font-weight: 600;
}

/* 迷你K线图 */
.detail-chart-container {
  width: 100%;
  height: 240px;
  margin-bottom: 14px;
  background: #fafbfc;
  border-radius: var(--radius);
}

/* 详情数据网格 */
.detail-data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.detail-data-grid .grid-cell {
  background: #fafbfc;
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.detail-data-grid .cell-label {
  color: var(--text-secondary);
  font-size: 12px;
}
.detail-data-grid .cell-value {
  font-weight: 600;
  font-size: 12px;
}

/* 行情中心快捷入口 */

/* 快捷入口 */
.quick-links-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 24px;
  background: #fafbfc;
  border-top: 1px solid var(--border);
}
.ql-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.ql-item:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* 页面底部 */
.welcome-footer {
  text-align: center;
  max-width: 900px;
  width: 100%;
}
.welcome-footer p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
}
.quick-codes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.tag {
  display: inline-block;
  padding: 8px 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.tag:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* === Loading & Error === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 16px;
  color: var(--text-secondary);
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  padding: 16px;
  margin: 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  border-radius: var(--radius);
  font-size: 14px;
}

/* === Dashboard === */
.dashboard { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* Stock Header Card */
.stock-header-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
}

/* 名称 + 徽章行 */
.stock-name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-bottom: 8px;
}
.stock-name-row h2 { font-size: 20px; font-weight: 700; }
.stock-code { font-size: 13px; color: var(--text-secondary); }
.stock-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge-kcb { background: #fef3c7; color: #d97706; }
.badge-cyb { background: #fce7f3; color: #db2777; }
.badge-bj { background: #f0fdf4; color: #16a34a; }
.badge-hs { background: #eff6ff; color: #2563eb; }
.badge-hk { background: #fef2f2; color: #dc2626; }
.badge-us { background: #f5f3ff; color: #7c3aed; }

/* 价格行 */
.stock-price-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 14px;
}
.current-price { font-size: 36px; font-weight: 700; line-height: 1.1; }
.price-change-block { display: flex; gap: 10px; align-items: baseline; }
.change-pct { font-size: 18px; font-weight: 700; }
.change-amt { font-size: 14px; font-weight: 600; }
.stock-status {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 2px 10px;
  border-radius: 10px;
  background: var(--bg);
}
.polling-status {
  font-size: 12px;
  color: var(--green);
  padding: 2px 10px;
  border-radius: 10px;
  background: #ecfdf5;
  font-weight: 600;
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* === 双列数据网格 === */
.stock-data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
}
.stock-data-grid .grid-cell {
  background: #fafbfc;
  padding: 7px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.stock-data-grid .grid-cell .cell-label {
  color: var(--text-secondary);
  font-size: 12px;
}
.stock-data-grid .grid-cell .cell-value {
  font-weight: 600;
  font-size: 13px;
}

/* 估值/股本行 */
.stock-valuation-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  font-size: 13px;
  padding: 8px 0 2px;
}
.stock-valuation-row .val-item {
  display: flex;
  gap: 4px;
  align-items: baseline;
}
.stock-valuation-row .val-label { color: var(--text-secondary); font-size: 12px; }
.stock-valuation-row .val-value { font-weight: 600; font-size: 13px; }

/* 通用颜色 */
.up { color: var(--primary); }
.down { color: var(--green); }

/* === Tabs === */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 1;
  min-width: fit-content;
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab.active { background: var(--primary); color: #fff; }
.tab:hover:not(.active) { background: var(--bg); }

/* === Panels === */
.panel { display: none; }
.panel.active { display: block; }

.panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.btn-group {
  display: flex;
  gap: 2px;
  background: var(--card-bg);
  border-radius: 6px;
  padding: 2px;
  box-shadow: var(--shadow);
}
.btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn.active { background: var(--primary); color: #fff; }
.btn:hover:not(.active) { background: var(--bg); }

/* Charts */
.chart-container {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  height: 420px;
}
.chart-container-half {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  height: 340px;
  margin-bottom: 12px;
}

/* === Data Tables === */
.data-table-wrap {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.data-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table-wrap th {
  background: #f8f9fc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table-wrap td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table-wrap tr:hover td { background: #fafbfc; }
.data-table-wrap .up { color: var(--primary); }
.data-table-wrap .down { color: var(--green); }

/* === Profile === */
.profile-content {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
}
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.profile-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.profile-item:last-child { border-bottom: none; }
.profile-item .label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.profile-item .value { font-size: 14px; font-weight: 600; }

/* === Footer === */
.footer {
  margin-top: auto;
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
}

/* === Mobile (< 768px) === */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
  }
  .logo { font-size: 18px; }
  .search-box input { font-size: 14px; padding: 8px 14px; }
  .search-box button { padding: 8px 16px; font-size: 14px; }

  .stock-header-card {
    padding: 12px;
  }
  .current-price { font-size: 28px; }
  .stock-name-row h2 { font-size: 17px; }
  .change-pct { font-size: 16px; }
  .change-amt { font-size: 13px; }
  .stock-data-grid .grid-cell { padding: 5px 10px; font-size: 12px; }
  .stock-data-grid .grid-cell .cell-label { font-size: 11px; }
  .stock-data-grid .grid-cell .cell-value { font-size: 12px; }
  .stock-valuation-row { gap: 6px 16px; font-size: 12px; }
  .stock-valuation-row .val-label { font-size: 11px; }
  .stock-valuation-row .val-value { font-size: 12px; }

  .tabs { gap: 2px; }
  .tab { padding: 8px 10px; font-size: 13px; }

  .chart-container { height: 320px; }
  .chart-container-half { height: 260px; }

  .panel-toolbar { gap: 6px; }
  .btn { padding: 5px 10px; font-size: 12px; }

  .dashboard { padding: 10px; }
  .welcome { padding: 16px 8px; gap: 16px; }

  /* 市场仪表盘移动端：上下布局 */
  .market-body { flex-direction: column; min-height: auto; }
  .market-left {
    width: 100%;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .market-right {
    min-height: 320px;
    padding: 14px 12px;
  }
  .market-tab { padding: 11px 14px; font-size: 14px; }
  .indices-list-item { padding: 8px 12px; font-size: 12px; }
  .il-name { font-size: 12px; }
  .il-price { font-size: 12px; }
  .il-change { font-size: 11px; min-width: 48px; }

  .detail-price { font-size: 28px; }
  .detail-name { font-size: 15px; }
  .detail-change-amt { font-size: 13px; }
  .detail-change-pct { font-size: 12px; }
  .detail-chart-container { height: 200px; }
  .detail-data-grid .grid-cell { padding: 4px 10px; font-size: 11px; }

  .quick-links-bar { padding: 10px 12px; gap: 6px; }
  .ql-item { padding: 5px 10px; font-size: 12px; }

  .data-table-wrap { font-size: 12px; }
  .data-table-wrap th, .data-table-wrap td { padding: 6px 8px; }
}

/* === Small mobile (< 480px) === */
@media (max-width: 480px) {
  .current-price { font-size: 24px; }
  .chart-container { height: 260px; }
  .chart-container-half { height: 220px; }
  .profile-grid { grid-template-columns: 1fr; }
  .btn { padding: 5px 8px; font-size: 11px; }
}
