/* === Images === */

/* ==================== 图片查看器 ==================== */
.image-viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.image-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 8px;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.image-viewer-close:hover {
  background: rgba(255,255,255,0.2);
}

.image-viewer-info {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
}

.image-viewer-hint {
  color: rgba(255,255,255,0.5);
  margin-left: 8px;
}

.image-viewer-img {
  max-width: none;
  cursor: grab;
  user-select: none;
  transition: transform 0.1s;
}

/* 可点击的图片 */
.markdown-body img.clickable-image {
  cursor: pointer;
  transition: opacity 0.15s;
}

.markdown-body img.clickable-image:hover {
  opacity: 0.9;
}

/* 编辑器中选中的图片 */
.preview-pane img.selected-image {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* 图片尺寸调整工具栏 */
.image-resize-toolbar {
  position: absolute;
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  border-radius: 8px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 100;
}

.image-resize-toolbar label {
  color: var(--neutral-400);
  font-size: 12px;
}

.image-resize-toolbar input[type="number"] {
  width: 60px;
  padding: 4px 8px;
  background: var(--neutral-900);
  border: 1px solid var(--neutral-700);
  border-radius: 4px;
  color: #fff;
  font-size: 13px;
}

.image-resize-toolbar input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-500);
}

.image-resize-toolbar button {
  padding: 4px 12px;
  background: var(--primary-500);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

.image-resize-toolbar button:hover {
  background: var(--primary-600);
}

.image-resize-toolbar .preset-btn {
  padding: 4px 8px;
  background: var(--neutral-700);
  color: var(--neutral-300);
}

.image-resize-toolbar .preset-btn:hover {
  background: var(--neutral-600);
}

/* ==================== 图片编辑器 ==================== */
.img-editor-container {
  position: relative;
  display: inline-block;
  margin: 16px 0;
}

.img-editor-container img {
  display: block;
  border-radius: 8px;
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* 工具栏 */
.img-editor-toolbar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: -44px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--neutral-800);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 100;
}

.img-tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--neutral-400);
  cursor: pointer;
  transition: all 0.15s;
}

.img-tool-btn:hover {
  background: var(--neutral-700);
  color: #fff;
}

.img-tool-btn.active {
  background: var(--primary-600);
  color: #fff;
}

.img-tool-btn svg {
  width: 18px;
  height: 18px;
}

.img-tool-divider {
  width: 1px;
  height: 20px;
  background: var(--neutral-600);
  margin: 0 4px;
}

.img-tool-save {
  color: #22c55e;
}

.img-tool-save:hover {
  background: #22c55e;
  color: #fff;
}

/* 缩放手柄 */
.img-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--primary-500);
  border-radius: 2px;
  z-index: 10;
}

.img-handle-nw { top: -5px; left: -5px; }
.img-handle-n { top: -5px; left: 50%; transform: translateX(-50%); }
.img-handle-ne { top: -5px; right: -5px; }
.img-handle-w { top: 50%; left: -5px; transform: translateY(-50%); }
.img-handle-e { top: 50%; right: -5px; transform: translateY(-50%); }
.img-handle-sw { bottom: -5px; left: -5px; }
.img-handle-s { bottom: -5px; left: 50%; transform: translateX(-50%); }
.img-handle-se { bottom: -5px; right: -5px; }

/* 裁剪遮罩 */
.img-crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.crop-mask {
  position: absolute;
  background: rgba(0, 0, 0, 0.5);
}

.crop-mask-top {
  top: 0;
  left: 0;
  right: 0;
}

.crop-mask-bottom {
  bottom: 0;
  left: 0;
  right: 0;
}

.crop-mask-left {
  left: 0;
  position: absolute;
}

.crop-mask-right {
  right: 0;
  position: absolute;
}

/* 裁剪手柄 */
.img-crop-handle {
  position: absolute;
  background: var(--primary-500);
  z-index: 10;
}

.img-crop-handle-top {
  height: 4px;
  cursor: ns-resize;
  transform: translateY(-50%);
}

.img-crop-handle-bottom {
  height: 4px;
  cursor: ns-resize;
  transform: translateY(50%);
}

.img-crop-handle-left {
  width: 4px;
  cursor: ew-resize;
  transform: translateX(-50%);
}

.img-crop-handle-right {
  width: 4px;
  cursor: ew-resize;
  transform: translateX(50%);
}

.img-crop-handle:hover {
  background: var(--primary-400);
}

/* 可编辑图片 hover 效果 */
.editable-img {
  cursor: pointer;
  transition: opacity 0.15s;
}

.editable-img:hover {
  opacity: 0.9;
}

/* ==================== 图片预览器 ==================== */
.image-viewer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.image-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.image-viewer-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.image-viewer-close svg {
  width: 24px;
  height: 24px;
  color: #fff;
}

.image-viewer-info {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.image-viewer-info svg {
  color: rgba(255, 255, 255, 0.7);
}

.image-viewer-scale {
  font-weight: 500;
  color: #fff;
}

.image-viewer-hint {
  color: rgba(255, 255, 255, 0.5);
  margin-left: 8px;
}

.image-viewer-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  cursor: grab;
  user-select: none;
}

.image-viewer-img:active {
  cursor: grabbing;
}

/* 阅读模式图片可点击 */
.doc-body .markdown-body img {
  cursor: zoom-in;
}

/* ==================== 渐进式图片加载 ==================== */
.img-progressive-wrap {
  display: inline-block;
  position: relative;
  line-height: 0;
  overflow: hidden;
}
.img-progressive {
  transition: filter 0.4s ease, transform 0.4s ease;
}
.img-blur {
  filter: blur(20px);
  transform: scale(1.05);
}
.img-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: img-spin 0.7s linear infinite;
  box-shadow: 0 0 8px rgba(0,0,0,0.15);
  pointer-events: none;
  transition: opacity 0.3s;
}
.img-spinner-done { opacity: 0; }
@keyframes img-spin { to { transform: rotate(360deg); } }
