:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --bg: #f8fafc;
  --sidebar-bg: #f1f5f9;
  --sidebar-active: #2563eb;
  --card-bg: #fff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1200px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }

.view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }

/* ============ Top Bar ============ */
.top-bar {
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: var(--shadow-lg);
  flex-shrink: 0;
}
.top-bar-inner {
  display: flex;
  align-items: center;
  padding: 14px 20px;
}
.logo { font-size: 22px; font-weight: 700; white-space: nowrap; }

/* 搜索栏（banner 下方） */
.search-bar {
  padding: 12px 20px;
  background: white;
  border-bottom: 1px solid var(--border);
}
.search-box {
  display: flex;
  background: var(--bg);
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: 600px;
  margin: 0 auto;
  transition: border-color 0.2s;
}
.search-box:focus-within { border-color: var(--primary); }
.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 18px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-btn {
  border: none;
  background: var(--primary);
  color: white;
  padding: 0 20px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s;
}
.search-btn:hover { background: var(--primary-dark); }

/* ============ Banner ============ */
.banner {
  position: relative;
  width: 100%;
  height: 200px;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.banner::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,0.1) 0%, transparent 50%);
}
.banner.has-image::before {
  background: linear-gradient(180deg, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.5) 100%);
}
.banner-overlay {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 20px;
}
.banner-title {
  font-size: 28px;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 8px rgba(0,0,0,0.25);
  margin-bottom: 6px;
  letter-spacing: 1px;
}
.banner-subtitle {
  font-size: 14px;
  color: rgba(255,255,255,0.92);
  text-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ============ Main Layout ============ */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 200px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 16px 12px 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.category-list { list-style: none; padding-bottom: 12px; }
.category-list > li {
  padding: 18px 14px;
  cursor: pointer;
  font-size: 18px;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: all 0.2s;
  text-align: left;
  position: relative;
}
.category-list > li:hover { background: rgba(37,99,235,0.08); }
.category-list > li.active {
  background: white;
  border-left-color: var(--sidebar-active);
  color: var(--sidebar-active);
  font-weight: 600;
}
.cat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.cat-arrow {
  width: 14px;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
  text-align: center;
}
.cat-arrow.expanded { transform: rotate(90deg); color: var(--sidebar-active); }
.cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-cats {
  list-style: none;
  margin: 6px 0 0 0;
  padding: 0;
}
.sub-cats li {
  padding: 14px 12px 14px 34px;
  font-size: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  margin: 2px 6px;
  border-left: none;
  position: relative;
}
.sub-cats li::before {
  content: '·';
  position: absolute;
  left: 22px;
  color: var(--text-muted);
  font-weight: bold;
}
.sub-cats li:hover { background: rgba(37,99,235,0.1); color: var(--text); }
.sub-cats li.active {
  background: rgba(99,102,241,0.12);
  color: var(--primary);
  font-weight: 600;
  border-left: none;
}

/* Product Area */
.product-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.current-category { font-size: 18px; font-weight: 700; }
.product-count {
  background: var(--primary);
  color: white;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
}

/* Product Grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.product-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}
.product-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  background: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}
.product-card:hover .product-thumb img { transform: scale(1.05); }
.product-info { padding: 12px 14px; }
.product-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
  line-height: 1.3;
}
.product-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-price {
  font-size: 16px;
  font-weight: 700;
  color: #ef4444;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 64px; margin-bottom: 12px; }
.empty-text { font-size: 16px; }

/* ============ Detail View ============ */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: white;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-btn {
  border: none;
  background: var(--bg);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.2s;
}
.back-btn:hover { background: var(--border); }
.detail-title { font-size: 16px; font-weight: 600; flex: 1; }
.header-icon-btn {
  border: none;
  background: var(--bg);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s;
}
.header-icon-btn:hover { background: var(--border); }

.detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* 顶部：左图右信息 */
.detail-top {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
  align-items: flex-start;
}
.detail-gallery {
  flex: 0 0 440px;
  max-width: 440px;
}
.detail-main-img {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.detail-main-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.no-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 80px;
  color: #cbd5e1;
}
.img-counter {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
}
.detail-thumbs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.detail-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--sidebar-bg);
  transition: border-color 0.2s;
}
.detail-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.detail-thumb.active { border-color: var(--primary); }
.detail-thumb:hover { border-color: var(--primary); }

/* 右侧信息 */
.detail-info {
  flex: 1;
  min-width: 0;
}
.detail-cat-tag {
  display: inline-block;
  background: rgba(37,99,235,0.1);
  color: var(--primary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-weight: 500;
}
.detail-name {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 16px;
  color: var(--text);
}
.detail-price-box {
  background: linear-gradient(135deg, #fff7ed 0%, #fef3c7 100%);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.price-label {
  font-size: 13px;
  color: var(--text-muted);
}
.detail-price {
  font-size: 32px;
  font-weight: 700;
  color: #ef4444;
  line-height: 1;
}
.detail-meta {
  background: white;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.meta-row {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.meta-row:last-child { border-bottom: none; }
.meta-label {
  width: 60px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.meta-value {
  flex: 1;
  color: var(--text);
  font-weight: 500;
}
.detail-actions {
  display: flex;
  gap: 12px;
}
.action-btn {
  flex: 1;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.action-btn.primary {
  background: var(--primary);
  color: white;
}
.action-btn.primary:hover { background: var(--primary-dark); }
.action-btn.ghost {
  background: white;
  color: var(--text);
  border-color: var(--border);
}
.action-btn.ghost:hover { background: var(--bg); }

/* 详情区块 */
.detail-section {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.section-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.title-bar {
  width: 4px;
  height: 18px;
  background: var(--primary);
  border-radius: 2px;
}
.detail-desc-content {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
}
.detail-images-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail-big-img {
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--sidebar-bg);
}
.detail-big-img img {
  width: 100%;
  display: block;
  transition: opacity 0.2s;
}
.detail-big-img:hover img { opacity: 0.92; }

/* 底部操作栏 */
.detail-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: white;
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  gap: 12px;
  z-index: 50;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  max-width: 1200px;
  margin: 0 auto;
}
.bar-btn {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  transition: all 0.2s;
  border: 1px solid transparent;
}
.bar-btn:hover { background: var(--border); }
.bar-btn.primary {
  background: var(--primary);
  color: white;
  flex: 2;
}
.bar-btn.primary:hover { background: var(--primary-dark); }
.bar-btn.favorited {
  color: #f59e0b;
  border-color: #f59e0b;
}

/* Toast */
.detail-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  white-space: nowrap;
}
.detail-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.detail-toast.success { background: var(--success); }

/* ============ Image Viewer ============ */
.image-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.image-viewer.active { display: flex; }
.image-viewer img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
}
.close-viewer {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.close-viewer:hover { background: rgba(255,255,255,0.3); }
.viewer-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 20px;
  color: white;
}
.viewer-nav button {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.viewer-nav button:hover { background: rgba(255,255,255,0.3); }
#viewer-counter { font-size: 16px; }

/* ============ Mobile ============ */
@media (max-width: 768px) {
  .top-bar-inner { padding: 10px 14px; }
  .logo { font-size: 18px; }
  .search-bar { padding: 10px 14px; }
  .search-box input { padding: 8px 14px; font-size: 13px; }
  .banner { height: 140px; }
  .banner-title { font-size: 20px; }
  .banner-subtitle { font-size: 12px; }
  .sidebar { width: 120px; }
  .sidebar-header { font-size: 11px; padding: 12px 8px 6px; }
  .category-list > li { padding: 14px 8px; font-size: 16px; }
  .cat-arrow { display: none; }
  .sub-cats { margin-top: 4px; }
  .sub-cats li { padding: 10px 8px; font-size: 15px; margin: 2px 4px; border-radius: 4px; }
  .sub-cats li::before { display: none; }
  .product-area { padding: 14px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .product-name { font-size: 14px; }
  .product-price { font-size: 14px; }
  .detail-content { padding: 14px; }
  .detail-top { flex-direction: column; gap: 16px; }
  .detail-gallery { flex: none; max-width: 100%; }
  .detail-name { font-size: 18px; }
  .detail-price { font-size: 24px; }
  .detail-price-box { padding: 12px 16px; }
  .detail-thumb { width: 54px; height: 54px; }
  .bar-btn { padding: 10px; font-size: 13px; }
}

@media (max-width: 480px) {
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 115px; }
  .category-list > li { font-size: 15px; padding: 12px 6px; }
  .sub-cats li { font-size: 14px; padding: 8px 6px; }
  .product-desc { -webkit-line-clamp: 1; }
}

/* Scrollbar */
.sidebar::-webkit-scrollbar,
.product-area::-webkit-scrollbar,
.detail-content::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-thumb,
.product-area::-webkit-scrollbar-thumb,
.detail-content::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 2px;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}
.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin-left: 10px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }