:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #dce2ea;
  --soft: #f8fafc;
  --primary: #111111;
  --primary-blue: #2563eb;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  background: var(--primary-blue);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(.95);
}

button:disabled {
  opacity: .55;
  cursor: wait;
}

button.ghost {
  background: #eef2f7;
  color: #243044;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
}

.side-nav {
  min-width: 0;
  padding: 22px 20px;
  background: #fbfaf7;
  border-right: 1px solid #e2e0d8;
  overflow: auto;
}

.brand {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #141414;
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.1;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.nav-item {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 999px;
  padding: 0 18px;
  background: transparent;
  color: #1f2937;
  font-size: 17px;
  font-weight: 900;
  text-align: left;
}

.nav-item::after {
  content: "↗";
  color: #9aa1ad;
  font-weight: 700;
}

.nav-item.active {
  background: #111;
  color: #fff;
}

.nav-item.active::after {
  color: #fff;
}

.nav-divider {
  height: 1px;
  margin: 26px 12px;
  background: #d9d6cf;
}

.side-summary {
  display: grid;
  gap: 8px;
  padding: 0 8px;
}

.side-summary span {
  height: 34px;
  display: flex;
  align-items: center;
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
  color: #344054;
  font-size: 13px;
  border: 1px solid #e7e5de;
}

.workspace {
  min-width: 0;
  min-height: 0;
  padding: 18px;
  overflow: hidden;
}

.view-panel {
  display: none;
  min-width: 0;
  height: 100%;
}

.view-panel.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 0 4px 12px;
  border-bottom: 1px solid var(--line);
}

.view-head h2 {
  font-size: 24px;
}

.view-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.section,
.products-panel,
.template-main,
.template-side {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.section {
  padding: 14px;
  background: var(--soft);
}

.section-head,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.section-head-actions .link-toggle {
  margin-top: 0;
}

h3 {
  font-size: 15px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.extract-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 14px;
}

.input-column {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(260px, .95fr) minmax(220px, .8fr);
  gap: 14px;
}

.table-section,
.copy-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
}

.copy-section {
  grid-template-rows: auto minmax(0, 1fr);
}

.table-actions {
  display: flex;
  justify-content: flex-end;
}

textarea {
  width: 100%;
  min-height: 0;
  resize: none;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  outline: none;
  line-height: 1.55;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.status {
  min-height: 36px;
  padding: 9px 10px;
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status.error {
  color: var(--danger);
  background: #fff1f2;
}

.products-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 14px;
}

.panel-head {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.products-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding-top: 12px;
}

.empty-card,
.product-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.empty-card {
  padding: 18px;
  color: var(--muted);
}

.product-row {
  padding: 10px;
  cursor: pointer;
}

.product-row.active {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .12);
}

.product-row.failed {
  border-color: #fecdd3;
}

.product-row header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.product-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.product-row span {
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 12px;
}

.product-row p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.text-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.text-editor label {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.text-editor label.wide {
  grid-column: 1 / -1;
}

.text-editor input {
  width: 100%;
  height: 34px;
  margin-top: 5px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
  color: var(--ink);
}

.candidate-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.candidate {
  position: relative;
  min-height: 0;
  padding: 0;
  border: 2px solid transparent;
  overflow: hidden;
  background: #eef2f7;
  color: #344054;
}

.candidate.selected {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .18);
}

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

.candidate span {
  position: absolute;
  left: 5px;
  top: 5px;
  min-width: 34px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: rgba(17, 24, 39, .72);
  color: #fff;
  font-size: 12px;
}

.template-actions select,
.control-grid input,
.export-dir-field input {
  height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0 9px;
  background: #fff;
  color: var(--ink);
}

.template-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
}

.template-main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

.template-toolbar {
  display: grid;
  grid-template-columns: minmax(420px, 1.4fr) minmax(300px, 1fr);
  gap: 14px;
}

.template-upload,
.export-section {
  min-height: 0;
}

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

.asset-upload-block {
  min-width: 0;
}

.template-drop {
  min-height: 118px;
  margin-top: 10px;
  display: grid;
  place-items: center;
  gap: 8px;
  border: 2px dashed #c9d3df;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  overflow: hidden;
}

.template-drop.dragging {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.template-drop img {
  display: none;
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  background: #eef2f7;
}

.template-drop.has-image img {
  display: block;
}

.logo-drop {
  background-image: linear-gradient(45deg, #eef2f7 25%, transparent 25%), linear-gradient(-45deg, #eef2f7 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eef2f7 75%), linear-gradient(-45deg, transparent 75%, #eef2f7 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.logo-slot-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin: 8px 0 6px;
  padding: 3px;
  border-radius: 6px;
  background: #e2e8f0;
}

.logo-slot-switch button {
  min-height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.logo-slot-switch button.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}

.logo-slot-switch button.has-logo::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 5px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: middle;
}

.export-dir-field {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.output-size-field {
  display: grid;
  gap: 6px;
}

.output-size-head {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  font-size: 13px;
}

.output-preset {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: #e2e8f0;
  border-radius: 6px;
}

.output-preset button {
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.output-preset button.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}

.output-size-note {
  color: var(--muted);
  font-size: 11px;
}

.export-dir-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  margin-top: 6px;
}

.export-dir-control input {
  width: 100%;
  height: 42px;
  margin-top: 0;
  border-radius: 6px 0 0 6px;
  border-right: 0;
  font-size: 15px;
  color: var(--ink);
}

.folder-btn {
  position: relative;
  min-height: 42px;
  border: 1px solid #cbd5e1;
  border-radius: 0 6px 6px 0;
  background: #f8fafc;
}

.folder-btn::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 14px;
  width: 18px;
  height: 13px;
  border: 2px solid #64748b;
  border-radius: 2px;
  box-sizing: border-box;
}

.folder-btn::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 11px;
  width: 9px;
  height: 5px;
  border: 2px solid #64748b;
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  box-sizing: border-box;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.download-link {
  display: none;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  border-radius: 7px;
  background: #111827;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  padding: 8px 10px;
  word-break: break-all;
  text-align: center;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background-color: #eef2f7;
  background-image: radial-gradient(circle at 24px 24px, rgba(100, 116, 139, .22) 1px, transparent 1.5px);
  background-size: 72px 72px;
}

#templateCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

#templateCanvas.pen-cursor {
  cursor: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='32'%20height='32'%20viewBox='0%200%2024%2024'%20fill='white'%20stroke='black'%20stroke-width='2.4'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='m18%2013-1.5-7.5L2%202l3.5%2014.5L13%2018Z'/%3E%3Cpath%20d='m2%202%207.6%207.6'/%3E%3Ccircle%20cx='11'%20cy='11'%20r='2'%20fill='black'/%3E%3Cpath%20d='m12%2019%207-7%203%203-7%207Z'/%3E%3C/svg%3E") 3 3, crosshair;
}

#templateCanvas.can-grab {
  cursor: grab;
}

#templateCanvas.is-grabbing {
  cursor: grabbing;
}

#canvasEmpty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  background: rgba(248, 250, 252, .86);
  pointer-events: none;
}

.template-side {
  min-height: 0;
  display: grid;
  grid-template-rows: none;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding-right: 2px;
  background: transparent;
  border: 0;
}

.template-side .section {
  padding: 12px;
}

.template-side h3 {
  font-size: 14px;
}

.mode-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding: 2px;
}

.mode-btn {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  word-break: keep-all;
}

.pen-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.pen-tool-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2.5'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='m18%2013-1.5-7.5L2%202l3.5%2014.5L13%2018Z'/%3E%3Cpath%20d='m2%202%207.6%207.6'/%3E%3Ccircle%20cx='11'%20cy='11'%20r='2'%20fill='black'/%3E%3Cpath%20d='m12%2019%207-7%203%203-7%207Z'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='black'%20stroke-width='2.5'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='m18%2013-1.5-7.5L2%202l3.5%2014.5L13%2018Z'/%3E%3Cpath%20d='m2%202%207.6%207.6'/%3E%3Ccircle%20cx='11'%20cy='11'%20r='2'%20fill='black'/%3E%3Cpath%20d='m12%2019%207-7%203%203-7%207Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.mode-btn.active {
  border-color: var(--primary-blue);
  background: #eff6ff;
  color: #1d4ed8;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .12);
}

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

.pen-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.pen-actions .small-btn {
  min-width: 0;
  padding: 0 6px;
}

.clear-expand-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.clear-expand-field input {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.control-grid label,
.stroke-grid label,
.control-full {
  color: var(--muted);
  font-size: 12px;
}

.control-grid input {
  width: 100%;
  height: 32px;
  margin-top: 4px;
}

.control-grid input[type="color"] {
  height: 36px;
  padding: 2px;
}

.control-full {
  display: block;
  margin-top: 10px;
}

.control-full select {
  width: 100%;
  height: 36px;
  margin-top: 5px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0 9px;
  background: #fff;
  color: var(--ink);
}

.bar-text-input {
  min-height: 54px;
  margin-top: 8px;
}

.small-btn {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.scale-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.scale-field input {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
}

.scale-field input[type="range"] {
  appearance: none;
  height: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #e5e7eb;
  accent-color: #ffffff;
}

.scale-field input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid #94a3b8;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .18);
}

.scale-field input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 1px solid #94a3b8;
  border-radius: 50%;
  background: #ffffff;
}

.drag-hint {
  margin-top: 8px;
  line-height: 1.45;
}

.stroke-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
  margin-top: 8px;
}

.stroke-grid input[type="color"],
.stroke-grid input[type="number"] {
  width: 100%;
  height: 32px;
  margin-top: 4px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
}

.stroke-toggle {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.link-toggle {
  margin-top: 8px;
  font-size: 13px;
}

.replace-list-wrap {
  min-height: 160px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

#replaceCount {
  color: var(--muted);
  font-size: 12px;
}

.replace-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 7px;
  margin-top: 10px;
}

.replace-empty {
  padding: 12px;
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.replace-item {
  min-height: 54px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.replace-item:hover,
.replace-item.active {
  border-color: var(--primary-blue);
  background: #eff6ff;
}

.replace-item img,
.replace-item .missing {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  object-fit: cover;
  background: #e2e8f0;
}

.replace-item .missing {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
}

.replace-item strong,
.replace-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replace-item strong {
  font-size: 12px;
}

.replace-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 1180px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .side-nav {
    border-right: 0;
    border-bottom: 1px solid #e2e0d8;
  }

  .workspace {
    overflow: visible;
  }

  .view-panel.active,
  .extract-layout,
  .template-workspace,
  .template-toolbar {
    grid-template-columns: 1fr;
  }

  .asset-upload-grid {
    grid-template-columns: 1fr 1fr;
  }

  .input-column {
    grid-template-rows: 260px 220px;
  }

  .template-main {
    min-height: 720px;
  }
}
