:root {
  --primary-color: #E4393C;
  --primary-hover: #C81623;
  --text-dark: #333;
  --text-gray: #666;
  --text-light: #999;
  --bg-gray: #F0F0F0;
  --border-color: #E3E4E5;
}

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

body {
  font-family: "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg-gray);
  color: var(--text-dark);
}

header {
  background: var(--primary-color);
  color: white;
  padding: 15px 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.logo {
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.search-bar {
  flex: 1;
  max-width: 500px;
  margin: 0 40px;
  display: flex;
}

.search-bar input {
  flex: 1;
  padding: 8px 15px;
  border: none;
  border-radius: 2px 0 0 2px;
}

.search-bar button {
  padding: 8px 20px;
  background: white;
  color: var(--primary-color);
  border: none;
  border-radius: 0 2px 2px 0;
  cursor: pointer;
  font-weight: bold;
}

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

.header-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 14px;
  position: relative;
}

.badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #FFD700;
  color: var(--primary-color);
  font-size: 12px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
}

main {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.product-card {
  background: white;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.product-image {
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.product-info {
  padding: 15px;
}

.product-name {
  font-size: 14px;
  color: var(--text-dark);
  height: 40px;
  overflow: hidden;
  margin-bottom: 8px;
}

.product-price {
  color: var(--primary-color);
  font-size: 20px;
  font-weight: bold;
}

.product-original-price {
  color: var(--text-light);
  font-size: 14px;
  text-decoration: line-through;
  margin-left: 8px;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.ai-float-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 1000;
}

.ai-float-btn button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(228, 57, 60, 0.4);
}

.ai-chat-window {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 400px;
  height: 500px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.ai-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid var(--border-color);
}

.ai-tabs {
  display: flex;
  gap: 10px;
}

.ai-tab {
  padding: 8px 16px;
  border: none;
  background: var(--bg-gray);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
}

.ai-tab.active {
  background: var(--primary-color);
  color: white;
}

.ai-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
}

.ai-message {
  margin-bottom: 15px;
  display: flex;
  gap: 10px;
}

.ai-message.user {
  justify-content: flex-end;
}

.ai-message-content {
  max-width: 70%;
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.ai-message.ai .ai-message-content {
  background: var(--bg-gray);
}

.ai-message.user .ai-message-content {
  background: var(--primary-color);
  color: white;
}

.ai-chat-footer {
  display: flex;
  gap: 10px;
  padding: 15px;
  border-top: 1px solid var(--border-color);
}

.ai-chat-footer input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

.ai-chat-footer button {
  padding: 8px 20px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  height: 100vh;
  background: white;
  box-shadow: -4px 0 12px rgba(0,0,0,0.2);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s;
}

.cart-drawer.open {
  transform: translateX(0);
}

.cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.cart-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.cart-footer {
  padding: 20px;
  border-top: 1px solid var(--border-color);
}

.cart-total {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 15px;
  text-align: right;
}

.cart-total span {
  color: var(--primary-color);
  font-size: 24px;
}

.hidden {
  display: none !important;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-gray);
}

.admin-panel {
  background: white;
  border-radius: 8px;
  padding: 30px;
  margin: 20px 0;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.form-group input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat-card {
  background: var(--bg-gray);
  padding: 20px;
  border-radius: 8px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: bold;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.stat-label {
  color: var(--text-gray);
  font-size: 14px;
}

header {
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr) auto;
  gap: 18px;
  align-items: center;
}

.brand {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
}

.search-form {
  display: flex;
  min-width: 0;
}

.search-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  outline: none;
  border-radius: 4px 0 0 4px;
}

.search-form button {
  border: 0;
  padding: 10px 18px;
  background: #fff;
  color: var(--primary-color);
  font-weight: 700;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.lang-btn {
  border: 0;
  min-width: 44px;
  padding: 7px 10px;
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.lang-btn.active {
  background: #fff;
  color: var(--primary-color);
  font-weight: 700;
}

.nav-btn,
.btn-secondary,
.btn-ghost,
.link-btn,
.qty-btn,
.chip {
  border: 0;
  cursor: pointer;
}

.nav-btn,
.btn-secondary,
.btn-ghost {
  padding: 9px 14px;
  border-radius: 4px;
  font-size: 14px;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ffd54a;
  color: #8d1f20;
  font-size: 12px;
  font-weight: 700;
}

.page-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-shell.narrow {
  max-width: 720px;
  margin: 0 auto;
}

.page-intro,
.toolbar,
.result-strip,
.panel,
.product-detail,
.checkout-layout {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.page-intro {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  align-items: end;
}

.page-intro h1,
.panel-head h1,
.panel-head h2,
.detail-title {
  color: var(--text-dark);
}

.page-intro p,
.detail-subtitle,
.product-subtitle {
  color: var(--text-gray);
  margin-top: 6px;
  line-height: 1.5;
}

.intro-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-chip {
  min-width: 84px;
  padding: 10px 14px;
  border-radius: 6px;
  background: #fff5f5;
  text-align: center;
}

.stat-chip span {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary-color);
}

.stat-chip small {
  color: var(--text-gray);
}

.toolbar,
.result-strip,
.panel-head,
.panel-body,
.crumbs {
  padding: 14px 18px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

.toolbar-label {
  display: inline-block;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-gray);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: #f7f7f7;
  color: var(--text-dark);
  font-size: 13px;
}

.chip.active {
  background: var(--primary-color);
  color: #fff;
}

.result-strip {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.muted {
  color: var(--text-gray);
}

.link-btn {
  background: transparent;
  color: var(--primary-color);
  padding: 0;
}

.link-btn.danger {
  color: var(--primary-hover);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.product-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.product-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-badges,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.flag,
.tag,
.status {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
}

.flag-hot,
.status-paid {
  background: #fff2f0;
  color: #c23131;
}

.flag-new,
.status-shipped {
  background: #eef7ff;
  color: #2d6bba;
}

.flag-deal,
.status-completed {
  background: #f1fff4;
  color: #2d8a4a;
}

.status-pending {
  background: #fff7e8;
  color: #b16a00;
}

.status-cancelled {
  background: #f4f4f4;
  color: #666;
}

.product-subtitle {
  font-size: 13px;
  height: 38px;
  overflow: hidden;
}

.product-meta,
.product-foot,
.detail-price-line,
.quantity-row,
.cart-summary,
.order-row,
.table-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.product-foot {
  font-size: 12px;
}

.tag {
  background: #f4f4f4;
  color: #555;
}

.btn-secondary {
  background: #f4f4f4;
  color: #333;
}

.btn-ghost {
  background: transparent;
  color: var(--text-gray);
  border: 1px solid var(--border-color);
}

.product-detail,
.checkout-layout {
  display: grid;
  gap: 0;
}

.product-detail {
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  overflow: hidden;
}

.product-gallery {
  background: #fff;
  padding: 18px;
  border-right: 1px solid var(--border-color);
}

.product-gallery img {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: #fafafa;
}

.product-pane {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.detail-title {
  font-size: 28px;
  line-height: 1.2;
}

.detail-price {
  font-size: 30px;
  font-weight: 700;
  color: var(--primary-color);
}

.detail-original {
  color: var(--text-light);
  text-decoration: line-through;
}

.detail-meta-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.detail-meta-grid > div {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px;
  background: #fafafa;
}

.detail-meta-grid label {
  display: block;
  color: var(--text-gray);
  font-size: 12px;
  margin-bottom: 6px;
}

.detail-meta-grid strong {
  font-size: 16px;
}

.detail-description {
  color: var(--text-dark);
  line-height: 1.7;
}

.detail-actions,
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.split-grid,
.checkout-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.panel {
  overflow: hidden;
}

.panel-head {
  border-bottom: 1px solid var(--border-color);
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.panel-body.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.spec-list {
  display: grid;
  gap: 10px;
}

.spec-list > div {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 8px;
}

.spec-list dt {
  color: var(--text-gray);
}

.spec-list dd {
  color: var(--text-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field.full {
  grid-column: 1 / -1;
}

.field span {
  font-size: 13px;
  color: var(--text-gray);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font: inherit;
  background: #fff;
  color: var(--text-dark);
}

.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
}

.field.checkbox input {
  width: auto;
}

.auth-panel {
  max-width: 680px;
  margin: 0 auto;
}

.empty-state,
.empty-inline,
.loading-box {
  padding: 24px;
  text-align: center;
  color: var(--text-gray);
}

.loading-box {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.crumbs {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--text-gray);
}

.cart-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cart-item,
.order-row {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
}

.cart-item {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 12px;
}

.cart-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
}

.cart-item-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: #f2f2f2;
}

.cart-summary {
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.table-like {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.order-row {
  cursor: pointer;
  margin-bottom: 10px;
}

.order-right {
  text-align: right;
}

.toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 3000;
}

.toast {
  min-width: 220px;
  max-width: 320px;
  padding: 12px 14px;
  border-radius: 6px;
  color: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.toast-success {
  background: #2f9e44;
}

.toast-error {
  background: #d94848;
}

.toast-info {
  background: #2d6bba;
}

.toast.fade-out {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.alert {
  padding: 14px 16px;
  border-radius: 6px;
}

.alert-danger {
  background: #fff1f1;
  color: #a52323;
  border: 1px solid #f1c0c0;
}

.ai-chat-window {
  width: min(420px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 150px));
}

.ai-chat-body {
  background: #fafafa;
}

.ai-message-content {
  word-break: break-word;
}

.cart-drawer {
  width: min(420px, 100vw);
}

.cart-footer {
  background: #fff;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .nav-group {
    justify-content: flex-start;
  }

  .toolbar,
  .page-intro,
  .result-strip,
  .split-grid,
  .checkout-layout,
  .product-detail,
  .form-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .product-gallery {
    border-right: 0;
    border-bottom: 1px solid var(--border-color);
  }

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

@media (max-width: 720px) {
  main {
    padding: 0 12px;
  }

  .detail-meta-grid,
  .stats-grid,
  .spec-list > div {
    grid-template-columns: 1fr;
  }

  .cart-drawer,
  .ai-chat-window {
    right: 12px;
    left: 12px;
    width: auto;
  }

  .cart-drawer {
    height: 80vh;
  }

  .page-intro {
    align-items: start;
  }
}
