/* 图片裁剪页专属样式（复用 app.css 基础变量与组件） */

.page-crop {
  max-width: 1180px;
}

/* 上传后专注裁剪：隐藏标题与教程 */
.page-crop.is-editing {
  max-width: 1280px;
  padding-top: 12px;
  padding-bottom: 16px;
}

.page-crop.is-editing .header,
.page-crop.is-editing .seo-content,
.page-crop.is-editing .footer {
  display: none !important;
}

.page-crop.is-editing .panel {
  padding: 14px;
}

/* 高度由 JS 按窗口可用空间写入 --crop-stage-h */
.page-crop.is-editing .crop-stage {
  height: var(--crop-stage-h, 42vh);
  min-height: 200px;
}

.crop-workspace[hidden] {
  display: none !important;
}

.crop-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  margin-top: 4px;
}

.crop-stage-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.crop-stage {
  position: relative;
  height: var(--crop-stage-h, min(42vh, 420px));
  min-height: 200px;
  border-radius: 16px;
  overflow: auto;
  background:
    linear-gradient(45deg, #e8edf3 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, #e8edf3 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(45deg, transparent 75%, #e8edf3 75%) 0 0 / 16px 16px,
    linear-gradient(-45deg, transparent 75%, #e8edf3 75%) 0 0 / 16px 16px,
    #f4f7fb;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border: 1px solid var(--line);
  outline: none;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.crop-stage:focus-visible {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.25);
}

.crop-stage.is-panning {
  cursor: grabbing;
}

.crop-canvas {
  position: relative;
  margin: 0 auto;
  transform-origin: 0 0;
  will-change: transform;
}

.crop-canvas img {
  display: block;
  max-width: none;
  width: 100%;
  height: auto;
  pointer-events: none;
  -webkit-user-drag: none;
}

.crop-shade {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.shade-top,
.shade-bottom,
.shade-side {
  background: rgba(15, 23, 32, 0.48);
  flex-shrink: 0;
}

.shade-mid {
  display: flex;
  flex: 0 0 auto;
  min-height: 0;
}

.crop-box {
  position: relative;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.95);
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}

.crop-box::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(15, 118, 110, 0.55);
  pointer-events: none;
}

.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent calc(33.333% - 0.5px), rgba(255, 255, 255, 0.45) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.45) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px)),
    linear-gradient(to right, transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) 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.45) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.45) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px)),
    linear-gradient(to bottom, transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px));
  opacity: 1;
  transition: opacity 0.15s;
}

.crop-grid.off {
  opacity: 0;
}

.handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  pointer-events: auto;
  touch-action: none;
  z-index: 2;
}

.handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.handle.n { top: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
.handle.s { bottom: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
.handle.w { left: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }
.handle.e { right: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }

.crop-stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 0;
}

.meta-live {
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.meta-live strong {
  color: var(--ink);
  font-weight: 600;
}

.stage-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  appearance: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.icon-btn:hover {
  border-color: rgba(15, 118, 110, 0.35);
  color: var(--accent);
}

.icon-btn.active {
  background: rgba(15, 118, 110, 0.1);
  border-color: rgba(15, 118, 110, 0.35);
  color: var(--accent);
}

.zoom-label {
  min-width: 48px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.crop-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.side-block {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.side-block h3 {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 600;
}

.preset-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.preset-tab {
  appearance: none;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 0.76rem;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}

.preset-tab:hover {
  border-color: rgba(15, 118, 110, 0.3);
  color: var(--ink);
}

.preset-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.preset-panel {
  display: none;
}

.preset-panel.active {
  display: block;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.chip {
  appearance: none;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.78rem;
  font-weight: 400;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
  line-height: 1.35;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip small {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  margin-top: 2px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip:hover {
  border-color: rgba(15, 118, 110, 0.35);
}

.chip.active {
  background: rgba(15, 118, 110, 0.08);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 400;
}

.chip.active small {
  color: rgba(15, 118, 110, 0.75);
}

/* 自由裁剪单按钮不拉满两列 */
.preset-panel[data-panel="free"] .chip {
  width: auto;
  display: inline-block;
}

.hint {
  margin: 10px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
}

.custom-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.custom-form label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.custom-form input,
.field select,
.field input[type="range"] {
  width: 100%;
}

.custom-form input,
.field select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.88rem;
  color: var(--ink);
  background: #fff;
  font-family: inherit;
}

.custom-form input:focus,
.field select:focus {
  outline: none;
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.times {
  padding-bottom: 10px;
  color: var(--muted);
  font-weight: 600;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 0.76rem;
  color: var(--muted);
  cursor: pointer;
}

.check-row input {
  margin-top: 2px;
  accent-color: var(--accent);
}

.btn-block {
  width: 100%;
}

.export-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
}

.field em {
  font-style: normal;
  color: var(--accent);
  font-weight: 600;
  float: right;
}

.field input[type="range"] {
  accent-color: var(--accent);
  height: 28px;
}

.output-info {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(15, 118, 110, 0.06);
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.output-info strong {
  color: var(--ink);
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.side-actions-row .btn {
  padding: 9px 8px;
  font-size: 0.8rem;
}

.preview-modal[hidden] {
  display: none !important;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 32, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.preview-box {
  width: min(720px, 100%);
  max-height: min(90vh, 800px);
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-head,
.preview-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.preview-foot {
  border-bottom: none;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}

.preview-head button {
  appearance: none;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}

.preview-body {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, #eef2f6 25%, transparent 25%) 0 0 / 14px 14px,
    linear-gradient(-45deg, #eef2f6 25%, transparent 25%) 0 0 / 14px 14px,
    #fff;
  background-position: 0 0, 0 7px;
}

.preview-body img {
  max-width: 100%;
  max-height: min(58vh, 520px);
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(24, 33, 43, 0.12);
}

@media (max-width: 900px) {
  .crop-layout {
    grid-template-columns: 1fr;
  }

  .crop-stage {
    min-height: 180px;
  }

  .crop-sidebar {
    order: 2;
  }
}

@media (max-width: 560px) {
  .handle {
    width: 16px;
    height: 16px;
  }

  .handle.nw, .handle.ne, .handle.sw, .handle.se,
  .handle.n, .handle.s, .handle.w, .handle.e {
    /* larger touch targets on mobile */
  }

  .handle.nw { top: -8px; left: -8px; }
  .handle.ne { top: -8px; right: -8px; }
  .handle.sw { bottom: -8px; left: -8px; }
  .handle.se { bottom: -8px; right: -8px; }
  .handle.n { top: -8px; margin-left: -8px; }
  .handle.s { bottom: -8px; margin-left: -8px; }
  .handle.w { left: -8px; margin-top: -8px; }
  .handle.e { right: -8px; margin-top: -8px; }

  .side-actions-row {
    grid-template-columns: 1fr 1fr;
  }

  .side-actions-row #btn-replace {
    grid-column: 1 / -1;
  }

  .preset-tabs {
    gap: 5px;
  }

  .preset-tab {
    padding: 6px 9px;
  }
}
