:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --panel: #ffffff;
  --subtle: #f1ede6;
  --text: #242321;
  --muted: #6b6761;
  --soft: #8f877d;
  --line: #e3ded6;
  --line-strong: #cfc7bc;
  --accent: #2f2f2f;
  --accent-hover: #1f1f1f;
  --gold: #b08a57;
  --gold-soft: #f4ebdd;
  --danger: #9f3a2f;
  --danger-soft: #f4e2df;
  --ok: #52665d;
  --ok-soft: #edf1ee;
  --shadow: 0 12px 34px rgba(36, 35, 33, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

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

button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 10px 15px;
  cursor: pointer;
  transition: 0.18s ease;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

button.secondary:hover {
  border-color: var(--line-strong);
  background: var(--subtle);
}

button.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger);
  color: #fff;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(176, 138, 87, 0.12);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

label input,
label select,
label textarea {
  color: var(--text);
  font-size: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 244, 239, 0.94);
  backdrop-filter: blur(10px);
}

.brand {
  margin-right: 12px;
  letter-spacing: 0.02em;
}

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

.hint {
  color: var(--soft);
  font-size: 12px;
  line-height: 1.6;
  margin: 8px 0 0;
}

.link {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.page {
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 54px;
}

.panel,
.consult {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.narrow {
  max-width: 420px;
  margin: 56px auto;
}

.form {
  display: grid;
  gap: 12px;
}

.message {
  min-height: 24px;
  color: var(--gold);
}

.module-message {
  grid-column: 1 / -1;
  min-height: 24px;
  margin: 0;
  border-radius: 10px;
  color: var(--gold);
  font-size: 13px;
}

.module-message.success {
  color: var(--ok);
}

.module-message.error {
  color: var(--danger);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 24px 0 14px;
  min-width: 0;
}

.section-head h1,
.section-head h2 {
  margin: 0;
  white-space: nowrap;
}

.small-head {
  margin-top: 0;
}

.admin-titlebar {
  align-items: flex-start;
}

.admin-titlebar p {
  margin: 8px 0 0;
}

.admin-shell {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  width: 100%;
}

.admin-nav {
  position: sticky;
  top: 78px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px;
  box-shadow: var(--shadow);
  width: 200px;
}

.admin-nav-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.admin-nav-item:hover,
.admin-nav-item.active {
  border-color: var(--line-strong);
  background: var(--accent);
  color: #fff;
}

.admin-content {
  display: grid;
  gap: 16px;
  min-width: 0;
  width: 100%;
}

.admin-module[hidden] {
  display: none;
}

.admin-editor {
  margin-bottom: 18px;
}

.product-editor-form {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 22px;
  align-items: start;
}

.image-uploader {
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  padding: 14px;
  background: #fbfaf7;
}

.gallery-uploader {
  grid-column: 1;
}

.product-editor-form > .form-grid {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  color: var(--text);
  font-weight: 700;
}

.upload-preview,
.item-thumb,
.thumb {
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(176, 138, 87, 0.13), rgba(47, 47, 47, 0.06)),
    repeating-linear-gradient(45deg, #ece8e1, #ece8e1 10px, #f7f4ef 10px, #f7f4ef 20px);
  color: var(--muted);
}

.upload-preview {
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.upload-preview img,
.item-thumb img,
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-preview {
  display: grid;
  gap: 10px;
  margin: 10px 0 12px;
}

.gallery-thumb {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
}

.gallery-thumb .thumb {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.gallery-thumb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.gallery-thumb-actions button {
  padding: 6px 9px;
  font-size: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
}

.form-section-title {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
}

.form-section-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.settings-panel {
  margin-bottom: 18px;
}

.settings-form textarea {
  min-height: 78px;
}

.span-2 {
  grid-column: span 3;
}

.switch-row,
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.switch-row label,
.inline-check {
  display: inline-flex;
  width: auto;
  grid-auto-flow: column;
  align-items: center;
  gap: 7px;
  color: var(--text);
}

.switch-row input,
.inline-check input {
  width: auto;
  min-height: auto;
}

.admin-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
}

.admin-filter-panel {
  display: grid;
  gap: 10px;
  margin: 6px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfaf7;
}

.admin-filter-search {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.admin-filters select {
  flex: 1 1 132px;
  min-width: 132px;
}

.admin-filters #pageSizeFilter {
  flex: 0 1 126px;
}

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

.admin-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 12px;
}

.rich-item {
  display: grid;
  grid-template-columns: 88px minmax(260px, 1fr) minmax(110px, auto) minmax(250px, auto);
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.item-thumb {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 12px;
}

.item-main strong {
  display: block;
  margin-bottom: 5px;
  word-break: break-word;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

.pill,
.status {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  line-height: 1.3;
}

.pill {
  background: var(--subtle);
  color: var(--muted);
}

.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.warn {
  background: var(--danger-soft);
  color: var(--danger);
}

.status {
  display: inline-block;
  margin-left: 5px;
  background: var(--subtle);
  color: var(--muted);
}

.status.on {
  background: var(--ok-soft);
  color: var(--ok);
}

.status.off {
  background: #efefef;
  color: var(--soft);
}

.status.gold {
  background: var(--gold-soft);
  color: var(--gold);
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
}

.pagination button {
  min-width: 88px;
}

.category-panel {
  margin-top: 18px;
}

.category-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 110px auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.compact-select {
  max-width: 180px;
}

.category-list {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.category-chip,
.category-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 86px 62px minmax(150px, auto);
  gap: 6px;
  align-items: center;
  min-height: 46px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 5px 8px;
  background: #fff;
}

.category-row:last-child {
  border-bottom: 0;
}

.category-chip input,
.category-row input {
  min-height: 32px;
  padding: 5px 8px;
  border-radius: 8px;
}

.category-chip small,
.category-row small {
  color: var(--muted);
}

.category-status {
  text-align: center;
}

.category-actions {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
}

.compact-btn,
.category-row button {
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
}

button.danger-ghost {
  border: 1px solid var(--danger-soft);
  background: #fff;
  color: var(--danger);
}

button.danger-ghost:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.compat-field {
  opacity: 0.82;
}

.image-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.image-stat {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf7;
  padding: 12px;
}

.image-stat strong {
  font-size: 24px;
  line-height: 1;
}

.image-stat span {
  color: var(--muted);
  font-size: 12px;
}

.image-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
  gap: 10px;
}

.image-card {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.image-card.unlinked {
  border-color: #d4b274;
  background: #fffaf0;
}

.image-thumb-button {
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 0;
  background: #f1ede6;
  padding: 0;
}

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

.image-card-body {
  display: grid;
  gap: 6px;
  padding: 8px;
}

.image-card-title {
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.image-type-texture {
  border-color: #c9d7cf;
  background: var(--ok-soft);
  color: var(--ok);
}

.image-type-gallery {
  border-color: #e4d0ae;
  background: var(--gold-soft);
  color: var(--gold);
}

.image-type-unlinked {
  border-color: #d8b36d;
  background: #fff3d8;
  color: #8a6427;
  font-weight: 700;
}

.image-products {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.image-products.compact {
  max-height: 50px;
  overflow: hidden;
}

.image-product-line {
  display: grid;
  gap: 2px;
  border-radius: 8px;
  background: var(--subtle);
  padding: 5px 6px;
  min-width: 0;
}

.image-product-line strong {
  color: var(--text);
}

.image-product-line.compact {
  background: transparent;
  border-radius: 0;
  padding: 0;
}

.image-product-main,
.image-product-sub,
.image-product-more {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-product-main {
  display: flex;
  gap: 6px;
  min-width: 0;
}

.image-product-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-product-main em {
  flex: none;
  color: var(--muted);
  font-style: normal;
}

.image-product-sub {
  color: var(--soft);
}

.image-product-more {
  color: var(--gold);
}

.image-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.image-card-actions .compact-btn {
  min-height: 28px;
  padding: 4px 7px;
  font-size: 12px;
}

.image-preview-modal[hidden] {
  display: none;
}

.image-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: grid;
  place-items: center;
  background: rgba(36, 35, 33, 0.48);
  padding: 24px;
}

.image-preview-dialog {
  position: relative;
  overflow: auto;
  width: min(920px, 100%);
  max-height: calc(100vh - 48px);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 16px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
}

.image-preview-dialog img {
  display: block;
  width: 100%;
  max-height: 66vh;
  border-radius: 12px;
  background: #f1ede6;
  object-fit: contain;
}

.image-preview-meta {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

#previewImageTitle,
#previewImagePath {
  overflow-wrap: anywhere;
}

#previewCopyImagePath {
  justify-self: start;
}

/* lightweight landing page */
.landing {
  min-height: calc(100vh - 60px);
  display: grid;
  align-items: center;
}

.landing-card {
  max-width: 760px;
  margin: 32px auto;
  padding: 34px;
}

.landing-card h1 {
  margin: 0 0 12px;
  font-size: clamp(32px, 6vw, 56px);
  line-height: 1.08;
}

.landing-card p {
  line-height: 1.8;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.qr-placeholder {
  display: grid;
  place-items: center;
  width: 132px;
  height: 132px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  color: var(--muted);
  background: var(--subtle);
  margin-top: 22px;
}

/* legacy preview page compatibility */
.hero,
.toolbar,
.grid,
.card,
dialog {
  display: none;
}

@media (max-width: 900px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-nav {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .product-editor-form,
  .rich-item {
    grid-template-columns: 1fr;
  }

  .gallery-uploader,
  .product-editor-form > .form-grid {
    grid-column: auto;
    grid-row: auto;
  }

  .form-grid,
  .category-form,
  .category-chip,
  .category-row {
    grid-template-columns: 1fr;
  }

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

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

  .span-2 {
    grid-column: auto;
  }

  .item-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 0 16px;
  }

  .page {
    width: min(100% - 24px, 1220px);
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }
}
