:root {
  --bg: #0d1117;
  --bg-2: #131a23;
  --panel: #161d27;
  --panel-2: #1c2531;
  --line: #263140;
  --line-2: #33415a;
  --text: #e6edf3;
  --text-2: #9fb0c3;
  --text-3: #6b7d94;
  --green: #3fb950;
  --green-2: #2ea043;
  --red: #f85149;
  --red-2: #da3633;
  --amber: #d29922;
  --blue: #58a6ff;
  --cyan: #39c5cf;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 18px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(13,17,23,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 18px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--green) 0%, #1a7f37 100%);
  display: grid; place-items: center;
  font-size: 19px; font-weight: 700; color: #fff;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .5px; }
.brand-text span { font-size: 11px; color: var(--text-3); }
.nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-btn {
  background: none; border: 0; color: var(--text-2);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; white-space: nowrap; font-family: inherit;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--panel-2); color: var(--text); }
.nav-btn.active { background: var(--green); color: #fff; font-weight: 600; }
.status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-3); flex-shrink: 0; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.status.ok .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(63,185,80,.18); }
.status.err .dot { background: var(--red); }

/* ---------- 主体 ---------- */
main { padding: 22px 0 40px; min-height: 60vh; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Hero ---------- */
.hero {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 24px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.hero h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: .5px; }
.hero-sub { margin: 0; color: var(--text-2); font-size: 13.5px; max-width: 780px; }
.hero-sub b { color: var(--green); font-weight: 600; }
.hero-side { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.date-nav { display: flex; align-items: center; gap: 6px; }
.date-nav button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 19px; line-height: 1;
}
.date-nav button:hover { background: var(--panel-2); border-color: var(--green); }
.date-nav input {
  background: var(--panel); border: 1px solid var(--line-2); color: var(--text);
  padding: 6px 10px; border-radius: 8px; font-family: inherit; font-size: 13px;
  color-scheme: dark;
}
.date-hint { font-size: 11.5px; color: var(--text-3); }

/* ---------- KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; position: relative; overflow: hidden;
}
.kpi::after { content:''; position:absolute; inset:0 auto 0 0; width: 3px; background: var(--line-2); }
.kpi.k-corn::after { background:#e3b341; } .kpi.k-soy::after { background:#3fb950; }
.kpi.k-rice::after { background:#58a6ff; } .kpi.k-wheat::after { background:#d29922; }
.kpi.k-total::after { background:var(--green); }
.kpi-label { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 25px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.kpi-unit { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 3px; }
.kpi-sub { font-size: 11.5px; color: var(--text-2); }
.up { color: var(--red); } .down { color: var(--green); } .flat { color: var(--text-3); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 16px; overflow: hidden;
}
.card-hd {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.card-hd h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-bd { padding: 16px; }
.tag { font-size: 11.5px; color: var(--text-3); background: var(--panel-2); padding: 3px 9px; border-radius: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sel {
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text);
  padding: 5px 9px; border-radius: 7px; font-family: inherit; font-size: 12.5px;
}
.chart { min-height: 260px; width: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 11px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
table.tbl th {
  text-align: left; padding: 9px 12px; background: var(--panel-2);
  color: var(--text-3); font-weight: 600; font-size: 11.5px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr:hover td { background: rgba(255,255,255,.022); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px; background: var(--panel-2); color: var(--text-2); }
.pill.g { background: rgba(63,185,80,.15); color: var(--green); }
.pill.b { background: rgba(88,166,255,.15); color: var(--blue); }
.pill.a { background: rgba(210,153,34,.15); color: var(--amber); }
.empty { padding: 34px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ---------- 筛选 ---------- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 140px; }
.fld.grow { flex: 1; min-width: 200px; }
.fld label { font-size: 11.5px; color: var(--text-3); }
.fld input, .fld select {
  background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text);
  padding: 7px 10px; border-radius: 8px; font-family: inherit; font-size: 13px;
}
.fld input:focus, .fld select:focus { outline: none; border-color: var(--green); }
.btn-primary {
  background: var(--green); border: 0; color: #fff; padding: 8px 20px; border-radius: 8px;
  cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600;
}
.btn-primary:hover { background: var(--green-2); }
.btn-ghost {
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text-2);
  padding: 5px 13px; border-radius: 7px; cursor: pointer; font-family: inherit; font-size: 12.5px;
}
.btn-ghost:hover { border-color: var(--green); color: var(--text); }
#pager:empty { display: none; }
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 0 4px; flex-wrap: wrap; }
.pager .btn-ghost { padding: 6px 13px; }
.pager .btn-ghost:disabled { opacity: .35; cursor: not-allowed; }
.pg-info { font-size: 12.5px; color: var(--text-2); padding: 0 6px; }

.result-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 12.5px; color: var(--text-2); }

/* ---------- 期货 ---------- */
.fut-list { display: flex; flex-direction: column; gap: 2px; }
.fut-item {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 9px 12px; border-radius: 8px; cursor: pointer; transition: background .15s;
}
.fut-item:hover { background: var(--panel-2); }
.fut-name { display: flex; flex-direction: column; }
.fut-name b { font-size: 13.5px; font-weight: 600; }
.fut-name span { font-size: 11px; color: var(--text-3); }
.fut-last { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.fut-chg { font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; min-width: 78px; }
.fut-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.fut-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; cursor: pointer; transition: border-color .15s; }
.fut-card:hover { border-color: var(--green); }
.fut-card .fc-hd { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.fut-card .fc-name { font-weight: 600; font-size: 14px; }
.fut-card .fc-ex { font-size: 10.5px; color: var(--text-3); }
.fut-card .fc-last { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.fut-card .fc-chg { font-size: 12.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.fut-card .fc-meta { font-size: 11px; color: var(--text-3); margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }

/* ---------- 图表 SVG ---------- */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font-size: 10.5px; }
.chart .line-path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area-path { opacity: .13; }
.chart .hover-dot { r: 4; stroke: var(--bg); stroke-width: 2; }

/* ---------- 品类目录 ---------- */
.cat-groups { display: flex; flex-direction: column; gap: 20px; }
.cat-group { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cat-group-hd {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
}
.cat-group-hd .ic { font-size: 20px; }
.cat-group-hd h3 { margin: 0; font-size: 15px; }
.cat-group-hd p { margin: 0; font-size: 12px; color: var(--text-3); }
.cat-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 0; }
.cat-item { padding: 14px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cat-item h4 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.cat-item h4 .gi { font-size: 10px; background: rgba(210,153,34,.16); color: var(--amber); padding: 1px 6px; border-radius: 20px; }
.cat-meta { font-size: 12px; color: var(--text-2); line-height: 1.8; }
.cat-meta b { color: var(--text-3); font-weight: 500; margin-right: 4px; }
.gi-list { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 5px; }
.gi-list span { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: rgba(210,153,34,.1); color: #d9b56a; }
.gi-list span.eu::after { content: ' 🇪🇺'; }

/* ---------- 数据源 ---------- */
.src-list { display: flex; flex-direction: column; gap: 14px; }
.src-item { border: 1px solid var(--line); border-radius: 10px; padding: 15px 16px; background: var(--bg-2); }
.src-item h3 { margin: 0 0 4px; font-size: 15px; }
.src-item .org { font-size: 12px; color: var(--green); margin-bottom: 10px; }
.src-item p { margin: 0 0 10px; font-size: 13px; color: var(--text-2); }
.src-kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 18px; font-size: 12px; }
.src-kv div { color: var(--text-2); }
.src-kv b { color: var(--text-3); font-weight: 500; margin-right: 5px; }
.src-item a { color: var(--blue); font-size: 12px; word-break: break-all; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-box { background: var(--panel-2); border-radius: 9px; padding: 12px 14px; }
.stat-box b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat-box span { font-size: 11.5px; color: var(--text-3); }
.note { font-size: 12px; color: var(--text-3); margin: 14px 0 0; line-height: 1.8; }
.note b { color: var(--text-2); }

/* ---------- 基差 ---------- */
.basis-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.hist-ctl { display: flex; align-items: center; gap: 8px; }
.hist-ctl input, .hist-ctl select {
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text);
  padding: 5px 9px; border-radius: 7px; font-family: inherit; font-size: 12.5px; color-scheme: dark;
}
.dash { color: var(--text-3); }

/* ---------- 页脚 ---------- */
.footer { border-top: 1px solid var(--line); padding: 18px 0; color: var(--text-3); font-size: 12px; }
.footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ver { font-variant-numeric: tabular-nums; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text);
  padding: 10px 18px; border-radius: 9px; font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s; z-index: 100;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================
   移动端：表格 → 卡片式列表
   ============================================================ */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: stretch; }
  .hero-side { align-items: stretch; }
  .date-nav { justify-content: space-between; }
  .date-nav input { flex: 1; }
  .hero h1 { font-size: 20px; }
}

@media (max-width: 760px) {
  body { font-size: 13.5px; }
  .wrap { padding: 0 13px; }
  .topbar-inner { height: auto; flex-wrap: wrap; padding: 10px 0 8px; gap: 10px; }
  .brand { order: 1; }
  .status { order: 2; margin-left: auto; }
  .nav { order: 3; width: 100%; margin-left: 0; padding-bottom: 2px; }
  .nav-btn { padding: 7px 11px; font-size: 13px; }
  main { padding: 16px 0 32px; }
  .hero h1 { font-size: 18px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .kpi { padding: 11px 12px; }
  .kpi-value { font-size: 21px; }
  .card-bd { padding: 13px; }
  .card-hd { padding: 11px 13px; }
  /* 卡片头在窄屏纵向堆叠，避免右侧控件被挤出屏幕 */
  .card-hd { flex-direction: column; align-items: stretch; gap: 9px; }
  .card-hd h2 { font-size: 14.5px; }
  .card-hd .sel, .card-hd select { width: 100%; }
  .card-hd .tag { align-self: flex-start; }
  .hist-ctl { width: 100%; }
  .hist-ctl input, .hist-ctl select { flex: 1; min-width: 0; }
  .filters { gap: 9px; }
  .fld { min-width: calc(50% - 5px); }
  .fld.grow { min-width: 100%; }
  .btn-primary { width: 100%; }

  /* 表格转卡片 */
  table.tbl { min-width: 0; }
  table.tbl thead { display: none; }
  table.tbl tr {
    display: block; margin-bottom: 9px;
    background: var(--bg-2); border: 1px solid var(--line);
    border-radius: 9px; padding: 10px 12px;
  }
  table.tbl tr:last-child { margin-bottom: 0; }
  table.tbl td {
    display: flex; justify-content: space-between; gap: 14px;
    padding: 4px 0; border: 0; text-align: right;
  }
  table.tbl td::before {
    content: attr(data-label);
    color: var(--text-3); font-size: 11.5px; font-weight: 500;
    text-align: left; flex-shrink: 0;
  }
  table.tbl td.cell-title {
    display: block; text-align: left; font-weight: 600; font-size: 14px;
    padding-bottom: 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line);
  }
  table.tbl td.cell-title::before { display: none; }
  table.tbl td.num { text-align: right; }
  table.tbl td[colspan] { display: block; text-align: center; }
  table.tbl td[colspan]::before { display: none; }
  .cat-cats { grid-template-columns: 1fr; }
  .cat-item { border-right: 0; }
  .fut-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 9px; }
  .fut-card .fc-last { font-size: 20px; }
  .chart { min-height: 220px; }
}

@media (max-width: 420px) {
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .fut-grid { grid-template-columns: 1fr; }
}
