/* ── 设计令牌 ──────────────────────────────────────────
   全站尺寸统一用 rem，根字号 = 16px × --scale。
   --scale 由 ui-scale.js 按分辨率自动设定，用户也可手动切换密度，
   因此改一个变量即可整体放大/缩小，不会破坏布局。            */
:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2230;
  --border: #262d3a;
  --text: #e6edf3;
  --muted: #8b949e;
  --up: #f0483e;
  --down: #22b07d;
  --accent: #3b82f6;

  --scale: 1;              /* 全局缩放（密度） */
  --sidebar-w: 16.5rem;    /* 侧栏宽度 */
  --pad-x: 1.25rem;        /* 主区左右内边距 */
  --pad-y: 1rem;           /* 主区上下内边距 */
  --gap: 1.25rem;          /* 头部元素间距 */
  --chart-min-h: 33rem;    /* 图表卡片最小高度（较原 22rem 拉高 50%） */
}

/* 大分辨率自动放大（用户手动选过密度后由 JS 内联覆盖） */
@media (min-width: 1500px) { :root { --scale: 1.06; --sidebar-w: 17.5rem; } }
@media (min-width: 1800px) { :root { --scale: 1.12; --sidebar-w: 18.5rem; } }
@media (min-width: 2200px) { :root { --scale: 1.2;  --sidebar-w: 20rem; } }

/* 小屏 / 窄屏自适应 */
@media (max-width: 1400px) { :root { --sidebar-w: 15rem; } }
@media (max-width: 1180px) {
  :root { --sidebar-w: 13.5rem; --pad-x: 1rem; --gap: .875rem; }
  .chart-head { gap: .75rem; }
}
@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto; flex: 0 0 auto; max-height: 34vh;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .search-box { position: static; }
  .search-list { top: auto; }
}
/* 矮屏（笔记本 768p 一类）压缩纵向占用 */
@media (max-height: 780px) {
  :root { --chart-min-h: 25.5rem; --pad-y: .625rem; }
  .chart { min-height: 19.5rem; }
  .topbar { padding: .5rem 1rem; }
  .search-box { padding: .625rem .75rem; }
}
@media (max-height: 620px) {
  :root { --chart-min-h: 21rem; }
  .chart { min-height: 15.75rem; }
}

* { box-sizing: border-box; }

html {
  font-size: calc(16px * var(--scale));
  -webkit-text-size-adjust: 100%;
}
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 0.9375rem;   /* 15px @ scale 1 */
  line-height: 1.5;
}

/* ── 顶栏 ─────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap;
  padding: .75rem var(--pad-x);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.logo {
  width: 2.25rem; height: 2.25rem; border-radius: .5625rem;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .875rem; letter-spacing: .5px;
  flex: 0 0 auto;
}
.topbar h1 { margin: 0; font-size: 1rem; font-weight: 600; white-space: nowrap; }
.sub { margin: .125rem 0 0; font-size: .75rem; color: var(--muted); }
.actions { display: flex; align-items: center; gap: .625rem; flex-wrap: wrap; }
.status { font-size: .75rem; color: var(--muted); min-width: 8.75rem; text-align: right; }

@media (max-width: 780px) {
  .status { min-width: 0; text-align: left; }
  .topbar h1 { white-space: normal; }
}

.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: .4375rem;
  padding: .4375rem .875rem; font-size: .8125rem; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #3d4759; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: #2f6fdd; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 显示密度切换 */
.density {
  display: flex; align-items: stretch;
  border: 1px solid var(--border); border-radius: .4375rem; overflow: hidden;
  flex: 0 0 auto;
}
.density button {
  background: var(--panel-2); border: none;
  border-left: 1px solid var(--border);
  color: var(--muted); font-size: .75rem; padding: .4375rem .5rem;
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.density button:first-child { border-left: none; }
.density button:hover { color: var(--text); }
.density button.active { background: #1b2b47; color: var(--text); }

/* ── 主体骨架（纯弹性，不再写死 100vh - 顶栏高度）───── */
.layout {
  flex: 1 1 auto; min-height: 0;
  display: flex;
}

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
}
.search-box {
  position: sticky; top: 0; z-index: 30;
  padding: .75rem; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.search-box input {
  width: 100%; padding: .5rem .625rem; border-radius: .4375rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: .8125rem; font-family: inherit; outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-list {
  position: absolute; left: .75rem; right: .75rem; top: 3.35rem; z-index: 30;
  margin: 0; padding: .25rem; list-style: none;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: .5rem; max-height: min(16rem, 42vh); overflow: auto;
  box-shadow: 0 12px 28px rgba(0,0,0,.45);
}
.search-list li { padding: .4375rem .5625rem; border-radius: .375rem; cursor: pointer; font-size: .8125rem; }
.search-list li:hover { background: #263244; }
.search-list .c { color: var(--muted); margin-right: .5rem; font-family: Consolas, monospace; }

.side-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: .625rem .875rem; font-size: .75rem; color: var(--muted);
  letter-spacing: .5px;
}
.watchlist {
  margin: 0; padding: 0 .5rem .5rem; list-style: none;
  flex: 0 0 auto;
}
.watchlist li {
  display: flex; align-items: center; gap: .5rem;
  padding: .5625rem .625rem; border-radius: .5rem; cursor: pointer;
  border: 1px solid transparent;
}
.watchlist li:hover { background: var(--panel-2); }
.watchlist li.active { background: #1b2b47; border-color: #2f4d7d; }
.wl-main { flex: 1; min-width: 0; }
.wl-name { font-size: .8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-code { font-size: .6875rem; color: var(--muted); font-family: Consolas, monospace; }
.wl-right { text-align: right; flex: 0 0 auto; }
.wl-price { font-size: .8125rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wl-pct { font-size: .6875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wl-del {
  opacity: 0; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: .9375rem; line-height: 1; padding: .125rem .25rem;
}
.watchlist li:hover .wl-del { opacity: 1; }
.wl-del:hover { color: var(--up); }
.tag {
  display: inline-block; font-size: .625rem; padding: .0625rem .3125rem;
  border-radius: .25rem; background: #29304a; color: #9fb4ff; margin-right: .25rem;
}

/* 侧栏很窄时隐藏次要信息，避免挤压 */
@media (max-width: 1180px) {
  .wl-code .tag { display: none; }
}

.hint, .tip { font-size: .6875rem; color: var(--muted); padding: 0 .875rem .75rem; line-height: 1.6; }
.tip { padding: .625rem 0 0; }

/* ── 主内容区 ─────────────────────────── */
.content {
  flex: 1 1 auto; min-width: 0; min-height: 0;
  padding: var(--pad-y) var(--pad-x);
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
}
.chart-head {
  display: flex; align-items: center; gap: var(--gap); flex-wrap: wrap;
  flex: 0 0 auto;
}
.title { min-width: 0; }
.title .name { font-size: 1.25rem; font-weight: 600; }
.title .code { font-size: .8125rem; color: var(--muted); margin-left: .5rem; font-family: Consolas, monospace; }

/* 磨损档位切换：崭新出厂 / 略有磨损 / 久经沙场 */
.wear-tabs {
  display: flex; gap: .375rem; flex-wrap: wrap;
  margin-top: .5rem;
}
.wear-tabs.hidden { display: none; }
.wear-tab {
  display: inline-flex; align-items: center; gap: .375rem;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  padding: .25rem .625rem; border-radius: .375rem; cursor: pointer;
  font-size: .75rem; font-family: inherit; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.wear-tab:hover { border-color: #2f4d7d; color: var(--text); }
.wear-tab.active {
  background: #1b2b47; border-color: #2f4d7d; color: var(--text);
  font-weight: 600;
}
.wear-tab .wt-price {
  font-variant-numeric: tabular-nums; color: #ff8b82; font-size: .6875rem;
}
.wear-tab.active .wt-price { color: var(--up); }
.wear-tab .wt-dot {
  width: .375rem; height: .375rem; border-radius: 50%; background: #4d5876;
  flex: 0 0 auto;
}
.wear-tab.active .wt-dot { background: var(--up); }
.price-box { display: flex; align-items: baseline; gap: .625rem; flex-wrap: wrap; }
.price { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.pct { font-size: .875rem; font-variant-numeric: tabular-nums; }
.periods { margin-left: auto; display: flex; gap: .375rem; flex-wrap: wrap; }
.periods button {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  padding: .3125rem .75rem; border-radius: .375rem; cursor: pointer; font-size: .75rem;
  font-family: inherit; white-space: nowrap;
}
.periods button.active { background: #1b2b47; border-color: #2f4d7d; color: var(--text); }

@media (max-width: 1180px) {
  .periods { margin-left: 0; }
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

.hits { margin: .625rem 0 .25rem; display: flex; gap: .375rem; flex-wrap: wrap; min-height: 1.375rem; flex: 0 0 auto; }
.hit {
  font-size: .6875rem; padding: .125rem .5rem; border-radius: .3125rem;
  background: rgba(240,72,62,.14); color: #ff8b82; border: 1px solid rgba(240,72,62,.35);
}

/* 图表容器：占满剩余高度，随窗口自适应（不再固定 520px）*/
.chart {
  position: relative; width: 100%;
  flex: 1 1 auto; min-height: 0;
}
/* 图表卡片：flex-shrink:0 防止被 flex+overflow 容器压扁到 min-height 以下，
   这是之前"成交量/做空"重叠的根因。 */
.chart-grow {
  flex: 1 0 0;
  min-height: var(--chart-min-h);
  display: flex; flex-direction: column;
}
/* A股页面：图表是 .content 的直接子节点，同样不允许被压扁 */
.content > .chart {
  flex: 1 0 0;
  min-height: 17rem;
}
@media (max-height: 780px) {
  .content > .chart { min-height: 13rem; }
}
@media (max-height: 620px) {
  .content > .chart { min-height: 10.5rem; }
}

.metrics {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: .5rem; margin-top: .75rem; flex: 0 0 auto;
}
.metric {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: .5rem; padding: .5rem .625rem;
}
.metric .k { font-size: .6875rem; color: var(--muted); }
.metric .v { font-size: .875rem; margin-top: .1875rem; font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }
.toast {
  position: fixed; left: 50%; bottom: 2.125rem; transform: translateX(-50%);
  background: #22293a; border: 1px solid var(--border);
  padding: .5625rem 1.125rem; border-radius: .5rem; font-size: .8125rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 99;
  max-width: 90vw; text-align: center;
}
.empty { color: var(--muted); font-size: .8125rem; padding: 1.25rem; text-align: center; }
