:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --text: #17211b;
  --muted: #69746c;
  --line: #dde5dc;
  --brand: #116149;
  --brand-2: #d84f2a;
  --soft: #e9f2ed;
  --shadow: 0 14px 36px rgba(31, 46, 38, .12);
}

body.theme-fresh {
  --bg: #f0f8f7;
  --brand: #087d8f;
  --brand-2: #f2a541;
  --soft: #e1f1f0;
}

body.theme-classic {
  --bg: #f7f4ee;
  --brand: #4e5f35;
  --brand-2: #9e3f2f;
  --soft: #ede6d8;
}

body.theme-taobao {
  --bg: #fff5ef;
  --brand: #ff5000;
  --brand-2: #ff8a00;
  --soft: #fff0e5;
}

body.theme-xianyu {
  --bg: #f9fbef;
  --brand: #f6c600;
  --brand-2: #18a058;
  --soft: #fff8cc;
  --text: #1e261f;
}

body.theme-jd {
  --bg: #fff7f7;
  --brand: #e1251b;
  --brand-2: #b30000;
  --soft: #ffe8e8;
}

body.theme-amazon {
  --bg: #f3f5f6;
  --brand: #232f3e;
  --brand-2: #ff9900;
  --soft: #e8edf1;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--brand);
  color: white;
  cursor: pointer;
}

td button, .pager button, .list-tools button {
  padding: 8px 11px;
}

button:hover { filter: brightness(.95); }
button.secondary, .nav button, .tabs button, #logoutBtn, #resetProduct {
  background: var(--soft);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 14px 28px;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand, .nav, .account, .tabs, .dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.logo-text, .logo-img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: white;
  font-weight: 800;
  object-fit: cover;
}

.logo-img[src=""] { display: none; }
.logo-img:not([src=""]) + .logo-text { display: none; }

main {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 64px;
}

.view, .admin-tab { display: none; }
.view.active, .admin-tab.active { display: block; }

.hero {
  min-height: 300px;
  display: grid;
  grid-template-columns: 1.4fr .8fr;
  align-items: end;
  gap: 26px;
  padding: 38px;
  border-radius: 8px;
  background:
    linear-gradient(110deg, rgba(17,97,73,.92), rgba(216,79,42,.62)),
    url("https://images.unsplash.com/photo-1556742502-ec7c0e9f34b1?auto=format&fit=crop&w=1600&q=80") center/cover;
  color: white;
  box-shadow: var(--shadow);
}

.hero h1 {
  margin: 8px 0 10px;
  font-size: clamp(32px, 6vw, 62px);
  line-height: 1.02;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  font-weight: 700;
}

.intro {
  max-width: 620px;
  font-size: 18px;
  line-height: 1.7;
}

.hero-panel {
  display: grid;
  gap: 10px;
  padding: 22px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 8px;
  background: rgba(255,255,255,.14);
}

.hero-panel strong { font-size: 24px; }

.hero-panel small {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar {
  margin: 24px 0;
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 12px;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: var(--text);
}

select {
  white-space: nowrap;
  text-overflow: ellipsis;
  padding-right: 34px;
}

#categoryFilter {
  padding-right: 42px;
}

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

.card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(40, 51, 45, .06);
}

.card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  display: block;
  background: #ffffff;
}

.card-body {
  padding: 16px;
  display: grid;
  gap: 10px;
}

.card-body h3 {
  margin: 0;
  cursor: pointer;
}

.card-body p {
  margin: 0;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.price {
  color: var(--brand-2);
  font-size: 22px;
  font-weight: 800;
}

.product-actions {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
}

.icon-btn {
  min-width: 44px;
  padding: 10px;
  font-size: 18px;
}

.stack {
  display: grid;
  gap: 14px;
}

.order, .admin-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tabs {
  flex-wrap: wrap;
  gap: 6px;
}

.tabs button.active, .nav button.active {
  background: var(--brand);
  color: white;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-grid.compact {
  grid-template-columns: minmax(220px, 360px) auto auto;
  align-items: end;
}

.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.form-grid .wide { grid-column: span 2; }
.form-grid .check {
  align-content: end;
  grid-template-columns: auto 1fr;
}
.form-grid .check input { width: auto; }

#productForm .check {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  font-size: 14px;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
}

.table-wrap { overflow-x: auto; }

.export-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.list-tools, .pager {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin: 0 0 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-tools {
  justify-content: flex-start;
}

.list-tools input[type="search"] {
  max-width: 460px;
  min-width: 280px;
}

.order-select-row {
  justify-content: space-between;
}

.order-select-row .check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.pager {
  margin: 12px 0 0;
  color: var(--muted);
  justify-content: flex-end;
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.cart-row {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.cart-row img {
  width: 96px;
  height: 76px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--soft);
}

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

.cart-actions input {
  width: 76px;
}

#cartCount {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: var(--brand-2);
  color: white;
  padding: 0 7px;
  font-size: 12px;
}

dialog {
  width: min(560px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
  position: relative;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(23, 33, 27, .12);
  display: grid;
  place-items: center;
}

.dialog-close span,
.dialog-close::before {
  content: "";
  width: 15px;
  height: 2px;
  border-radius: 999px;
  background: var(--muted);
  grid-area: 1 / 1;
}

.dialog-close span {
  transform: rotate(45deg);
}

.dialog-close::before {
  transform: rotate(-45deg);
}

.dialog-close:hover {
  background: var(--soft);
}

.address-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

dialog::backdrop {
  background: rgba(0,0,0,.36);
}

dialog form, #detailBox {
  display: grid;
  gap: 13px;
}

.captcha-row {
  display: grid;
  grid-template-columns: 1fr 138px auto;
  gap: 8px;
  align-items: center;
}

.captcha-row img {
  width: 138px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.dialog-form {
  position: static;
}

.settings-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  margin-top: -4px;
}

#savedAddressWrap {
  white-space: normal;
}

#savedAddressWrap select {
  white-space: normal;
}

.site-footer {
  width: min(1180px, calc(100% - 32px));
  margin: -6px auto 10px;
  padding: 8px 0 0;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

#loadingOverlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  background: rgba(255,255,255,.58);
  backdrop-filter: blur(3px);
}

#loadingOverlay.show {
  display: grid;
}

#loadingText {
  padding: 14px 18px;
  border-radius: 8px;
  background: #17211b;
  color: white;
  box-shadow: var(--shadow);
}

#profileDialog {
  width: min(760px, calc(100% - 24px));
}

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

.address-item {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.float-actions {
  position: fixed;
  right: 22px;
  bottom: 88px;
  z-index: 8;
  display: grid;
  gap: 10px;
}

.float-actions button {
  position: relative;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  box-shadow: 0 10px 26px rgba(0,0,0,.18);
  font-size: 20px;
}

#floatCartCount {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--brand-2);
  color: white;
  font-size: 12px;
  padding: 0 5px;
}

#detailBox img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 8px;
  background: #ffffff;
}

.detail-images {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.detail-images img {
  max-height: 180px;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17211b;
  color: white;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}

#toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 14px 16px;
  }
  .nav, .account { flex-wrap: wrap; }
  .hero { grid-template-columns: 1fr; padding: 26px; }
  .toolbar { grid-template-columns: 1fr; }
  .admin-head { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.compact { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .cart-row { grid-template-columns: 74px 1fr; }
  .cart-row img { width: 74px; height: 62px; }
  .cart-actions { grid-column: 1 / -1; }
  .address-grid { grid-template-columns: 1fr; }
}
