/* === Base Reset & Variables === */
:root {
  --jd-red: #e2231a;
  --jd-red-dark: #c81e1a;
  --primary: #e2231a;
  --bg: #f4f4f4;
  --card-bg: #fff;
  --text: #333;
  --text-light: #999;
  --border: #eee;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 12px;
}

/* === Header === */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  position: relative;
}
.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--jd-red);
}
.logo.center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}
.header-nav {
  display: flex;
  gap: 20px;
}
.header-nav a {
  font-size: 14px;
  color: var(--text-light);
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: all .2s;
}
.header-nav a.active,
.header-nav a:hover {
  color: var(--jd-red);
  border-bottom-color: var(--jd-red);
}
.back-btn {
  font-size: 14px;
  color: var(--text-light);
  width: 60px;
}
.back-btn::before { content: ''; margin-right: 0; }

/* === Footer === */
.site-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-light);
  font-size: 12px;
  margin-top: 40px;
}

/* === Loading spinner === */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 0;
  color: var(--text-light);
  gap: 12px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f0f0f0;
  border-top-color: var(--jd-red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Category Tabs === */
.category-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0;
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid #ddd;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
}
.tab-btn.active {
  background: var(--jd-red);
  color: #fff;
  border-color: var(--jd-red);
}

/* === Rank Cards (Grid) === */
.rank-list {
  padding: 8px 0 20px;
}
.rank-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.rank-card {
  display: block;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
}
.rank-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
}
.rank-card-inner { display: flex; flex-direction: column; }
.rank-card-cover {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: #f9f9f9;
}
.rank-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.rank-card-mask {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s;
}
.rank-card:hover .rank-card-mask { opacity: 1; }
.view-btn {
  background: var(--jd-red);
  color: #fff;
  padding: 6px 20px;
  border-radius: 20px;
  font-size: 13px;
}
.rank-card-info { padding: 12px; }
.rank-card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rank-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
}
.rank-tag {
  background: #fff0f0;
  color: var(--jd-red);
  padding: 2px 8px;
  border-radius: 10px;
}
.empty {
  text-align: center;
  padding: 60px 0;
  color: var(--text-light);
}

/* === Rank Detail Page === */
.rank-header {
  background: linear-gradient(135deg, #d13438 0%, #c81e1a 100%);
  padding: 16px 0;
  margin-bottom: 10px;
}
.rank-header-inner {
  display: flex;
  gap: 14px;
  align-items: center;
}
.rank-header-cover {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(255,255,255,.2);
  display: none; /* 默认隐藏，有图再显示 */
}
.rank-header-cover.visible { display: block; }
.rank-header-info { flex: 1; min-width: 0; }
.rank-header-info h2 {
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.3;
  text-align: center;
}
.rank-header-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.rank-header-meta .rank-tag {
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
}

/* === Rank Items List (Detail) === */
.rank-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 80px; /* 底部留空避免被遮挡 */
}

.rank-item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rank-item-left {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.rank-item-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.rank-item-rank {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 1;
  width: 22px;
  height: 22px;
  background: var(--jd-red);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.rank-item-rank.top3 {
  background: linear-gradient(135deg, #FFD700, #FF6B00);
  color: #fff;
}

.rank-item-img-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  background: #f5f5f5;
}
.rank-item-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.rank-item-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--jd-red);
  text-align: center;
}

.rank-item-info {
  flex: 1;
  min-width: 0;
}
.rank-item-title {
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
  color: var(--text);
  font-weight: 500;
}
.rank-item-price-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.price {
  color: var(--jd-red);
  font-weight: 700;
  font-size: 15px;
}
.price-tag {
  background: #fff0f0;
  color: var(--jd-red);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 3px;
}
.rank-item-sales {
  font-size: 11px;
  color: var(--text-light);
}
.rank-item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}
.tag-repurchase {
  background: #fff3e0;
  color: #e65100;
}
.tag-rebuy {
  background: #e8f5e9;
  color: #2e7d32;
}
.tag-topdays {
  background: #fff8e1;
  color: #f57f17;
}
.tag-self {
  background: #fce4ec;
  color: #c2185b;
}
.tag-sales {
  background: #e3f2fd;
  color: #1565c0;
}

.rank-item-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  align-items: flex-end;
}
.btn-link {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  background: var(--jd-red);
  color: #fff;
  text-align: center;
  white-space: nowrap;
  min-width: 52px;
}
.btn-link:hover { background: var(--jd-red-dark); }

.btn-copy, .btn-convert {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  background: #f5f5f5;
  color: var(--text);
  border: 1px solid #e0e0e0;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
  min-width: 52px;
}
.btn-copy:hover, .btn-convert:hover {
  background: var(--jd-red);
  color: #fff;
  border-color: var(--jd-red);
}
.btn-copy.success, .btn-convert.success {
  background: #4caf50;
  color: #fff;
  border-color: #4caf50;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.75);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 9999;
  animation: fadeIn .2s;
  white-space: nowrap;
}
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* === QR Code Modal === */
.modal-qr {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-qr-content {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  min-width: 240px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-qr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.modal-qr-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-light);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.modal-qr-close:hover { color: var(--text); }
.modal-qr-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
}
.modal-qr-footer {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-light);
}
.btn-jd-scan {
  background: #fff3e0 !important;
  color: #e65100 !important;
  border-color: #ffb74d !important;
}

/* === Mobile Action Bar === */
.mobile-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #eee;
  padding: 8px 12px;
  z-index: 200;
  box-shadow: 0 -2px 10px rgba(0,0,0,.06);
}
.mobile-action-inner {
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile-tips {
  font-size: 12px;
  color: var(--text-light);
}

/* === Mobile Responsive === */
@media screen and (max-width: 768px) {
  .site-header .container { height: 56px; }
  .logo { font-size: 20px; }
  .logo.center { font-size: 17px; }
  .back-btn { font-size: 15px; }

  .rank-header { padding: 14px 0; }
  .rank-header-info h2 { font-size: 19px; }

  .rank-item {
    padding: 14px;
    gap: 12px;
  }
  .rank-item-card { flex-shrink: 0; }
  .rank-item-img-wrap {
    width: 100px;
    height: 100px;
    border-radius: 10px;
  }
  .rank-item-rank {
    width: 26px;
    height: 26px;
    font-size: 13px;
    top: 6px;
    left: 6px;
  }
  .rank-item-price {
    font-size: 15px;
    margin-top: 2px;
  }
  .rank-item-title {
    font-size: 15px;
    line-height: 1.5;
    -webkit-line-clamp: 3;
    margin-bottom: 6px;
  }
  .rank-item-tags {
    gap: 6px;
    margin-top: 6px;
  }
  .tag {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 4px;
  }
  .rank-item-info { flex: 1; }

  .rank-item-actions {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }
  .btn-link {
    font-size: 14px;
    padding: 9px 12px;
    min-width: unset;
    border-radius: 6px;
    text-align: center;
  }
  .btn-copy {
    font-size: 12px !important;
    padding: 8px !important;
    min-width: unset !important;
    border-radius: 6px;
    font-weight: 600;
    background: #e2231a !important;
    color: #fff !important;
    border-color: #e2231a !important;
  }
  .btn-link {
    font-size: 12px !important;
    padding: 8px !important;
    min-width: unset;
    border-radius: 6px;
    text-align: center;
    background: #fff !important;
    color: #333 !important;
    border: 1px solid #ddd !important;
  }
  .rank-cards {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }
  .rank-card-info { padding: 10px; }
  .rank-card-title { font-size: 13px; }

  .tab-btn {
    padding: 8px 18px;
    font-size: 15px;
  }

  .toast {
    bottom: 90px;
    font-size: 15px;
    padding: 12px 24px;
  }

  .mobile-action-bar { padding: 10px 16px; }
  .mobile-tips { font-size: 13px; }

  .empty { padding: 40px 0; font-size: 15px; }
  .loading { padding: 40px 0; }
}

/* === Small Mobile === */
@media screen and (max-width: 400px) {
  .rank-item-img-wrap { width: 88px; height: 88px; }
  .rank-item-title { font-size: 14px; }
  .rank-item { padding: 12px 10px; }
  .btn-link {
    font-size: 13px;
    padding: 8px 10px;
  }
  .btn-copy {
    font-size: 14px !important;
    padding: 9px 10px !important;
  }
}

/* === JD Tab Bar style === */
.jd-tabs {
  display: flex;
  border-bottom: 2px solid var(--jd-red);
}
.jd-tabs .tab-btn {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-light);
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  position: relative;
}
.jd-tabs .tab-btn.active {
  background: transparent;
  color: var(--jd-red);
}
.jd-tabs .tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--jd-red);
}

/* ========================
   移动端响应式 (手机优先)
   ======================== */
@media (max-width: 640px) {
  .container { padding: 0 10px; }

  /* 排行榜列表页 - 卡片网格 */
  .rank-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .rank-card-info { padding: 8px; }
  .rank-card-title { font-size: 12px; }
  .rank-card-meta { font-size: 11px; }

  /* 详情页头部 */
  .rank-header { padding: 12px 0; }
  .rank-header-cover { width: 52px; height: 52px; }
  .rank-header-info h2 { font-size: 15px; }

  /* 详情页商品列表 - 移动端优化 */
  .rank-items { gap: 8px; padding-bottom: 70px; }

  .rank-item {
    padding: 10px;
    border-radius: 10px;
    flex-wrap: wrap;
  }

  .rank-item-left { gap: 8px; }

  .rank-item-rank {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .rank-item-img-wrap {
    width: 54px;
    height: 54px;
    border-radius: 6px;
  }

  .rank-item-title { font-size: 12px; -webkit-line-clamp: 2; }
  .price { font-size: 14px; }

  .rank-item-actions {
    flex-direction: row;
    width: 100%;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid #f0f0f0;
  }

  .btn-link, .btn-copy, .btn-convert {
    font-size: 11px;
    padding: 4px 8px;
    min-width: 46px;
  }
}

/* 超小屏幕 (< 380px) */
@media (max-width: 380px) {
  .rank-cards { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .rank-item-img-wrap { width: 48px; height: 48px; }
  .rank-item-title { font-size: 11px; }
  .price { font-size: 13px; }
}

/* PC端 (641px以上) */
@media (min-width: 641px) {
  .rank-header-cover.visible { display: block; }

  .rank-item:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
  }

  .rank-item-actions {
    flex-direction: column;
    width: auto;
    align-items: flex-end;
  }

  .rank-item-actions > * + * { margin-top: 5px; }
}