/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-dim: rgba(88,166,255,0.15);
  --green: #3fb950;
  --green-dim: rgba(63,185,80,0.15);
  --red: #f85149;
  --red-dim: rgba(248,81,73,0.12);
  --yellow: #d29922;
  --yellow-dim: rgba(210,153,34,0.15);
  --orange: #db6d28;
  --orange-dim: rgba(219,109,40,0.15);
  --purple: #bc8cff;
  --teal: #39d0d8;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

#app { max-width: 1400px; margin: 0 auto; padding: 0 16px 40px; }

/* === Header === */
.header {
  background: linear-gradient(135deg, #161b22 0%, #0d1117 100%);
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  margin-bottom: 24px;
  margin-left: -16px;
  margin-right: -16px;
  padding-left: 16px;
  padding-right: 16px;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; color: #fff;
}
.logo-text h1 { font-size: 20px; color: #fff; font-weight: 700; }
.logo-text p { font-size: 12px; color: var(--text-dim); }
.update-badge {
  font-size: 12px; color: var(--text-dim);
  background: var(--bg-3); padding: 6px 12px;
  border-radius: 20px; border: 1px solid var(--border);
}

/* === Cards === */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* === Summary === */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card { padding: 16px 18px; }
.stat-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.stat-value {
  font-size: 28px; font-weight: 800; color: #fff;
  line-height: 1.2;
}
.stat-value .unit { font-size: 14px; color: var(--text-dim); font-weight: 400; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* === Controls === */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.sort-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.sort-tab {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
  display: flex; align-items: center; gap: 6px;
  font-family: inherit;
}
.sort-tab:hover { border-color: var(--accent); color: var(--accent); }
.sort-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.tab-icon {
  font-size: 11px; font-weight: 700;
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px; background: rgba(255,255,255,0.08);
}

.filter-bar { flex: 1; max-width: 300px; min-width: 180px; }
.search-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  transition: var(--transition);
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

/* === Legend === */
.legend {
  display: flex; gap: 16px; margin-bottom: 12px;
  flex-wrap: wrap; font-size: 12px; color: var(--text-dim);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-low { background: var(--green); }
.dot-mid { background: var(--yellow); }
.dot-high { background: var(--orange); }
.dot-max { background: var(--red); }
.dot-prem-danger { background: #f85149; }
.dot-prem-high { background: var(--orange); }
.dot-prem-mid { background: var(--yellow); }
.dot-prem-low { background: var(--green); }
.legend-divider { width: 1px; height: 14px; background: var(--border); margin: 0 4px; }

/* === Table === */
.table-section { margin-bottom: 24px; }
.table-wrap { overflow-x: auto; }
.etf-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.etf-table th {
  background: var(--bg-3);
  color: var(--text-dim);
  font-weight: 600;
  padding: 12px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
}
.etf-table th.sortable { cursor: pointer; user-select: none; }
.etf-table th.sortable:hover { color: var(--accent); }
.etf-table th.sorted { color: var(--accent); }
.etf-table th .arrow { font-size: 10px; margin-left: 3px; }
.etf-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.etf-table tbody tr { transition: var(--transition); }
.etf-table tbody tr:hover { background: rgba(88,166,255,0.04); }
.etf-table tbody tr:last-child td { border-bottom: none; }
.loading-row { text-align: center; color: var(--text-dim); padding: 40px 0; }

/* Cell styles */
.cell-code { font-family: "SF Mono", "Fira Code", monospace; color: var(--purple); font-weight: 600; }
.cell-fee-low { color: var(--green); font-weight: 700; }
.cell-fee-mid { color: var(--yellow); font-weight: 600; }
.cell-fee-high { color: var(--orange); }
.cell-fee-max { color: var(--red); }
.cell-size-xl { color: var(--accent); font-weight: 700; }
.cell-size-l { color: var(--teal); font-weight: 600; }
.cell-size-m { color: var(--text); }
.cell-size-s { color: var(--text-dim); }

.bar-container {
  width: 70px; height: 5px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px; overflow: hidden;
  display: inline-block; vertical-align: middle; margin-left: 6px;
}
.bar-fill { display: block; height: 100%; border-radius: 3px; }

.exchange-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.tag-sh { background: var(--yellow-dim); color: var(--yellow); }
.tag-sz { background: var(--green-dim); color: var(--green); }

.status-ok { color: var(--green); }
.status-stop { color: var(--red); }

/* Change percentage (Chinese convention: red=up, green=down) */
.cell-up { color: var(--red); font-weight: 700; }
.cell-down { color: var(--green); font-weight: 700; }
.cell-flat { color: var(--text-dim); }

/* Market status banner */
.market-status {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.market-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
}
.market-badge.open {
  background: var(--green-dim);
  border-color: var(--green);
  color: var(--green);
}
.market-badge.closed {
  background: var(--bg-3);
  color: var(--text-dim);
}
.market-badge .market-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}
.market-badge.open .market-dot {
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}
.market-badge.closed .market-dot {
  background: var(--text-muted);
}
.market-badge .market-time {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Real-time refresh indicator */
.refresh-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 8px;
}
.refresh-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}
.refresh-dot.idle { background: var(--text-muted); animation: none; }

/* Premium rate cell colors */
.cell-premium-danger { color: #f85149; font-weight: 700; }
.cell-premium-high { color: var(--orange); font-weight: 600; }
.cell-premium-mid { color: var(--yellow); }
.cell-premium-low { color: var(--green); }
.cell-premium-discount { color: var(--teal); }
.cell-na { color: var(--text-muted); }

.detail-btn {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: var(--transition);
}
.detail-btn:hover { background: var(--accent); color: #fff; }

/* === Charts === */
.charts-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card { padding: 16px; }
.chart-title { font-size: 14px; color: #fff; margin-bottom: 12px; font-weight: 600; }

/* === Insights === */
.insights { margin-bottom: 24px; }
.insight-card { padding: 18px; }
.insight-card h3 { font-size: 15px; color: #fff; margin-bottom: 12px; }
.insight-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
}
.insight-item:last-child { border-bottom: none; }
.insight-item .hl { color: var(--accent); font-weight: 600; }
.insight-item .warn { color: var(--yellow); }
.insight-item .danger { color: var(--red); }

/* === Footer === */
.footer { margin-top: 32px; }
.disclaimer {
  padding: 14px 16px;
  background: var(--red-dim);
  border: 1px solid rgba(248,81,73,0.25);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.7;
  margin-bottom: 16px;
}
.disclaimer strong { color: var(--red); }
.footer-info {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* === Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; color: #fff; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  transition: var(--transition);
}
.modal-close:hover { background: var(--bg-3); color: var(--red); }
.modal-body { padding: 20px; }
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.detail-item {
  background: var(--bg-3);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.detail-label { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.detail-value { font-size: 16px; color: #fff; font-weight: 600; }
.detail-value.accent { color: var(--accent); }
.detail-value.green { color: var(--green); }
.detail-value.red { color: var(--red); }
.detail-value.yellow { color: var(--yellow); }

/* === Responsive === */
@media (max-width: 768px) {
  html { font-size: 14px; }
  .header-inner { flex-direction: column; align-items: flex-start; }
  .summary { grid-template-columns: 1fr 1fr; }
  .charts-section { grid-template-columns: 1fr; }
  .controls { flex-direction: column; align-items: stretch; }
  .filter-bar { max-width: 100%; }
  .sort-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .etf-table { font-size: 12px; }
  .etf-table th, .etf-table td { padding: 8px 10px; }
  .detail-grid { grid-template-columns: 1fr; }
  .footer-info { flex-direction: column; gap: 4px; }
}

@media (max-width: 480px) {
  .summary { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }
  .logo-text h1 { font-size: 16px; }
  .logo-text p { font-size: 11px; }
}
