:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #101828;
  --ink-2: #475467;
  --ink-3: #98a2b3;
  --line: #e4e7ec;
  --brand: #2f5aff;
  --brand-dark: #1d3fbf;
  --accent: #12b76a;
  --warn: #f79009;
  --danger: #f04438;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

/* the [hidden] attribute must win over the layout display rules below */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; }
button { font: inherit; cursor: pointer; }

/* ------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(135deg, #172554 0%, #2f5aff 55%, #5b8cff 100%);
  color: #fff;
  box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.brand > div { min-width: 0; }
.brand-logo {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, .18);
  font-weight: 700; font-size: 20px;
}
.brand h1 { font-size: 17px; font-weight: 650; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { margin: 2px 0 0; font-size: 12px; opacity: .82; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.lang-select {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255, 255, 255, .16);
  border-radius: 999px; padding: 4px 8px; font-size: 13px;
}
.lang-select select {
  background: transparent; border: none; color: #fff; font-size: 13px;
  padding: 2px 0; max-width: 120px;
}
.lang-select select option { color: #101828; }

.scope-switch {
  display: inline-flex; border: 1px solid var(--line); border-radius: 999px;
  overflow: hidden; background: #fbfcfe;
}

/* ---------------------------------------------------- vendor multi select */
.ms-wrap { position: relative; display: inline-flex; flex-direction: column; gap: 4px; }
.ms-label { font-size: 12px; color: var(--ink-2); }
.multi-select { position: relative; }
.ms-btn {
  min-width: 150px; text-align: left; background: #fbfcfe; color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 28px 8px 10px;
  font-size: 13px; position: relative;
}
.ms-btn::after {
  content: ""; position: absolute; right: 10px; top: 50%; margin-top: -3px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid #98a2b3;
}
.ms-panel {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0;
  width: 260px; max-height: 320px; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .14); padding: 10px;
}
.ms-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.ms-actions button {
  flex: 1; border: 1px solid #c7d7fe; background: #eef2ff; color: var(--brand);
  border-radius: 8px; padding: 6px 0; font-size: 12px; font-weight: 600;
}
.ms-search { width: 100%; margin-bottom: 8px; }
.ms-list { display: flex; flex-direction: column; gap: 2px; }
.ms-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px;
  border-radius: 8px; font-size: 13px; cursor: pointer;
}
.ms-item:hover { background: #f4f7ff; }
.ms-item input { width: 15px; height: 15px; }
.ms-item .region-tag {
  margin-left: auto; font-size: 11px; color: var(--ink-3);
}
.scope-btn {
  border: none; background: transparent; color: var(--ink-2);
  padding: 8px 14px; font-size: 13px;
}
.scope-btn + .scope-btn { border-left: 1px solid var(--line); }
.scope-btn.active { background: var(--brand); color: #fff; font-weight: 600; }

.collect-time {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .16);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.collect-time .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .25);
}

.ghost-btn {
  background: rgba(255, 255, 255, .14);
  color: #fff; border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 10px; padding: 7px 13px; font-size: 13px;
}
.ghost-btn:hover { background: rgba(255, 255, 255, .24); }

.primary-btn {
  background: var(--brand); color: #fff; border: none;
  border-radius: 10px; padding: 9px 16px; font-size: 13px; font-weight: 600;
}
.primary-btn:hover { background: var(--brand-dark); }

.settings-panel {
  max-width: 1400px; margin: 0 auto; padding: 0 18px 16px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
}
.settings-panel label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; flex: 1 1 320px; }
.settings-panel input {
  padding: 9px 11px; border-radius: 9px; border: 1px solid rgba(255, 255, 255, .4);
  background: rgba(255, 255, 255, .95); font-size: 13px; color: var(--ink);
}
.settings-actions { display: flex; gap: 8px; }
.settings-panel .hint { width: 100%; margin: 0; font-size: 12px; opacity: .8; }

/* price range filter group */
.filters.ranges {
  width: 100%;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}
.filters .range {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.filters .range small { color: var(--ink-3); font-size: 11px; }
.range-inputs { display: inline-flex; align-items: center; gap: 6px; }
.range-inputs input { width: 84px; max-width: 84px; }
.range-inputs em { color: var(--ink-3); font-style: normal; }
.filters .check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2); cursor: pointer;
}
.filters .check input { width: 15px; height: 15px; }
.link-btn {
  align-self: flex-start;
  background: #eef2ff; color: #2f5aff; border: 1px solid #c7d7fe;
  border-radius: 9px; padding: 7px 13px; font-size: 13px; font-weight: 600;
}
.link-btn:hover { background: #e0e7ff; }
.doc-link { color: var(--brand); text-decoration: none; }
.doc-link:hover { text-decoration: underline; }

/* -------------------------------------------------------------- tabs */
.tabs {
  position: sticky; top: var(--topbar-h, 68px); z-index: 20;
  display: flex; gap: 4px; overflow-x: auto;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 12px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: none; background: transparent; color: var(--ink-2);
  padding: 14px 14px 12px; font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ----------------------------------------------------------- layout */
.content { max-width: 1400px; margin: 0 auto; padding: 18px; }
.view { display: block; }
.h2 { font-size: 15px; margin: 18px 0 10px; }
.section-hint { color: var(--ink-2); font-size: 13px; margin: 0 0 14px; }
.muted { color: var(--ink-3); }

/* ------------------------------------------------------------ stats */
.stat-row {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.stat {
  background: var(--panel); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .k { font-size: 12px; color: var(--ink-3); }
.stat .v { font-size: 22px; font-weight: 650; margin-top: 4px; }

/* ---------------------------------------------------------- toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--panel); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.search {
  flex: 1 1 260px; min-width: 200px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: #fbfcfe; font-size: 14px;
}
.search:focus, select:focus, input:focus { outline: 2px solid rgba(47, 90, 255, .25); border-color: var(--brand); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters label, .inline {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2);
}
select, .filters input, .inline input {
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line);
  background: #fbfcfe; font-size: 13px; color: var(--ink); max-width: 220px;
}
select[multiple] { min-width: 150px; height: 36px; }

/* ------------------------------------------------------------ table */
.table-wrap {
  background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: visible;
}
@media (max-width: 1100px) {
  .table-wrap { overflow-x: auto; }
}
table.price-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.price-table th, .price-table td {
  padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line);
  font-size: 13px; vertical-align: top;
}
.price-table th {
  background: #f8fafc; color: var(--ink-2); font-weight: 600;
  white-space: nowrap;
}
.content .price-table thead th {
  position: sticky;
  top: calc(var(--topbar-h, 68px) + var(--tabs-h, 46px));
  z-index: 6;
  box-shadow: inset 0 -1px 0 var(--line);
}
.price-table th[data-sort] { cursor: pointer; user-select: none; }
.price-table th[data-sort]:hover { color: var(--brand); }
/* 排序图标：上下三角（未排序灰色，当前排序方向高亮） */
.price-table th .sort-ico {
  display: inline-block; width: 9px; height: 15px; margin-left: 4px;
  position: relative; vertical-align: -3px;
}
.price-table th .sort-ico::before,
.price-table th .sort-ico::after {
  content: ""; position: absolute; left: 0; width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
}
.price-table th .sort-ico::before { top: 1px; border-bottom: 5px solid #c8ced8; }
.price-table th .sort-ico::after { bottom: 1px; border-top: 5px solid #c8ced8; }
.price-table th.sorted-asc .sort-ico::before { border-bottom-color: var(--brand); }
.price-table th.sorted-desc .sort-ico::after { border-top-color: var(--brand); }
.price-table th.sorted-asc, .price-table th.sorted-desc { color: var(--brand); }
.price-unit-hint { color: var(--ink-3); font-size: 12px; margin: 8px 2px 0; }
.price-table td.num, .price-table th.num {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.price-table tbody tr:hover { background: #f8faff; }
.price-table tbody tr.clickable { cursor: pointer; }
.price-table small { color: var(--ink-3); font-weight: 400; }

.model-cell { display: flex; flex-direction: column; gap: 2px; }
.model-cell .name { font-weight: 600; }
.model-cell .sub { color: var(--ink-3); font-size: 12px; }
.vendor-pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: #eef2ff; color: #3538cd; font-size: 12px; white-space: nowrap;
}
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: #f2f4f7; color: var(--ink-2); font-size: 11px; margin: 0 4px 3px 0;
  white-space: nowrap;
}
.tag.green { background: #e7f8ef; color: #067647; }
.tag.orange { background: #fef3e6; color: #b54708; }
.free { color: var(--accent); font-weight: 600; }
.strike { color: var(--ink-3); text-decoration: line-through; font-size: 11px; }
.cny { color: var(--ink-3); font-size: 11px; white-space: nowrap; }

/* -------------------------------------------------------- recommend */
.card-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.rec-card {
  background: var(--panel); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.rec-card .rank {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: #eef2ff; color: #3538cd; font-weight: 700; font-size: 13px;
}
.rec-card h4 { margin: 0; font-size: 15px; }
.rec-card .price-line { font-size: 13px; color: var(--ink-2); }
.rec-card .price-line b { color: var(--ink); font-size: 15px; }
.rec-card ul { margin: 0; padding-left: 16px; color: var(--ink-2); font-size: 12px; }
.rec-card .head { display: flex; align-items: center; gap: 10px; }
.score-bar { height: 6px; border-radius: 999px; background: #eef2ff; overflow: hidden; }
.score-bar i { display: block; height: 100%; background: linear-gradient(90deg, #5b8cff, #2f5aff); }

/* --------------------------------------------------------- chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  border-radius: 999px; padding: 6px 12px; font-size: 12px;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------------------------------------------------------- pager */
.pager { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 16px 0; flex-wrap: wrap; }
.pager button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 9px;
  padding: 7px 12px; font-size: 13px; color: var(--ink-2);
}
.pager button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.pager button:disabled { opacity: .45; cursor: not-allowed; }
.pager .info { font-size: 12px; color: var(--ink-3); }

/* --------------------------------------------------------- drawer */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 100%);
  background: var(--panel); z-index: 41; display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(16, 24, 40, .18);
}
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.drawer-head .ghost-btn { background: #f2f4f7; color: var(--ink-2); border-color: var(--line); }
.drawer-body { padding: 16px 18px 40px; overflow: auto; }
.drawer-body h4 { margin: 18px 0 8px; font-size: 14px; }
.drawer-body h4:first-child { margin-top: 0; }
.drawer-body .price-table { min-width: 0; }
.model-desc { color: var(--ink-2); font-size: 13px; line-height: 1.65; margin: 0; }
.channel-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
}
.channel-row .left { display: flex; flex-direction: column; gap: 3px; }
.channel-row .right { text-align: right; font-variant-numeric: tabular-nums; }
.best { border-color: #b7ebd2; background: #f3fcf7; }
.bar-list { display: flex; flex-direction: column; gap: 6px; }
.bar-item { display: grid; grid-template-columns: 120px 1fr 70px; gap: 8px; align-items: center; font-size: 12px; }
.bar-track { height: 8px; background: #eef2ff; border-radius: 999px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: #2f5aff; }

/* --------------------------------------------------- history chart */
.history-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 14px 0 8px; flex-wrap: wrap;
}
.history-toolbar h4 { margin: 0; }
.switch-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 8px; padding: 5px 10px; font-size: 12px;
}
.switch-btn.active { background: #eef2ff; border-color: #c7d7fe; color: var(--brand); font-weight: 600; }
.chart-wrap { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 12px; }
.chart-wrap canvas { width: 100%; height: 220px; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.chart-legend span i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.history-empty { color: var(--ink-3); font-size: 13px; }
.source-list { display: flex; flex-direction: column; gap: 8px; }
.source-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px;
}
.source-item a { color: var(--brand); text-decoration: none; font-weight: 600; }
.source-item a:hover { text-decoration: underline; }
.attr-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px; margin-bottom: 4px;
}
.attr-box { background: #f8fafc; border-radius: 10px; padding: 9px 11px; }
.attr-box .k { color: var(--ink-3); font-size: 11px; }
.attr-box .v { font-weight: 600; margin-top: 3px; font-size: 13px; }

/* --------------------------------------------------------- footer */
.footer {
  max-width: 1400px; margin: 0 auto; padding: 22px 18px 40px;
  color: var(--ink-3); font-size: 12px; display: flex; justify-content: space-between; gap: 10px;
}
.empty { padding: 40px 16px; text-align: center; color: var(--ink-3); }
.error-box {
  background: #fef3f2; border: 1px solid #fecdca; color: #b42318;
  border-radius: 10px; padding: 12px 14px; font-size: 13px; margin-bottom: 12px;
}

/* ------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .brand-sub { display: none; }
  .topbar-inner { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .brand { flex: 1 1 100%; }
  .brand h1 { font-size: 16px; }
  .brand-logo { width: 32px; height: 32px; flex-basis: 32px; font-size: 17px; border-radius: 10px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .collect-time { font-size: 11px; padding: 5px 10px; }
  .content { padding: 12px; }
  .toolbar { padding: 10px; gap: 8px; }
  .filters { width: 100%; }
  .filters label {
    flex: 1 1 45%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    white-space: nowrap;
  }
  .inline { flex-direction: column; align-items: stretch; gap: 4px; }
  .filters select, .filters input { max-width: none; width: 100%; }
  .filters.ranges { gap: 12px; }
  .filters .range { flex: 1 1 100%; }
  .range-inputs { width: 100%; }
  .range-inputs input { width: 100%; max-width: none; }
  .filters .check { flex: 1 1 100%; }
  .filters .check { flex-direction: row; align-items: center; justify-content: flex-start; white-space: normal; }

  /* tables become stacked cards on phones */
  table.price-table { min-width: 0; }
  .price-table thead { display: none; }
  .price-table tbody tr {
    display: block; border: 1px solid var(--line); border-radius: 12px;
    margin: 8px; padding: 6px 12px 8px;
  }
  .price-table tbody td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
    border: none; padding: 4px 0; text-align: right; min-height: 22px;
  }
  .price-table tbody td::before {
    content: attr(data-label); color: var(--ink-3); font-size: 12px;
    text-align: left; flex: 0 0 72px;
  }
  .price-table tbody td.num { text-align: right; }
  .price-table tbody tr:first-child { margin-top: 10px; }
  .price-unit-hint { margin: 6px 12px 0; }
  .chart-wrap canvas { height: 190px; }
  .drawer { width: 100%; top: 8%; border-radius: 16px 16px 0 0; }
  .bar-item { grid-template-columns: 84px 1fr 56px; }
  .footer { flex-direction: column; }
}
