/* ======================================================================
   老郭骑牛 - 样式
   ====================================================================== */
:root {
  --red: #e53935;
  --green: #43a047;
  --bg: #f5f6fa;
  --card-bg: #fff;
  --border: #e0e3eb;
  --text: #1a1a2e;
  --text-secondary: #666;
  --accent: #1565c0;
  --accent-light: #e3f2fd;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Header ---- */
.header {
  background: linear-gradient(135deg, #1565c0 0%, #1e88e5 100%);
  color: #fff;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(21, 101, 192, 0.3);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header h1 { font-size: 1.25rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.header h1 small { font-size: 0.75rem; opacity: 0.8; font-weight: 400; }
.header-actions { display: flex; gap: 10px; align-items: center; }
.header-actions button {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s;
}
.header-actions button:hover { background: rgba(255, 255, 255, 0.3); }
.header-actions .badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
}

/* ---- Stats Bar ---- */
.stats-bar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  font-size: 0.85rem;
  align-items: center;
}
.stats-bar .stat { white-space: nowrap; }
.stats-bar .stat strong { font-weight: 600; }
.stats-bar .up { color: var(--red); }
.stats-bar .down { color: var(--green); }
.stats-bar .vr-high { color: var(--accent); }

/* ---- Market Tabs ---- */
.market-tabs {
  display: flex;
  gap: 4px;
  margin-right: 8px;
}
.market-tab {
  padding: 3px 10px;
  border: 1px solid var(--border);
  background: #f5f6fa;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
  transition: all 0.2s;
}
.market-tab:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}
.market-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

/* ---- Filter Panel ---- */
.filter-panel {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: none;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
}
.filter-panel.open { display: flex; }
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-group label { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; }
.filter-group input[type="number"],
.filter-group select {
  width: 70px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  background: #fff;
}
.filter-group select { width: auto; min-width: 90px; }
.filter-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-presets button {
  padding: 3px 10px;
  border: 1px solid var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.78rem;
  white-space: nowrap;
  transition: all 0.2s;
}
.filter-presets button:hover {
  background: var(--accent);
  color: #fff;
}
.filter-apply {
  padding: 5px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

/* ---- Main Table ---- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 12px;
}
.table-wrap {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead {
  background: #f8f9fc;
  position: sticky;
  top: 0;
}
th {
  padding: 10px 6px;
  text-align: right;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th:first-child { text-align: center; }
th .sort-icon { margin-left: 3px; opacity: 0.4; }
th.active .sort-icon { opacity: 1; color: var(--accent); }
th:hover { color: var(--text); }

td {
  padding: 8px 6px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  white-space: nowrap;
}
td:first-child {
  text-align: center;
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
td.name-cell {
  text-align: left;
  font-weight: 500;
}

/* 列宽百分比分配 */
.col-code { width: 8%; }
.col-name { width: 13%; overflow: hidden; text-overflow: ellipsis; }
.col-price { width: 11%; }
.col-pct { width: 11%; }
.col-vr { width: 10%; }
.col-tvr { width: 10%; }
.col-pe { width: 9%; }
.col-pb { width: 9%; }
.col-perc { width: 19%; white-space: nowrap; }
.col-wl { width: 40px; text-align: center; cursor: pointer; }
.col-wl .wl-toggle { cursor: pointer; font-size: 1.1rem; }
.stock-link {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}
.stock-link:hover {
  color: #e53935;
  text-decoration: underline;
}
tr:hover td { background: #f0f4ff; }

.price-up { color: var(--red); }
.price-down { color: var(--green); }

/* Percentile bar */
.percentile-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
.percentile-bar {
  width: 50px;
  height: 6px;
  background: #e8e8e8;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}
.percentile-bar .fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.percentile-bar .fill.low { background: var(--green); }
.percentile-bar .fill.mid { background: #ffa726; }
.percentile-bar .fill.high { background: var(--red); }

/* Loading state */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}
.loading .spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading .hint { font-size: 0.8rem; color: #999; margin-top: 4px; }

/* Error */
.error-box {
  text-align: center;
  padding: 40px 20px;
  color: #c62828;
}

/* Empty */
.empty-box {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

/* ---- Watchlist Panel ---- */
.watchlist-panel {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 999;
  background: rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 60px;
  overflow-y: auto;
}

.wl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  width: 100%;
  max-width: 1100px;
  border-radius: var(--radius) var(--radius) 0 0;
  box-sizing: border-box;
}
.wl-header h2 { font-size: 1rem; font-weight: 600; }
.wl-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 8px;
}
.wl-close:hover { color: var(--text); }

.wl-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #f8f9fc;
  width: 100%;
  max-width: 1100px;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}
.wl-count { font-size: 0.85rem; color: var(--text-secondary); }
.wl-clear-btn {
  padding: 3px 10px;
  border: 1px solid #c62828;
  background: #fff;
  color: #c62828;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
}
.wl-clear-btn:hover { background: #fff5f5; }

.wl-table-wrap {
  width: 100%;
  max-width: 1100px;
  background: #fff;
  overflow-x: auto;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}
.wl-table-wrap table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.wl-table-wrap thead { background: #f8f9fc; }
.wl-table-wrap th {
  padding: 6px 4px;
  text-align: right;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.wl-table-wrap th:first-child { text-align: center; }
.wl-table-wrap td {
  padding: 5px 4px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.wl-table-wrap td:first-child { text-align: center; }
.wl-table-wrap td.name-cell { text-align: left; }
.wl-table-wrap tr:hover td { background: #f0f4ff; }

.wl-remove-btn {
  padding: 2px 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.72rem;
}
.wl-remove-btn:hover {
  border-color: #c62828;
  color: #c62828;
}

/* 列宽 */
.wl-col-code { width: 6%; }
.wl-col-name { width: 9%; }
.wl-col-market { width: 5%; }
.wl-col-price { width: 7%; }
.wl-col-open { width: 7%; }
.wl-col-pre { width: 7%; }
.wl-col-avg30 { width: 7%; }
.wl-col-vol { width: 7%; }
.wl-col-avgv30 { width: 7%; }
.wl-col-pe { width: 5%; }
.wl-col-pb { width: 5%; }
.wl-col-eps { width: 6%; }
.wl-col-bvps { width: 6%; }
.wl-col-biz { width: 13%; }
.wl-col-action { width: 5%; }

.wl-loading, .wl-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  background: #fff;
  width: 100%;
  max-width: 1100px;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* 主表星标 */
.wl-toggle {
  cursor: pointer;
  user-select: none;
  margin-right: 4px;
  font-size: 0.9rem;
}
.wl-toggle:hover { opacity: 0.7; }

.header-actions .badge + button#btnWatchlist {
  position: relative;
}
#wlBadge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #c62828;
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
  line-height: 1.3;
}

/* ---- Footer ---- */
.footer {
  text-align: center;
  padding: 16px;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* ---- Mobile Responsive ---- */
@media (max-width: 768px) {
  html { font-size: 12px; }
  .header h1 { font-size: 1rem; }
  .header-actions button { padding: 4px 10px; font-size: 0.78rem; }
  
  .stats-bar { font-size: 0.78rem; gap: 6px 12px; }
  .filter-panel { padding: 8px 10px; gap: 6px 10px; }
  .filter-group input[type="number"] { width: 56px; }
  .filter-group select { min-width: 70px; }

  th, td { padding: 6px 4px; }
  .percentile-bar { width: 32px; }
}

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
tr { animation: fadeIn 0.2s ease; }
