:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #fafbfc;
  --line: #e3e6ec;
  --line-strong: #d3d8e0;
  --text: #15171c;
  --muted: #6f7683;
  --accent: #d6407a;
  --accent-hover: #c1326b;
  --accent-weak: #fbeaf1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 33, 0.06), 0 8px 24px rgba(20, 24, 33, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 54px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--accent);
  position: relative;
}

.mark::after {
  content: "";
  position: absolute;
  inset: 4px 4px auto 4px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 6px 0 rgba(255, 255, 255, 0.45);
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: 999px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 13px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: var(--muted);
}

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

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: #b42318;
  border-color: #f0c8c5;
  background: #fff7f6;
}

.btn.danger:hover:not(:disabled) {
  background: #fdeceb;
}

.btn.block {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.panel {
  width: 268px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 6px 0 24px;
}

.group {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.group:last-child {
  border-bottom: none;
}

.group h2 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}

.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 0;
}

.hint {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--muted);
}

.chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 3px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.chips.small {
  grid-template-columns: repeat(2, 1fr);
  flex: 1;
  max-width: 130px;
}

.chips button {
  border: none;
  background: transparent;
  border-radius: 6px;
  padding: 6px 2px;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.chips button:hover {
  color: var(--text);
}

.chips button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(20, 24, 33, 0.1);
  font-weight: 500;
}

.row,
.field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin: 6px 0;
}

.row > span,
.field > span {
  width: 58px;
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.row select {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
}

/* 滑块统一用主题色，避免某个弹窗里漏写 accent-color 就退回系统蓝 */
input[type="range"] {
  accent-color: var(--accent);
}

.row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  height: 18px;
}

.row output,
.field output {
  width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
}

.field {
  justify-content: space-between;
}

.swatches {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.swatches button {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--c, #fff);
  cursor: pointer;
  padding: 0;
  position: relative;
}

.swatches button.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.swatches button.transparent {
  background-image: linear-gradient(45deg, #d9dde5 25%, transparent 25%),
    linear-gradient(-45deg, #d9dde5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d9dde5 75%),
    linear-gradient(-45deg, transparent 75%, #d9dde5 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #fff;
}

.swatches input[type="color"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.stage-inner {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background-image: linear-gradient(45deg, #e9ebef 25%, transparent 25%),
    linear-gradient(-45deg, #e9ebef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9ebef 75%),
    linear-gradient(-45deg, transparent 75%, #e9ebef 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.stage-inner.dragover::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  pointer-events: none;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

#canvas.visible {
  display: block;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 46px;
  height: 38px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 8px;
  position: relative;
  margin-bottom: 4px;
}

.empty-icon::before {
  content: "";
  position: absolute;
  left: 8px;
  bottom: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-weak);
}

.empty-icon::after {
  content: "";
  position: absolute;
  right: 7px;
  bottom: 8px;
  width: 18px;
  height: 10px;
  background: linear-gradient(135deg, var(--accent-weak) 50%, transparent 50%);
  border-radius: 2px;
}

.empty-title {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.empty-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 40px;
  padding: 0 14px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  flex: none;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

#size-label {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.warn {
  color: #b54708;
  background: #fffaeb;
  border: 1px solid #fedf89;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  cursor: pointer;
  color: var(--muted);
}

.zoom button:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

#zoom-label {
  width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 12px);
  background: #1d2027;
  color: #fff;
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.save-state {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.save-state.show {
  opacity: 1;
}

.link {
  border: none;
  background: none;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font-size: inherit;
}

.link:hover {
  color: var(--accent);
}

/* ---------------------------------------------------------- 裁剪弹窗 */

body.modal-open {
  overflow: hidden;
}

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.crop-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(19, 22, 29, 0.45);
  backdrop-filter: blur(2px);
}

.crop-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1040px, 100%);
  height: min(720px, 100%);
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(16, 20, 28, 0.28);
  overflow: hidden;
}

.crop-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.crop-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.crop-head .hint {
  margin: 4px 0 0;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  flex: none;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.crop-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.crop-stage {
  flex: 1;
  min-width: 0;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #22252c;
  background-image: linear-gradient(45deg, #2a2e36 25%, transparent 25%),
    linear-gradient(-45deg, #2a2e36 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2e36 75%),
    linear-gradient(-45deg, transparent 75%, #2a2e36 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  overflow: hidden;
}

.crop-frame {
  position: relative;
  flex: none;
  touch-action: none;
  user-select: none;
}

.crop-frame img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}

.crop-box {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 9999px rgba(12, 14, 19, 0.58);
  cursor: move;
}

.crop-box::before,
.crop-box::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* 三分线 */
.crop-box::before {
  background-image: linear-gradient(
      to right,
      transparent calc(33.333% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(33.333% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(33.333% + 0.5px),
      transparent calc(33.333% + 0.5px),
      transparent calc(66.666% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(66.666% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(66.666% + 0.5px),
      transparent calc(66.666% + 0.5px)
    ),
    linear-gradient(
      to bottom,
      transparent calc(33.333% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(33.333% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(33.333% + 0.5px),
      transparent calc(33.333% + 0.5px),
      transparent calc(66.666% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(66.666% - 0.5px),
      rgba(255, 255, 255, 0.35) calc(66.666% + 0.5px),
      transparent calc(66.666% + 0.5px)
    );
}

.crop-handles {
  position: absolute;
  inset: 0;
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  background: #fff;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.handle-nw { left: 0; top: 0; cursor: nwse-resize; }
.handle-n  { left: 50%; top: 0; cursor: ns-resize; }
.handle-ne { left: 100%; top: 0; cursor: nesw-resize; }
.handle-e  { left: 100%; top: 50%; cursor: ew-resize; }
.handle-se { left: 100%; top: 100%; cursor: nwse-resize; }
.handle-s  { left: 50%; top: 100%; cursor: ns-resize; }
.handle-sw { left: 0; top: 100%; cursor: nesw-resize; }
.handle-w  { left: 0; top: 50%; cursor: ew-resize; }

.crop-side {
  width: 244px;
  flex: none;
  padding: 18px;
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.crop-side .field {
  display: block;
  margin-bottom: 16px;
}

.crop-side .field > span {
  display: block;
  width: auto;
  margin-bottom: 6px;
}

.crop-side select {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
}

.crop-side .chips {
  grid-template-columns: repeat(4, 1fr);
}

.crop-size {
  display: flex;
  align-items: center;
  gap: 8px;
}

.crop-size input {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

.crop-size span {
  color: var(--muted);
}

.crop-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  flex: none;
}

.crop-foot .hint {
  margin: 0;
}

.crop-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 820px) {
  .panel {
    width: 220px;
  }
  .brand .badge {
    display: none;
  }
}

/* 窄屏才把参数面板放到预览下方；只是窗口矮就把超出部分变成滚动 */
@media (max-width: 640px) {
  .crop-modal {
    padding: 8px;
  }
  .crop-body {
    flex-direction: column;
    overflow-y: auto;
  }
  .crop-side {
    width: auto;
    flex: none;
    border-left: none;
    border-top: 1px solid var(--line);
  }
  .crop-foot .hint {
    display: none;
  }
}

@media (max-height: 620px) {
  .crop-body {
    overflow-y: auto;
  }
  .crop-side {
    overflow: visible;
  }
}

/* ------------------------------------------------------------- 批量处理 */

.muted {
  color: var(--muted);
  font-style: normal;
}

.batch-dialog {
  width: min(920px, 100%);
  /* 高度跟内容走，内容多时靠 max-height 卡住再滚动；写死高度会让空列表下面空一大块 */
  height: auto;
  max-height: min(760px, calc(100vh - 48px));
}

.batch-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  padding: 14px 18px;
  overflow-y: auto;
  min-height: 0;
}

.batch-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.batch-toolbar select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
}

.batch-toolbar .hint {
  margin-left: auto;
}

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

.batch-step {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 12px;
}

.batch-step.off {
  opacity: 0.55;
}

.batch-step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.batch-step-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.batch-step-toggle input {
  accent-color: var(--accent);
}

.batch-step-order {
  display: flex;
  gap: 2px;
}

.icon-btn.tiny {
  width: 22px;
  height: 22px;
  font-size: 12px;
  line-height: 1;
}

.batch-step-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.batch-kb {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 3px;
  max-width: 360px;
  flex: none;
}

.batch-step-body select,
.batch-step-body input[type="text"] {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  width: 100%;
}

.batch-step-body input[type="number"] {
  height: 30px;
  width: 92px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
}

.batch-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.batch-inline select {
  width: auto;
  flex: 1 1 140px;
}

.batch-inline input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.batch-add {
  position: relative;
}

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

.batch-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  min-width: 150px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.batch-menu button {
  border: none;
  background: none;
  text-align: left;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.batch-menu button:hover {
  background: var(--accent-weak);
  color: var(--accent);
}

.batch-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.batch-empty {
  margin: 10px 0;
}

.batch-item {
  display: grid;
  grid-template-columns: 36px 1fr 178px 66px 52px;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
}

.batch-item:nth-child(odd) {
  background: var(--surface-soft);
}

.batch-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  overflow: hidden;
  background: #eceef2;
  display: block;
}

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

.batch-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-dims {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.batch-size {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.batch-state {
  text-align: right;
}

@media (max-width: 640px) {
  .batch-item {
    grid-template-columns: 32px 1fr 60px;
  }
  .batch-dims {
    display: none;
  }
  .batch-dialog {
    height: auto;
    max-height: calc(100vh - 24px);
  }
}

/* ------------------------------------------------------------- 导出 PDF */

.pdf-dialog {
  width: min(720px, 100%);
  height: auto;
  max-height: calc(100vh - 48px);
}

.pdf-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px;
  overflow-y: auto;
  min-height: 0;
}

.pdf-body .field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 6px;
  margin: 0;
  min-width: 0;
}

.pdf-body .field > span {
  font-size: 12px;
  color: var(--muted);
  text-align: left;
}

.pdf-body select {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  width: 100%;
}

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

.pdf-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pdf-inline input[type="range"] {
  flex: 1;
  min-width: 0;
}

.pdf-inline output {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 22px;
  text-align: right;
}

.pdf-sources {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 380px;
}

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

@media (max-width: 640px) {
  .pdf-grid {
    grid-template-columns: 1fr;
  }
  .pdf-sources {
    max-width: none;
  }
}
