/* 中信市场数据 — one stylesheet, no framework. A-share colours: red up, green down. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d2330;
  --ink-2: #4a5363;
  --muted: #6b7482;
  --line: #e3e6eb;
  --brand: #b4232a;
  --brand-ink: #8f1b21;
  --accent: #2f5bd3;
  --up: #d23b3b;
  --down: #1a9a5c;
  --warn: #b86a00;
  --ok: #1a8a52;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.6 var(--font); color: var(--ink); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid #8fb0ff; outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 8px; background: #fff; padding: 6px 10px; z-index: 100; }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--ink-2); }

/* -------- top bar -------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--brand) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 22l6-7 5 4 7-9' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat; }
.search { position: relative; flex: 1; max-width: 560px; }
.search input { width: 100%; padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px; font: inherit; background: var(--bg); }
.search input:focus { background: #fff; border-color: #9db4ee; outline: none; box-shadow: 0 0 0 3px rgba(47, 91, 211, .15); }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 6px); margin: 0; padding: 6px; list-style: none; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(20, 30, 50, .14); max-height: 420px; overflow: auto; }
.search-results li { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.search-results li.active, .search-results li:hover { background: #eef2fc; }
.sr-kind { font-size: 12px; color: var(--muted); min-width: 34px; }
.sr-name { font-weight: 600; }
.sr-code { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.sr-extra { margin-left: auto; font-size: 12px; color: var(--warn); }
.sr-empty { color: var(--muted); cursor: default !important; }
.nav-toggle { display: none; margin-left: auto; }

/* -------- layout -------- */
.layout { flex: 1; display: grid; grid-template-columns: 188px minmax(0, 1fr); }
.nav { border-right: 1px solid var(--line); background: var(--panel); padding: 16px 10px; }
.nav ul { list-style: none; margin: 0; padding: 0; position: sticky; top: 76px; }
.nav a { display: block; padding: 8px 14px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a[aria-current="page"] { background: #fbeaea; color: var(--brand-ink); font-weight: 700; }
.main { padding: 24px 28px 40px; min-width: 0; outline: none; }
.page { display: flex; flex-direction: column; gap: 18px; max-width: 1280px; }
.footer { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; padding: 12px 24px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel); }
.footer .warn { color: var(--warn); }

/* -------- page pieces -------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.lede { margin-top: 6px; color: var(--ink-2); max-width: 760px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 18px 0; }
.card-head .hint { margin-top: 4px; font-size: 13px; color: var(--muted); }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card-body { padding: 14px 18px 16px; min-width: 0; }
.card.flush .card-body { padding: 0; }

/* tiles on home page */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--ink); }
.tile:hover { border-color: #b8c7ef; text-decoration: none; box-shadow: 0 4px 16px rgba(47, 91, 211, .12); }
.tile strong { font-size: 16px; }
.tile span { color: var(--ink-2); font-size: 14px; }
.tile em { font-style: normal; color: var(--muted); font-size: 12px; margin-top: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: #eef2fc; color: var(--accent); font-size: 14px; border: 0; cursor: pointer; font: inherit; }
.chip:hover { background: #dfe7fa; text-decoration: none; }
.hero { background: linear-gradient(135deg, #fff 0%, #fdf2f2 100%); border: 1px solid var(--line); border-radius: 14px; padding: 26px 28px; display: flex; flex-direction: column; gap: 14px; }
.hero h1 { font-size: 28px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin: 0; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px 14px; }
.stat dt { font-size: 13px; color: var(--muted); }
.stat dd { margin: 2px 0 0; display: flex; flex-direction: column; }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 13px; font-variant-numeric: tabular-nums; }
.quote-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 18px; }
.quote-head .price { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; }
.quote-head .chg { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); }
.badge.ok { background: #e7f6ee; color: var(--ok); border-color: #c6ead6; }
.badge.warn { background: #fff4e0; color: var(--warn); border-color: #f4dcae; }
.badge.bad { background: #fdecec; color: var(--up); border-color: #f6caca; }
.badge.info { background: #eef2fc; color: var(--accent); border-color: #d3def8; }

/* tabs & segmented */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs [role="tab"] { padding: 10px 16px; border: 0; background: none; font: inherit; color: var(--ink-2); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs [role="tab"][aria-selected="true"] { color: var(--brand-ink); border-color: var(--brand); font-weight: 700; }
.tab-panel { padding-top: 18px; display: flex; flex-direction: column; gap: 18px; }
.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.segmented button { border: 0; background: none; font: inherit; font-size: 13px; padding: 4px 12px; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.segmented button[aria-checked="true"] { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; cursor: pointer; }
.btn:hover { border-color: #b8c2d2; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.param-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.field input, .field select { font: inherit; font-size: 14px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); min-width: 140px; }
input[type="search"], input[type="text"] { font: inherit; }

/* states */
.state { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 18px; color: var(--ink-2); border-radius: 8px; }
.state.error { background: #fdf0f0; color: #8b2020; }
.state.empty { background: var(--bg); color: var(--muted); justify-content: center; }
.spinner { width: 16px; height: 16px; border: 2px solid #c9d2e3; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* tables */
.table-wrap { display: flex; flex-direction: column; gap: 8px; }
.table-scroll { overflow: auto; max-height: 620px; border: 1px solid var(--line); border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data thead th { position: sticky; top: 0; background: #f2f4f7; z-index: 1; font-weight: 600; color: var(--ink-2); padding: 0; }
table.data th .th-btn { all: unset; display: block; padding: 8px 12px; cursor: pointer; }
table.data th[aria-sort="ascending"] .th-btn::after { content: " ▲"; font-size: 10px; }
table.data th[aria-sort="descending"] .th-btn::after { content: " ▼"; font-size: 10px; }
table.data .num { text-align: right; }
table.data th.num .th-btn { text-align: right; }
table.data tbody tr:hover { background: #f7f9fd; }
.pager { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.pager-btns { display: inline-flex; align-items: center; gap: 8px; }
.pager > .btn:last-child { margin-left: auto; }
table.kv { border-collapse: collapse; font-size: 14px; }
table.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 16px 4px 0; vertical-align: top; white-space: nowrap; }
table.kv td { padding: 4px 0; }

/* charts & provenance */
.chart { width: 100%; }
.source-note { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.source-note .note { color: var(--ink-2); background: #fbf8ef; border-left: 3px solid #e6cf8f; padding: 6px 10px; border-radius: 4px; }
.source-note summary { cursor: pointer; }
pre.sql { background: #1f2430; color: #e6e9ef; padding: 12px 14px; border-radius: 8px; overflow: auto; font: 12px/1.5 var(--mono); max-height: 360px; }
.callout { padding: 12px 16px; border-radius: 8px; background: #eef2fc; color: #23407f; }
.callout.warn { background: #fff4e0; color: #7a4800; }
.prose { max-width: 820px; display: flex; flex-direction: column; gap: 10px; }
.prose ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login form { background: #fff; padding: 28px; border-radius: 12px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; width: 320px; }
.login input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.login button { padding: 8px; border: 0; border-radius: 8px; background: var(--brand); color: #fff; font: inherit; cursor: pointer; }
.login .error { color: var(--up); }

/* responsive */
@media (max-width: 1080px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .nav-toggle { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .nav { display: none; border-right: 0; border-bottom: 1px solid var(--line); }
  body.nav-open .nav { display: block; }
  .main { padding: 16px 14px 32px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .quote-head .price { font-size: 30px; }
}

/* the hidden attribute always wins over display rules on components */
[hidden] { display: none !important; }
