:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #6b7280;
  --line: #dfe3ea;
  --brand: #1f7a5c;
  --brand-dark: #155c45;
  --danger: #b42318;
}

* { box-sizing: border-box; }

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

a { color: var(--brand-dark); text-decoration: none; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 700; font-size: 18px; }

.nav { display: flex; gap: 14px; align-items: center; }
.nav a { padding: 8px 10px; border-radius: 6px; color: #25313d; }
.nav a:hover { background: #eef7f3; }

.wrap { max-width: 1220px; margin: 0 auto; padding: 24px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 14px; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.btn {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
}
.btn.secondary { background: #fff; color: var(--brand-dark); border-color: #b7d5ca; }
.btn.danger { background: #fff; color: var(--danger); border-color: #e5b7b2; }
.btn.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }

input, textarea, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
}

textarea { min-height: 110px; resize: vertical; }
label { display: block; font-size: 13px; color: #374151; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f0f3f6; font-size: 13px; color: #374151; }

.thumb-cell {
  width: 58px;
  max-width: 58px;
}

td.thumb-cell {
  padding: 6px 8px;
}

.thumb-cell .muted {
  white-space: nowrap;
}

.table-thumb {
  width: 32px !important;
  height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #edf0f4;
  display: block;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  background: #eef2ff;
  color: #3538cd;
}

.flash { padding: 11px 14px; border-radius: 6px; background: #e7f6ef; color: #16563f; margin-bottom: 16px; }
.error { padding: 11px 14px; border-radius: 6px; background: #fdecec; color: #9b1c13; margin-bottom: 16px; }
.muted { color: var(--muted); font-size: 13px; }

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

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

.image-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: #edf0f4;
}

.image-card .meta { padding: 8px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.image-card label { margin: 0; display: flex; gap: 7px; align-items: center; }
.image-card input { width: auto; min-height: auto; }

.detail-image-inserter {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.product-image-selector {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.product-image-workspace {
  display: grid;
  grid-template-columns: minmax(240px, .8fr) minmax(0, 1.2fr);
  gap: 16px;
  align-items: start;
}

.product-image-column {
  min-width: 0;
}

.product-selected-images {
  min-height: 130px;
}

.product-image-grid {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

.detail-image-grid {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

.detail-image-card {
  padding: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.sortable { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.sortable-item { cursor: grab; }
.sortable-item.dragging { opacity: .45; }
.position-badge { position: absolute; margin: 6px; background: rgba(0,0,0,.68); color: #fff; border-radius: 999px; padding: 3px 7px; font-size: 12px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.tab {
  border: 1px solid #cfd6df;
  background: #fff;
  color: #25313d;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.tab.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.tag-picker {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

.tag-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

.tag-group-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.tag-options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

[hidden] {
  display: none !important;
}

.tag-chip {
  border: 1px solid #cfd6df;
  background: #fff;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  cursor: pointer;
  color: #25313d;
}

.tag-chip:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.tag-chip.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.tag-choice {
  border: 1px solid #cfd6df;
  background: #fff;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  cursor: pointer;
  color: #25313d;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
}

.tag-choice input {
  width: auto;
  min-height: auto;
}

.selected-tags {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  font-size: 13px;
}

.topic-filter-tree,
.tag-tree {
  display: grid;
  gap: 10px;
}

.topic-filter-group,
.tag-tree-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.topic-parent {
  margin-bottom: 8px;
}

.tag-tree-parent {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
  align-items: end;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.tag-tree-child {
  margin-left: 18px;
}

.tag-rule-table th,
.tag-rule-table td {
  vertical-align: middle;
}

.tag-rule-table input {
  min-height: 32px;
  padding: 6px 8px;
}

.tag-rule-table .btn.danger {
  width: 100%;
}

.tag-row-level-1 {
  background: #f8fafc;
  font-weight: 700;
}

.tag-row-level-2 {
  background: #fff;
}

.tag-row-level-3 {
  background: #fcfdff;
}

.tree-title {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.tag-title-input {
  font-weight: 600;
  color: var(--ink);
}

.tree-indent-1 { padding-left: 22px; }
.tree-indent-2 { padding-left: 52px; }

.tree-spacer,
.tree-line {
  width: 12px;
  height: 20px;
  border-left: 1px solid #cfd6df;
  border-bottom: 1px solid #cfd6df;
}

.tree-spacer {
  border: 0;
}

.tag-code-fields {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 6px;
}

.tag-topic-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
  display: block;
}

.topic-choice {
  border-radius: 8px;
}

.topic-choice-thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
}

.upload-progress {
  display: none;
  margin-top: 12px;
}

.upload-progress.is-active { display: block; }

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #e5eaf0;
  overflow: hidden;
  border: 1px solid #d5dce5;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--brand);
  transition: width .15s ease;
}

.progress-text {
  margin-top: 7px;
  font-size: 13px;
  color: var(--muted);
}

.preview-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}

.preview-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.preview-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

@media (max-width: 860px) {
  .grid.two, .grid.three, .row, .row.three, .row.four, .product-image-workspace { grid-template-columns: 1fr; }
  .topbar { height: auto; padding: 12px 16px; align-items: flex-start; flex-direction: column; gap: 8px; }
  .wrap { padding: 16px; }
  .page-head { align-items: flex-start; flex-direction: column; }
}
