:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f7f9fa;
  --ink: #19232d;
  --muted: #667482;
  --line: #d9e0e5;
  --line-strong: #c6d0d8;
  --accent: #087f70;
  --accent-dark: #06685d;
  --accent-soft: #e5f4f0;
  --blue-soft: #edf2ff;
  --blue-ink: #4053a3;
  --price: #b34f0a;
  --warning-soft: #fff4df;
  --warning-ink: #8b5a08;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1520px, calc(100% - 36px));
  margin: 0 auto;
  padding: 20px 0 48px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 56px;
  margin-bottom: 14px;
}

.brand-block {
  min-width: 0;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-line h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #b9dcd4;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  white-space: nowrap;
}

.brand-block p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-switch {
  display: grid;
  grid-template-columns: repeat(2, 70px);
  height: 36px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #edf1f3;
}

.view-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.view-switch button.active {
  background: var(--accent);
  color: #fff;
}

#reset-button,
.open-link,
.load-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

#reset-button:hover {
  border-color: #93a2ad;
  background: var(--panel-soft);
}

.overview-band,
.filter-band {
  border: 1px solid var(--line);
  background: var(--panel);
}

.overview-band {
  border-radius: 6px 6px 0 0;
}

.section-kicker {
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric {
  min-width: 0;
  padding: 14px 16px 15px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric > span,
.metric p {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.metric p {
  margin: 5px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-band {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 170px 210px 170px;
  align-items: end;
  gap: 10px;
  padding: 12px 14px 14px;
  border-top: 0;
  border-radius: 0 0 6px 6px;
}

.search-box,
.select-box {
  display: grid;
  gap: 5px;
  min-width: 0;
}

label {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input {
  padding: 0 11px;
}

select {
  padding: 0 32px 0 10px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 112, 0.12);
}

.result-section {
  margin-top: 18px;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.result-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.result-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.content {
  display: grid;
}

.product-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.product-card {
  display: grid;
  grid-template-rows: auto minmax(48px, auto) auto auto;
  gap: 10px;
  min-width: 0;
  min-height: 190px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.product-card:hover {
  border-color: #aebbc4;
}

.product-card-head,
.product-title-row,
.price-line,
.supplier-line,
.product-tags,
.shop-name-line {
  display: flex;
  align-items: center;
  min-width: 0;
}

.product-card-head {
  justify-content: space-between;
  gap: 8px;
}

.rank {
  color: #8a98a4;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.product-tags {
  justify-content: flex-end;
  gap: 5px;
  overflow: hidden;
}

.tag,
.source-pill,
.category-list span,
.crawl-state {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  white-space: nowrap;
}

.tag {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag.type {
  flex: 0 0 auto;
  background: var(--blue-soft);
  color: var(--blue-ink);
}

.product-title-row {
  align-items: flex-start;
  gap: 9px;
}

.product-thumb {
  display: block;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-soft);
}

.product-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-thumb.empty::before {
  content: "--";
  display: grid;
  height: 100%;
  place-items: center;
  color: #9ca8b1;
  font-size: 11px;
}

.product-thumb.empty img {
  display: none;
}

.product-card h3,
.shop-entry h3 {
  margin: 0;
  letter-spacing: 0;
}

.product-card h3 {
  display: -webkit-box;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.price-line {
  gap: 8px;
}

.price-label {
  color: var(--muted);
  font-size: 10px;
}

.price-line strong {
  color: var(--price);
  font-size: 21px;
  line-height: 1;
  letter-spacing: 0;
}

.market-price {
  color: #8a97a1;
  font-size: 11px;
  white-space: nowrap;
}

.stock {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.supplier-line {
  gap: 7px;
  min-height: 34px;
  padding-top: 9px;
  border-top: 1px solid #e8ecef;
}

.shop-link {
  min-width: 0;
  overflow: hidden;
  color: #3d4b56;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-name {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.open-link {
  min-height: 29px;
  margin-left: auto;
  padding: 0 10px;
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
}

.open-link:hover {
  background: var(--accent-dark);
}

.open-link.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.shop-table {
  grid-template-columns: 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.shop-table-head,
.shop-entry {
  display: grid;
  grid-template-columns: minmax(210px, 1.3fr) 100px 72px 72px 92px minmax(220px, 1.4fr) 62px;
  align-items: center;
  gap: 12px;
}

.shop-table-head {
  min-height: 36px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11px;
}

.shop-entry {
  min-height: 70px;
  padding: 10px 12px;
  border-bottom: 1px solid #e8ecef;
}

.shop-entry:last-child {
  border-bottom: 0;
}

.shop-entry:hover {
  background: #fbfcfc;
}

.shop-identity,
.shop-name-line {
  min-width: 0;
}

.shop-name-line {
  gap: 7px;
}

.shop-entry h3 {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shop-identity p {
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crawl-state {
  flex: 0 0 auto;
  min-height: 19px;
  padding: 0 5px;
  background: var(--warning-soft);
  color: var(--warning-ink);
  font-size: 10px;
}

.crawl-state.done {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.source-pill {
  width: fit-content;
  background: var(--blue-soft);
  color: var(--blue-ink);
}

.shop-number {
  color: #3c4953;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.price-number {
  color: var(--price);
  font-weight: 650;
}

.category-list {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.category-list span {
  flex: 0 0 auto;
  background: #f0f3f5;
  color: #596772;
}

.shop-entry .open-link {
  justify-self: end;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  min-height: 180px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.load-more {
  width: min(320px, 100%);
  margin: 14px auto 0;
}

@media (max-width: 1180px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .shop-table-head,
  .shop-entry {
    grid-template-columns: minmax(200px, 1.2fr) 90px 65px 65px 85px minmax(160px, 1fr) 58px;
    gap: 8px;
  }
}

@media (max-width: 900px) {
  .site-header {
    align-items: flex-start;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .filter-band {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .shop-table {
    gap: 8px;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .shop-table-head {
    display: none;
  }

  .shop-entry {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 9px 14px;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
  }

  .shop-identity {
    grid-column: 1 / 4;
  }

  .shop-entry .source-pill {
    grid-column: 4;
    grid-row: 1;
  }

  .shop-number::before {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 400;
  }

  .items-number::before {
    content: "条目";
  }

  .stock-number::before {
    content: "现货";
  }

  .price-number::before {
    content: "低价";
  }

  .category-list {
    grid-column: 1 / 4;
  }

  .shop-entry .open-link {
    grid-column: 4;
    grid-row: 2 / 4;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1520px);
    padding-top: 12px;
  }

  .site-header {
    display: grid;
    gap: 12px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .view-switch {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }

  .brand-line h1 {
    font-size: 21px;
  }

  .metric {
    padding: 12px;
  }

  .metric strong {
    font-size: 20px;
  }

  .filter-band {
    grid-template-columns: 1fr 1fr;
  }

  .search-box,
  .sort-select {
    grid-column: 1 / -1;
  }

  .product-grid {
    grid-template-columns: 1fr;
  }

  .product-card {
    min-height: 176px;
  }

  .result-head {
    align-items: flex-end;
  }

  .shop-entry {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  }

  .shop-identity {
    grid-column: 1 / 4;
  }

  .category-list {
    grid-column: 1 / 4;
  }
}
